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. 15
      src/input.cpp

7
include/input.h

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

15
src/input.cpp

@ -1,15 +1,14 @@
#include <SDL2/SDL.h>
#include <cassert>
#include "input.h"
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) {
case SDL_QUIT:
is->window_closed = true;
@ -35,5 +34,13 @@ inputProcessEvents(input_state* is)
default: break;
}
}
void
inputProcessEvents(input_state* is)
{
SDL_Event e;
while (SDL_PollEvent(&e))
inputProcessEvent(is, e);
}

Loading…
Cancel
Save