1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 03:15:32 +00:00

Separate engage combat timer for each actor

Use DeviatingPeriodicTimer to distribute calls over time. This reduces
stuttering and make AI more natural.
This commit is contained in:
elsid 2021-03-20 01:50:51 +01:00
parent 675c0ab72f
commit 62c0ecbbd0
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 11 additions and 5 deletions

View file

@ -5,6 +5,8 @@
#include "../mwmechanics/actorutil.hpp"
#include <components/misc/timer.hpp>
namespace MWRender
{
class Animation;
@ -41,12 +43,18 @@ namespace MWMechanics
bool isTurningToPlayer() const;
void setTurningToPlayer(bool turning);
Misc::TimerStatus updateEngageCombatTimer(float duration)
{
return mEngageCombat.update(duration);
}
private:
std::unique_ptr<CharacterController> mCharacterController;
int mGreetingTimer{0};
float mTargetAngleRadians{0.f};
GreetingState mGreetingState{Greet_None};
bool mIsTurningToPlayer{false};
Misc::DeviatingPeriodicTimer mEngageCombat{1.0f, 0.25f, Misc::Rng::deviate(0, 0.25f)};
};
}

View file

@ -1901,14 +1901,11 @@ namespace MWMechanics
{
if(!paused)
{
static float timerUpdateAITargets = 0;
static float timerUpdateHeadTrack = 0;
static float timerUpdateEquippedLight = 0;
static float timerUpdateHello = 0;
const float updateEquippedLightInterval = 1.0f;
// target lists get updated once every 1.0 sec
if (timerUpdateAITargets >= 1.0f) timerUpdateAITargets = 0;
if (timerUpdateHeadTrack >= 0.3f) timerUpdateHeadTrack = 0;
if (timerUpdateHello >= 0.25f) timerUpdateHello = 0;
if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0;
@ -1961,6 +1958,8 @@ namespace MWMechanics
iter->first.getClass().getCreatureStats(iter->first).getActiveSpells().update(duration);
const Misc::TimerStatus engageCombatTimerStatus = iter->second->updateEngageCombatTimer(duration);
// For dead actors we need to update looping spell particles
if (iter->first.getClass().getCreatureStats(iter->first).isDead())
{
@ -1989,7 +1988,7 @@ namespace MWMechanics
}
if (aiActive && inProcessingRange)
{
if (timerUpdateAITargets == 0)
if (engageCombatTimerStatus == Misc::TimerStatus::Elapsed)
{
if (!isPlayer)
adjustCommandedActor(iter->first);
@ -2076,7 +2075,6 @@ namespace MWMechanics
if (avoidCollisions)
predictAndAvoidCollisions();
timerUpdateAITargets += duration;
timerUpdateHeadTrack += duration;
timerUpdateEquippedLight += duration;
timerUpdateHello += duration;