Files
balatro-gba-chinese-jocker-…/include/random.h
T
Geralt 1df8402900 [Feature] Implement seeded runs by adding a Seed selection menu (#482)
* initial commit

* wip

* WIP

* WIP

* clang format

* Choose Seed navigation mostly done

* seed input navigation done

* seed input done

* cleanup and clang format

* Implement base 10 to 36 conversions

* Enable seeded runs

* clang format

* show default deck sprite, name and description

* Rename Deck enum to DeckType

* Implement arbitrary 9-patch expand system

* Make 9-patch example smaller in the docs

* Improve NinePatchRect docs

* fix Deck back side sprite palette

* clang format

* Add last deck description

* clang format

* Fix 'Z' in seed input keyboard

* Fix rebase issue

* fix deck sprite not updating

* Documents static funcs in run_setup.c

* more documentation

* clang format

* Move Play button to the left in its row

* Tests WIP

* removing tests for random.h

* use the new StateMachine struct

* First wave of fixes

* Fix the 9-patch again

* Changed the base 36 logic so it's in big endian

* properly set end of base 36 string to '\0'

* typos

* fix cursor position after rolling a seed + fix random seed generation

* Make keyboard more intuitive to use

* static const var

* Address more comment from @ricfehr3

* clang format

* clang format

* clang format

* clang format

* clang format

* clang format

* clang format

* fix deck palette

* create the `DEF_SEED_KEYBOARD_BUTTON_OBJECT` macro

* Replace `expand_3x3` by a call to `expand_9-patch`

* clang format

* clang format

* clang format

* fix rebase iussue in state_machine.h

---------

Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
2026-06-02 00:06:37 -07:00

72 lines
2.1 KiB
C

/**
* @file random.h
*
* @brief Common functions to handle RNG manipulation. Using this interface has three goals:
* 1. Make RNG repeatable so that people can share seeds and saves, and end up with the same run
* 2. Prevent the players from engaging in save-scumming since the pseudo-RNG is deterministic
* 3. Accomodate for base-36 seeds, so that we can freely chose one with alpha-numeric characters in
* the seed screen input
*/
#ifndef RANDOM_H
#define RANDOM_H
#include <tonc.h>
/**
* @brief Information to track and restore RNG state
*/
typedef struct
{
/** Initial seed */
u32 seed;
/** Position in the rng sequence. */
u32 step;
} RngInfo;
/**
* @brief Starts counting CPU cycles, this will be used by rng_shuffle_seed to
* generate a more random seed. To be called once on game start.
*/
void rng_init(void);
/**
* @brief Update the CPU cycles counter and accumulate it into a bigger u32 `timer_acc` variable.
*/
void rng_update(void);
/**
* @brief Set the rng seed to the chosen value, and reset the step counter to 0.
* The seed will be capped at `MAX_BASE36` for compatibility with the Seed Input screen
* used to choose a seed for seeded runs.
*
* @param seed the new RNG seed
*/
void rng_set_seed(u32 seed);
/**
* @brief Uses the CPU cycles counter to randomize the RNG seed as much as possible.
* This will be called by the main menu and the game over screens so that
* the next run's seed isn't the same as the last's.
* rng_start_sampling needs to have been called, and will stop the profiling.
*/
void rng_shuffle_seed(void);
/**
* @brief Get the next "randomly" generated number in the sequence from the current seed.
*
* @return u32
*/
u32 rng_get_u32(void);
/**
* @brief Restore RNG info struct in the GameVariables. Sets the `seed` and seeks the
* position `step` in the rng sequence.
*
* @param info RngInfo struct applied
*
* @note Consistency of the RNG after reloading the RngInfo struct has yet to be tested properly
*/
void rng_restore(RngInfo info);
#endif // RANDOM_H