Add functions to get number of digits required for map dimensions

This commit is contained in:
Jonathan G Rennison 2024-08-31 11:08:08 +01:00
parent 4ce8a36e4d
commit 572c261832
2 changed files with 24 additions and 0 deletions

View File

@ -32,6 +32,8 @@ uint _map_size_x; ///< Size of the map along the X
uint _map_size_y; ///< Size of the map along the Y
uint _map_size; ///< The number of tiles on the map
uint _map_tile_mask; ///< _map_size - 1 (to mask the mapsize)
uint _map_digits_x; ///< Number of base-10 digits for _map_size_x
uint _map_digits_y; ///< Number of base-10 digits for _map_size_y
Tile *_m = nullptr; ///< Tiles of the map
TileExtended *_me = nullptr; ///< Extended Tiles of the map
@ -80,6 +82,8 @@ void AllocateMap(uint size_x, uint size_y)
_map_size_y = size_y;
_map_size = size_x * size_y;
_map_tile_mask = _map_size - 1;
_map_digits_x = GetBase10DigitsRequired(_map_size_x);
_map_digits_y = GetBase10DigitsRequired(_map_size_y);
#if defined(__linux__) && defined(MADV_HUGEPAGE)
if (_munmap_size != 0) {

View File

@ -114,6 +114,26 @@ inline uint MapMaxY()
return MapSizeY() - 1;
}
/**
* Get the number of base-10 digits required for the size of the map along the X
* @return the number of digits required
*/
inline uint MapDigitsX()
{
extern uint _map_digits_x;
return _map_digits_x;
}
/**
* Get the number of base-10 digits required for the size of the map along the Y
* @return the number of digits required
*/
inline uint MapDigitsY()
{
extern uint _map_digits_y;
return _map_digits_y;
}
/**
* Scales the given value by the map size, where the given value is
* for a 256 by 256 map.