Browse Source

Abstract SDL event handling

Delegate the event handling solely in input state.
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
afa8fcce02
4 changed files with 8 additions and 9 deletions
  1. +3
    -3
      src/packages/game/IZ_app.c
  2. +0
    -2
      src/packages/game/IZ_app.h
  3. +3
    -3
      src/packages/game/input/IZ_input.c
  4. +2
    -1
      src/packages/game/input/IZ_input.h

+ 3
- 3
src/packages/game/IZ_app.c View File

@@ -39,13 +39,13 @@ void IZ_AppTeardown(IZ_App* app) {
}

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

IZ_InputHandleSDLEvents(app->sdl_event, &app->input_state);
IZ_InputHandleSDLEvents(&app->input_state);
}
}



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

@@ -13,8 +13,6 @@
#include "memory/IZ_pool.h"

typedef struct {
SDL_Event sdl_event;

IZ_InputState input_state;
IZ_VideoState video_state;



+ 3
- 3
src/packages/game/input/IZ_input.c View File

@@ -1,8 +1,8 @@
#include "IZ_input.h"

void IZ_InputHandleSDLEvents(SDL_Event e, IZ_InputState* state) {
IZ_JoystickHandleEvents(e, &state->joystick_state, &state->action);
IZ_KeyboardHandleEvents(e, &state->keyboard_state, &state->action);
void IZ_InputHandleSDLEvents(IZ_InputState* state) {
IZ_JoystickHandleEvents(state->sdl_event, &state->joystick_state, &state->action);
IZ_KeyboardHandleEvents(state->sdl_event, &state->keyboard_state, &state->action);
}

void IZ_InputHandlePortMIDIEvents(PmEvent e, IZ_InputState* state) {


+ 2
- 1
src/packages/game/input/IZ_input.h View File

@@ -7,13 +7,14 @@
#include "IZ_midi.h"

typedef struct {
SDL_Event sdl_event;
IZ_Action action[PLAYERS];
IZ_KeyboardState keyboard_state[PLAYERS];
IZ_JoystickState joystick_state[PLAYERS];
IZ_MIDIInputState midi_input_state[PLAYERS];
} IZ_InputState;

void IZ_InputHandleSDLEvents(SDL_Event, IZ_InputState*);
void IZ_InputHandleSDLEvents(IZ_InputState*);

void IZ_InputHandlePortMIDIEvents(PmEvent, IZ_InputState*);



Loading…
Cancel
Save