Browse Source

Simplify game loop

Only check if events should break the game loop instead of having a
separate member for game loop checking.
feature/data-structs
TheoryOfNekomata 1 year ago
parent
commit
9643ac37bc
2 changed files with 9 additions and 10 deletions
  1. +9
    -8
      src/packages/game/IZ_app.c
  2. +0
    -2
      src/packages/game/IZ_app.h

+ 9
- 8
src/packages/game/IZ_app.c View File

@@ -27,7 +27,6 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) {

// TODO put into its timer module
app->ticks = 0;
app->quit = false;
return 0;
}

@@ -38,15 +37,15 @@ void IZ_AppTeardown(IZ_App* app) {
SDL_Quit();
}

void IZ_AppHandleSDLEvents(IZ_App* app) {
IZ_ProcedureResult IZ_AppHandleSDLEvents(IZ_App* app) {
while (SDL_PollEvent(&app->input_state.sdl_event) != 0) {
if (app->input_state.sdl_event.type == SDL_QUIT) {
app->quit = true;
break;
return 1;
}

IZ_InputHandleSDLEvents(&app->input_state);
}
return 0;
}

void IZ_AppHandlePortMIDIEvents(IZ_App* app) {
@@ -74,9 +73,12 @@ void IZ_AppHandlePortMIDIEvents(IZ_App* app) {
}
}

void IZ_AppHandleEvents(IZ_App* app) {
IZ_AppHandleSDLEvents(app);
IZ_ProcedureResult IZ_AppHandleEvents(IZ_App* app) {
if (IZ_AppHandleSDLEvents(app)) {
return 1;
}
IZ_AppHandlePortMIDIEvents(app);
return 0;
}

IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 arg_count, char* arg_values[]) {
@@ -98,8 +100,7 @@ IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 arg_count, char* arg_values[]) {
// TODO do audio processing
// TODO do networking?

IZ_AppHandleEvents(app);
if (app->quit) {
if (IZ_AppHandleEvents(app)) {
break;
}



+ 0
- 2
src/packages/game/IZ_app.h View File

@@ -2,7 +2,6 @@
#define IZ_APP_H

#include <SDL.h>
#include <stdbool.h>
#ifdef __WIN32__
#include <getopt.h>
#else
@@ -18,7 +17,6 @@ typedef struct {

IZ_Pool pool;
u64 ticks;
bool quit;
} IZ_App;

IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, char**);


Loading…
Cancel
Save