Changeset - r26788:0785302ccc5b
[Not reviewed]
master
0 5 0
Rubidium - 20 months ago 2023-01-21 10:05:19
rubidium@openttd.org
Codechange: move TILE_MASK to Map::WrapToMap
5 files changed with 17 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1007,13 +1007,13 @@ static bool IsSuitableForFarmField(TileI
 
 */
 
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, DiagDirection side)
 
{
 
	TileIndexDiff diff = (DiagDirToAxis(side) == AXIS_Y ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 

	
 
	do {
 
		tile = TILE_MASK(tile);
 
		tile = Map::WrapToMap(tile);
 

	
 
		if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) {
 
			byte or_ = type;
 

	
 
			if (or_ == 1 && Chance16(1, 7)) or_ = 2;
 

	
src/map.cpp
Show inline comments
 
@@ -89,13 +89,13 @@ TileIndex TileAdd(TileIndex tile, TileIn
 
		fprintf(stderr, "%s:%d %s\n", file, line, buf);
 
#else
 
		_assert(buf, (char*)file, line);
 
#endif
 
	}
 

	
 
	assert(TileXY(x, y) == TILE_MASK(tile + add));
 
	assert(TileXY(x, y) == Map::WrapToMap(tile + add));
 

	
 
	return TileXY(x, y);
 
}
 
#endif
 

	
 
/**
src/map_func.h
Show inline comments
 
@@ -12,22 +12,12 @@
 

	
 
#include "core/math_func.hpp"
 
#include "tile_type.h"
 
#include "map_type.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.
 
 *
 
 * This variable points to the tile-array which contains the tiles of
 
 * the map.
 
 */
 
@@ -114,12 +104,24 @@ struct Map {
 
	 */
 
	static inline uint MaxY()
 
	{
 
		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
 
	 * for a 256 by 256 map.
 
	 * @param n the value to scale
 
	 * @return the scaled size
 
	 */
 
@@ -426,13 +428,13 @@ bool CircularTileSearch(TileIndex *tile,
 
 * Get a random tile out of a given seed.
 
 * @param r the random 'seed'
 
 * @return a valid tile
 
 */
 
static inline TileIndex RandomTileSeed(uint32 r)
 
{
 
	return TILE_MASK(r);
 
	return Map::WrapToMap(r);
 
}
 

	
 
/**
 
 * Get a valid random tile.
 
 * @note a define so 'random' gets inserted in the place where it is actually
 
 *       called, thus making the random traces more explicit.
src/newgrf_commons.cpp
Show inline comments
 
@@ -430,13 +430,13 @@ TileIndex GetNearbyTile(byte parameter, 
 

	
 
	/* Swap width and height depending on axis for railway stations */
 
	if (axis == INVALID_AXIS && HasStationTileRail(tile)) axis = GetRailStationAxis(tile);
 
	if (axis == AXIS_Y) Swap(x, y);
 

	
 
	/* 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));
 
}
 

	
 
/**
 
 * Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
 
 *
 
 * @param tile the tile of interest.
src/newgrf_house.cpp
Show inline comments
 
@@ -343,13 +343,13 @@ static uint32 GetDistanceFromNearbyHouse
 
			CargoID cid = GetCargoTranslation(parameter, this->ro.grffile);
 
			if (cid == CT_INVALID) return 0;
 

	
 
			/* Extract tile offset. */
 
			int8 x_offs = GB(GetRegister(0x100), 0, 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));
 
			const StationList *sl = stations.GetStations();
 

	
 
			/* Collect acceptance stats. */
 
			uint32 res = 0;
0 comments (0 inline, 0 general)