Added some time functions.

This commit is contained in:
2021-04-27 07:26:19 -07:00
parent e323cf2721
commit 96db74a546
10 changed files with 43 additions and 16 deletions

View File

@ -30,8 +30,8 @@ bool gameInit() {
return true;
}
bool gameUpdate() {
gameTimeUpdate();
bool gameUpdate(float platformDelta) {
gameTimeUpdate(platformDelta);
renderFrameStart();
inputUpdate();

View File

@ -24,9 +24,10 @@ bool gameInit();
/**
* Tick the main game loop.
*
* @param platformDelta The platform tick delta between the last render.
* @return True if successful, false if safe exit requested..
*/
bool gameUpdate();
bool gameUpdate(float platformDelta);
/**
* Cleanup the game instance.

View File

@ -10,13 +10,18 @@
gametime_t TIME_STATE;
void gameTimeInit() {
TIME_STATE.delta = GAMETIME_STEP;
TIME_STATE.last = GAMETIME_STEP;
TIME_STATE.current = GAMETIME_STEP + GAMETIME_STEP;
TIME_STATE.delta = GAMETIME_FIXED_STEP;
TIME_STATE.last = GAMETIME_FIXED_STEP;
TIME_STATE.current = GAMETIME_FIXED_STEP + GAMETIME_FIXED_STEP;
}
void gameTimeUpdate() {
void gameTimeUpdate(float platformDelta) {
platformDelta = mathMax(
mathMin(platformDelta, GAMETIME_FIXED_STEP),
0
);
TIME_STATE.last = TIME_STATE.current;
TIME_STATE.current = TIME_STATE.current + GAMETIME_STEP;
TIME_STATE.current = TIME_STATE.current + platformDelta;
TIME_STATE.delta = TIME_STATE.current - TIME_STATE.last;
}

View File

@ -7,6 +7,7 @@
#pragma once
#include <dawn/dawn.h>
#include "../util/math.h"
/**
* Initializes the gametime global time tracking.
@ -15,5 +16,7 @@ void gameTimeInit();
/**
* Ticks the current game time.
*
* @param platformDelta The delta step between frames from the platform engine.
*/
void gameTimeUpdate();
void gameTimeUpdate(float platformDelta);