From 31cb9ba97cfd14e80fb46a759d523d42156ab47a Mon Sep 17 00:00:00 2001 From: NotAdam Date: Thu, 31 Jan 2019 23:44:53 +1100 Subject: [PATCH] minor cleanup, some improvements to bnpc avoidance --- src/world/Actor/BNpc.cpp | 9 +++++---- src/world/Actor/Chara.cpp | 8 ++++++++ src/world/Actor/Chara.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index 7440c8cd..97dd4db9 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -90,8 +90,6 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, BNpcTemplatePtr pTemplate, float posX memcpy( m_customize, pTemplate->getCustomize(), sizeof( m_customize ) ); memcpy( m_modelEquip, pTemplate->getModelEquip(), sizeof( m_modelEquip ) ); - m_lastTickTime = 0; - auto exdData = m_pFw->get< Data::ExdDataGenerated >(); assert( exdData ); @@ -641,6 +639,9 @@ void Sapphire::Entity::BNpc::pushNearbyBNpcs() // todo: not sure what's good here auto factor = bNpc->getNaviTargetReachedDistance(); + auto delta = static_cast< float >( Util::getTimeMs() - bNpc->getLastUpdateTime() ) / 1000.f; + delta = std::min< float >( factor, delta ); + // too far away, ignore it if( distance > factor ) continue; @@ -650,9 +651,9 @@ void Sapphire::Entity::BNpc::pushNearbyBNpcs() auto x = ( cosf( angle ) ); auto z = ( sinf( angle ) ); - bNpc->setPos( pos.x + ( x * factor ), + bNpc->setPos( pos.x + ( x * factor * delta ), pos.y, - pos.z + ( z * factor ) ); + pos.z + ( z * factor * delta ) ); // setPos( m_pos.x + ( xBase * -pushDistance ), // m_pos.y, diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index ad81acf6..8002db79 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -40,6 +40,10 @@ Sapphire::Entity::Chara::Chara( ObjKind type, FrameworkPtr pFw ) : m_targetId( INVALID_GAME_OBJECT_ID64 ), m_pFw( std::move( std::move( pFw ) ) ) { + + m_lastTickTime = 0; + m_lastUpdate = 0; + // initialize the free slot queue for( uint8_t i = 0; i < MAX_STATUS_EFFECTS; i++ ) { @@ -791,3 +795,7 @@ bool Sapphire::Entity::Chara::hasStatusEffect( uint32_t id ) return m_statusEffectMap.find( id ) != m_statusEffectMap.end(); } +int64_t Sapphire::Entity::Chara::getLastUpdateTime() const +{ + return m_lastUpdate; +} diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index 896404b5..fcf38ded 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -118,6 +118,8 @@ namespace Sapphire::Entity virtual void calculateStats() {}; + int64_t getLastUpdateTime() const; + /// Status effect functions void addStatusEffect( StatusEffect::StatusEffectPtr pEffect );