Re: [Warzone-dev] Question about datatype
On Tuesday 17 July 2007, Per Inge Mathisen wrote: On 7/17/07, Martin Koller [EMAIL PROTECTED] wrote: What about the follwing patch ? Just a quick glance at src/multibot.c tells me you missed cases. That will break multiplayer games badly, so it is important you catch them all. Do I see this correct, that NetAdd(m,4,psDroid-x); NetAdd(m,6,psDroid-y); adds the value psDroid-x/y at byte position 4/6 ? So that means x/y must be 2 bytes to make it work ? If so ... what a code .. :-( It should better use a size counter and sizeof() instead. -- Best regards/Schöne Grüße Martin() ascii ribbon campaign - against html mail /\- against microsoft attachments Computers and Internet gave you freedom. TCPA would TAKE your FREEDOM! http://www.againsttcpa.com signature.asc Description: This is a digitally signed message part. ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] Question about datatype
On 7/18/07, Martin Koller [EMAIL PROTECTED] wrote: Do I see this correct, that NetAdd(m,4,psDroid-x); NetAdd(m,6,psDroid-y); adds the value psDroid-x/y at byte position 4/6 ? So that means x/y must be 2 bytes to make it work ? Yes. If so ... what a code .. :-( Indeed. It is on the list of things to fix for 2.1. - Per ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] Question about datatype
On Wednesday 18 July 2007, Martin Koller wrote: It should better use a size counter and sizeof() instead. What do you think about the following approach: A new NETadd macro simply counts on its own what is given to its NETMSG. So e.g. sendHappyVtol() would change from: NETMSG m; NetAdd(m,0,psDroid-player); NetAdd(m,1,psDroid-id); m.size =5; to NETMSG m; NETmsgInit(m); NETadd(m, psDroid-player); NETadd(m, psDroid-id); See attached patch. If ok, I would start to migrate all NetAdd calls to the new NETadd -- Best regards/Schöne Grüße Martin() ascii ribbon campaign - against html mail /\- against microsoft attachments Computers and Internet gave you freedom. TCPA would TAKE your FREEDOM! http://www.againsttcpa.com Index: netplay.h === --- netplay.h (revision 2130) +++ netplay.h (working copy) @@ -162,6 +162,11 @@ extern void NETsetMasterserverPort(unsigned int port); extern void NETsetGameserverPort(unsigned int port); +extern void NETmsgInit(NETMSG *m); + +#define NETadd(m, thing) \ + memcpy((m.body[m.size]),(thing),sizeof(thing)); m.size += sizeof(thing) + // Some shortcuts to help you along! /* FIXME: This is _not_ portable! Bad, Pumpkin, bad! - Per */ #define NetAdd(m,pos,thing) \ Index: netplay.c === --- netplay.c (revision 2130) +++ netplay.c (working copy) @@ -1509,3 +1509,16 @@ { gameserver_port = port; } + + +/*! + * Initialize the NETMSG data structure; Needed at least before using NETadd + * \param m the NETMSG data structure + */ +void NETmsgInit(NETMSG *m) +{ + m-size = 0; + m-paddedBytes = 0; + m-type = 0; + m-destination = 0; +} signature.asc Description: This is a digitally signed message part. ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] Question about datatype
On 7/17/07, Martin Koller [EMAIL PROTECTED] wrote: What about the follwing patch ? Just a quick glance at src/multibot.c tells me you missed cases. That will break multiplayer games badly, so it is important you catch them all. See eg sendDroidDisEmbark(). I would grep for psDroid-x, psStruct-x and psD-x, and then go through at least src/multibot.c and src/multistruct.c manually to be sure. Probably some others too. Then you also need to use %u instead of %d when using printf/debug with unsigned ints. Also there was a bug I think as previously there was - NetAdd(m,m.size,x); m.size += sizeof(UWORD); - NetAdd(m,m.size,x); m.size += sizeof(UWORD); 2 times sending x seems wrong to me, right ? Good catch. - Per ___ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev
Re: [Warzone-dev] Question about datatype
On Monday 16 July 2007, Per Inge Mathisen wrote: On 7/16/07, Martin Koller [EMAIL PROTECTED] wrote: I ask myself: what is the x,y,z position supposed to have as datatype ? I find UWORD but also UDWORD. .. I think this should be made consistent to be able to correctly fix the compiler warnings. Please do. I think that there is no reason to use UWORD, so changing them all to UDWORD would be good. Attached is a patch that does that. -- Best regards/Schöne Grüße Martin() ascii ribbon campaign - against html mail /\- against microsoft attachments Computers and Internet gave you freedom. TCPA would TAKE your FREEDOM! http://www.againsttcpa.com Index: action.c === --- action.c (revision 2119) +++ action.c (working copy) @@ -1255,9 +1255,9 @@ } addDroid(psDroid, apsDroidLists); //set the x/y up since they were set to INVALID_XY when moved offWorld -missionGetTransporterExit(selectedPlayer, (UWORD*)droidX, (UWORD*)droidY); // FIXME passing type-punned pointer of wrong size! -psDroid-x = (UWORD)droidX; -psDroid-y = (UWORD)droidY; +missionGetTransporterExit(selectedPlayer, droidX, droidY); +psDroid-x = droidX; +psDroid-y = droidY; //fly Transporter back to get some more droids orderDroidLoc( psDroid, DORDER_TRANSPORTIN, getLandingX(selectedPlayer), getLandingY(selectedPlayer)); Index: transporter.c === --- transporter.c (revision 2119) +++ transporter.c (working copy) @@ -1731,7 +1731,7 @@ /*launches the defined transporter to the offworld map*/ BOOL launchTransporter(DROID *psTransporter) { - UWORD iX, iY; + UDWORD iX, iY; //close the interface intResetScreen(TRUE); Index: basedef.h === --- basedef.h (revision 2119) +++ basedef.h (working copy) @@ -51,7 +51,7 @@ #define BASE_ELEMENTS1(pointerType) \ OBJECT_TYPE type; /* The type of object */ \ UDWORDid; /* ID number of the object */ \ - UWORDx,y,z; /* Object's location */ \ + UDWORDx,y,z; /* Object's location */ \ floatdirection; /* Object's direction +ve rotation about y axis*/ \ SWORDpitch; /* Object's pitch +ve nose up*/ \ SWORDroll /* Object's roll +ve left up, right down */ Index: mission.c === --- mission.c (revision 2119) +++ mission.c (working copy) @@ -777,26 +777,26 @@ #define EDGE_SIZE 1 /* pick nearest map edge to point */ -void missionGetNearestCorner( UWORD iX, UWORD iY, UWORD *piOffX, UWORD *piOffY ) +void missionGetNearestCorner( UDWORD iX, UDWORD iY, UDWORD *piOffX, UDWORD *piOffY ) { UDWORD iMidX = (scrollMinX + scrollMaxX)/2, iMidY = (scrollMinY + scrollMaxY)/2; - if ( ((UDWORD)(iXTILE_SHIFT)) iMidX ) + if ( (iXTILE_SHIFT) iMidX ) { - *piOffX = (UWORD) ((scrollMinX TILE_SHIFT) + (EDGE_SIZE*TILE_UNITS)); + *piOffX = (scrollMinX TILE_SHIFT) + (EDGE_SIZE*TILE_UNITS); } else { - *piOffX = (UWORD) ((scrollMaxX TILE_SHIFT) - (EDGE_SIZE*TILE_UNITS)); + *piOffX = (scrollMaxX TILE_SHIFT) - (EDGE_SIZE*TILE_UNITS); } - if ( ((UDWORD)(iYTILE_SHIFT)) iMidY ) + if ( (iYTILE_SHIFT) iMidY ) { - *piOffY = (UWORD) ((scrollMinY TILE_SHIFT) + (EDGE_SIZE*TILE_UNITS)); + *piOffY = (scrollMinY TILE_SHIFT) + (EDGE_SIZE*TILE_UNITS); } else { - *piOffY = (UWORD) ((scrollMaxY TILE_SHIFT) - (EDGE_SIZE*TILE_UNITS)); + *piOffY = (scrollMaxY TILE_SHIFT) - (EDGE_SIZE*TILE_UNITS); } } @@ -804,7 +804,7 @@ void missionFlyTransportersIn( SDWORD iPlayer, BOOL bTrackTransporter ) { DROID *psTransporter, *psNext; - UWORD iX, iY, iZ; + UDWORD iX, iY, iZ; SDWORD iLandX, iLandY, iDx, iDy; FRACT_D fR; @@ -2590,7 +2590,7 @@ DROID *psDroid, *psNext; DROID **ppCurrentList, **ppStoredList; UDWORD droidX, droidY; - UWORD iX, iY; + UDWORD iX, iY; DROID_GROUP *psGroup; if (goingHome) @@ -3953,18 +3953,18 @@ } //returns the x coord for where the Transporter can land (for player 0) -UWORD getLandingX( SDWORD iPlayer ) +UDWORD getLandingX( SDWORD iPlayer ) { ASSERT( iPlayerMAX_NOGO_AREAS, getLandingX: player %d out of range, iPlayer ); - return (UWORD)((sLandingZone[iPlayer].x1 + (sLandingZone[iPlayer].x2 - + return ((sLandingZone[iPlayer].x1 + (sLandingZone[iPlayer].x2 - sLandingZone[iPlayer].x1)/2) TILE_SHIFT); } //returns the y coord for where the Transporter can land -UWORD getLandingY( SDWORD iPlayer ) +UDWORD getLandingY( SDWORD iPlayer ) { ASSERT( iPlayerMAX_NOGO_AREAS, getLandingY: player %d out of range, iPlayer ); - return (UWORD)((sLandingZone[iPlayer].y1 + (sLandingZone[iPlayer].y2 - + return ((sLandingZone[iPlayer].y1 + (sLandingZone[iPlayer].y2 - sLandingZone[iPlayer].y1)/2) TILE_SHIFT); } @@ -4034,20 +4034,20 @@ } } -void missionGetTransporterEntry( SDWORD
Re: [Warzone-dev] Question about datatype
On Monday 16 July 2007, Per Inge Mathisen wrote: Nice, this removes a lot of ugly casts. Unfortunately, that patch would break the netcode badly. In order to convert basedef's xyz from UWORD to UDWORD, we will have to check or change the size of all xyz coordinates going over the network, too (in src/multi*.c). So the patch needs a little more work before it can be committed, unfortunately. What about the follwing patch ? I'm not sure about multigifts.c changes as I don't know why there was an explicit cast from UDWORD to UWORD (the nx/ny stuff) Also there was a bug I think as previously there was - NetAdd(m,m.size,x); m.size += sizeof(UWORD); - NetAdd(m,m.size,x); m.size += sizeof(UWORD); 2 times sending x seems wrong to me, right ? Also please note that I just compiled the changes but did no test via a multiplayer network game. -- Best regards/Schöne Grüße Martin() ascii ribbon campaign - against html mail /\- against microsoft attachments Computers and Internet gave you freedom. TCPA would TAKE your FREEDOM! http://www.againsttcpa.com Index: action.c === --- action.c (revision 2124) +++ action.c (working copy) @@ -1255,9 +1255,9 @@ } addDroid(psDroid, apsDroidLists); //set the x/y up since they were set to INVALID_XY when moved offWorld -missionGetTransporterExit(selectedPlayer, (UWORD*)droidX, (UWORD*)droidY); // FIXME passing type-punned pointer of wrong size! -psDroid-x = (UWORD)droidX; -psDroid-y = (UWORD)droidY; +missionGetTransporterExit(selectedPlayer, droidX, droidY); +psDroid-x = droidX; +psDroid-y = droidY; //fly Transporter back to get some more droids orderDroidLoc( psDroid, DORDER_TRANSPORTIN, getLandingX(selectedPlayer), getLandingY(selectedPlayer)); Index: multibot.c === --- multibot.c (revision 2124) +++ multibot.c (working copy) @@ -252,7 +252,7 @@ { DROID *psDroid; UDWORD id,player; -UWORD x, y; +UDWORD x, y; NetGet(pMsg,0,id); NetGet(pMsg,4,x); @@ -942,7 +942,7 @@ UDWORD sizecount=0; DROID_TEMPLATE dt; DROID *pD,*existingdroid; - UWORD x,y,z; + UDWORD x,y,z; UDWORD id; UBYTE player; UBYTE i; Index: multigifts.c === --- multigifts.c (revision 2124) +++ multigifts.c (working copy) @@ -573,7 +573,6 @@ { UDWORD i; UDWORD x,y; - UWORD nx,ny; FEATURE *pF=NULL; SDWORD type = FEAT_GEN_ARTE; NETMSG m; @@ -602,13 +601,11 @@ NetAdd(m,m.size,type); m.size += sizeof(type); - nx = (UWORD)x; - NetAdd(m,m.size,nx); - m.size += sizeof(UWORD); + NetAdd(m,m.size,x); + m.size += sizeof(x); - ny = (UWORD)y; - NetAdd(m,m.size,ny); - m.size += sizeof(UWORD); + NetAdd(m,m.size,y); + m.size += sizeof(y); NetAdd(m,m.size,pF-id); m.size += sizeof(pF-id); @@ -638,7 +635,6 @@ // Vector3i position; static UDWORD lastgift=0; UDWORD i,x,y,quantity,count; - UWORD nx,ny; NETMSG m; FEATURE *pF; SDWORD type = FEAT_OIL_DRUM; @@ -688,10 +684,8 @@ pF = buildFeature((asFeatureStats+i),xTILE_SHIFT, yTILE_SHIFT,FALSE); - nx = (UWORD)x; - ny = (UWORD)y; - NetAdd(m,m.size,x); m.size += sizeof(UWORD); - NetAdd(m,m.size,x); m.size += sizeof(UWORD); + NetAdd(m,m.size,x); m.size += sizeof(x); + NetAdd(m,m.size,y); m.size += sizeof(y); NetAdd(m,m.size,pF-id); m.size += sizeof(pF-id); m.body[m.size] = ONEPLAYER; @@ -760,7 +754,6 @@ FEATURE *pF; UDWORD i,count; UDWORD x,y; - UWORD nx,ny; m.type = NET_ARTIFACTS; m.size = 1; @@ -785,12 +778,10 @@ pF = buildFeature((asFeatureStats+i),xTILE_SHIFT, yTILE_SHIFT,FALSE); - nx = (UWORD)x; - ny = (UWORD)y; - NetAdd(m,m.size,nx); - m.size += sizeof(UWORD); - NetAdd(m,m.size,ny); - m.size += sizeof(UWORD); + NetAdd(m,m.size,x); + m.size += sizeof(x); + NetAdd(m,m.size,y); + m.size += sizeof(y); NetAdd(m,m.size,pF-id); m.size += sizeof(pF-id); @@ -827,7 +818,7 @@ UDWORD index,count,i,quantity,ref; SDWORD type; FEATURE *pF; - UWORD tx,ty; + UDWORD tx,ty; quantity = (UDWORD) pMsg-body[0]; index = 1; Index: multistruct.c === --- multistruct.c (revision 2124) +++ multistruct.c (working copy) @@ -88,7 +88,8 @@ BOOL recvBuildStarted(NETMSG *pMsg) { UDWORD targetId,order,droidId,structId,structStat; - UWORD x,z,y,player; + UDWORD x,z,y; +UWORD player; STRUCTURE_STATS *psStats; DROID *psDroid; UDWORD typeindex,actionX,actionY; @@ -175,7 +176,7 @@ { UDWORD strId;//,i; STRUCTURE *psStr; - UWORD x,y,z; + UDWORD x,y,z; UDWORD type,typeindex; UBYTE player; Index: transporter.c