diff options
author | tron <tron@openttd.org> | 2005-11-16 13:11:28 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-11-16 13:11:28 +0000 |
commit | ec57ef78a21fc57f752e1ee2c353b42da663f007 (patch) | |
tree | 658be9e3a7c385d16ddddacc093d3d9fe27855d0 | |
parent | 8cebe2f607d65de4df376bb5bc4f3caac62a2616 (diff) | |
download | openttd-ec57ef78a21fc57f752e1ee2c353b42da663f007.tar.xz |
(svn r3205) Some more uses for GB/SB
-rw-r--r-- | industry_cmd.c | 6 | ||||
-rw-r--r-- | macros.h | 26 | ||||
-rw-r--r-- | oldloader.c | 4 | ||||
-rw-r--r-- | rail_gui.c | 4 | ||||
-rw-r--r-- | tunnelbridge_cmd.c | 5 |
5 files changed, 24 insertions, 21 deletions
diff --git a/industry_cmd.c b/industry_cmd.c index b11176aff..8e78e1619 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -561,8 +561,8 @@ static void AnimateTile_Industry(TileIndex tile) case 10: if ((_tick_counter & 3) == 0) { m = _m[tile].m1; - if ((m & (31<<2)) == (6 << 2)) { - _m[tile].m1 = m&~(31<<2); + if (GB(m, 2, 5) == 6) { + SB(_m[tile].m1, 2, 5, 0); DeleteAnimatedTile(tile); } else { _m[tile].m1 = m + (1<<2); @@ -614,7 +614,7 @@ static void AnimateTile_Industry(TileIndex tile) _m[tile].m5 = 29; DeleteAnimatedTile(tile); } else { - _m[tile].m1 = (_m[tile].m1 & ~3) | m; + SB(_m[tile].m1, 0, 2, m); _m[tile].m5 = n; MarkTileDirtyByTile(tile); } @@ -5,6 +5,13 @@ #include "map.h" +/// Fetch n bits starting at bit s from x +#define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1)) +/// Set n bits starting at bit s in x to d +#define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s))) +/// Add i to the n bits starting at bit s in x +#define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s)))) + #ifdef min #undef min #endif @@ -86,20 +93,20 @@ static inline int FindFirstBit2x64(int value) Faster ( or at least cleaner ) implementation below? */ - if ( (byte) value == 0) { - return FIND_FIRST_BIT((value >> 8) & 0x3F) + 8; + if (GB(value, 0, 8) == 0) { + return FIND_FIRST_BIT(GB(value, 8, 6)) + 8; } else { - return FIND_FIRST_BIT(value & 0x3F); + return FIND_FIRST_BIT(GB(value, 0, 6)); } } static inline int KillFirstBit2x64(int value) { - if ( (byte) value == 0) { - return KILL_FIRST_BIT((value >> 8) & 0x3F) << 8; + if (GB(value, 0, 8) == 0) { + return KILL_FIRST_BIT(GB(value, 8, 6)) << 8; } else { - return value & (KILL_FIRST_BIT(value & 0x3F)|0x3F00); + return value & (KILL_FIRST_BIT(GB(value, 0, 6)) | 0x3F00); } } @@ -144,13 +151,6 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a } #endif -/// Fetch n bits starting at bit s from x -#define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1)) -/// Set n bits starting at bit s in x to d -#define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s))) -/// Add i to the n bits starting at bit s in x -#define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s)))) - /** * ROtate x Left/Right by n (must be >= 0) * @note Assumes a byte has 8 bits diff --git a/oldloader.c b/oldloader.c index 214d0dddf..b11482891 100644 --- a/oldloader.c +++ b/oldloader.c @@ -193,7 +193,7 @@ static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks) uint32 res = 0; /* Reading from the file: bit 16 to 23 have the FILE */ - switch (((chunk->type >> 16) & 0xFF) << 16) { + switch (GB(chunk->type, 16, 8) << 16) { case OC_FILE_I8: res = ReadByte(ls); res = (int8)res; @@ -234,7 +234,7 @@ static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks) assert(base_ptr != NULL || chunk->ptr != NULL); /* Writing to the var: bit 8 till 15 have the VAR */ - switch (((chunk->type >> 8) & 0xFF) << 8) { + switch (GB(chunk->type, 8, 8) << 8) { case OC_VAR_I8: /* Write the data */ if (chunk->ptr != NULL) { diff --git a/rail_gui.c b/rail_gui.c index 415498958..800371a73 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -85,8 +85,8 @@ static void PlaceExtraDepotRail(TileIndex tile, uint16 extra) { byte b = _m[tile].m5; - if (b & 0xC0 || !(b & (extra >> 8))) - return; + if (GB(b, 6, 2) != RAIL_TYPE_NORMAL >> 6) return; + if (!(b & (extra >> 8))) return; DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER); } diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index cb88c0bdd..817c742cd 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -430,7 +430,10 @@ static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) FindLandscapeHeightByTile(&ti, tile); } while (z < ti.z); - if (z == ti.z && ti.type == MP_TUNNELBRIDGE && (ti.map5&0xF0) == 0 && (ti.map5&3) == dir) { + if (z == ti.z && + ti.type == MP_TUNNELBRIDGE && + GB(ti.map5, 4, 4) == 0 && + GB(ti.map5, 0, 2) == dir) { _error_message = STR_5003_ANOTHER_TUNNEL_IN_THE_WAY; return false; } |