Browse Source

break out SDL_PollEvents() while loop to new function

render_group_fix
cinnaboot 5 years ago
parent
commit
ef11271049
  1. 7
      include/input.h
  2. 17
      src/input.cpp

7
include/input.h

@ -1,6 +1,9 @@
#pragma once #pragma once
#include <SDL2/SDL.h>
struct input_state struct input_state
{ {
bool window_closed; bool window_closed;
@ -11,6 +14,10 @@ struct input_state
bool down; bool down;
}; };
void
inputProcessEvent(input_state* is, SDL_Event& e);
// NOTE: convenience function that provides a while(SDL_PollEvents()) loop
void void
inputProcessEvents(input_state* is); inputProcessEvents(input_state* is);

17
src/input.cpp

@ -1,15 +1,14 @@
#include <SDL2/SDL.h> #include <cassert>
#include "input.h" #include "input.h"
void void
inputProcessEvents(input_state* is) inputProcessEvent(input_state* is, SDL_Event& e)
{ {
SDL_Event e; assert(is != nullptr);
while (SDL_PollEvent(&e)) {
switch (e.type) { switch (e.type) {
case SDL_QUIT: case SDL_QUIT:
is->window_closed = true; is->window_closed = true;
@ -34,6 +33,14 @@ inputProcessEvents(input_state* is)
break; break;
default: break; default: break;
} }
} }
void
inputProcessEvents(input_state* is)
{
SDL_Event e;
while (SDL_PollEvent(&e))
inputProcessEvent(is, e);
} }

Loading…
Cancel
Save