Added some time functions.
This commit is contained in:
@ -30,8 +30,8 @@ bool gameInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gameUpdate() {
|
||||
gameTimeUpdate();
|
||||
bool gameUpdate(float platformDelta) {
|
||||
gameTimeUpdate(platformDelta);
|
||||
renderFrameStart();
|
||||
inputUpdate();
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
Reference in New Issue
Block a user