9static void s_init_rng_states(
void);
10static void s_xorshift32(u32* state);
13static u32 s_timer_acc = 0;
19 REG_TM1CNT = TM_FREQ_1 | TM_ENABLE;
24 s_timer_acc += (u32)REG_TM1D;
39 g_game_vars.rng_info.
seed = (capped_seed == 0) ?
MAX_BASE36 : capped_seed;
47static inline void s_init_rng_states(
void)
49 srand(g_game_vars.rng_info.
seed);
50 for (
enum RngSequence key = 0; key < RNG_SEQ_MAX; key++)
52 g_game_vars.rng_info.
states[key] = rand();
58 s_xorshift32(&g_game_vars.rng_info.
states[key]);
59 return g_game_vars.rng_info.
states[key];
70static inline void s_xorshift32(u32* state)
72 *(state) ^= *(state) << 13;
73 *(state) ^= *(state) >> 17;
74 *(state) ^= *(state) << 5;
79 g_game_vars.rng_info = info;
Game global game variables struct definition.
Common functions to handle RNG manipulation. Using this interface has three goals:
void rng_update(void)
Accumulates CPU cycles for RNG seed generation, call exaclty once per frame.
void rng_shuffle_seed(void)
Sets a new randomized seed for the RNG using a source of entropy.
u32 rng_get_u32(enum RngSequence key)
Get the next "randomly" generated number in the sequence corresponding to the given type.
void rng_set_seed(u32 seed)
Set the rng seed to the chosen value, and reset the step counter to 0. The seed will be capped at MAX...
RngSequence
Keys to different independent RNG sequences.
void rng_restore(RngInfo info)
Restore RNG info struct in the GameVariables. Sets the seed and restores the state for each independe...
void rng_init(void)
Starts counting CPU cycles, which will be used by rng_shuffle_seed to generate a more random seed....
Information to track and restore RNG state.
Utilities relating around number string representation and protected arithmatic helper functions.
#define MAX_BASE36
Hex value of "ZZZZZZ" in base 36.