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,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();
}