Fixed time.
This commit is contained in:
@@ -7,4 +7,17 @@
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
time.c
|
||||
)
|
||||
)
|
||||
|
||||
# Compiler defs
|
||||
if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
DUSK_TIME_SDL2=1
|
||||
)
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
DUSK_TIME_FIXED=1
|
||||
)
|
||||
endif()
|
@@ -9,33 +9,31 @@
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
#if DUSK_TIME_SDL2
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
dusktime_t TIME;
|
||||
|
||||
void timeInit(void) {
|
||||
memoryZero(&TIME, sizeof(TIME));
|
||||
|
||||
// Set these to something non-zero.
|
||||
TIME.lastTick = DUSK_TIME_STEP;
|
||||
TIME.delta = TIME.realDelta = DUSK_TIME_STEP;
|
||||
TIME.realTime = TIME.time = DUSK_TIME_STEP * 2;
|
||||
TIME.time = DUSK_TIME_STEP;
|
||||
TIME.delta = DUSK_TIME_STEP;
|
||||
}
|
||||
|
||||
void timeUpdate(void) {
|
||||
TIME.realDelta = timeDeltaGet();
|
||||
|
||||
#if DUSK_TIME_DYNAMIC
|
||||
TIME.delta = TIME.realDelta;
|
||||
float_t delta;
|
||||
#if DUSK_TIME_SDL2
|
||||
delta = (float_t)SDL_GetTicks() / 1000.0f - TIME.time;
|
||||
#elif DUSK_TIME_FIXED
|
||||
delta = DUSK_TIME_PLATFORM_STEP;
|
||||
#else
|
||||
TIME.delta = DUSK_TIME_PLATFORM_STEP;
|
||||
#error "No time platform defined"
|
||||
#endif
|
||||
|
||||
|
||||
TIME.delta = delta;
|
||||
assertTrue(TIME.delta >= 0.0f, "Time delta is negative");
|
||||
assertTrue(TIME.realDelta >= 0.0f, "Real time delta is negative");
|
||||
|
||||
TIME.time += TIME.delta;
|
||||
TIME.realTime += TIME.realDelta;
|
||||
}
|
||||
|
||||
float_t timeDeltaGet(void) {
|
||||
return 0.1f;
|
||||
}
|
@@ -10,26 +10,13 @@
|
||||
|
||||
typedef struct {
|
||||
float_t delta;
|
||||
float_t lastTick;
|
||||
float_t time;
|
||||
float_t realDelta;
|
||||
float_t realTime;
|
||||
} dusktime_t;
|
||||
|
||||
extern dusktime_t TIME;
|
||||
|
||||
#define DUSK_TIME_STEP (1.0f / 60.0f) // Default to 60FPS
|
||||
|
||||
#ifndef DUSK_TIME_DYNAMIC
|
||||
#define DUSK_TIME_DYNAMIC 1
|
||||
#endif
|
||||
|
||||
#if DUSK_TIME_DYNAMIC == 0
|
||||
#ifndef DUSK_TIME_PLATFORM_STEP
|
||||
#define DUSK_TIME_PLATFORM_STEP DUSK_TIME_STEP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes the time system.
|
||||
*/
|
||||
@@ -38,15 +25,4 @@ void timeInit(void);
|
||||
/**
|
||||
* Updates the time system
|
||||
*/
|
||||
void timeUpdate(void);
|
||||
|
||||
#if DUSK_TIME_DYNAMIC == 1
|
||||
/**
|
||||
* Gets the time delta since the last frame, in seconds. Tied to the
|
||||
* platform.
|
||||
*
|
||||
* This will only get called once per gameUpdate.
|
||||
*/
|
||||
float_t timeDeltaGet(void);
|
||||
#endif
|
||||
|
||||
void timeUpdate(void);
|
Reference in New Issue
Block a user