engine internal functions are now static inline

pull/2/head
Sara 2023-05-05 23:27:08 +02:00
parent 182cfc66cb
commit a55bf84aef
1 changed files with 15 additions and 9 deletions

View File

@ -4,24 +4,29 @@
#include "corelib/input.h" #include "corelib/input.h"
#include "time.h" #include "time.h"
int engine_start() {
static float _delta_time = 0; static float _delta_time = 0;
static struct timespec start_last_frame; static struct timespec start_last_frame;
inline float delta_time() { inline float delta_time() {
return _delta_time; return _delta_time;
} }
static inline
int _engine_start() {
init_context(); init_context();
return 0; return 0;
} }
int engine_shutdown() { static inline
int _engine_shutdown() {
game_exit(); game_exit();
clean_assets(); clean_assets();
close_context(); close_context();
exit(0); exit(0);
} }
void handle_events() { static inline
void _handle_events() {
while(SDL_PollEvent(&g_context.event)) { while(SDL_PollEvent(&g_context.event)) {
input_event(g_context.event); input_event(g_context.event);
switch(g_context.event.type) { switch(g_context.event.type) {
@ -32,7 +37,8 @@ void handle_events() {
} }
} }
int engine_run() { static inline
int _engine_run() {
SDL_Window* window = SDL_CreateWindow("Tabletop", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 420, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_Window* window = SDL_CreateWindow("Tabletop", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 420, SDL_WINDOW_FULLSCREEN_DESKTOP);
g_context = (context_t){ g_context = (context_t){
@ -47,11 +53,11 @@ int engine_run() {
timespec_get(&start_last_frame, TIME_UTC); timespec_get(&start_last_frame, TIME_UTC);
struct timespec next_time; struct timespec next_time;
while(g_context.running) { while(g_context.running) {
handle_events();
timespec_get(&next_time, TIME_UTC); timespec_get(&next_time, TIME_UTC);
_delta_time = (next_time.tv_nsec - start_last_frame.tv_nsec) * 1E-9; _delta_time = (next_time.tv_nsec - start_last_frame.tv_nsec) * 1E-9;
if(next_time.tv_nsec < start_last_frame.tv_nsec) _delta_time = 0; if(next_time.tv_nsec < start_last_frame.tv_nsec) _delta_time = 0;
start_last_frame = next_time; start_last_frame = next_time;
_handle_events();
_render_mode = 1; _render_mode = 1;
update_ui(); update_ui();
_render_mode = 0; _render_mode = 0;
@ -62,7 +68,7 @@ int engine_run() {
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
engine_start(); _engine_start();
engine_run(); _engine_run();
engine_shutdown(); _engine_shutdown();
} }