diff --git a/src/twn_input.c b/src/twn_input.c index cae2220..cc00eca 100644 --- a/src/twn_input.c +++ b/src/twn_input.c @@ -216,11 +216,14 @@ void input_state_deinit(InputState *input) { } -void input_state_update(InputState *input) { +void input_state_update_postframe(InputState *input) { /* TODO: don't spam it if it happens */ if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture && ctx.window_mouse_resident) != 0) log_warn("(%s) Mouse capture isn't supported.", __func__); +} + +void input_state_update(InputState *input) { int x, y; input->keyboard_state = SDL_GetKeyboardState(NULL); diff --git a/src/twn_input_c.h b/src/twn_input_c.h index d30d129..cd6d196 100644 --- a/src/twn_input_c.h +++ b/src/twn_input_c.h @@ -76,6 +76,8 @@ void input_state_deinit(InputState *input); void input_state_update(InputState *input); +void input_state_update_postframe(InputState *input); + void input_reset_state(InputState *input); #endif diff --git a/src/twn_loop.c b/src/twn_loop.c index b3e2cfc..b817ba6 100644 --- a/src/twn_loop.c +++ b/src/twn_loop.c @@ -212,14 +212,17 @@ static void main_loop(void) { poll_events(); if (ctx.window_size_has_changed) update_viewport(); + input_state_update(&ctx.input); game_object_tick(); + input_state_update_postframe(&ctx.input); + #ifdef TWN_FEATURE_PUSH_AUDIO static uint8_t audio_buffer[(AUDIO_FREQUENCY / 60) * sizeof (float) * 2]; audio_callback(NULL, audio_buffer, sizeof audio_buffer); if (SDL_QueueAudio(ctx.audio_device, audio_buffer, sizeof audio_buffer)) CRY_SDL("Error queueing audio: "); #endif - input_state_update(&ctx.input); + preserve_persistent_ctx_fields(); ctx.frame_accumulator -= ctx.desired_frametime;