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:
commit
9620e5fb05
7 changed files with 51 additions and 20 deletions
|
@ -228,7 +228,6 @@ void Sapphire::Entity::BNpc::step()
|
|||
bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
||||
{
|
||||
|
||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
||||
|
||||
if( !pNaviProvider )
|
||||
|
@ -239,21 +238,24 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
|||
return false;
|
||||
}
|
||||
|
||||
pNaviProvider->addAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
|
||||
|
||||
auto pos1 = pNaviProvider->getMovePos( *this );
|
||||
|
||||
if( Util::distance( pos1, pos ) < ( getScale() / 2 ) )
|
||||
if( Util::distance( pos1, pos ) < getScale() )
|
||||
{
|
||||
// Reached destination
|
||||
face( pos1 );
|
||||
face( pos );
|
||||
setPos( pos1 );
|
||||
sendPositionUpdate();
|
||||
//pNaviProvider->resetMoveTarget( *this );
|
||||
pNaviProvider->updateAgentPosition( *this );
|
||||
pNaviProvider->removeAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
|
||||
return true;
|
||||
}
|
||||
|
||||
m_pCurrentZone->updateActorPosition( *this );
|
||||
face( pos1 );
|
||||
face( pos );
|
||||
setPos( pos1 );
|
||||
sendPositionUpdate();
|
||||
return false;
|
||||
|
@ -262,7 +264,6 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos )
|
|||
bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
|
||||
{
|
||||
|
||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
||||
|
||||
if( !pNaviProvider )
|
||||
|
@ -273,21 +274,24 @@ bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara )
|
|||
return false;
|
||||
}
|
||||
|
||||
pNaviProvider->addAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
|
||||
|
||||
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
|
||||
face( pos1 );
|
||||
face( targetChara.getPos() );
|
||||
setPos( pos1 );
|
||||
sendPositionUpdate();
|
||||
//pNaviProvider->resetMoveTarget( *this );
|
||||
pNaviProvider->updateAgentPosition( *this );
|
||||
pNaviProvider->removeAgentUpdateFlag( *this, DT_CROWD_OBSTACLE_AVOIDANCE );
|
||||
return true;
|
||||
}
|
||||
|
||||
m_pCurrentZone->updateActorPosition( *this );
|
||||
face( pos1 );
|
||||
face( targetChara.getPos() );
|
||||
setPos( pos1 );
|
||||
sendPositionUpdate();
|
||||
return false;
|
||||
|
@ -446,7 +450,6 @@ void Sapphire::Entity::BNpc::update( uint64_t tickCount )
|
|||
const uint8_t maxDistanceToOrigin = 40;
|
||||
const uint32_t roamTick = 20;
|
||||
|
||||
auto pNaviMgr = m_pFw->get< World::Manager::NaviMgr >();
|
||||
auto pNaviProvider = m_pCurrentZone->getNaviProvider();
|
||||
|
||||
switch( m_state )
|
||||
|
|
|
@ -137,7 +137,6 @@ namespace Sapphire::Entity
|
|||
|
||||
uint32_t m_flags;
|
||||
|
||||
float m_scale;
|
||||
float m_naviTargetReachedDistance;
|
||||
|
||||
uint32_t m_timeOfDeath;
|
||||
|
|
|
@ -570,12 +570,12 @@ int32_t Sapphire::World::Navi::NaviProvider::addAgent( Entity::Chara& chara )
|
|||
{
|
||||
dtCrowdAgentParams params;
|
||||
std::memset( ¶ms, 0, sizeof( params ) );
|
||||
params.height = 7.f;
|
||||
params.maxAcceleration = 126.f;
|
||||
params.maxSpeed = 13.5f;
|
||||
params.height = 3.f;
|
||||
params.maxAcceleration = 25.f;
|
||||
params.maxSpeed = std::pow( 2, chara.getScale() * 0.35f ) + 1.f;
|
||||
params.radius = chara.getScale() / 2;
|
||||
params.collisionQueryRange = params.radius * 20.0f;
|
||||
params.pathOptimizationRange = params.radius * 10.0f;
|
||||
params.collisionQueryRange = params.radius * 12.0f;
|
||||
params.pathOptimizationRange = params.radius * 20.0f;
|
||||
params.updateFlags = 0;
|
||||
//params.updateFlags |= DT_CROWD_OBSTACLE_AVOIDANCE;
|
||||
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 );
|
||||
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;
|
||||
}
|
|
@ -69,6 +69,9 @@ namespace Sapphire::World::Navi
|
|||
|
||||
bool syncPosToChara( Entity::Chara& chara );
|
||||
|
||||
void addAgentUpdateFlag( Entity::Chara& chara, uint8_t flags );
|
||||
void removeAgentUpdateFlag( Entity::Chara& chara, uint8_t flags );
|
||||
|
||||
protected:
|
||||
std::string m_internalName;
|
||||
|
||||
|
|
|
@ -159,6 +159,8 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
|
|||
|
||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||
pScriptMgr->onInstanceUpdate( getAsInstanceContent(), tickCount );
|
||||
|
||||
m_lastUpdate = tickCount;
|
||||
}
|
||||
|
||||
void Sapphire::InstanceContent::onFinishLoading( Entity::Player& player )
|
||||
|
|
|
@ -159,6 +159,8 @@ void Sapphire::QuestBattle::onUpdate( uint64_t tickCount )
|
|||
|
||||
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
|
||||
pScriptMgr->onInstanceUpdate( getAsQuestBattle(), tickCount );
|
||||
|
||||
m_lastUpdate = tickCount;
|
||||
}
|
||||
|
||||
void Sapphire::QuestBattle::onFinishLoading( Entity::Player& player )
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "InstanceContent.h"
|
||||
#include "QuestBattle.h"
|
||||
#include "Manager/TerritoryMgr.h"
|
||||
#include "Navi/Naviprovider.h"
|
||||
#include "Navi/NaviProvider.h"
|
||||
|
||||
#include "Session.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
|
||||
bool changedWeather = checkWeather();
|
||||
|
||||
auto dt = std::difftime( tickCount, m_lastUpdate ) / 1000.f;
|
||||
|
||||
if( m_pNaviProvider )
|
||||
m_pNaviProvider->updateCrowd( 0.02f );
|
||||
m_pNaviProvider->updateCrowd( dt );
|
||||
|
||||
updateSessions( tickCount, changedWeather );
|
||||
onUpdate( tickCount );
|
||||
|
||||
updateSpawnPoints();
|
||||
|
||||
if( m_playerMap.size() > 0 )
|
||||
if( !m_playerMap.empty() )
|
||||
m_lastActivityTime = tickCount;
|
||||
|
||||
m_lastUpdate = tickCount;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -508,8 +512,6 @@ void Sapphire::Zone::updateSessions( uint64_t tickCount, bool changedWeather )
|
|||
return;
|
||||
}
|
||||
|
||||
m_lastUpdate = tickCount;
|
||||
|
||||
if( changedWeather )
|
||||
{
|
||||
auto weatherChangePacket = makeZonePacket< FFXIVIpcWeatherChange >( pPlayer->getId() );
|
||||
|
|
Loading…
Add table
Reference in a new issue