From bde06e75b42c469247ee3afbd8078713402707de Mon Sep 17 00:00:00 2001 From: celestar Date: Wed, 14 Feb 2007 11:53:39 +0000 Subject: (svn r8732) -Codechange/Fix(r8705): Turned the bit-handling macros into template functions. Fixes a problem with MSVC and 64-bit shifts. --- src/ai/trolly/pathfinder.cpp | 4 ++-- src/macros.h | 27 +++++++++++++++++++++++---- src/tunnelbridge_cmd.cpp | 4 ++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp index 5ba50ca7f..297d12a00 100644 --- a/src/ai/trolly/pathfinder.cpp +++ b/src/ai/trolly/pathfinder.cpp @@ -372,9 +372,9 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr extern uint GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c extern uint GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c extern uint GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c -enum { +typedef enum BridgeFoundations{ BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12, -}; +} BridgeFoundation; // The most important function: it calculates the g-value static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent) diff --git a/src/macros.h b/src/macros.h index 2371804f9..56dc219e3 100644 --- a/src/macros.h +++ b/src/macros.h @@ -62,11 +62,30 @@ static inline int64 BIGMULS(int32 a, int32 b) { //#define IS_INSIDE_1D(x, base, size) ((x) >= (base) && (x) < (base) + (size)) #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) ) +template +static inline bool HASBIT(T x, int y) +{ + return (x & (((T)1) << y)) != 0; +} + +template +static inline T SETBIT(T& x, int y) +{ + return x |= (((T)1) << y); +} + +template +static inline T CLRBIT(T& x, int y) +{ + return x &= ~(((T)1) << y); +} + +template +static inline T TOGGLEBIT(T& x, int y) +{ + return x ^= (((T)1) << y); +} -#define HASBIT(x,y) (((x) & (1 << (y))) != 0) -#define SETBIT(x,y) ((x) |= (1 << (y))) -#define CLRBIT(x,y) ((x) &= ~(1 << (y))) -#define TOGGLEBIT(x,y) ((x) ^= (1 << (y))) // checking more bits. Maybe unneccessary, but easy to use #define HASBITS(x,y) ((x) & (y)) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 12d2bb109..c370f0735 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -77,7 +77,7 @@ int CalcBridgeLenCostFactor(int x) } #define M(x) (1 << (x)) -enum { +typedef enum BridgeFoundations{ // foundation, whole tile is leveled up --> 3 corners raised BRIDGE_FULL_LEVELED_FOUNDATION = M(SLOPE_WSE) | M(SLOPE_NWS) | M(SLOPE_ENW) | M(SLOPE_SEN), // foundation, tile is partly leveled up --> 1 corner raised @@ -85,7 +85,7 @@ enum { // no foundations (X,Y direction) BRIDGE_NO_FOUNDATION = M(SLOPE_FLAT) | M(SLOPE_SW) | M(SLOPE_SE) | M(SLOPE_NW) | M(SLOPE_NE), BRIDGE_HORZ_RAMP = (BRIDGE_PARTLY_LEVELED_FOUNDATION | BRIDGE_NO_FOUNDATION) & ~M(SLOPE_FLAT) -}; +} BridgeFoundataion; #undef M static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table) -- cgit v1.2.3-70-g09d2