Refactor/RNG system (#476)

* Extract rng manipulation to its own file

* clang format

* Get CPU cycles since game start to use for RNG

* change a few things

* clang format

* Implement suggestions from @ricfehr3

* clang format

* Fix rebase issue

* clang format

* Create RngInfo struct to hold seed and step

* clang format

* Make a note about rng_restore system not having been tested properly yet

* Apply suggestions from @ricfehr3

Co-authored-by: Rickey <ric@rf3.xyz>

* clang format

---------

Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
Co-authored-by: Rickey <ric@rf3.xyz>
This commit is contained in:
Geralt
2026-05-21 19:47:48 -07:00
committed by GitHub
co-authored by Rickey MathisMartin31
parent e3f680d6d0
commit c2844a5d32
14 changed files with 162 additions and 57 deletions
+6 -16
View File
@@ -105,8 +105,8 @@ typedef struct JokerObjectSaveData
* 2 | 'L' | ' ' | 'D' | 'A' | - | -
* 3 | 'T' | 'A' | ' ' | '-' | - | -
* 4 | T[0] | T[1] | T[2] | T[3] | GLOB TIMER | The global timer used for animations thoughout the game
* 5 | SED[0] | SED[1] | SED[2] | SED[3] | RNG SEED | The seed used for RNG, either randomly shuffled or chosen by the player at game start
* 6 | STP[0] | STP[1] | STP[2] | STP[3] | RNG STEP | The current position in the RNG sequence for the given seed, since the start of the run
* 5 | RNG[0] | RNG[1] | RNG[2] | RNG[3] | RNG INFO | RNG Info struct, containing the seed used for RNG, either randomly shuffled or chosen by the player
* 6 | RNG[4] | RNG[5] | RNG[6] | RNG[7] | - | at game start, and the current position in the RNG sequence for the given seed, since the start of the run
* 7 | RND[0] | RND[1] | RND[2] | RND[3] | ROUND | What Round we are about to start
* 8 | ANT[0] | ANT[1] | ANT[2] | ANT[3] | ANTE | What Ante we are on
* 9 | MNY[0] | MNY[1] | MNY[2] | MNY[3] | MONEY | How much money we currently have left
@@ -127,8 +127,7 @@ typedef struct SaveGame
{
char tag_internal[SAVE_LABEL_SIZE];
s32 timer;
u32 rng_seed;
u32 rng_step;
RngInfo rng_info;
int round;
int ante;
int money;
@@ -168,8 +167,7 @@ static const SaveOptions SaveOptions_default = {
static const SaveGame SaveGame_default = {
.tag_internal = "-INTERNAL DATA -",
.timer = 0,
.rng_seed = 0,
.rng_step = 0,
.rng_info = {0, 0},
.round = 0,
.ante = 0,
.money = 0,
@@ -328,8 +326,7 @@ void save_game(void)
// Fixed data
game.timer = g_game_vars.timer;
game.rng_seed = g_game_vars.rng_seed;
game.rng_step = g_game_vars.rng_step;
game.rng_info = g_game_vars.rng_info;
game.round = g_game_vars.round;
game.ante = g_game_vars.ante;
game.money = g_game_vars.money;
@@ -370,17 +367,10 @@ void load_game(void)
read_sram(GAME_ADDRESS, (u8*)&game, sizeof(game));
g_game_vars.timer = game.timer;
g_game_vars.rng_seed = game.rng_seed;
g_game_vars.rng_step = game.rng_step;
rng_restore(game.rng_info);
g_game_vars.round = game.round;
g_game_vars.ante = game.ante;
g_game_vars.money = game.money;
// TODO: load Jokers from stored minimal data
// return to where we were in the random sequence so that the run stays reproducible
for (u32 i = 0; i < g_game_vars.rng_step; i++)
{
(void)rand();
}
}