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:
co-authored by
Rickey
MathisMartin31
parent
e3f680d6d0
commit
c2844a5d32
@@ -7,6 +7,7 @@
|
||||
#include "game/main_menu.h"
|
||||
#include "graphic_utils.h"
|
||||
#include "layout.h"
|
||||
#include "random.h"
|
||||
#include "soundbank.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
@@ -128,4 +129,5 @@ void game_over_on_exit(void)
|
||||
{
|
||||
condition = END_CONDITION_NONE;
|
||||
game_reset();
|
||||
rng_shuffle_seed();
|
||||
}
|
||||
|
||||
@@ -127,14 +127,6 @@ void game_main_menu_on_update(void)
|
||||
main_menu_ace->sprite_object->trotation = lu_sin((g_game_vars.timer << 8) / 2) / 3;
|
||||
card_object_update(main_menu_ace);
|
||||
|
||||
// Seed randomization
|
||||
g_game_vars.rng_seed++;
|
||||
// If the keys have changed, make it more pseudo-random
|
||||
if (key_curr_state() != key_prev_state())
|
||||
{
|
||||
g_game_vars.rng_seed *= 2;
|
||||
}
|
||||
|
||||
selection_grid_process_input(&main_menu_selection_grid);
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -17,6 +17,7 @@
|
||||
#include "joker.h"
|
||||
#include "layout.h"
|
||||
#include "list.h"
|
||||
#include "random.h"
|
||||
#include "save.h"
|
||||
#include "soundbank.h"
|
||||
#include "timer.h"
|
||||
@@ -196,7 +197,7 @@ static inline int game_shop_get_rand_available_joker_id(void)
|
||||
return UNDEFINED;
|
||||
|
||||
int matching_joker_ids[jokers_avail_size];
|
||||
int fallback_random_idx = get_rand() % jokers_avail_size;
|
||||
int fallback_random_idx = rng_get_u32() % jokers_avail_size;
|
||||
int fallback_random_joker_id = UNDEFINED;
|
||||
int match_count = 0;
|
||||
|
||||
@@ -215,8 +216,8 @@ static inline int game_shop_get_rand_available_joker_id(void)
|
||||
}
|
||||
}
|
||||
|
||||
int selected_joker_id =
|
||||
(match_count > 0) ? matching_joker_ids[get_rand() % match_count] : fallback_random_joker_id;
|
||||
int selected_joker_id = (match_count > 0) ? matching_joker_ids[rng_get_u32() % match_count]
|
||||
: fallback_random_joker_id;
|
||||
|
||||
return selected_joker_id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user