Skip to content

Commit

Permalink
Add new keyword WZ_DECL_ALWAYS_INLINE to label functions that we alwa…
Browse files Browse the repository at this point in the history
…ys want to inline, even when compiling in debug mode.

Also manually inline map tile lookups in the danger map code for maximum performance (avoiding some checks).
  • Loading branch information
perim committed Nov 2, 2010
1 parent b1c4980 commit 1617b4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
13 changes: 13 additions & 0 deletions lib/framework/wzglobal.h
Expand Up @@ -423,6 +423,19 @@
#endif


/*!
* \def WZ_DECL_ALWAYS_INLINE
* GCC: "Generally, functions are not inlined unless optimization is specified. For functions
* declared inline, this attribute inlines the function even if no optimization level
* was specified."
*/
#if WZ_CC_GNU_PREREQ(2,5)
# define WZ_DECL_ALWAYS_INLINE __attribute__((__always_inline__))
#else
# define WZ_DECL_ALWAYS_INLINE
#endif


/*!
* \def WZ_DECL_PURE
* GCC: "Many functions have no effects except the return value and their return value depends
Expand Down
4 changes: 2 additions & 2 deletions src/map.c
Expand Up @@ -1560,7 +1560,7 @@ static void dangerFloodFill(int player)

do
{
MAPTILE *currTile = mapTile(pos.x, pos.y);
MAPTILE *currTile = &psMapTiles[pos.x + (pos.y * mapWidth)];

// Add accessible neighbouring tiles to the open list
for (i = 0; i < NUM_DIR; i++)
Expand All @@ -1572,7 +1572,7 @@ static void dangerFloodFill(int player)
{
continue;
}
psTile = mapTile(npos.x, npos.y);
psTile = &psMapTiles[npos.x + (npos.y * mapWidth)];

if (!(psTile->tileInfoBits & BITS_TEMPORARY)
&& !(psTile->threatBits & (1 << player))
Expand Down
12 changes: 6 additions & 6 deletions src/map.h
Expand Up @@ -355,7 +355,7 @@ static inline void setTileHeight(SDWORD x, SDWORD y, float height)
}

/* Return whether a tile coordinate is on the map */
static inline BOOL tileOnMap(SDWORD x, SDWORD y)
WZ_DECL_ALWAYS_INLINE static inline BOOL tileOnMap(SDWORD x, SDWORD y)
{
return (x >= 0) && (x < (SDWORD)mapWidth) && (y >= 0) && (y < (SDWORD)mapHeight);
}
Expand All @@ -368,29 +368,29 @@ static inline BOOL tileInsideBuildRange(SDWORD x, SDWORD y)
}

/* Return whether a world coordinate is on the map */
static inline BOOL worldOnMap(int x, int y)
WZ_DECL_ALWAYS_INLINE static inline BOOL worldOnMap(int x, int y)
{
return (x >= 0) && (x < ((SDWORD)mapWidth << TILE_SHIFT)) &&
(y >= 0) && (y < ((SDWORD)mapHeight << TILE_SHIFT));
}


/* Return whether a world coordinate is on the map */
static inline bool worldOnMap2i(Vector2i pos)
WZ_DECL_ALWAYS_INLINE static inline bool worldOnMap2i(Vector2i pos)
{
return worldOnMap(pos.x, pos.y);
}


/* Return whether a world coordinate is on the map */
static inline bool worldOnMap3i(Vector3i pos)
WZ_DECL_ALWAYS_INLINE static inline bool worldOnMap3i(Vector3i pos)
{
return worldOnMap(pos.x, pos.y);
}


/* Return whether a world coordinate is on the map */
static inline bool worldOnMap3f(Vector3f pos)
WZ_DECL_ALWAYS_INLINE static inline bool worldOnMap3f(Vector3f pos)
{
return worldOnMap(pos.x, pos.y);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ extern bool fireOnLocation(unsigned int x, unsigned int y);
* Transitive sensor check for tile. Has to be here rather than
* visibility.h due to header include order issues.
*/
static inline bool hasSensorOnTile(MAPTILE *psTile, unsigned player)
WZ_DECL_ALWAYS_INLINE static inline bool hasSensorOnTile(MAPTILE *psTile, unsigned player)
{
return ((player == selectedPlayer && godMode) || (alliancebits[selectedPlayer] & (satuplinkbits | psTile->sensorBits)));
}
Expand Down

0 comments on commit 1617b4c

Please sign in to comment.