mirror of https://github.com/OpenTTD/OpenTTD
(svn r2758) Add the AB() macro to add a value to a bit range and use it in a few places, also make use of GB and SB nearby
parent
79620db9be
commit
9b676d2cd9
4
macros.h
4
macros.h
|
@ -146,8 +146,10 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
|
||||||
|
|
||||||
/// Fetch n bits starting at bit s from x
|
/// Fetch n bits starting at bit s from x
|
||||||
#define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
|
#define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
|
||||||
/// Set n bits in x starting at bit s to d
|
/// Set n bits starting at bit s in x to d
|
||||||
#define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | ((d) << (s)))
|
#define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (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) & ~(((1 << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1 << (n)) - 1) << (s))))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ROtate x Left/Right by n (must be >= 0)
|
* ROtate x Left/Right by n (must be >= 0)
|
||||||
|
|
14
town_cmd.c
14
town_cmd.c
|
@ -180,7 +180,7 @@ static void AnimateTile_Town(TileIndex tile)
|
||||||
i = (Random()&7) - 1;
|
i = (Random()&7) - 1;
|
||||||
} while (i < 0 || i == 1 || i*6==old);
|
} while (i < 0 || i == 1 || i*6==old);
|
||||||
|
|
||||||
_m[tile].m5 = (_m[tile].m5 & ~0x3F) | i;
|
SB(_m[tile].m5, 0, 6, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
a = _m[tile].owner&0x7F;
|
a = _m[tile].owner&0x7F;
|
||||||
|
@ -255,18 +255,12 @@ uint32 GetWorldPopulation(void)
|
||||||
|
|
||||||
static void MakeSingleHouseBigger(TileIndex tile)
|
static void MakeSingleHouseBigger(TileIndex tile)
|
||||||
{
|
{
|
||||||
byte b;
|
|
||||||
|
|
||||||
assert(IsTileType(tile, MP_HOUSE));
|
assert(IsTileType(tile, MP_HOUSE));
|
||||||
|
|
||||||
b = _m[tile].m5;
|
if (_m[tile].m5 & 0x80) return;
|
||||||
if (b & 0x80)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_m[tile].m5 = (b & 0xC0) | ((b+1)&7);
|
AB(_m[tile].m5, 0, 3, 1);
|
||||||
|
if (GB(_m[tile].m5, 0, 3) != 0) return;
|
||||||
if ((_m[tile].m5&7) != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_m[tile].m3 = _m[tile].m3 + 0x40;
|
_m[tile].m3 = _m[tile].m3 + 0x40;
|
||||||
|
|
||||||
|
|
|
@ -485,11 +485,8 @@ static void TileLoop_Trees(TileIndex tile)
|
||||||
TileLoopClearHelper(tile);
|
TileLoopClearHelper(tile);
|
||||||
|
|
||||||
/* increase counter */
|
/* increase counter */
|
||||||
{
|
AB(_m[tile].m2, 0, 4, 1);
|
||||||
uint16 m2 = _m[tile].m2;
|
if (GB(_m[tile].m2, 0, 4) != 0) return;
|
||||||
_m[tile].m2 = m2 = (m2 & 0xF0) | ((m2 + 1) & 0xF);
|
|
||||||
if ((m2 & 0xF) != 0) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m5 = _m[tile].m5;
|
m5 = _m[tile].m5;
|
||||||
if (GB(m5, 0, 3) == 3) {
|
if (GB(m5, 0, 3) == 3) {
|
||||||
|
|
Loading…
Reference in New Issue