Skip to content

Draft: WIP RNG overhaul

tertu marybig requested to merge tertu/RingRacers:rng into master

Changes how RNGs work, more or less. Can't be merged right now because some things don't work right (notably: netgames).

There's a general base class, srb2::math::rng, which implements the standard C++ UniformRandomBitGenerator named requirement set plus methods that more or less correspond to the M_Random/P_Random interface. This is done because exactly how those methods are implemented has to be the same, or demos can desync.

C++ code can create rng instances whenever or wherever it would like, making it easier to add non-synchronized generators that are used for one specific purpose without making m_random.cpp more complicated, such as apparently was done with the HUD interpolation.

There are two implementations of that class:

  • srb2::math::sfc32_rng: based on the SFC32 RNG. Additionally, it implements some algorithms differently and fixes the RandomByte bug.
  • srb2::math::legacy_rng: A completely backwards-compatible implementation of the current Ring Racers RNG.

It also exposes srb2::math::default_rng, which is a type alias for srb2::math::default_rng. If a new RNG is added in the future, it can be set as default_rng and the old ones can be retained for backwards compatibility. Non-synchronized generators are always default_rng.

Old demos will be played back with legacy_rng in use. New demos explicitly save the RNG type they are using.

New rngs of both types default to being seeded by std::random_device, which I believe is usually based on whatever the "good quality OS source" (e.g. /dev/urandom) would be on a particular platform.

Some new P_Random functions have been added, and some old ones have been removed. This will be documented later.

Edited by tertu marybig

Merge request reports

Loading