make inputs up-to-date for game tick

This commit is contained in:
veclavtalica 2025-01-15 00:43:46 +03:00
parent 63abf3d374
commit 688d71953a
3 changed files with 10 additions and 2 deletions

View File

@ -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 */ /* TODO: don't spam it if it happens */
if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture && ctx.window_mouse_resident) != 0) if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture && ctx.window_mouse_resident) != 0)
log_warn("(%s) Mouse capture isn't supported.", __func__); log_warn("(%s) Mouse capture isn't supported.", __func__);
}
void input_state_update(InputState *input) {
int x, y; int x, y;
input->keyboard_state = SDL_GetKeyboardState(NULL); input->keyboard_state = SDL_GetKeyboardState(NULL);

View File

@ -76,6 +76,8 @@ void input_state_deinit(InputState *input);
void input_state_update(InputState *input); void input_state_update(InputState *input);
void input_state_update_postframe(InputState *input);
void input_reset_state(InputState *input); void input_reset_state(InputState *input);
#endif #endif

View File

@ -212,14 +212,17 @@ static void main_loop(void) {
poll_events(); poll_events();
if (ctx.window_size_has_changed) if (ctx.window_size_has_changed)
update_viewport(); update_viewport();
input_state_update(&ctx.input);
game_object_tick(); game_object_tick();
input_state_update_postframe(&ctx.input);
#ifdef TWN_FEATURE_PUSH_AUDIO #ifdef TWN_FEATURE_PUSH_AUDIO
static uint8_t audio_buffer[(AUDIO_FREQUENCY / 60) * sizeof (float) * 2]; static uint8_t audio_buffer[(AUDIO_FREQUENCY / 60) * sizeof (float) * 2];
audio_callback(NULL, audio_buffer, sizeof audio_buffer); audio_callback(NULL, audio_buffer, sizeof audio_buffer);
if (SDL_QueueAudio(ctx.audio_device, audio_buffer, sizeof audio_buffer)) if (SDL_QueueAudio(ctx.audio_device, audio_buffer, sizeof audio_buffer))
CRY_SDL("Error queueing audio: "); CRY_SDL("Error queueing audio: ");
#endif #endif
input_state_update(&ctx.input);
preserve_persistent_ctx_fields(); preserve_persistent_ctx_fields();
ctx.frame_accumulator -= ctx.desired_frametime; ctx.frame_accumulator -= ctx.desired_frametime;