mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::source_location over __FILE__ and __LINE__ for TILE_ADD(XY)
parent
9c95fbdb07
commit
4dc99fc8d9
26
src/map.cpp
26
src/map.cpp
|
@ -69,32 +69,26 @@ extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned);
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
|
TileIndex TILE_ADD(TileIndex tile, TileIndexDiff offset, std::source_location location)
|
||||||
const char *exp, const char *file, int line)
|
|
||||||
{
|
{
|
||||||
int dx;
|
int dx = offset & Map::MaxX();
|
||||||
int dy;
|
|
||||||
uint x;
|
|
||||||
uint y;
|
|
||||||
|
|
||||||
dx = add & Map::MaxX();
|
|
||||||
if (dx >= (int)Map::SizeX() / 2) dx -= Map::SizeX();
|
if (dx >= (int)Map::SizeX() / 2) dx -= Map::SizeX();
|
||||||
dy = (add - dx) / (int)Map::SizeX();
|
int dy = (offset - dx) / (int)Map::SizeX();
|
||||||
|
|
||||||
x = TileX(tile) + dx;
|
uint x = TileX(tile) + dx;
|
||||||
y = TileY(tile) + dy;
|
uint y = TileY(tile) + dy;
|
||||||
|
|
||||||
if (x >= Map::SizeX() || y >= Map::SizeY()) {
|
if (x >= Map::SizeX() || y >= Map::SizeY()) {
|
||||||
std::string message = fmt::format("TILE_ADD({}) when adding 0x{:04X} and 0x{:04X} failed",
|
std::string message = fmt::format("TILE_ADD when adding 0x{:04X} and 0x{:04X} failed",
|
||||||
exp, tile, add);
|
tile, offset);
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
fmt::print(stderr, "{}:{} {}\n", file, line, message);
|
fmt::print(stderr, "{}:{}:{} {}\n", location.file_name(), location.line(), location.column(), message);
|
||||||
#else
|
#else
|
||||||
_assert(message.data(), (char*)file, line);
|
_assert(message.data(), (char*)location.file_name(), location.line());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(TileXY(x, y) == Map::WrapToMap(tile + add));
|
assert(TileXY(x, y) == Map::WrapToMap(tile + offset));
|
||||||
|
|
||||||
return TileXY(x, y);
|
return TileXY(x, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,29 +455,31 @@ inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef _DEBUG
|
/**
|
||||||
/**
|
* Adds a given offset to a tile.
|
||||||
* Adds two tiles together.
|
|
||||||
*
|
*
|
||||||
* @param x One tile
|
* @param tile The tile to add an offset to.
|
||||||
* @param y Another tile to add
|
* @param offset The offset to add.
|
||||||
* @return The resulting tile(index)
|
* @return The resulting tile.
|
||||||
*/
|
*/
|
||||||
# define TILE_ADD(x, y) ((x) + (y))
|
#ifndef _DEBUG
|
||||||
|
constexpr TileIndex TILE_ADD(TileIndex tile, TileIndexDiff offset, [[maybe_unused]] const std::source_location location = std::source_location::current()) { return tile + offset; }
|
||||||
#else
|
#else
|
||||||
extern TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
|
TileIndex TILE_ADD(TileIndex tile, TileIndexDiff offset, const std::source_location location = std::source_location::current());
|
||||||
const char *exp, const char *file, int line);
|
|
||||||
# define TILE_ADD(x, y) (TileAdd((x), (y), #x " + " #y, __FILE__, __LINE__))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a given offset to a tile.
|
* Adds a given offset to a tile.
|
||||||
*
|
*
|
||||||
* @param tile The tile to add an offset on it
|
* @param tile The tile to add an offset to.
|
||||||
* @param x The x offset to add to the tile
|
* @param x The x offset to add to the tile.
|
||||||
* @param y The y offset to add to the tile
|
* @param y The y offset to add to the tile.
|
||||||
|
* @return The resulting tile.
|
||||||
*/
|
*/
|
||||||
#define TILE_ADDXY(tile, x, y) TILE_ADD(tile, TileDiffXY(x, y))
|
inline TileIndex TILE_ADDXY(TileIndex tile, int x, int y, const std::source_location location = std::source_location::current())
|
||||||
|
{
|
||||||
|
return TILE_ADD(tile, TileDiffXY(x, y), location);
|
||||||
|
}
|
||||||
|
|
||||||
TileIndex TileAddWrap(TileIndex tile, int addx, int addy);
|
TileIndex TileAddWrap(TileIndex tile, int addx, int addy);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue