浏览代码

Abstract SDL event handling

Delegate the event handling solely in input state.
feature/data-structs
父节点
当前提交
afa8fcce02
共有 4 个文件被更改,包括 8 次插入9 次删除
  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 查看文件

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


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


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




+ 0
- 2
src/packages/game/IZ_app.h 查看文件

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


typedef struct { typedef struct {
SDL_Event sdl_event;

IZ_InputState input_state; IZ_InputState input_state;
IZ_VideoState video_state; IZ_VideoState video_state;




+ 3
- 3
src/packages/game/input/IZ_input.c 查看文件

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


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


void IZ_InputHandlePortMIDIEvents(PmEvent e, IZ_InputState* state) { void IZ_InputHandlePortMIDIEvents(PmEvent e, IZ_InputState* state) {


+ 2
- 1
src/packages/game/input/IZ_input.h 查看文件

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


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


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


void IZ_InputHandlePortMIDIEvents(PmEvent, IZ_InputState*); void IZ_InputHandlePortMIDIEvents(PmEvent, IZ_InputState*);




||||||
x
 
000:0
正在加载...
取消
保存