summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-09 17:55:11 +0000
committertron <tron@openttd.org>2005-01-09 17:55:11 +0000
commit55e6b4f928656c23b1f8bb5cbb3763152213a0b0 (patch)
tree0fc0024c473c2a61c0b6b9be4b9fcaae7e056ddd
parent32f480a4aebb85abc03dad56149c2d05bcf8a65b (diff)
downloadopenttd-55e6b4f928656c23b1f8bb5cbb3763152213a0b0.tar.xz
(svn r1447) Move TILE_ADD(), TILE_ADDXY() and SafeTileAdd() to map.[ch] and make the latter map size agnostic
-rw-r--r--macros.h10
-rw-r--r--map.c36
-rw-r--r--map.h12
-rw-r--r--misc.c21
4 files changed, 48 insertions, 31 deletions
diff --git a/macros.h b/macros.h
index b9fa59104..f4c8cfc42 100644
--- a/macros.h
+++ b/macros.h
@@ -81,16 +81,6 @@ enum {
#define TILE_ASSERT(x) assert( TILE_MASK(x) == (x) );
-uint SafeTileAdd(uint x, int add, const char *exp, const char *file, int line);
-
-#if !defined(_DEBUG)
-# define TILE_ADD(x,y) ((x)+(y))
-#else
-# define TILE_ADD(x,y) (SafeTileAdd((x),(y), #x ", " #y, __FILE__, __LINE__))
-#endif
-
-#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x,y))
-
//#define REMADP_COORDS(x,y,z) { int t = x; x = (y-t)*2; y+=t-z; }
#define PACK_POINT(x,y) ((x) | ((y) << 16))
diff --git a/map.c b/map.c
index 7c0791db4..a158dd6de 100644
--- a/map.c
+++ b/map.c
@@ -18,6 +18,42 @@ byte _map_owner [MAP_SIZE];
uint16 _map2 [MAP_SIZE];
byte _map_extra_bits [MAP_SIZE / 4];
+
+#ifdef _DEBUG
+TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
+ const char *exp, const char *file, int line)
+{
+ int dx;
+ int dy;
+ uint x;
+ uint y;
+
+ dx = add & MapMaxX();
+ if (dx >= MapSizeX() / 2) dx -= MapSizeX();
+ dy = (add - dx) / (int)MapSizeX();
+
+ x = TileX(tile) + dx;
+ y = TileY(tile) + dy;
+
+ if (x >= MapSizeX() || y >= MapSizeY()) {
+ char buf[512];
+
+ sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
+ exp, tile, add);
+#if !defined(_MSC_VER)
+ fprintf(stderr, "%s:%d %s\n", file, line, buf);
+#else
+ _assert(buf, (char*)file, line);
+#endif
+ }
+
+ assert(TILE_XY(x,y) == TILE_MASK(tile + add));
+
+ return TILE_XY(x,y);
+}
+#endif
+
+
const TileIndexDiffC _tileoffs_by_dir[] = {
{-1, 0},
{ 0, 1},
diff --git a/map.h b/map.h
index 289d80a13..ba69cfb8a 100644
--- a/map.h
+++ b/map.h
@@ -52,6 +52,18 @@ static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
return (tidc.y << MapLogX()) + tidc.x;
}
+
+#ifndef _DEBUG
+ #define TILE_ADD(x,y) ((x) + (y))
+#else
+ extern TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
+ const char *exp, const char *file, int line);
+ #define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__))
+#endif
+
+#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TILE_XY(x, y))
+
+
static inline TileIndexDiff TileOffsByDir(uint dir)
{
extern const TileIndexDiffC _tileoffs_by_dir[4];
diff --git a/misc.c b/misc.c
index 81aa6601f..f439bad8b 100644
--- a/misc.c
+++ b/misc.c
@@ -730,27 +730,6 @@ int FindFirstBit(uint32 value)
}
-uint SafeTileAdd(uint tile, int add, const char *exp, const char *file, int line)
-{
- uint x = TileX(tile) + (signed char)(add & 0xFF);
- uint y = TileY(tile) + ((((0x8080 + add)>>8) & 0xFF) - 0x80);
-
- if (x >= MapSizeX() || y >= MapSizeY()) {
- char buf[512];
-
- sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and %d failed", exp, tile, add);
-#if !defined(_DEBUG) || !defined(_MSC_VER)
- fprintf(stderr, "%s:%d %s\n", file, line, buf);
-#else
- _assert(buf, (char*)file, line);
-#endif
- }
-
- assert(TILE_XY(x,y) == TILE_MASK(tile + add));
-
- return TILE_XY(x,y);
-}
-
static void Save_NAME()
{
int i;