diff --git a/CMakeLists.txt b/CMakeLists.txt index 261b240..7846e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT DEFINED DUSK_TARGET_SYSTEM) + #set(DUSK_TARGET_SYSTEM "psp") set(DUSK_TARGET_SYSTEM "linux") - # set(DUSK_TARGET_SYSTEM "psp") endif() # Prep cache diff --git a/src/dusk/game.c b/src/dusk/game.c index 9f00400..cafc159 100644 --- a/src/dusk/game.c +++ b/src/dusk/game.c @@ -33,14 +33,22 @@ void gameInit(void) { void gameUpdate(void) { timeUpdate(); - sceneUpdate(); - uiTextboxUpdate(); - eventUpdate(); - consoleUpdate(); - inputUpdate(); + // Game logic is tied to 60FPS for now, saves me a lot of hassle with float + // issues + float_t timeSinceLastTick = TIME.time - TIME.lastTick; + while(timeSinceLastTick >= DUSK_TIME_STEP) { + sceneUpdate(); + uiTextboxUpdate(); + eventUpdate(); + inputUpdate(); + + timeSinceLastTick -= DUSK_TIME_STEP; + TIME.lastTick = TIME.time; + } if(inputPressed(INPUT_BIND_QUIT)) consoleExec("quit"); + consoleUpdate(); } void gameDispose(void) { diff --git a/src/dusk/time.c b/src/dusk/time.c index f58e472..a649f72 100644 --- a/src/dusk/time.c +++ b/src/dusk/time.c @@ -16,10 +16,10 @@ void timeInit(void) { } void timeUpdate(void) { - #if DUSK_DYNAMIC_TIME + #if DUSK_TIME_DYNAMIC TIME.delta = timeDeltaGet(); #else - TIME.delta = DUSK_TIME_STEP; + TIME.delta = DUSK_TIME_PLATFORM_STEP; #endif TIME.time += TIME.delta; diff --git a/src/dusk/time.h b/src/dusk/time.h index 2e5a03f..ae9796d 100644 --- a/src/dusk/time.h +++ b/src/dusk/time.h @@ -10,18 +10,21 @@ typedef struct { float_t delta; + float_t lastTick; float_t time; } dusktime_t; extern dusktime_t TIME; -#ifndef DUSK_DYNAMIC_TIME - #define DUSK_DYNAMIC_TIME 1 +#define DUSK_TIME_STEP (1.0f / 60.0f) // Default to 60FPS + +#ifndef DUSK_TIME_DYNAMIC + #define DUSK_TIME_DYNAMIC 1 #endif -#if DUSK_DYNAMIC_TIME == 0 - #ifndef DUSK_TIME_STEP - #define DUSK_TIME_STEP (1.0f / 60.0f) +#if DUSK_TIME_DYNAMIC == 0 + #ifndef DUSK_TIME_PLATFORM_STEP + #define DUSK_TIME_PLATFORM_STEP DUSK_TIME_STEP #endif #endif @@ -35,7 +38,7 @@ void timeInit(void); */ void timeUpdate(void); -#if DUSK_DYNAMIC_TIME == 1 +#if DUSK_TIME_DYNAMIC == 1 /** * Gets the time delta since the last frame, in seconds. Tied to the * platform. diff --git a/src/duskpsp/CMakeLists.txt b/src/duskpsp/CMakeLists.txt index f9f5efc..822d982 100644 --- a/src/duskpsp/CMakeLists.txt +++ b/src/duskpsp/CMakeLists.txt @@ -20,7 +20,7 @@ target_compile_definitions(${DUSK_TARGET_NAME} RENDER_HEIGHT=272 RENDER_WINDOW_WIDTH_DEFAULT=480 RENDER_WINDOW_HEIGHT_DEFAULT=272 - DUSK_DYNAMIC_TIME=0 + DUSK_TIME_DYNAMIC=0 ) # Includes diff --git a/src/dusksdl2/time.c b/src/dusksdl2/time.c index 55cab73..a656061 100644 --- a/src/dusksdl2/time.c +++ b/src/dusksdl2/time.c @@ -8,7 +8,7 @@ #include "time.h" #include "dusksdl2.h" -#if DUSK_DYNAMIC_TIME +#if DUSK_TIME_DYNAMIC uint32_t TIME_LAST = 0; float_t timeDeltaGet(void) {