From ecf534522c76212df268585174c1cc17442aa45b Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 10 Mar 2024 14:54:25 +0100 Subject: [PATCH] Codechange: replace macro with function for TileAdd(XY) --- src/map_func.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/map_func.h b/src/map_func.h index 736727c7a6..948165df0d 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -455,27 +455,31 @@ inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc) } +/** + * Adds a given offset to a tile. + * + * @param tile The tile to add an offset to. + * @param offset The offset to add. + * @return The resulting tile. + */ #ifndef _DEBUG - /** - * Adds two tiles together. - * - * @param x One tile - * @param y Another tile to add - * @return The resulting tile(index) - */ -# define TileAdd(x, y) ((x) + (y)) + constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset) { return tile + offset; } #else - extern TileIndex TileAdd(TileIndex tile, TileIndexDiff offset); + TileIndex TileAdd(TileIndex tile, TileIndexDiff offset); #endif /** * Adds a given offset to a tile. * - * @param tile The tile to add an offset on it - * @param x The x offset to add to the tile - * @param y The y offset to add to the tile + * @param tile The tile to add an offset to. + * @param x The x offset to add to the tile. + * @param y The y offset to add to the tile. + * @return The resulting tile. */ -#define TileAddXY(tile, x, y) TileAdd(tile, TileDiffXY(x, y)) +inline TileIndex TileAddXY(TileIndex tile, int x, int y) +{ + return TileAdd(tile, TileDiffXY(x, y)); +} TileIndex TileAddWrap(TileIndex tile, int addx, int addy);