edit: sorry connection issue I think the post got posted twice
I have some confusion or a misunderstanding using SDL2 events and getting data around to other areas in my code. There’s two ways that I’ve come to and I’m curious if one is better then the other or if perhaps there is a better way to go about this.
The first way I take the data and make my own event to be sent to listeners
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
events.fire<KeyEvent>(true, event.key.keysym.sym);
break;
case SDL_KEYDOWN:
events.fire<KeyEvent>(true, event.key.keysym.sym);
break;
}
This seems to be the most logical way to do it, but I just can’t help but feel that jamming the data from an event into my own worst event system isn’t beneficial unless I’m overthinking/not seeing the bigger picture. Perhaps the soltuion is instead of trying to make my own event system I can create a SDLEventHandler and then stuff can handle events that way.
The second way I believe is just delegating the work to something else
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
gameDetails.requestExit(); // Would set some bool to true which the main loop would check via gameDetails.shouldExit()
break;
}