From 96ea7246ae1ed0dd628366926a8c826dd5f3d858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 3 Oct 2020 21:26:48 +0200 Subject: [PATCH] Add signal handler --- main_sdl.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main_sdl.c b/main_sdl.c index 5a39bcc..7ad579f 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -44,6 +44,7 @@ damage to make it a bit harder. */ #define SFG_PLAYER_DAMAGE_MULTIPLIER 1024 +#define SFG_DITHERED_SHADOW 1 #define MUSIC_VOLUME 64 @@ -270,13 +271,15 @@ void mainLoopIteration() while (SDL_PollEvent(&event)) // also automatically updates sdlKeyboardState { - if(event.type == SDL_MOUSEWHEEL) + if (event.type == SDL_MOUSEWHEEL) { if (event.wheel.y > 0) // scroll up sdlMouseWheelState++; else if (event.wheel.y < 0) // scroll down sdlMouseWheelState--; } + else if (event.type == SDL_QUIT) + running = 0; } sdlMouseButtonState = SDL_GetMouseState(NULL,NULL); @@ -342,6 +345,11 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume) } } +void handleSignal(int signal) +{ + running = 0; +} + int main(int argc, char *argv[]) { uint8_t argHelp = 0; @@ -386,7 +394,7 @@ int main(int argc, char *argv[]) puts("SDL: initializing SDL"); - SFG_init(); + SFG_init(SDL_INIT_EVERYTHING); window = SDL_CreateWindow("raycasting", SDL_WINDOWPOS_UNDEFINED, @@ -417,6 +425,10 @@ int main(int argc, char *argv[]) SDL_Init(SDL_INIT_AUDIO); + signal(SIGINT,handleSignal); + signal(SIGQUIT,handleSignal); + signal(SIGTERM,handleSignal); + SDL_AudioSpec audioSpec; SDL_memset(&audioSpec, 0, sizeof(audioSpec));