1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 07:07:45 +00:00

Merge pull request #551 from NotAdam/crowd

correctly calculate deltatime, set agent flags on dormant bnpcs
This commit is contained in:
Mordred 2019-04-20 15:05:53 +02:00 committed by GitHub
commit 9620e5fb05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 20 deletions

View file

@ -228,7 +228,6 @@ void Sapphire::Entity::BNpc::step()
bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos ) bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
{ {
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = m_pCurrentZone->getNaviProvider(); auto pNaviProvider = m_pCurrentZone->getNaviProvider();
if( !pNaviProvider ) if( !pNaviProvider )
@ -239,21 +238,24 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
return false; return false;
} }
pNaviProvider->addAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
auto pos1 = pNaviProvider->getMovePos( *this ); auto pos1 = pNaviProvider->getMovePos( *this );
if( Util::distance( pos1, pos ) < ( getScale() / 2 ) ) if( Util::distance( pos1, pos ) < getScale() )
{ {
// Reached destination // Reached destination
face( pos1 ); face( pos );
setPos( pos1 ); setPos( pos1 );
sendPositionUpdate(); sendPositionUpdate();
//pNaviProvider->resetMoveTarget( *this ); //pNaviProvider->resetMoveTarget( *this );
pNaviProvider->updateAgentPosition( *this ); pNaviProvider->updateAgentPosition( *this );
pNaviProvider->removeAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
return true; return true;
} }
m_pCurrentZone->updateActorPosition( *this ); m_pCurrentZone->updateActorPosition( *this );
face( pos1 ); face( pos );
setPos( pos1 ); setPos( pos1 );
sendPositionUpdate(); sendPositionUpdate();
return false; return false;
@ -262,7 +264,6 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara ) bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
{ {
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = m_pCurrentZone->getNaviProvider(); auto pNaviProvider = m_pCurrentZone->getNaviProvider();
if( !pNaviProvider ) if( !pNaviProvider )
@ -273,21 +274,24 @@ bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
return false; return false;
} }
pNaviProvider->addAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
auto pos1 = pNaviProvider->getMovePos( *this ); auto pos1 = pNaviProvider->getMovePos( *this );
if( Util::distance( pos1, targetChara.getPos() ) <= ( ( getScale() / 2 + targetChara.getScale() / 2 ) ) ) if( Util::distance( pos1, targetChara.getPos() ) <= ( getScale() + targetChara.getScale() ) )
{ {
// Reached destination // Reached destination
face( pos1 ); face( targetChara.getPos() );
setPos( pos1 ); setPos( pos1 );
sendPositionUpdate(); sendPositionUpdate();
//pNaviProvider->resetMoveTarget( *this ); //pNaviProvider->resetMoveTarget( *this );
pNaviProvider->updateAgentPosition( *this ); pNaviProvider->updateAgentPosition( *this );
pNaviProvider->removeAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
return true; return true;
} }
m_pCurrentZone->updateActorPosition( *this ); m_pCurrentZone->updateActorPosition( *this );
face( pos1 ); face( targetChara.getPos() );
setPos( pos1 ); setPos( pos1 );
sendPositionUpdate(); sendPositionUpdate();
return false; return false;
@ -446,7 +450,6 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
const uint8_t maxDistanceToOrigin = 40; const uint8_t maxDistanceToOrigin = 40;
const uint32_t roamTick = 20; const uint32_t roamTick = 20;
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
auto pNaviProvider = m_pCurrentZone->getNaviProvider(); auto pNaviProvider = m_pCurrentZone->getNaviProvider();
switch( m_state ) switch( m_state )

View file

@ -137,7 +137,6 @@ namespace Sapphire::Entity
uint32_t m_flags; uint32_t m_flags;
float m_scale;
float m_naviTargetReachedDistance; float m_naviTargetReachedDistance;
uint32_t m_timeOfDeath; uint32_t m_timeOfDeath;

View file

@ -570,12 +570,12 @@ int32_t Sapphire::World::Navi::NaviProvider::addAgent( Entity::Chara& chara )
{ {
dtCrowdAgentParams params; dtCrowdAgentParams params;
std::memset( &params, 0, sizeof( params ) ); std::memset( &params, 0, sizeof( params ) );
params.height = 7.f; params.height = 3.f;
params.maxAcceleration = 126.f; params.maxAcceleration = 25.f;
params.maxSpeed = 13.5f; params.maxSpeed = std::pow( 2, chara.getScale() * 0.35f ) + 1.f;
params.radius = chara.getScale() / 2; params.radius = chara.getScale() / 2;
params.collisionQueryRange = params.radius * 20.0f; params.collisionQueryRange = params.radius * 12.0f;
params.pathOptimizationRange = params.radius * 10.0f; params.pathOptimizationRange = params.radius * 20.0f;
params.updateFlags = 0; params.updateFlags = 0;
//params.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE; //params.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE;
float position[] = { chara.getPos().x, chara.getPos().y, chara.getPos().z }; float position[] = { chara.getPos().x, chara.getPos().y, chara.getPos().z };
@ -664,4 +664,24 @@ bool Sapphire::World::Navi::NaviProvider::syncPosToChara( Entity::Chara& chara )
chara.setPos( pos ); chara.setPos( pos );
return true; return true;
}
void Sapphire::World::Navi::NaviProvider::addAgentUpdateFlag( Sapphire::Entity::Chara& chara, uint8_t flags )
{
auto ag = m_pCrowd->getEditableAgent( chara.getAgentId() );
if( !ag )
return;
ag->params.updateFlags |= flags;
}
void Sapphire::World::Navi::NaviProvider::removeAgentUpdateFlag( Sapphire::Entity::Chara& chara, uint8_t flags )
{
auto ag = m_pCrowd->getEditableAgent( chara.getAgentId() );
if( !ag )
return;
ag->params.updateFlags &= ~flags;
} }

View file

@ -69,6 +69,9 @@ namespace Sapphire::World::Navi
bool syncPosToChara( Entity::Chara& chara ); bool syncPosToChara( Entity::Chara& chara );
void addAgentUpdateFlag( Entity::Chara& chara, uint8_t flags );
void removeAgentUpdateFlag( Entity::Chara& chara, uint8_t flags );
protected: protected:
std::string m_internalName; std::string m_internalName;

View file

@ -159,6 +159,8 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >(); auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
pScriptMgr->onInstanceUpdate( getAsInstanceContent(), tickCount ); pScriptMgr->onInstanceUpdate( getAsInstanceContent(), tickCount );
m_lastUpdate = tickCount;
} }
void Sapphire::InstanceContent::onFinishLoading( Entity::Player& player ) void Sapphire::InstanceContent::onFinishLoading( Entity::Player& player )

View file

@ -159,6 +159,8 @@ void Sapphire::QuestBattle::onUpdate( uint64_t tickCount )
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >(); auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
pScriptMgr->onInstanceUpdate( getAsQuestBattle(), tickCount ); pScriptMgr->onInstanceUpdate( getAsQuestBattle(), tickCount );
m_lastUpdate = tickCount;
} }
void Sapphire::QuestBattle::onFinishLoading( Entity::Player& player ) void Sapphire::QuestBattle::onFinishLoading( Entity::Player& player )

View file

@ -19,7 +19,7 @@
#include "InstanceContent.h" #include "InstanceContent.h"
#include "QuestBattle.h" #include "QuestBattle.h"
#include "Manager/TerritoryMgr.h" #include "Manager/TerritoryMgr.h"
#include "Navi/Naviprovider.h" #include "Navi/NaviProvider.h"
#include "Session.h" #include "Session.h"
#include "Actor/Chara.h" #include "Actor/Chara.h"
@ -473,17 +473,21 @@ bool Sapphire::Zone::update( uint64_t tickCount )
//TODO: this should be moved to a updateWeather call and pulled out of updateSessions //TODO: this should be moved to a updateWeather call and pulled out of updateSessions
bool changedWeather = checkWeather(); bool changedWeather = checkWeather();
auto dt = std::difftime( tickCount, m_lastUpdate ) / 1000.f;
if( m_pNaviProvider ) if( m_pNaviProvider )
m_pNaviProvider->updateCrowd( 0.02f ); m_pNaviProvider->updateCrowd( dt );
updateSessions( tickCount, changedWeather ); updateSessions( tickCount, changedWeather );
onUpdate( tickCount ); onUpdate( tickCount );
updateSpawnPoints(); updateSpawnPoints();
if( m_playerMap.size() > 0 ) if( !m_playerMap.empty() )
m_lastActivityTime = tickCount; m_lastActivityTime = tickCount;
m_lastUpdate = tickCount;
return true; return true;
} }
@ -508,8 +512,6 @@ void Sapphire::Zone::updateSessions( uint64_t tickCount, bool changedWeather )
return; return;
} }
m_lastUpdate = tickCount;
if( changedWeather ) if( changedWeather )
{ {
auto weatherChangePacket = makeZonePacket< FFXIVIpcWeatherChange >( pPlayer->getId() ); auto weatherChangePacket = makeZonePacket< FFXIVIpcWeatherChange >( pPlayer->getId() );