fix resizing events, clean up the code

This commit is contained in:
veclavtalica 2025-02-04 00:24:31 +03:00
parent 42253fc58a
commit 00636d65a9

View File

@ -24,46 +24,7 @@
static SDL_Thread *opengl_load_thread;
static int event_callback(void *userdata, SDL_Event *event) {
(void)userdata;
switch (event->type) {
case SDL_WINDOWEVENT:
if (event->window.windowID != ctx.window_id)
break;
switch (event->window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
ctx.window_dims.x = (float)event->window.data1;
ctx.window_dims.y = (float)event->window.data2;
ctx.resync_flag = true;
break;
case SDL_WINDOWEVENT_FOCUS_LOST: {
ctx.window_mouse_resident = false;
break;
}
case SDL_WINDOWEVENT_FOCUS_GAINED: {
ctx.window_mouse_resident = true;
break;
}
default:
break;
}
break;
default:
break;
}
/* ignored */
return 0;
}
/* note: it drives most of IO implicitly, such as audio callbacks */
static void poll_events(void) {
SDL_Event e;
@ -81,9 +42,22 @@ static void poll_events(void) {
switch (e.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
ctx.window_dims.x = (float)e.window.data1;
ctx.window_dims.y = (float)e.window.data2;
ctx.resync_flag = true;
ctx.window_size_has_changed = true;
break;
case SDL_WINDOWEVENT_FOCUS_LOST: {
ctx.window_mouse_resident = false;
break;
}
case SDL_WINDOWEVENT_FOCUS_GAINED: {
ctx.window_mouse_resident = true;
break;
}
default:
break;
}
@ -547,9 +521,6 @@ static bool initialize(void) {
ctx.game.resolution.x = (float)ctx.base_render_width;
ctx.game.resolution.y = (float)ctx.base_render_height;
/* add a watcher for immediate updates on window size */
SDL_AddEventWatch(event_callback, NULL);
/* random seeding */
/* SDL_GetPerformanceCounter returns some platform-dependent number. */
/* it should vary between game instances. i checked! random enough for me. */
@ -584,8 +555,7 @@ static bool initialize(void) {
ctx.time_averager[i] = ctx.desired_frametime;
}
/* rendering */
/* configuration */
/* engine configuration */
{
toml_datum_t datum_texture_atlas_size = toml_int_in(engine, "texture_atlas_size");
if (!datum_texture_atlas_size.ok) {