I'm using SDL2 in my game engine and I'm trying to figure out how I can prevent having a monolithic control statement like this:
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_w:
// Move player forward
// if debug mode move camera forward
// if in menu navigate the ui
}
break;
case SDL_QUIT:
running = false;
break;
}
}
For the sake of readability and length I kept it short, but basically having a case for every key I might want to use say ~10 and each might do multiple different things depending on the state of the game plus the plethora of other events I feel like it'll spiral out of control and become a big blob of ugly/messy code.
Looking for any suggestions on what I could do to approach this problem or if there's any typical solutions.
event.key.keysym.symandSDLK_w) will do the wrong thing on non-QWERTY keyboards, preferevent.key.keysym.scancodeandSDL_SCANCODE_W. \$\endgroup\$