From a55bf84aef99e666e2981f770a49dc718ef2100a Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 5 May 2023 23:27:08 +0200 Subject: [PATCH] engine internal functions are now static inline --- src/engine.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/engine.c b/src/engine.c index 2a4ab5f..bdf201a 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4,35 +4,41 @@ #include "corelib/input.h" #include "time.h" -int engine_start() { static float _delta_time = 0; static struct timespec start_last_frame; + inline float delta_time() { return _delta_time; } + +static inline +int _engine_start() { init_context(); return 0; } -int engine_shutdown() { +static inline +int _engine_shutdown() { game_exit(); clean_assets(); close_context(); exit(0); } -void handle_events() { +static inline +void _handle_events() { while(SDL_PollEvent(&g_context.event)) { input_event(g_context.event); switch(g_context.event.type) { - case SDL_QUIT: + case SDL_QUIT: g_context.running = 0; break; } } } -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); g_context = (context_t){ @@ -47,11 +53,11 @@ int engine_run() { timespec_get(&start_last_frame, TIME_UTC); struct timespec next_time; while(g_context.running) { - handle_events(); timespec_get(&next_time, TIME_UTC); _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; start_last_frame = next_time; + _handle_events(); _render_mode = 1; update_ui(); _render_mode = 0; @@ -62,7 +68,7 @@ int engine_run() { } int main(int argc, char* argv[]) { - engine_start(); - engine_run(); - engine_shutdown(); + _engine_start(); + _engine_run(); + _engine_shutdown(); }