mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-04 01:37:47 +00:00
More transitional work towards actors as base
This commit is contained in:
parent
8b5d30802d
commit
d05f523eb9
5 changed files with 66 additions and 66 deletions
|
@ -227,8 +227,8 @@ namespace Packets {
|
|||
OutOfRangeEventHandler = 0x014B, // updated 4.2
|
||||
EnterTeriEventHandler = 0x014C, // updated 4.2
|
||||
|
||||
ReturnEventHandler = 0x0151, // updated 4.2 ?
|
||||
TradeReturnEventHandler = 0x0152, // updated 4.2 ?
|
||||
ReturnEventHandler = 0x0151, // updated 4.2
|
||||
TradeReturnEventHandler = 0x0152, // updated 4.2
|
||||
|
||||
|
||||
LinkshellEventHandler = 0x0144, // updated 4.1 ??
|
||||
|
|
|
@ -18,7 +18,7 @@ Core::Cell::Cell() :
|
|||
|
||||
Core::Cell::~Cell()
|
||||
{
|
||||
removeCharas();
|
||||
removeActors();
|
||||
}
|
||||
|
||||
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_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() )
|
||||
++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() )
|
||||
--m_playerCount;
|
||||
|
||||
m_charas.erase(pAct);
|
||||
m_actors.erase( pAct );
|
||||
}
|
||||
|
||||
void Core::Cell::setActivity( bool state )
|
||||
|
@ -51,7 +51,7 @@ void Core::Cell::setActivity( bool state )
|
|||
if( !m_bActive && state )
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
// 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();
|
||||
|
||||
m_charas.clear();
|
||||
m_actors.clear();
|
||||
|
||||
//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(); )
|
||||
for( auto itr = m_actors.begin(); itr != m_actors.end(); )
|
||||
{
|
||||
pAct = (*itr);
|
||||
itr++;
|
||||
|
@ -126,7 +126,7 @@ void Core::Cell::unload()
|
|||
if( m_bActive )
|
||||
return;
|
||||
|
||||
removeCharas();
|
||||
removeActors();
|
||||
m_bUnloadPending = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
typedef std::set< Entity::CharaPtr > CharaSet;
|
||||
typedef std::set< Entity::ActorPtr > ActorSet;
|
||||
|
||||
class Cell
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ namespace Core {
|
|||
bool m_bForcedActive;
|
||||
uint16_t m_posX;
|
||||
uint16_t m_posY;
|
||||
CharaSet m_charas;
|
||||
ActorSet m_actors;
|
||||
bool m_bActive;
|
||||
bool m_bLoaded;
|
||||
bool m_bUnloadPending;
|
||||
|
@ -33,13 +33,13 @@ namespace Core {
|
|||
|
||||
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
|
||||
|
@ -47,21 +47,21 @@ namespace Core {
|
|||
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);
|
||||
|
|
|
@ -168,10 +168,10 @@ Weather Core::Zone::getNextWeather()
|
|||
return Weather::FairSkies;
|
||||
}
|
||||
|
||||
void Core::Zone::pushActor( Entity::CharaPtr pChara )
|
||||
void Core::Zone::pushActor( Entity::ActorPtr pActor )
|
||||
{
|
||||
float mx = pChara->getPos().x;
|
||||
float my = pChara->getPos().z;
|
||||
float mx = pActor->getPos().x;
|
||||
float my = pActor->getPos().z;
|
||||
uint32_t cx = getPosX( mx );
|
||||
uint32_t cy = getPosY( my );
|
||||
|
||||
|
@ -182,12 +182,12 @@ void Core::Zone::pushActor( Entity::CharaPtr pChara )
|
|||
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 cellY = getPosY( pChara->getPos().z );
|
||||
uint32_t cellX = getPosX( pActor->getPos().x );
|
||||
uint32_t cellY = getPosY( pActor->getPos().z );
|
||||
|
||||
uint32_t endX = cellX <= _sizeX ? cellX + 1 : ( _sizeX - 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);
|
||||
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() );
|
||||
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 )
|
||||
{
|
||||
pCell->removeChara(pChara);
|
||||
pCell->removeActor( pActor );
|
||||
pCell = nullptr;
|
||||
}
|
||||
|
||||
if( pChara->isPlayer() )
|
||||
if( pActor->isPlayer() )
|
||||
{
|
||||
|
||||
// If it's a player and he's inside boundaries - update his nearby cells
|
||||
if( pChara->getPos().x <= _maxX && pChara->getPos().x >= _minX &&
|
||||
pChara->getPos().z <= _maxY && pChara->getPos().z >= _minY )
|
||||
if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX &&
|
||||
pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY )
|
||||
{
|
||||
uint32_t x = getPosX( pChara->getPos().x );
|
||||
uint32_t y = getPosY( pChara->getPos().z );
|
||||
uint32_t x = getPosX( pActor->getPos().x );
|
||||
uint32_t y = getPosY( pActor->getPos().z );
|
||||
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
|
||||
pChara->removeFromInRange();
|
||||
pChara->clearInRangeSet();
|
||||
pActor->removeFromInRange();
|
||||
pActor->clearInRangeSet();
|
||||
|
||||
}
|
||||
|
||||
|
@ -534,9 +534,9 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor )
|
|||
{
|
||||
|
||||
if( pOldCell )
|
||||
pOldCell->removeChara(actor.getAsChara());
|
||||
pOldCell->removeActor( actor.shared_from_this() );
|
||||
|
||||
pCell->addChara( actor.getAsChara() );
|
||||
pCell->addActor( actor.shared_from_this() );
|
||||
pOldCell = pCell;
|
||||
|
||||
// if player we need to update cell activity
|
||||
|
@ -568,13 +568,13 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor )
|
|||
{
|
||||
pCell = getCellPtr(posX, posY);
|
||||
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 )
|
||||
return;
|
||||
|
@ -583,36 +583,36 @@ void Core::Zone::updateInRangeSet( Entity::CharaPtr pChara, Cell* pCell )
|
|||
if( g_territoryMgr.isPrivateTerritory( getTerritoryId() ) )
|
||||
return;
|
||||
|
||||
auto iter = pCell->m_charas.begin();
|
||||
auto iter = pCell->m_actors.begin();
|
||||
|
||||
float fRange = 70.0f;
|
||||
int32_t count = 0;
|
||||
while( iter != pCell->m_charas.end() )
|
||||
while( iter != pCell->m_actors.end() )
|
||||
{
|
||||
auto pCurAct = *iter;
|
||||
++iter;
|
||||
|
||||
if( !pCurAct || pCurAct == pChara )
|
||||
if( !pCurAct || pCurAct == pActor )
|
||||
continue;
|
||||
|
||||
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 isInRangeSet = pChara->isInRangeSet( pCurAct );
|
||||
bool isInRangeSet = pActor->isInRangeSet( pCurAct );
|
||||
|
||||
// Add if range == 0 or distance is withing range.
|
||||
if( isInRange && !isInRangeSet )
|
||||
{
|
||||
|
||||
if( pChara->isPlayer() && !pChara->getAsPlayer()->isLoadingComplete() )
|
||||
if( pActor->isPlayer() && !pActor->getAsPlayer()->isLoadingComplete() )
|
||||
continue;
|
||||
|
||||
if( pCurAct->isPlayer() && !pCurAct->getAsPlayer()->isLoadingComplete() )
|
||||
continue;
|
||||
|
||||
pChara->addInRangeActor( pCurAct );
|
||||
pCurAct->addInRangeActor( pChara );
|
||||
pActor->addInRangeActor( pCurAct );
|
||||
pCurAct->addInRangeActor( pActor );
|
||||
|
||||
// this is a hack to limit actor spawn in one packetset
|
||||
if( count++ > 12 )
|
||||
|
@ -620,8 +620,8 @@ void Core::Zone::updateInRangeSet( Entity::CharaPtr pChara, Cell* pCell )
|
|||
}
|
||||
else if( !isInRange && isInRangeSet )
|
||||
{
|
||||
pCurAct->removeInRangeActor( *pChara );
|
||||
pChara->removeInRangeActor( *pCurAct );
|
||||
pCurAct->removeInRangeActor( *pActor );
|
||||
pActor->removeInRangeActor( *pCurAct );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,9 +74,9 @@ public:
|
|||
|
||||
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 );
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
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 );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue