1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-04 09:47:46 +00:00

More transitional work towards actors as base

This commit is contained in:
Mordred 2018-02-22 22:15:32 +01:00
parent 8b5d30802d
commit d05f523eb9
5 changed files with 66 additions and 66 deletions

View file

@ -227,8 +227,8 @@ namespace Packets {
OutOfRangeEventHandler = 0x014B, // updated 4.2 OutOfRangeEventHandler = 0x014B, // updated 4.2
EnterTeriEventHandler = 0x014C, // updated 4.2 EnterTeriEventHandler = 0x014C, // updated 4.2
ReturnEventHandler = 0x0151, // updated 4.2 ? ReturnEventHandler = 0x0151, // updated 4.2
TradeReturnEventHandler = 0x0152, // updated 4.2 ? TradeReturnEventHandler = 0x0152, // updated 4.2
LinkshellEventHandler = 0x0144, // updated 4.1 ?? LinkshellEventHandler = 0x0144, // updated 4.1 ??

View file

@ -18,7 +18,7 @@ Core::Cell::Cell() :
Core::Cell::~Cell() Core::Cell::~Cell()
{ {
removeCharas(); removeActors();
} }
void Core::Cell::init( uint32_t x, uint32_t y, ZonePtr pZone ) void Core::Cell::init( uint32_t x, uint32_t y, ZonePtr pZone )
@ -27,23 +27,23 @@ void Core::Cell::init( uint32_t x, uint32_t y, ZonePtr pZone )
m_posX = x; m_posX = x;
m_posY = y; m_posY = y;
m_charas.clear(); m_actors.clear();
} }
void Core::Cell::addChara( Entity::CharaPtr pAct ) void Core::Cell::addActor( Entity::ActorPtr pAct )
{ {
if( pAct->isPlayer() ) if( pAct->isPlayer() )
++m_playerCount; ++m_playerCount;
m_charas.insert( pAct ); m_actors.insert( pAct );
} }
void Core::Cell::removeChara( Entity::CharaPtr pAct ) void Core::Cell::removeActor( Entity::ActorPtr pAct )
{ {
if( pAct->isPlayer() ) if( pAct->isPlayer() )
--m_playerCount; --m_playerCount;
m_charas.erase(pAct); m_actors.erase( pAct );
} }
void Core::Cell::setActivity( bool state ) void Core::Cell::setActivity( bool state )
@ -51,7 +51,7 @@ void Core::Cell::setActivity( bool state )
if( !m_bActive && state ) if( !m_bActive && state )
{ {
// Move all objects to active set. // Move all objects to active set.
//for( auto itr = m_charas.begin(); itr != m_charas.end(); ++itr ) //for( auto itr = m_actors.begin(); itr != m_actors.end(); ++itr )
//{ //{
//} //}
@ -63,7 +63,7 @@ void Core::Cell::setActivity( bool state )
else if( m_bActive && !state ) else if( m_bActive && !state )
{ {
// Move all objects from active set. // Move all objects from active set.
//for(auto itr = m_charas.begin(); itr != m_charas.end(); ++itr) //for(auto itr = m_actors.begin(); itr != m_actors.end(); ++itr)
//{ //{
//} //}
@ -75,15 +75,15 @@ void Core::Cell::setActivity( bool state )
} }
void Core::Cell::removeCharas() void Core::Cell::removeActors()
{ {
//uint32_t ltime = getMSTime(); //uint32_t ltime = getMSTime();
m_charas.clear(); m_actors.clear();
//This time it's simpler! We just remove everything //This time it's simpler! We just remove everything
Entity::ActorPtr pAct; //do this outside the loop! Entity::ActorPtr pAct; //do this outside the loop!
for( auto itr = m_charas.begin(); itr != m_charas.end(); ) for( auto itr = m_actors.begin(); itr != m_actors.end(); )
{ {
pAct = (*itr); pAct = (*itr);
itr++; itr++;
@ -126,7 +126,7 @@ void Core::Cell::unload()
if( m_bActive ) if( m_bActive )
return; return;
removeCharas(); removeActors();
m_bUnloadPending = false; m_bUnloadPending = false;
} }

View file

@ -9,7 +9,7 @@
namespace Core { namespace Core {
typedef std::set< Entity::CharaPtr > CharaSet; typedef std::set< Entity::ActorPtr > ActorSet;
class Cell class Cell
{ {
@ -19,7 +19,7 @@ namespace Core {
bool m_bForcedActive; bool m_bForcedActive;
uint16_t m_posX; uint16_t m_posX;
uint16_t m_posY; uint16_t m_posY;
CharaSet m_charas; ActorSet m_actors;
bool m_bActive; bool m_bActive;
bool m_bLoaded; bool m_bLoaded;
bool m_bUnloadPending; bool m_bUnloadPending;
@ -33,13 +33,13 @@ namespace Core {
void init( uint32_t x, uint32_t y, ZonePtr pZone ); void init( uint32_t x, uint32_t y, ZonePtr pZone );
void addChara( Entity::CharaPtr pAct ); void addActor( Entity::ActorPtr pAct );
void removeChara( Entity::CharaPtr pAct ); void removeActor( Entity::ActorPtr pAct );
bool hasChara( Entity::CharaPtr pAct ) bool hasActor( Entity::ActorPtr pAct )
{ {
return (m_charas.find(pAct) != m_charas.end()); return ( m_actors.find(pAct) != m_actors.end() );
} }
bool hasPlayers() const bool hasPlayers() const
@ -47,21 +47,21 @@ namespace Core {
return ((m_playerCount > 0) ? true : false); return ((m_playerCount > 0) ? true : false);
} }
size_t getCharaCount() const size_t getActorCount() const
{ {
return m_charas.size(); return m_actors.size();
} }
void removeCharas(); void removeActors();
CharaSet::iterator begin() ActorSet::iterator begin()
{ {
return m_charas.begin(); return m_actors.begin();
} }
CharaSet::iterator end() ActorSet::iterator end()
{ {
return m_charas.end(); return m_actors.end();
} }
void setActivity(bool state); void setActivity(bool state);

View file

@ -168,10 +168,10 @@ Weather Core::Zone::getNextWeather()
return Weather::FairSkies; return Weather::FairSkies;
} }
void Core::Zone::pushActor( Entity::CharaPtr pChara ) void Core::Zone::pushActor( Entity::ActorPtr pActor )
{ {
float mx = pChara->getPos().x; float mx = pActor->getPos().x;
float my = pChara->getPos().z; float my = pActor->getPos().z;
uint32_t cx = getPosX( mx ); uint32_t cx = getPosX( mx );
uint32_t cy = getPosY( my ); uint32_t cy = getPosY( my );
@ -182,12 +182,12 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara )
pCell->init( cx, cy, shared_from_this() ); pCell->init( cx, cy, shared_from_this() );
} }
pCell->addChara(pChara); pCell->addActor( pActor );
pChara->setCell( pCell ); pActor->setCell( pCell );
uint32_t cellX = getPosX( pChara->getPos().x ); uint32_t cellX = getPosX( pActor->getPos().x );
uint32_t cellY = getPosY( pChara->getPos().z ); uint32_t cellY = getPosY( pActor->getPos().z );
uint32_t endX = cellX <= _sizeX ? cellX + 1 : ( _sizeX - 1 ); uint32_t endX = cellX <= _sizeX ? cellX + 1 : ( _sizeX - 1 );
uint32_t endY = cellY <= _sizeY ? cellY + 1 : ( _sizeY - 1 ); uint32_t endY = cellY <= _sizeY ? cellY + 1 : ( _sizeY - 1 );
@ -201,13 +201,13 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara )
{ {
pCell = getCellPtr(posX, posY); pCell = getCellPtr(posX, posY);
if( pCell ) if( pCell )
updateInRangeSet( pChara, pCell ); updateInRangeSet( pActor, pCell );
} }
} }
if( pChara->isPlayer() ) if( pActor->isPlayer() )
{ {
auto pPlayer = pChara->getAsPlayer(); auto pPlayer = pActor->getAsPlayer();
auto pSession = g_serverZone.getSession( pPlayer->getId() ); auto pSession = g_serverZone.getSession( pPlayer->getId() );
if( pSession ) if( pSession )
@ -217,36 +217,36 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara )
} }
} }
void Core::Zone::removeActor( Entity::CharaPtr pChara ) void Core::Zone::removeActor( Entity::ActorPtr pActor )
{ {
auto pCell = pChara->getCellPtr(); auto pCell = pActor->getCellPtr();
if( pCell ) if( pCell )
{ {
pCell->removeChara(pChara); pCell->removeActor( pActor );
pCell = nullptr; pCell = nullptr;
} }
if( pChara->isPlayer() ) if( pActor->isPlayer() )
{ {
// If it's a player and he's inside boundaries - update his nearby cells // If it's a player and he's inside boundaries - update his nearby cells
if( pChara->getPos().x <= _maxX && pChara->getPos().x >= _minX && if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX &&
pChara->getPos().z <= _maxY && pChara->getPos().z >= _minY ) pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY )
{ {
uint32_t x = getPosX( pChara->getPos().x ); uint32_t x = getPosX( pActor->getPos().x );
uint32_t y = getPosY( pChara->getPos().z ); uint32_t y = getPosY( pActor->getPos().z );
updateCellActivity( x, y, 3 ); updateCellActivity( x, y, 3 );
} }
m_playerMap.erase( pChara->getId() ); m_playerMap.erase( pActor->getId() );
onLeaveTerritory( *pChara->getAsPlayer() ); onLeaveTerritory( *pActor->getAsPlayer() );
} }
// remove from lists of other actors // remove from lists of other actors
pChara->removeFromInRange(); pActor->removeFromInRange();
pChara->clearInRangeSet(); pActor->clearInRangeSet();
} }
@ -534,9 +534,9 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor )
{ {
if( pOldCell ) if( pOldCell )
pOldCell->removeChara(actor.getAsChara()); pOldCell->removeActor( actor.shared_from_this() );
pCell->addChara( actor.getAsChara() ); pCell->addActor( actor.shared_from_this() );
pOldCell = pCell; pOldCell = pCell;
// if player we need to update cell activity // if player we need to update cell activity
@ -568,13 +568,13 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor )
{ {
pCell = getCellPtr(posX, posY); pCell = getCellPtr(posX, posY);
if( pCell ) if( pCell )
updateInRangeSet( actor.getAsChara(), pCell ); updateInRangeSet( actor.shared_from_this(), pCell );
} }
} }
} }
void Core::Zone::updateInRangeSet( Entity::CharaPtr pChara, Cell* pCell ) void Core::Zone::updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell )
{ {
if( pCell == nullptr ) if( pCell == nullptr )
return; return;
@ -583,36 +583,36 @@ void Core::Zone::updateInRangeSet( Entity::CharaPtr pChara, Cell* pCell )
if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) ) if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) )
return; return;
auto iter = pCell->m_charas.begin(); auto iter = pCell->m_actors.begin();
float fRange = 70.0f; float fRange = 70.0f;
int32_t count = 0; int32_t count = 0;
while( iter != pCell->m_charas.end() ) while( iter != pCell->m_actors.end() )
{ {
auto pCurAct = *iter; auto pCurAct = *iter;
++iter; ++iter;
if( !pCurAct || pCurAct == pChara ) if( !pCurAct || pCurAct == pActor )
continue; continue;
float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z, float distance = Math::Util::distance( pCurAct->getPos().x, pCurAct->getPos().y, pCurAct->getPos().z,
pChara->getPos().x, pChara->getPos().y, pChara->getPos().z ); pActor->getPos().x, pActor->getPos().y, pActor->getPos().z );
bool isInRange = ( fRange == 0.0f || distance <= fRange ); bool isInRange = ( fRange == 0.0f || distance <= fRange );
bool isInRangeSet = pChara->isInRangeSet( pCurAct ); bool isInRangeSet = pActor->isInRangeSet( pCurAct );
// Add if range == 0 or distance is withing range. // Add if range == 0 or distance is withing range.
if( isInRange && !isInRangeSet ) if( isInRange && !isInRangeSet )
{ {
if( pChara->isPlayer() && !pChara->getAsPlayer()->isLoadingComplete() ) if( pActor->isPlayer() && !pActor->getAsPlayer()->isLoadingComplete() )
continue; continue;
if( pCurAct->isPlayer() && !pCurAct->getAsPlayer()->isLoadingComplete() ) if( pCurAct->isPlayer() && !pCurAct->getAsPlayer()->isLoadingComplete() )
continue; continue;
pChara->addInRangeActor( pCurAct ); pActor->addInRangeActor( pCurAct );
pCurAct->addInRangeActor( pChara ); pCurAct->addInRangeActor( pActor );
// this is a hack to limit actor spawn in one packetset // this is a hack to limit actor spawn in one packetset
if( count++ > 12 ) if( count++ > 12 )
@ -620,8 +620,8 @@ void Core::Zone::updateInRangeSet( Entity::CharaPtr pChara, Cell* pCell )
} }
else if( !isInRange && isInRangeSet ) else if( !isInRange && isInRangeSet )
{ {
pCurAct->removeInRangeActor( *pChara ); pCurAct->removeInRangeActor( *pActor );
pChara->removeInRangeActor( *pCurAct ); pActor->removeInRangeActor( *pCurAct );
} }
} }
} }

View file

@ -74,9 +74,9 @@ public:
Common::Weather getNextWeather(); Common::Weather getNextWeather();
void pushActor( Entity::CharaPtr pActor ); void pushActor( Entity::ActorPtr pActor );
void removeActor( Entity::CharaPtr pActor ); void removeActor( Entity::ActorPtr pActor );
void updateActorPosition( Entity::Actor &pActor ); void updateActorPosition( Entity::Actor &pActor );
@ -84,7 +84,7 @@ public:
void updateCellActivity( uint32_t x, uint32_t y, int32_t radius ); void updateCellActivity( uint32_t x, uint32_t y, int32_t radius );
void updateInRangeSet( Entity::CharaPtr pActor, Cell* pCell ); void updateInRangeSet( Entity::ActorPtr pActor, Cell* pCell );
void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry ); void queueOutPacketForRange( Entity::Player& sourcePlayer, uint32_t range, Network::Packets::GamePacketPtr pPacketEntry );