From 99a1784aaf74d2af36d24c61e3706d23e50febae Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 11 Jun 2011 12:54:14 +0200 Subject: [PATCH] Move window logic away from SDL input. We weren't using the event loop anyways ... --- gfx/gl.c | 31 +++++++++++++++++++++++++++---- gfx/sdl.c | 19 ++++++++++++++++++- input/sdl.c | 32 ++------------------------------ input/ssnes_sdl_input.h | 6 ------ 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 910f78af78..a6e78a2a47 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -679,9 +679,36 @@ static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yam coords[7] = yamt; } +static void check_window(gl_t *gl) +{ + SDL_Event event; + + // Search for events we care about ... + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + gl->quitting = true; + break; + + case SDL_VIDEORESIZE: + gl->should_resize = true; + gl->win_width = event.resize.w; + gl->win_height = event.resize.h; + break; + + default: + break; + } + } +} + static bool gl_frame(void *data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = data; + check_window(gl); + gl_shader_use(1); gl->frame_count++; @@ -1135,10 +1162,6 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo sdl_input_t *sdl_input = input_sdl.init(); if (sdl_input) { - sdl_input->quitting = &gl->quitting; - sdl_input->should_resize = &gl->should_resize; - sdl_input->new_width = &gl->win_width; - sdl_input->new_height = &gl->win_height; *input = &input_sdl; *input_data = sdl_input; } diff --git a/gfx/sdl.c b/gfx/sdl.c index 04e83713ba..e870afe455 100644 --- a/gfx/sdl.c +++ b/gfx/sdl.c @@ -270,7 +270,6 @@ static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu sdl_input_t *sdl_input = input_sdl.init(); if (sdl_input) { - sdl_input->quitting = &vid->quitting; *input = &input_sdl; *input_data = sdl_input; } @@ -407,9 +406,27 @@ static void convert_32bit_32bit_shift(uint32_t *out, unsigned outpitch, const ui } } +static void check_window(sdl_video_t *vid) +{ + SDL_Event event; + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + vid->quitting = true; + break; + + default: + break; + } + } +} + static bool sdl_gfx_frame(void *data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { sdl_video_t *vid = data; + check_window(vid); if (SDL_MUSTLOCK(vid->buffer)) SDL_LockSurface(vid->buffer); diff --git a/input/sdl.c b/input/sdl.c index 0744e07971..28ff41b7e2 100644 --- a/input/sdl.c +++ b/input/sdl.c @@ -317,9 +317,8 @@ static void sdl_poll_mouse(sdl_input_t *sdl) static void sdl_input_poll(void *data) { - sdl_input_t *sdl = data; SDL_PumpEvents(); - SDL_Event event; + sdl_input_t *sdl = data; #ifdef HAVE_DINPUT sdl_dinput_poll(sdl->di); @@ -327,34 +326,7 @@ static void sdl_input_poll(void *data) SDL_JoystickUpdate(); #endif - sdl_poll_mouse(data); - - // Search for events... - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - if (sdl->quitting) - { - *sdl->quitting = true; - return; - } - break; - - case SDL_VIDEORESIZE: - if (sdl->should_resize) - { - *sdl->new_width = event.resize.w; - *sdl->new_height = event.resize.h; - *sdl->should_resize = true; - } - break; - - default: - break; - } - } + sdl_poll_mouse(sdl); } const input_driver_t input_sdl = { diff --git a/input/ssnes_sdl_input.h b/input/ssnes_sdl_input.h index ca425dc521..f1d59ff152 100644 --- a/input/ssnes_sdl_input.h +++ b/input/ssnes_sdl_input.h @@ -39,14 +39,8 @@ typedef struct sdl_input bool use_keyboard; - // A video driver could pre-init with the SDL driver and have it handle resizing events... - bool *quitting; - bool *should_resize; - unsigned *new_width; - unsigned *new_height; int16_t mouse_x, mouse_y; int16_t mouse_l, mouse_r, mouse_m; - } sdl_input_t; #endif