Refactor main loop back to using switch/case
@@ -302,21 +302,21 @@ int main(int argc, char *argv[]) {
t_system_timer = SDL_CreateThread(system_timer, "Run", (void *)NULL);
- while (running) {
SDL_Event event;
- while (SDL_WaitEvent(&event)) {
- if (event.type == SDL_QUIT) {
+ while (running && SDL_WaitEvent(&event)) {
+ switch (event.type) {
+ case SDL_QUIT:
running = false;
break;
- }
- if (event.type == SDL_WINDOWEVENT) {
+
+ case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
resize_renderer(event.window.data1, event.window.data2);
}
break;
- }
- if (event.type == SDL_MOUSEBUTTONDOWN) {
+
+ case SDL_MOUSEBUTTONDOWN:
if(event.button.button == SDL_BUTTON_LEFT){
if(left_ctrl){
virtual_tilt(event.button.x, event.button.y);
@@ -329,13 +329,14 @@ int main(int argc, char *argv[]) {
}
}
break;
- }
- if (event.type == SDL_MOUSEBUTTONUP) {
+
+ case SDL_MOUSEBUTTONUP:
if(event.button.button == SDL_BUTTON_LEFT){
virtual_analog(0, 0);
}
- }
- if (event.type == SDL_MOUSEMOTION) {
+ break;
+
+ case SDL_MOUSEMOTION:
if(event.motion.state & SDL_MOUSEBUTTONDOWN){
if(left_ctrl){
virtual_tilt(event.motion.x, event.motion.y);
@@ -348,8 +349,10 @@ int main(int argc, char *argv[]) {
}
}
break;
- }
- if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) {
+
+ case SDL_KEYDOWN: // fall-though
+ case SDL_KEYUP:
+ {
auto iter = keys.find(event.key.keysym.sym);
if (iter == keys.end()) {
switch (event.key.keysym.sym) {
@@ -399,15 +402,22 @@ int main(int argc, char *argv[]) {
blit::buttons &= ~iter->second;
}
}
- if (event.type == SDL_RENDER_TARGETS_RESET) {
+ break;
+
+ case SDL_RENDER_TARGETS_RESET:
std::cout << "Targets reset" << std::endl;
- }
- if (event.type == SDL_RENDER_DEVICE_RESET) {
+ break;
+
+ case SDL_RENDER_DEVICE_RESET:
std::cout << "Device reset" << std::endl;
- }
- if (event.type == SDL_USEREVENT) {
+ break;
+
+ case SDL_USEREVENT:
system_tick();
- }
+ break;
+
+ default:
+ break;
}
}
