use floats for ctx.frame_number and ctx.random_seed
This commit is contained in:
		@@ -16,10 +16,10 @@ typedef struct Context {
 | 
				
			|||||||
    void *udata;
 | 
					    void *udata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* which frame is it, starting from 0 at startup */
 | 
					    /* which frame is it, starting from 0 at startup */
 | 
				
			||||||
    uint64_t frame_number;
 | 
					    float frame_number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* real time spent on one frame (in seconds) */
 | 
					    /* real time spent on one frame (in seconds) */
 | 
				
			||||||
    /* townengine is fixed step based, so you don't have */
 | 
					    /* townengine is fixed step based, so you don't have to use delta */
 | 
				
			||||||
    /* TODO: actually set it */
 | 
					    /* TODO: actually set it */
 | 
				
			||||||
    float frame_duration;
 | 
					    float frame_duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,7 +30,7 @@ typedef struct Context {
 | 
				
			|||||||
    Vec2 mouse_movement;
 | 
					    Vec2 mouse_movement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* is set on startup, should be used as source of randomness */
 | 
					    /* is set on startup, should be used as source of randomness */
 | 
				
			||||||
    uint64_t random_seed;
 | 
					    float random_seed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* whether debugging logic should be enabled in user code */
 | 
					    /* whether debugging logic should be enabled in user code */
 | 
				
			||||||
    bool debug;
 | 
					    bool debug;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ static void (*game_end_callback)(void);
 | 
				
			|||||||
static x_watcher *watcher;
 | 
					static x_watcher *watcher;
 | 
				
			||||||
static void *handle = NULL;
 | 
					static void *handle = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint64_t last_tick_modified;
 | 
					static float last_tick_modified;
 | 
				
			||||||
static bool loaded_after_modification = true;
 | 
					static bool loaded_after_modification = true;
 | 
				
			||||||
static SDL_mutex *lock;
 | 
					static SDL_mutex *lock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -59,7 +59,7 @@ static void load_game_object(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    handle = new_handle;
 | 
					    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");
 | 
					        log_info("Game object was reloaded\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ void start_render_frame(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void end_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();
 | 
					        issue_deferred_draw_commands();
 | 
				
			||||||
        SDL_GL_SwapWindow(ctx.window);
 | 
					        SDL_GL_SwapWindow(ctx.window);
 | 
				
			||||||
        arrsetlen(deferred_commands, 0);
 | 
					        arrsetlen(deferred_commands, 0);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -236,7 +236,7 @@ static void main_loop(void) {
 | 
				
			|||||||
            preserve_persistent_ctx_fields();
 | 
					            preserve_persistent_ctx_fields();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ctx.frame_accumulator -= ctx.desired_frametime;
 | 
					            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;
 | 
					            ctx.game.initialization_needed = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -584,9 +584,9 @@ static bool initialize(void) {
 | 
				
			|||||||
    /* random seeding */
 | 
					    /* random seeding */
 | 
				
			||||||
    /* SDL_GetPerformanceCounter returns some platform-dependent number. */
 | 
					    /* SDL_GetPerformanceCounter returns some platform-dependent number. */
 | 
				
			||||||
    /* it should vary between game instances. i checked! random enough for me. */
 | 
					    /* 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);
 | 
					    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 */
 | 
					    /* main loop machinery */
 | 
				
			||||||
    toml_datum_t datum_ticks_per_second = toml_int_in(engine, "ticks_per_second");
 | 
					    toml_datum_t datum_ticks_per_second = toml_int_in(engine, "ticks_per_second");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user