mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 16:15:31 +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:
parent
675c0ab72f
commit
62c0ecbbd0
2 changed files with 11 additions and 5 deletions
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include "../mwmechanics/actorutil.hpp"
|
#include "../mwmechanics/actorutil.hpp"
|
||||||
|
|
||||||
|
#include <components/misc/timer.hpp>
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
class Animation;
|
class Animation;
|
||||||
|
@ -41,12 +43,18 @@ namespace MWMechanics
|
||||||
bool isTurningToPlayer() const;
|
bool isTurningToPlayer() const;
|
||||||
void setTurningToPlayer(bool turning);
|
void setTurningToPlayer(bool turning);
|
||||||
|
|
||||||
|
Misc::TimerStatus updateEngageCombatTimer(float duration)
|
||||||
|
{
|
||||||
|
return mEngageCombat.update(duration);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<CharacterController> mCharacterController;
|
std::unique_ptr<CharacterController> mCharacterController;
|
||||||
int mGreetingTimer{0};
|
int mGreetingTimer{0};
|
||||||
float mTargetAngleRadians{0.f};
|
float mTargetAngleRadians{0.f};
|
||||||
GreetingState mGreetingState{Greet_None};
|
GreetingState mGreetingState{Greet_None};
|
||||||
bool mIsTurningToPlayer{false};
|
bool mIsTurningToPlayer{false};
|
||||||
|
Misc::DeviatingPeriodicTimer mEngageCombat{1.0f, 0.25f, Misc::Rng::deviate(0, 0.25f)};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1901,14 +1901,11 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
if(!paused)
|
if(!paused)
|
||||||
{
|
{
|
||||||
static float timerUpdateAITargets = 0;
|
|
||||||
static float timerUpdateHeadTrack = 0;
|
static float timerUpdateHeadTrack = 0;
|
||||||
static float timerUpdateEquippedLight = 0;
|
static float timerUpdateEquippedLight = 0;
|
||||||
static float timerUpdateHello = 0;
|
static float timerUpdateHello = 0;
|
||||||
const float updateEquippedLightInterval = 1.0f;
|
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 (timerUpdateHeadTrack >= 0.3f) timerUpdateHeadTrack = 0;
|
||||||
if (timerUpdateHello >= 0.25f) timerUpdateHello = 0;
|
if (timerUpdateHello >= 0.25f) timerUpdateHello = 0;
|
||||||
if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0;
|
if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0;
|
||||||
|
@ -1961,6 +1958,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
iter->first.getClass().getCreatureStats(iter->first).getActiveSpells().update(duration);
|
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
|
// For dead actors we need to update looping spell particles
|
||||||
if (iter->first.getClass().getCreatureStats(iter->first).isDead())
|
if (iter->first.getClass().getCreatureStats(iter->first).isDead())
|
||||||
{
|
{
|
||||||
|
@ -1989,7 +1988,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
if (aiActive && inProcessingRange)
|
if (aiActive && inProcessingRange)
|
||||||
{
|
{
|
||||||
if (timerUpdateAITargets == 0)
|
if (engageCombatTimerStatus == Misc::TimerStatus::Elapsed)
|
||||||
{
|
{
|
||||||
if (!isPlayer)
|
if (!isPlayer)
|
||||||
adjustCommandedActor(iter->first);
|
adjustCommandedActor(iter->first);
|
||||||
|
@ -2076,7 +2075,6 @@ namespace MWMechanics
|
||||||
if (avoidCollisions)
|
if (avoidCollisions)
|
||||||
predictAndAvoidCollisions();
|
predictAndAvoidCollisions();
|
||||||
|
|
||||||
timerUpdateAITargets += duration;
|
|
||||||
timerUpdateHeadTrack += duration;
|
timerUpdateHeadTrack += duration;
|
||||||
timerUpdateEquippedLight += duration;
|
timerUpdateEquippedLight += duration;
|
||||||
timerUpdateHello += duration;
|
timerUpdateHello += duration;
|
||||||
|
|
Loading…
Reference in a new issue