mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-07 12:54:00 +00:00
675c0ab72f
This allows to distribute AI reaction calls over time. Before this change actors appearing at the same frame will react in the same frame over and over because AI reaction period is constant. It creates a non-uniform CPU usage over frames. If a single frame has too many AI reactions it may cause stuttering when there are too many actors on a scene for current system. Another concern is a synchronization of actions between creatures and NPC. They start to go or hit at the same frame that is unnatural.
27 lines
681 B
C++
27 lines
681 B
C++
#ifndef OPENMW_MECHANICS_AITIMER_H
|
|
#define OPENMW_MECHANICS_AITIMER_H
|
|
|
|
#include <components/misc/rng.hpp>
|
|
#include <components/misc/timer.hpp>
|
|
|
|
namespace MWMechanics
|
|
{
|
|
constexpr float AI_REACTION_TIME = 0.25f;
|
|
|
|
class AiReactionTimer
|
|
{
|
|
public:
|
|
static constexpr float sDeviation = 0.1f;
|
|
|
|
Misc::TimerStatus update(float duration) { return mImpl.update(duration); }
|
|
|
|
void reset() { mImpl.reset(Misc::Rng::deviate(0, sDeviation)); }
|
|
|
|
private:
|
|
Misc::DeviatingPeriodicTimer mImpl {AI_REACTION_TIME, sDeviation,
|
|
Misc::Rng::deviate(0, sDeviation)};
|
|
};
|
|
}
|
|
|
|
#endif
|