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

133 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"
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
Core::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
Core::Cell::~Cell()
{
removeCharas();
}
2017-08-08 13:53:47 +02:00
void Core::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_charas.clear();
}
2017-08-08 13:53:47 +02:00
void Core::Cell::addChara( Entity::CharaPtr pAct )
{
if( pAct->isPlayer() )
++m_playerCount;
2017-08-08 13:53:47 +02:00
2018-02-21 12:48:27 +01:00
m_charas.insert( pAct );
}
2017-08-08 13:53:47 +02:00
void Core::Cell::removeChara( Entity::CharaPtr pAct )
{
if( pAct->isPlayer() )
--m_playerCount;
2017-08-08 13:53:47 +02:00
m_charas.erase(pAct);
}
2017-08-08 13:53:47 +02:00
void Core::Cell::setActivity( bool state )
{
if( !m_bActive && state )
2017-08-08 13:53:47 +02:00
{
// Move all objects to active set.
//for( auto itr = m_charas.begin(); itr != m_charas.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_charas.begin(); itr != m_charas.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 Core::Cell::removeCharas()
{
//uint32_t ltime = getMSTime();
2017-08-08 13:53:47 +02:00
m_charas.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_charas.begin(); itr != m_charas.end(); )
2017-08-08 13:53:47 +02:00
{
pAct = (*itr);
itr++;
2017-08-08 13:53:47 +02:00
if(!pAct)
2017-08-08 13:53:47 +02:00
{
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
}
m_playerCount = 0;
m_bLoaded = false;
}
2017-08-08 13:53:47 +02:00
void Core::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 Core::Cell::cancelPendingUnload()
{
if( !m_bUnloadPending )
return;
}
2017-08-08 13:53:47 +02:00
void Core::Cell::unload()
{
2017-08-08 13:53:47 +02:00
assert( m_bUnloadPending );
if( m_bActive )
return;
removeCharas();
m_bUnloadPending = false;
}