* Replace macro function CLIP_WORLD_OFFMAP with static inline function clip_world_offmap

* Add a Doxygen header to this function

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2487 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-09-28 15:11:58 +00:00
parent 930396af83
commit beb24f3d10
2 changed files with 17 additions and 9 deletions

View File

@ -807,7 +807,7 @@ static void actionUpdateTransporter( DROID *psDroid )
}
// check that the target has not become on the same side as psDroid,
// check that the target has not become on the same side as psDroid,
// eg through Electronic Warfare
if (psDroid->psActionTarget[0] != NULL
&& psDroid->player == psDroid->psActionTarget[0]->player)
@ -908,7 +908,7 @@ static void actionCalcPullBackPoint(BASE_OBJECT *psObj, BASE_OBJECT *psTarget, S
*py = (SDWORD)psObj->y + ydiff * PULL_BACK_DIST;
// make sure coordinates stay inside of the map
CLIP_WORLD_OFFMAP(*px, *py);
clip_world_offmap(px, py);
}

View File

@ -163,13 +163,6 @@ extern MAPTILE *psMapTiles;
/* The number of units accross a tile */
#define TILE_UNITS (1<<TILE_SHIFT)
/* Make sure world coordinates are inside the map */
#define CLIP_WORLD_OFFMAP(worldX, worldY) \
worldX = MAX(0, worldX); \
worldY = MAX(0, worldY); \
worldX = MIN((SDWORD)mapWidth << TILE_SHIFT, worldX); \
worldY = MIN((SDWORD)mapHeight << TILE_SHIFT, worldY);
static inline UDWORD world_coord(UDWORD mapCoord)
{
return mapCoord * TILE_UNITS;
@ -180,6 +173,21 @@ static inline UDWORD map_coord(UDWORD worldCoord)
return worldCoord / TILE_UNITS;
}
/* Make sure world coordinates are inside the map */
/** Clip world coordinates to make sure they're inside the map's boundaries
* \param worldX a pointer to a X coordinate inside the map
* \param worldY a pointer to a Y coordinate inside the map
* \post 0 <= *worldX <= world_coord(mapWidth) and
* 0 <= *worldy <= world_coord(mapHeight)
*/
static inline void clip_world_offmap(int* worldX, int* worldY)
{
*worldX = MAX(0, *worldX);
*worldY = MAX(0, *worldY);
*worldX = MIN(world_coord(mapWidth), *worldX);
*worldY = MIN(world_coord(mapHeight), *worldY);
}
/* maps a position down to the corner of a tile */
#define map_round(coord) (coord & (TILE_UNITS - 1))