mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-19 10:35:46 +01:00
replace spaces with tabs
This commit is contained in:
@@ -10,19 +10,19 @@
|
||||
#include "gametime.h"
|
||||
|
||||
void game_init(gamedata* dat) {
|
||||
*dat = (gamedata){
|
||||
gametime_new(),
|
||||
};
|
||||
*dat = (gamedata){
|
||||
gametime_new(),
|
||||
};
|
||||
}
|
||||
|
||||
void game_update(gamedata* dat) {
|
||||
gametime_update(&dat->time);
|
||||
uint8_t const* keys = SDL_GetKeyboardState(NULL);
|
||||
gametime_update(&dat->time);
|
||||
uint8_t const* keys = SDL_GetKeyboardState(NULL);
|
||||
|
||||
if (keys[SDL_SCANCODE_ESCAPE])
|
||||
set_gamestatus(STATUS_SUCCESS);
|
||||
if (keys[SDL_SCANCODE_ESCAPE])
|
||||
set_gamestatus(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
void game_free(gamedata* dat) {
|
||||
*dat = (gamedata){0};
|
||||
*dat = (gamedata){0};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define TAUf (M_PIf * 2.0F) // τ constant as a 32-bit floating point
|
||||
|
||||
typedef struct {
|
||||
gametime time;
|
||||
gametime time;
|
||||
} gamedata;
|
||||
|
||||
void game_init(gamedata*); // initializes everything needed to start the game; outputs to game_data
|
||||
|
||||
@@ -3,35 +3,35 @@
|
||||
#include <time.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
|
||||
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
|
||||
static inline gametime gametime_new(void) {
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
struct timespec ts;
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
|
||||
return (gametime){
|
||||
ts,
|
||||
0.0,
|
||||
1.0F,
|
||||
0.0F,
|
||||
};
|
||||
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
|
||||
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
|
||||
static inline float gametime_get_ups(gametime* gt) {
|
||||
return 1.0F / gt->delta;
|
||||
return 1.0F / gt->delta;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user