From e1d03dafe460e00a27975519e4d911274f13eeb5 Mon Sep 17 00:00:00 2001 From: 0scar Date: Tue, 13 Feb 2024 09:37:14 +0100 Subject: Add delta time to update function --- src/core/include/engine/core/state.h | 4 ++-- src/core/src/loop.c | 4 ++-- src/core/src/state.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/include/engine/core/state.h b/src/core/include/engine/core/state.h index f407acc..ee4741e 100644 --- a/src/core/include/engine/core/state.h +++ b/src/core/include/engine/core/state.h @@ -13,11 +13,11 @@ typedef enum StateType { extern const char* StateTypeStr[]; -StateType (*State_updateFunc(StateType type))(void*); +StateType (*State_updateFunc(StateType type))(f64, void*); void State_init(StateType type, memory* mem, void* arg); void* State_free(StateType type, memory* mem); -StateType State_update(StateType type, memory* mem); +StateType State_update(StateType type, f64 dt, memory* mem); /* Reloads shared object file associated with state */ #ifdef DAW_BUILD_HOTRELOAD diff --git a/src/core/src/loop.c b/src/core/src/loop.c index c4435fb..ac82603 100644 --- a/src/core/src/loop.c +++ b/src/core/src/loop.c @@ -316,7 +316,7 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { // Update ticks u64 ticks = 0; - StateType (*update_func)(void*) = State_updateFunc(state); + StateType (*update_func)(f64,void*) = State_updateFunc(state); f64 last_fps_measurement = get_time(); @@ -359,7 +359,7 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { // // /* update */ StateType next_state; - next_state = update_func((void*)(mem->data)); + next_state = update_func(dt, (void*)(mem->data)); if (next_state != STATE_null) { if (next_state == STATE_quit) break; diff --git a/src/core/src/state.c b/src/core/src/state.c index c393566..9b1e14c 100644 --- a/src/core/src/state.c +++ b/src/core/src/state.c @@ -7,7 +7,7 @@ //typedef void state_init_t(void*,void*); //typedef void* (state_free_t(void*)); -typedef StateType state_update_t(void*); +typedef StateType state_update_t(f64, void*); const char* StateTypeStr[] = { "null", @@ -90,7 +90,7 @@ void* State_free(StateType type, memory* mem) { return state_retval; } -StateType (*State_updateFunc(StateType type))(void*) { +StateType (*State_updateFunc(StateType type))(f64, void*) { switch (type) { #ifdef DAW_BUILD_HOTRELOAD #define State(name) \ @@ -117,7 +117,7 @@ StateType (*State_updateFunc(StateType type))(void*) { return NULL; } -StateType State_update(StateType type, memory* mem) { +StateType State_update(StateType type, f64 dt, memory* mem) { StateType next_state = STATE_null; switch (type) { #define State(name) \ -- cgit v1.3