mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +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.
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#ifndef OPENMW_COMPONENTS_MISC_RNG_H
|
|
#define OPENMW_COMPONENTS_MISC_RNG_H
|
|
|
|
#include <cassert>
|
|
#include <random>
|
|
|
|
namespace Misc
|
|
{
|
|
|
|
/*
|
|
Provides central implementation of the RNG logic
|
|
*/
|
|
class Rng
|
|
{
|
|
public:
|
|
class Seed
|
|
{
|
|
std::mt19937 mGenerator;
|
|
public:
|
|
Seed();
|
|
Seed(const Seed&) = delete;
|
|
Seed(unsigned int seed);
|
|
friend class Rng;
|
|
};
|
|
|
|
static Seed& getSeed();
|
|
|
|
/// seed the RNG
|
|
static void init(unsigned int seed = generateDefaultSeed());
|
|
|
|
/// return value in range [0.0f, 1.0f) <- note open upper range.
|
|
static float rollProbability(Seed& seed = getSeed());
|
|
|
|
/// return value in range [0.0f, 1.0f] <- note closed upper range.
|
|
static float rollClosedProbability(Seed& seed = getSeed());
|
|
|
|
/// return value in range [0, max) <- note open upper range.
|
|
static int rollDice(int max, Seed& seed = getSeed());
|
|
|
|
/// return value in range [0, 99]
|
|
static int roll0to99(Seed& seed = getSeed()) { return rollDice(100, seed); }
|
|
|
|
/// returns default seed for RNG
|
|
static unsigned int generateDefaultSeed();
|
|
|
|
static float deviate(float mean, float deviation, Seed& seed = getSeed());
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|