twn_loop.c: use event watcher for more immediate resize redraw
This commit is contained in:
parent
7d92eff691
commit
fab958c963
@ -21,6 +21,31 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
|
static int event_callback(void *userdata, SDL_Event *event) {
|
||||||
|
switch (event->type) {
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
if (event->window.windowID != ctx.window_id)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (event->window.event) {
|
||||||
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
|
ctx.game.window_w = event->window.data1;
|
||||||
|
ctx.game.window_h = event->window.data2;
|
||||||
|
ctx.resync_flag = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void poll_events(void) {
|
static void poll_events(void) {
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
|
|
||||||
@ -163,13 +188,6 @@ static void main_loop(void) {
|
|||||||
|
|
||||||
poll_events();
|
poll_events();
|
||||||
|
|
||||||
if (ctx.game.window_size_has_changed) {
|
|
||||||
Vec2i size;
|
|
||||||
SDL_GetWindowSize(ctx.window, &size.x, &size.y);
|
|
||||||
ctx.game.window_w = size.x;
|
|
||||||
ctx.game.window_h = size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
input_state_update(&ctx.game.input);
|
input_state_update(&ctx.game.input);
|
||||||
|
|
||||||
game_object_tick();
|
game_object_tick();
|
||||||
@ -478,6 +496,9 @@ static bool initialize(void) {
|
|||||||
ctx.game.window_w = (int)ctx.base_render_width;
|
ctx.game.window_w = (int)ctx.base_render_width;
|
||||||
ctx.game.window_h = (int)ctx.base_render_height;
|
ctx.game.window_h = (int)ctx.base_render_height;
|
||||||
|
|
||||||
|
/* add a watcher for immediate updates on window size */
|
||||||
|
SDL_AddEventWatch(event_callback, NULL);
|
||||||
|
|
||||||
/* audio initialization */
|
/* audio initialization */
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user