twn_loop.c: use event watcher for more immediate resize redraw

This commit is contained in:
veclav talica 2024-10-07 22:35:48 +03:00
parent 7d92eff691
commit fab958c963

View File

@ -21,6 +21,31 @@
#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) {
SDL_Event e;
@ -163,13 +188,6 @@ static void main_loop(void) {
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);
game_object_tick();
@ -478,6 +496,9 @@ static bool initialize(void) {
ctx.game.window_w = (int)ctx.base_render_width;
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 */
{