use floats for ctx.frame_number and ctx.random_seed

This commit is contained in:
veclavtalica
2025-01-10 02:20:21 +03:00
parent f3848d2d52
commit 951d9c76c8
4 changed files with 9 additions and 9 deletions

View File

@ -19,7 +19,7 @@ static void (*game_end_callback)(void);
static x_watcher *watcher;
static void *handle = NULL;
static uint64_t last_tick_modified;
static float last_tick_modified;
static bool loaded_after_modification = true;
static SDL_mutex *lock;
@ -59,7 +59,7 @@ static void load_game_object(void) {
handle = new_handle;
if (ctx.game.frame_number != 0)
if (fabsf(0.0f - ctx.game.frame_number) > 0.00001f)
log_info("Game object was reloaded\n");
return;

View File

@ -20,7 +20,7 @@ void start_render_frame(void) {
void end_render_frame(void) {
if (!ctx.render_double_buffered || ctx.game.frame_number == 1) {
if (!ctx.render_double_buffered || (fabsf(1.0f - ctx.game.frame_number) < 0.00001f)) {
issue_deferred_draw_commands();
SDL_GL_SwapWindow(ctx.window);
arrsetlen(deferred_commands, 0);

View File

@ -236,7 +236,7 @@ static void main_loop(void) {
preserve_persistent_ctx_fields();
ctx.frame_accumulator -= ctx.desired_frametime;
ctx.game.frame_number = (ctx.game.frame_number % ULLONG_MAX) + 1;
ctx.game.frame_number++;
ctx.game.initialization_needed = false;
}
}
@ -584,9 +584,9 @@ static bool initialize(void) {
/* random seeding */
/* SDL_GetPerformanceCounter returns some platform-dependent number. */
/* it should vary between game instances. i checked! random enough for me. */
ctx.game.random_seed = SDL_GetPerformanceCounter();
ctx.game.random_seed = (float)(SDL_GetPerformanceCounter() % 16777216);
srand((unsigned int)ctx.game.random_seed);
stbds_rand_seed(ctx.game.random_seed);
stbds_rand_seed((size_t)ctx.game.random_seed);
/* main loop machinery */
toml_datum_t datum_ticks_per_second = toml_int_in(engine, "ticks_per_second");