Codechange: use std::unique_ptr over CallocT for tiles

This commit is contained in:
Rubidium 2025-01-13 21:39:10 +01:00 committed by rubidium42
parent 3541ba4d0c
commit 3a7cfafe51
2 changed files with 16 additions and 19 deletions

View File

@ -24,8 +24,8 @@
/* static */ uint Map::size; ///< The number of tiles on the map
/* static */ uint Map::tile_mask; ///< _map_size - 1 (to mask the mapsize)
/* static */ Tile::TileBase *Tile::base_tiles = nullptr; ///< Base tiles of the map
/* static */ Tile::TileExtended *Tile::extended_tiles = nullptr; ///< Extended tiles of the map
/* static */ std::unique_ptr<Tile::TileBase[]> Tile::base_tiles; ///< Base tiles of the map
/* static */ std::unique_ptr<Tile::TileExtended[]> Tile::extended_tiles; ///< Extended tiles of the map
/**
@ -53,11 +53,8 @@
Map::size = size_x * size_y;
Map::tile_mask = Map::size - 1;
free(Tile::base_tiles);
free(Tile::extended_tiles);
Tile::base_tiles = CallocT<Tile::TileBase>(Map::size);
Tile::extended_tiles = CallocT<Tile::TileExtended>(Map::size);
Tile::base_tiles = std::make_unique<Tile::TileBase[]>(Map::size);
Tile::extended_tiles = std::make_unique<Tile::TileExtended[]>(Map::size);
AllocateWaterRegions();
}

View File

@ -30,13 +30,13 @@ private:
* Look at docs/landscape.html for the exact meaning of the members.
*/
struct TileBase {
uint8_t type; ///< The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
uint8_t height; ///< The height of the northern corner.
uint16_t m2; ///< Primarily used for indices to towns, industries and stations
uint8_t m1; ///< Primarily used for ownership information
uint8_t m3; ///< General purpose
uint8_t m4; ///< General purpose
uint8_t m5; ///< General purpose
uint8_t type = 0; ///< The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
uint8_t height = 0; ///< The height of the northern corner.
uint16_t m2 = 0; ///< Primarily used for indices to towns, industries and stations
uint8_t m1 = 0; ///< Primarily used for ownership information
uint8_t m3 = 0; ///< General purpose
uint8_t m4 = 0; ///< General purpose
uint8_t m5 = 0; ///< General purpose
};
static_assert(sizeof(TileBase) == 8);
@ -46,13 +46,13 @@ private:
* Look at docs/landscape.html for the exact meaning of the members.
*/
struct TileExtended {
uint8_t m6; ///< General purpose
uint8_t m7; ///< Primarily used for newgrf support
uint16_t m8; ///< General purpose
uint8_t m6 = 0; ///< General purpose
uint8_t m7 = 0; ///< Primarily used for newgrf support
uint16_t m8 = 0; ///< General purpose
};
static TileBase *base_tiles; ///< Pointer to the tile-array.
static TileExtended *extended_tiles; ///< Pointer to the extended tile-array.
static std::unique_ptr<TileBase[]> base_tiles; ///< Pointer to the tile-array.
static std::unique_ptr<TileExtended[]> extended_tiles; ///< Pointer to the extended tile-array.
TileIndex tile; ///< The tile to access the map data for.