Time dr freeman?

This commit is contained in:
2025-08-17 16:18:56 -05:00
parent 3d4317260f
commit 3e19771d8f
6 changed files with 27 additions and 16 deletions

View File

@@ -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 "linux")
#set(DUSK_TARGET_SYSTEM "psp")
set(DUSK_TARGET_SYSTEM "linux")
endif()
# Prep cache

View File

@@ -33,14 +33,22 @@ void gameInit(void) {
void gameUpdate(void) {
timeUpdate();
// 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();
consoleUpdate();
inputUpdate();
timeSinceLastTick -= DUSK_TIME_STEP;
TIME.lastTick = TIME.time;
}
if(inputPressed(INPUT_BIND_QUIT)) consoleExec("quit");
consoleUpdate();
}
void gameDispose(void) {

View File

@@ -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;

View File

@@ -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.

View File

@@ -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

View File

@@ -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) {