1
0
Fork 0

Codechange: move TILE_MASK to Map::WrapToMap

pull/10397/head
Rubidium 2023-01-21 11:05:19 +01:00 committed by rubidium42
parent fe2bcd2a58
commit de6bc8e692
5 changed files with 17 additions and 15 deletions

View File

@ -1010,7 +1010,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirecti
TileIndexDiff diff = (DiagDirToAxis(side) == AXIS_Y ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); TileIndexDiff diff = (DiagDirToAxis(side) == AXIS_Y ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
do { do {
tile = TILE_MASK(tile); tile = Map::WrapToMap(tile);
if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) { if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) {
byte or_ = type; byte or_ = type;

View File

@ -92,7 +92,7 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
#endif #endif
} }
assert(TileXY(x, y) == TILE_MASK(tile + add)); assert(TileXY(x, y) == Map::WrapToMap(tile + add));
return TileXY(x, y); return TileXY(x, y);
} }

View File

@ -15,16 +15,6 @@
#include "map_type.h" #include "map_type.h"
#include "direction_func.h" #include "direction_func.h"
extern uint _map_tile_mask;
/**
* 'Wraps' the given tile to it is within the map. It does
* this by masking the 'high' bits of.
* @param x the tile to 'wrap'
*/
#define TILE_MASK(x) ((x) & _map_tile_mask)
/** /**
* Pointer to the tile-array. * Pointer to the tile-array.
* *
@ -117,6 +107,18 @@ struct Map {
return Map::SizeY() - 1; return Map::SizeY() - 1;
} }
/**
* 'Wraps' the given "tile" so it is within the map.
* It does this by masking the 'high' bits of.
* @param tile the tile to 'wrap'
*/
static inline TileIndex WrapToMap(uint tile)
{
extern uint _map_tile_mask;
return tile & _map_tile_mask;
}
/** /**
* Scales the given value by the map size, where the given value is * Scales the given value by the map size, where the given value is
* for a 256 by 256 map. * for a 256 by 256 map.
@ -429,7 +431,7 @@ bool CircularTileSearch(TileIndex *tile, uint radius, uint w, uint h, TestTileOn
*/ */
static inline TileIndex RandomTileSeed(uint32 r) static inline TileIndex RandomTileSeed(uint32 r)
{ {
return TILE_MASK(r); return Map::WrapToMap(r);
} }
/** /**

View File

@ -433,7 +433,7 @@ TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axi
if (axis == AXIS_Y) Swap(x, y); if (axis == AXIS_Y) Swap(x, y);
/* Make sure we never roam outside of the map, better wrap in that case */ /* Make sure we never roam outside of the map, better wrap in that case */
return TILE_MASK(tile + TileDiffXY(x, y)); return Map::WrapToMap(tile + TileDiffXY(x, y));
} }
/** /**

View File

@ -346,7 +346,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Extract tile offset. */ /* Extract tile offset. */
int8 x_offs = GB(GetRegister(0x100), 0, 8); int8 x_offs = GB(GetRegister(0x100), 0, 8);
int8 y_offs = GB(GetRegister(0x100), 8, 8); int8 y_offs = GB(GetRegister(0x100), 8, 8);
TileIndex testtile = TILE_MASK(this->tile + TileDiffXY(x_offs, y_offs)); TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs));
StationFinder stations(TileArea(testtile, 1, 1)); StationFinder stations(TileArea(testtile, 1, 1));
const StationList *sl = stations.GetStations(); const StationList *sl = stations.GetStations();