1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 15:17:46 +00:00
sapphire/src/world/Territory/Cell.cpp

134 lines
2.1 KiB
C++
Raw Normal View History

2017-08-08 13:53:47 +02:00
#include "Cell.h"
#include "Actor/Chara.h"
#include "Forwards.h"
2017-08-08 13:53:47 +02:00
#include "Zone.h"
#include <Logging/Logger.h>
2017-08-08 13:53:47 +02:00
// TODO: the entire zone / areahandling is a bit outdated ( in parts i used this for the 1.0 iteration )
// likely this could be greatly improved or redone
Sapphire::Cell::Cell() :
m_bActive( false ),
m_bLoaded( false ),
m_playerCount( 0 ),
m_bUnloadPending( false )
{
m_bForcedActive = false;
}
2017-08-08 13:53:47 +02:00
Sapphire::Cell::~Cell()
{
removeActors();
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::init( uint32_t x, uint32_t y, ZonePtr pZone )
{
m_pZone = pZone;
m_posX = x;
m_posY = y;
2017-08-08 13:53:47 +02:00
m_actors.clear();
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::addActor( Entity::ActorPtr pAct )
{
if( pAct->isPlayer() )
++m_playerCount;
2017-08-08 13:53:47 +02:00
m_actors.insert( pAct );
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::removeActor( Entity::ActorPtr pAct )
{
if( pAct->isPlayer() )
--m_playerCount;
2017-08-08 13:53:47 +02:00
m_actors.erase( pAct );
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::setActivity( bool state )
{
if( !m_bActive && state )
{
// Move all objects to active set.
//for( auto itr = m_actors.begin(); itr != m_actors.end(); ++itr )
//{
2017-08-08 13:53:47 +02:00
//}
2017-08-08 13:53:47 +02:00
if( m_bUnloadPending )
cancelPendingUnload();
2017-08-08 13:53:47 +02:00
}
else if( m_bActive && !state )
{
// Move all objects from active set.
//for(auto itr = m_actors.begin(); itr != m_actors.end(); ++itr)
//{
2017-08-08 13:53:47 +02:00
//}
2017-08-08 13:53:47 +02:00
}
2017-08-08 13:53:47 +02:00
m_bActive = state;
2017-08-08 13:53:47 +02:00
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::removeActors()
{
//uint32_t ltime = getMSTime();
2017-08-08 13:53:47 +02:00
m_actors.clear();
2017-08-08 13:53:47 +02:00
//This time it's simpler! We just remove everything
Entity::ActorPtr pAct; //do this outside the loop!
for( auto itr = m_actors.begin(); itr != m_actors.end(); )
{
pAct = ( *itr );
itr++;
2017-08-08 13:53:47 +02:00
if( !pAct )
{
continue;
}
2017-08-08 13:53:47 +02:00
if( m_bUnloadPending )
{
2017-08-08 13:53:47 +02:00
}
2017-08-08 13:53:47 +02:00
}
2017-08-08 13:53:47 +02:00
m_playerCount = 0;
m_bLoaded = false;
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::queueUnloadPending()
{
if( m_bUnloadPending )
return;
2017-08-08 13:53:47 +02:00
m_bUnloadPending = true;
2017-08-08 13:53:47 +02:00
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::cancelPendingUnload()
{
if( !m_bUnloadPending )
return;
}
2017-08-08 13:53:47 +02:00
void Sapphire::Cell::unload()
{
2017-08-08 13:53:47 +02:00
assert( m_bUnloadPending );
if( m_bActive )
return;
removeActors();
m_bUnloadPending = false;
}