From 5d00438a858bb4a404d2b5d5c6f9d9fa9e58663f Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 21 Nov 2018 15:24:28 +0100 Subject: ScaleByMapSize should not scale by layerCount(), too - and we need to move some lines from layer_func.h to map_func.h to avoid cyclic includes --- src/layer_func.h | 59 ------------------------------------------------------- src/map_func.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/layer_func.h b/src/layer_func.h index be060cc27..d472d23b5 100644 --- a/src/layer_func.h +++ b/src/layer_func.h @@ -28,65 +28,6 @@ void FixUndergroundHeights(); #define FOR_ALL_LAYERS(var) for (uint var = 0; var < LayerCount(); var++) - -/** - * Get the size of the layer along the X - * @return the number of tiles along the X of the layer - */ -static inline uint LayerSizeX() -{ - extern uint _map_size_x; - return _map_size_x; -} - -/** - * Get the size of the layer along the Y - * @return the number of tiles along the Y of the layer - */ -static inline uint LayerSizeY() -{ - extern uint _layer_size_y; - return _layer_size_y; -} - -/** - * Gets the maximum X coordinate within the map, including MP_VOID - * @return the maximum X coordinate - */ -static inline uint LayerMaxX() -{ - return LayerSizeX() - 1; -} - -/** - * Gets the maximum Y coordinate within the map, including MP_VOID - * @return the maximum Y coordinate - */ -static inline uint LayerMaxY() -{ - return LayerSizeY() - 1; -} - -/** - * Get the layer counts - * @return the number of layers - */ -static inline uint LayerCount() -{ - extern uint _layer_count; - return _layer_count; -} - -/** - * Get the layer counts - * @return the number of layers - */ -static inline uint LayerCountLog() -{ - extern uint _layer_count_log; - return _layer_count_log; -} - /** * Get the X component of a tile * @param tile the tile to get the X component of diff --git a/src/map_func.h b/src/map_func.h index e8ab9036e..e00251243 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -113,6 +113,64 @@ static inline uint MapMaxY() return MapSizeY() - 1; } +/** + * Get the size of the layer along the X + * @return the number of tiles along the X of the layer + */ +static inline uint LayerSizeX() +{ + extern uint _map_size_x; + return _map_size_x; +} + +/** + * Get the size of the layer along the Y + * @return the number of tiles along the Y of the layer + */ +static inline uint LayerSizeY() +{ + extern uint _layer_size_y; + return _layer_size_y; +} + +/** + * Gets the maximum X coordinate within the map, including MP_VOID + * @return the maximum X coordinate + */ +static inline uint LayerMaxX() +{ + return LayerSizeX() - 1; +} + +/** + * Gets the maximum Y coordinate within the map, including MP_VOID + * @return the maximum Y coordinate + */ +static inline uint LayerMaxY() +{ + return LayerSizeY() - 1; +} + +/** + * Get the layer counts + * @return the number of layers + */ +static inline uint LayerCount() +{ + extern uint _layer_count; + return _layer_count; +} + +/** + * Get the layer counts + * @return the number of layers + */ +static inline uint LayerCountLog() +{ + extern uint _layer_count_log; + return _layer_count_log; +} + /** * Scales the given value by the map size, where the given value is * for a 256 by 256 map. @@ -123,7 +181,7 @@ static inline uint ScaleByMapSize(uint n) { /* Subtract 12 from shift in order to prevent integer overflow * for large values of n. It's safe since the min mapsize is 64x64. */ - return CeilDiv(n << (MapLogX() + MapLogY() - 12), 1 << 4); + return CeilDiv(n << (MapLogX() + MapLogY() - LayerCountLog() - 12), 1 << 4); } -- cgit v1.2.3-70-g09d2