mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-19 10:35:46 +01:00
fix: two gametimes were present
This commit is contained in:
@@ -8,15 +8,15 @@
|
||||
|
||||
#include "gametime.h"
|
||||
|
||||
void game_init(gamedata* dat) {
|
||||
void game_init(gamedata* dat, gametime* gt) {
|
||||
*dat = (gamedata){
|
||||
gametime_new(),
|
||||
gt,
|
||||
true,
|
||||
};
|
||||
}
|
||||
|
||||
void game_update(gamedata* dat) {
|
||||
gametime_update(&dat->time);
|
||||
gametime_update(dat->time);
|
||||
uint8_t const* keys = SDL_GetKeyboardState(NULL);
|
||||
|
||||
if (keys[SDL_SCANCODE_ESCAPE])
|
||||
@@ -24,5 +24,6 @@ void game_update(gamedata* dat) {
|
||||
}
|
||||
|
||||
void game_free(gamedata* dat) {
|
||||
gametime_free(dat->time);
|
||||
*dat = (gamedata){0};
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#define TAUf (M_PIf * 2.0F) // τ constant as a 32-bit floating point
|
||||
|
||||
typedef struct {
|
||||
gametime time;
|
||||
gametime* time;
|
||||
bool run;
|
||||
} gamedata;
|
||||
|
||||
void game_init(gamedata*); // initializes everything needed to start the game; outputs to game_data
|
||||
void game_init(gamedata*, gametime*); // initializes everything needed to start the game; outputs to game_data
|
||||
void game_update(gamedata*); // causes an update to occur within the game
|
||||
void game_free(gamedata*); // frees the resources associated with the game
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef struct {
|
||||
@@ -22,6 +23,10 @@ static inline gametime gametime_new(void) {
|
||||
};
|
||||
}
|
||||
|
||||
static inline void gametime_free(gametime* gt) {
|
||||
free(gt);
|
||||
}
|
||||
|
||||
// updates the internal variables
|
||||
static inline void gametime_update(gametime* gt) {
|
||||
struct timespec ts;
|
||||
|
||||
Reference in New Issue
Block a user