Skip to content

Commit

Permalink
Change SystemState Tile to vector
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Dec 22, 2022
1 parent b96728d commit e5a34f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pol-core/plib/systemstate.cpp
Expand Up @@ -18,7 +18,7 @@ SystemState::SystemState()
accounts_txt_dirty( false ),
accounts_txt_stat(),
config(),
tile( nullptr ),
tile(),
tiles_loaded( false )
{
}
Expand All @@ -27,14 +27,14 @@ void SystemState::deinitialize()
{
Clib::delete_all( packages );
packages_byname.clear();
if ( tile != nullptr )
delete[] tile;
tile.clear();
}

size_t SystemState::estimatedSize() const
{
size_t size = sizeof( SystemState );
size += ( config.max_tile_id + 1 ) * sizeof( Tile );

size += sizeof( std::vector<Tile> ) + sizeof( Tile ) * tile.capacity();

size += 3 * sizeof( Package** ) + packages.capacity() * sizeof( Package* );
for ( const auto& pkg : packages )
Expand Down
2 changes: 1 addition & 1 deletion pol-core/plib/systemstate.h
Expand Up @@ -40,7 +40,7 @@ class SystemState
struct stat accounts_txt_stat;

Core::PolConfig config;
Tile* tile;
std::vector<Tile> tile;
bool tiles_loaded;

size_t estimatedSize() const;
Expand Down
5 changes: 2 additions & 3 deletions pol-core/plib/tiles.cpp
Expand Up @@ -25,7 +25,7 @@ void load_tile_entry( const Package* /*pkg*/, Clib::ConfigElem& elem )
{
unsigned short graphic = static_cast<unsigned short>( strtoul( elem.rest(), nullptr, 0 ) );
passert_always( graphic < ( systemstate.config.max_tile_id + 1 ) );
Tile& entry = systemstate.tile[graphic];
Tile& entry = systemstate.tile.at(graphic);
entry.desc = elem.remove_string( "Desc" );
entry.uoflags = elem.remove_ulong( "UoFlags" );
entry.layer = static_cast<u8>( elem.remove_ushort( "Layer", 0 ) );
Expand All @@ -39,8 +39,7 @@ void load_tile_entry( const Package* /*pkg*/, Clib::ConfigElem& elem )
void load_tiles_cfg()
{
u32 tile_count = systemstate.config.max_tile_id + 1;
systemstate.tile = new Tile[static_cast<size_t>( tile_count )];
memset( systemstate.tile, 0, sizeof( Tile ) * tile_count );
systemstate.tile.resize( tile_count );

load_all_cfgs( "tiles.cfg", "TILE", load_tile_entry );

Expand Down

0 comments on commit e5a34f7

Please sign in to comment.