Skip to content

Commit

Permalink
wrappers for realm/uworld methods accepting Posclasses.
Browse files Browse the repository at this point in the history
switched memoryorder of realm zone
  • Loading branch information
turleypol committed Sep 15, 2021
1 parent ce9834e commit 4a5392e
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 219 deletions.
2 changes: 1 addition & 1 deletion pol-core/pol/decay.cpp
Expand Up @@ -54,7 +54,7 @@ namespace Core

void decay_worldzone( unsigned wx, unsigned wy, Realms::Realm* realm )
{
Zone& zone = realm->zone[wx][wy];
Zone& zone = realm->getzone( (u16)wx, (u16)wy );
gameclock_t now = read_gameclock();
bool statistics = Plib::systemstate.config.thread_decay_statistics;

Expand Down
78 changes: 33 additions & 45 deletions pol-core/pol/globals/uvars.cpp
Expand Up @@ -27,10 +27,6 @@
#include "../accounts/accounts.h"
#include "../checkpnt.h"
#include "../console.h"
#include "regions/guardrgn.h"
#include "regions/musicrgn.h"
#include "regions/resource.h"
#include "regions/miscrgn.h"
#include "../guilds.h"
#include "../item/equipmnt.h"
#include "../item/itemdesc.h"
Expand All @@ -44,7 +40,6 @@
#include "../party.h"
#include "../polcfg.h"
#include "../polsem.h"
#include "realms/realm.h"
#include "../scrstore.h"
#include "../spells.h"
#include "../startloc.h"
Expand All @@ -57,6 +52,11 @@
#include "multidefs.h"
#include "network.h"
#include "object_storage.h"
#include "realms/realm.h"
#include "regions/guardrgn.h"
#include "regions/miscrgn.h"
#include "regions/musicrgn.h"
#include "regions/resource.h"
#include "script_internals.h"
#include "ucfg.h"

Expand Down Expand Up @@ -121,15 +121,15 @@ GameState::GameState()
// on OSI uses the 301+ spellrange that we can find. 5/30/06 - MuadDib
// We use Mysticism at array entry 3 because Mysticism spellids are 678 -> 693 and this slot
// is free.
spell_scroll_objtype_limits( {{// TODO: Comment those objtypes :D
{{0x1F2D, 0x1F6C}},
{{0x2260, 0x226F}},
{{0x2270, 0x227C}},
{{0x2D9E, 0x2DAD}},
{{0x238D, 0x2392}},
{{0x23A1, 0x23A8}},
{{0x2D51, 0x2D60}},
{{0x574B, 0x5750}}}} ),
spell_scroll_objtype_limits( { { // TODO: Comment those objtypes :D
{ { 0x1F2D, 0x1F6C } },
{ { 0x2260, 0x226F } },
{ { 0x2270, 0x227C } },
{ { 0x2D9E, 0x2DAD } },
{ { 0x238D, 0x2392 } },
{ { 0x23A1, 0x23A8 } },
{ { 0x2D51, 0x2D60 } },
{ { 0x574B, 0x5750 } } } } ),
spells(),
spellcircles(),
export_scripts(),
Expand Down Expand Up @@ -271,50 +271,38 @@ void GameState::cleanup_vars()

for ( auto& realm : Realms )
{
unsigned wgridx = realm->grid_width();
unsigned wgridy = realm->grid_height();

for ( unsigned wx = 0; wx < wgridx; ++wx )
for ( const auto& p : realm->gridarea() )
{
for ( unsigned wy = 0; wy < wgridy; ++wy )
for ( auto& item : realm->getzone( p ).items )
{
for ( auto& item : realm->zone[wx][wy].items )
{
item->destroy();
}
realm->zone[wx][wy].items.clear();
item->destroy();
}
realm->getzone( p ).items.clear();
}

for ( unsigned wx = 0; wx < wgridx; ++wx )
for ( const auto& p : realm->gridarea() )
{
for ( unsigned wy = 0; wy < wgridy; ++wy )
for ( auto& chr : realm->getzone( p ).characters )
{
chr->acct.clear(); // dave added 9/27/03, see above comment re: mutual references
chr->destroy();
}
realm->getzone( p ).characters.clear();
for ( auto& chr : realm->getzone( p ).npcs )
{
for ( auto& chr : realm->zone[wx][wy].characters )
{
chr->acct.clear(); // dave added 9/27/03, see above comment re: mutual references
chr->destroy();
}
realm->zone[wx][wy].characters.clear();
for ( auto& chr : realm->zone[wx][wy].npcs )
{
chr->acct.clear(); // dave added 9/27/03, see above comment re: mutual references
chr->destroy();
}
realm->zone[wx][wy].npcs.clear();
chr->acct.clear(); // dave added 9/27/03, see above comment re: mutual references
chr->destroy();
}
realm->getzone( p ).npcs.clear();
}

for ( unsigned wx = 0; wx < wgridx; ++wx )
for ( const auto& p : realm->gridarea() )
{
for ( unsigned wy = 0; wy < wgridy; ++wy )
for ( auto& multi : realm->getzone( p ).multis )
{
for ( auto& multi : realm->zone[wx][wy].multis )
{
multi->destroy();
}
realm->zone[wx][wy].multis.clear();
multi->destroy();
}
realm->getzone( p ).multis.clear();
}
}

Expand Down
4 changes: 2 additions & 2 deletions pol-core/pol/mobile/npc.cpp
Expand Up @@ -213,7 +213,7 @@ bool NPC::npc_path_blocked( Core::UFACING fdir ) const

if ( Core::settingsManager.ssopt.mobiles_block_npc_movement )
{
for ( const auto& chr : realm()->zone[wx][wy].characters )
for ( const auto& chr : realm()->getzone( wx, wy ).characters )
{
// First check if there really is a character blocking
if ( chr->pos2d() == new_pos.xy() && chr->z() >= z() - 10 && chr->z() <= z() + 10 )
Expand All @@ -223,7 +223,7 @@ bool NPC::npc_path_blocked( Core::UFACING fdir ) const
}
}
}
for ( const auto& chr : realm()->zone[wx][wy].npcs )
for ( const auto& chr : realm()->getzone( wx, wy ).npcs )
{
// First check if there really is a character blocking
if ( chr->pos2d() == new_pos.xy() && chr->z() >= z() - 10 && chr->z() <= z() + 10 )
Expand Down
16 changes: 8 additions & 8 deletions pol-core/pol/multi/house.cpp
Expand Up @@ -698,11 +698,11 @@ bool multis_exist_in( unsigned short mywest, unsigned short mynorth, unsigned sh

Core::zone_convert_clip( mywest - 100, mynorth - 100, realm, &wxL, &wyL );
Core::zone_convert_clip( myeast + 100, mysouth + 100, realm, &wxH, &wyH );
for ( unsigned short wx = wxL; wx <= wxH; ++wx )
for ( unsigned short wy = wyL; wy <= wyH; ++wy )
{
for ( unsigned short wy = wyL; wy <= wyH; ++wy )
for ( unsigned short wx = wxL; wx <= wxH; ++wx )
{
for ( const auto& multi : realm->zone[wx][wy].multis )
for ( const auto& multi : realm->getzone( wx, wy ).multis )
{
const MultiDef& edef = multi->multidef();
// find out if any of our walls would fall within its footprint.
Expand Down Expand Up @@ -766,21 +766,21 @@ bool objects_exist_in( unsigned short x1, unsigned short y1, unsigned short x2,
}
return false;
};
for ( unsigned short wx = wxL; wx <= wxH; ++wx )
for ( unsigned short wy = wyL; wy <= wyH; ++wy )
{
for ( unsigned short wy = wyL; wy <= wyH; ++wy )
for ( unsigned short wx = wxL; wx <= wxH; ++wx )
{
for ( const auto& chr : realm->zone[wx][wy].characters )
for ( const auto& chr : realm->getzone( wx, wy ).characters )
{
if ( includes( chr ) )
return true;
}
for ( const auto& chr : realm->zone[wx][wy].npcs )
for ( const auto& chr : realm->getzone( wx, wy ).npcs )
{
if ( includes( chr ) )
return true;
}
for ( const auto& item : realm->zone[wx][wy].items )
for ( const auto& item : realm->getzone( wx, wy ).items )
{
if ( includes( item ) )
return true;
Expand Down
28 changes: 14 additions & 14 deletions pol-core/pol/realms/realm.cpp
Expand Up @@ -40,10 +40,10 @@ Realm::Realm( const std::string& realm_name, const std::string& realm_path )
size_t gridwidth = grid_width();
size_t gridheight = grid_height();

zone = new Core::Zone*[gridwidth];
zone = new Core::Zone*[gridheight];

for ( size_t i = 0; i < gridwidth; i++ )
zone[i] = new Core::Zone[gridheight];
for ( size_t i = 0; i < gridheight; i++ )
zone[i] = new Core::Zone[gridwidth];
}

Realm::Realm( const std::string& realm_name, Realm* realm )
Expand All @@ -60,16 +60,16 @@ Realm::Realm( const std::string& realm_name, Realm* realm )
size_t gridwidth = grid_width();
size_t gridheight = grid_height();

zone = new Core::Zone*[gridwidth];
zone = new Core::Zone*[gridheight];

for ( size_t i = 0; i < gridwidth; i++ )
zone[i] = new Core::Zone[gridheight];
for ( size_t i = 0; i < gridheight; i++ )
zone[i] = new Core::Zone[gridwidth];
}

Realm::~Realm()
{
size_t gridwidth = grid_width();
for ( size_t i = 0; i < gridwidth; i++ )
size_t gridheight = grid_height();
for ( size_t i = 0; i < gridheight; i++ )
delete[] zone[i];
delete[] zone;
}
Expand All @@ -82,14 +82,14 @@ size_t Realm::sizeEstimate() const
unsigned gridwidth = grid_width();
unsigned gridheight = grid_height();

for ( unsigned x = 0; x < gridwidth; ++x )
for ( unsigned y = 0; y < gridheight; ++y )
{
for ( unsigned y = 0; y < gridheight; ++y )
for ( unsigned x = 0; x < gridwidth; ++x )
{
size += 3 * sizeof( void** ) + zone[x][y].characters.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[x][y].npcs.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[x][y].items.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[x][y].multis.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[y][x].characters.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[y][x].npcs.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[y][x].items.capacity() * sizeof( void* );
size += 3 * sizeof( void** ) + zone[y][x].multis.capacity() * sizeof( void* );
}
}

Expand Down

0 comments on commit 4a5392e

Please sign in to comment.