synchronise with the template

- use the version of audio management which doesn't crash the
application if something goes wrong
- include colour32
- update error management to be more reflective of the one defined in
the template
- modify the renderer functions to be more reflective of the template
- modify the game functions to be more reflective of the template (& use
a more failproof method of initializing)
- add gametime
- remove set_gamestatus logic and just use a run boolean in gamedata
- remove emscripten preprocessors as those haven't really been used
This commit is contained in:
2025-03-22 15:29:42 +01:00
parent 7fb624311f
commit 60ae11de10
17 changed files with 416 additions and 265 deletions

39
src/game/gametime.h Normal file
View File

@@ -0,0 +1,39 @@
#pragma once
#include <time.h>
#include "../util/attributes.h"
typedef struct {
struct timespec ts; // stores the time at the current update
double sec; // stores the current time in seconds
float scale; // multiplier for the time calculation, default value is 1.0
float delta; // the time that it took between updates
} gametime;
// initializes the gametime struct
atrb_const static inline gametime gametime_new(void) {
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return (gametime){
ts,
0.0,
1.0F,
0.0F,
};
}
// updates the internal variables
static inline void gametime_update(gametime* gt) {
struct timespec ts;
timespec_get(&ts, TIME_UTC);
gt->sec = (double)ts.tv_nsec * 1e-9; // calculate the current time in seconds
gt->delta = ((double)(ts.tv_nsec - gt->ts.tv_nsec) * 1e-9) * gt->scale; // calculate how much time has passed between this and last frame
gt->ts = ts; // update the game's timespec
}
// gets how many times the game updates per second
atrb_const static inline float gametime_get_ups(gametime* gt) {
return 1.0F / gt->delta;
}