(svn r3205) Some more uses for GB/SB

This commit is contained in:
tron 2005-11-16 13:11:28 +00:00
parent d09db07ca1
commit ef7fb8b515
5 changed files with 24 additions and 21 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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) {

View File

@ -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);
}

View File

@ -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;
}