summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-02-14 11:53:39 +0000
committercelestar <celestar@openttd.org>2007-02-14 11:53:39 +0000
commit59a814c6d321dcc53cc6d855501062ade8f035f7 (patch)
tree5cebc76c7639e1dcf5e6ca5716240cb6277da593
parent447b16930e7b03304ca72d0ec3dd240c7a44dc5d (diff)
downloadopenttd-59a814c6d321dcc53cc6d855501062ade8f035f7.tar.xz
(svn r8732) -Codechange/Fix(r8705): Turned the bit-handling macros into template functions. Fixes a problem with MSVC and 64-bit shifts.
-rw-r--r--src/ai/trolly/pathfinder.cpp4
-rw-r--r--src/macros.h27
-rw-r--r--src/tunnelbridge_cmd.cpp4
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 <typename T>
+static inline bool HASBIT(T x, int y)
+{
+ return (x & (((T)1) << y)) != 0;
+}
+
+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);
+}
-#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)