changeset 16:ae58e7c3c328

Poll events regularly to avoid unresponsive app warnings. Handle quit event
author Michael Pavone <pavone@retrodev.com>
date Sun, 27 Mar 2016 21:42:10 -0700
parents c8a0dbd7752c
children 41ec033ef8c3
files src/main.c src/system.h src/system_sdl.c
diffstat 3 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.c	Sun Mar 27 21:31:34 2016 -0700
+++ b/src/main.c	Sun Mar 27 21:42:10 2016 -0700
@@ -107,6 +107,7 @@
 		vdp_run(&context->video, CYCLES_PER_FRAME);
 		context->proc->cycles -= CYCLES_PER_FRAME;
 		context->video.cycles -= CYCLES_PER_FRAME;
+		system_poll_events();
 	}
 }
 
--- a/src/system.h	Sun Mar 27 21:31:34 2016 -0700
+++ b/src/system.h	Sun Mar 27 21:42:10 2016 -0700
@@ -4,5 +4,6 @@
 int system_init(int width, int height);
 uint16_t *system_get_framebuffer(int *pitch);
 void system_framebuffer_updated();
+void system_poll_events();
 
 #endif //SYSTEM_H_
--- a/src/system_sdl.c	Sun Mar 27 21:31:34 2016 -0700
+++ b/src/system_sdl.c	Sun Mar 27 21:42:10 2016 -0700
@@ -1,5 +1,6 @@
 #include <SDL.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 
 SDL_Window   *window;
@@ -49,3 +50,17 @@
 	SDL_RenderPresent(renderer);
 }
 
+void system_poll_events()
+{
+	SDL_Event event;
+	while(SDL_PollEvent(&event))
+	{
+		switch (event.type)
+		{
+		case SDL_QUIT:
+			exit(0);
+			break;
+		}
+	}
+}
+