(svn r8732) -Codechange/Fix(r8705): Turned the bit-handling macros into template functions. Fixes a problem with MSVC and 64-bit shifts.
authorcelestar
Wed, 14 Feb 2007 11:53:39 +0000
changeset 6336 16879925b259
parent 6335 0c3dc188f099
child 6337 6f3f247870f1
(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
src/macros.h
src/tunnelbridge_cmd.cpp
--- a/src/ai/trolly/pathfinder.cpp	Wed Feb 14 10:33:36 2007 +0000
+++ b/src/ai/trolly/pathfinder.cpp	Wed Feb 14 11:53:39 2007 +0000
@@ -372,9 +372,9 @@
 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)
--- a/src/macros.h	Wed Feb 14 10:33:36 2007 +0000
+++ b/src/macros.h	Wed Feb 14 11:53:39 2007 +0000
@@ -62,11 +62,30 @@
 //#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 <typename T>
+static inline bool HASBIT(T x, int y)
+{
+	return (x & (((T)1) << y)) != 0;
+}
 
-#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)))
+template <typename T>
+static inline T SETBIT(T& x, int y)
+{
+	return x |= (((T)1) << y);
+}
+
+template <typename T>
+static inline T CLRBIT(T& x, int y)
+{
+	return x &= ~(((T)1) << y);
+}
+
+template <typename T>
+static inline T TOGGLEBIT(T& x, int y)
+{
+	return x ^= (((T)1) << y);
+}
+
 
 // checking more bits. Maybe unneccessary, but easy to use
 #define HASBITS(x,y) ((x) & (y))
--- a/src/tunnelbridge_cmd.cpp	Wed Feb 14 10:33:36 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Wed Feb 14 11:53:39 2007 +0000
@@ -77,7 +77,7 @@
 }
 
 #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 @@
 	// 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)