From 9f9d1e9caad6ca654149d235cdc20c8700f03463 Mon Sep 17 00:00:00 2001 From: Saga port Date: Sun, 15 Nov 2026 10:08:40 +0100 Subject: [PATCH 1/2] Cutscenes: don't let the key that started a movie skip it Movies are skipped on the release of Escape, Enter or Space. When a movie is started by one of those keys, for example Enter in the tech room cutscene list, its release arrives once playback has begun and skips the movie at once. #4461 already dropped deferred releases from the loading screen, but a live release still gets through. Skip only on the release of a key whose press arrived during playback, ignoring auto-repeat. The press listener only observes, so the other key listeners and the On Key Pressed hook still see presses, and it runs ahead of them so none can hide a press from it. Only the release that stops playback is consumed; other releases pass on, so a key held from before the movie is not left marked as down. Deferred key-downs are now dropped together with their releases, since a replayed down would count as a press. --- code/cutscene/movie.cpp | 38 ++++++++++++++++++++++++++------------ code/osapi/osapi.cpp | 4 +++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/code/cutscene/movie.cpp b/code/cutscene/movie.cpp index 0ac531a81db..003d8411aee 100644 --- a/code/cutscene/movie.cpp +++ b/code/cutscene/movie.cpp @@ -41,6 +41,9 @@ using namespace cutscene; struct PlaybackState { bool playing = true; + // Skip keys whose press arrived during playback. Only their release skips the movie, so a + // key that was already held when the movie started (e.g. Enter in the tech room) cannot. + SCP_unordered_set skip_keys_pressed; vec2d posTopLeft; vec2d posBottomRight; @@ -207,20 +210,30 @@ void movie_display_loop(Player* player, PlaybackState* state) { // We will sleep at most half the time a frame would be displayed auto sleepTime = static_cast((1. / (4. * player->getMovieProperties().fps)) * 1000.); - auto listener = [state](const SDL_Event& event) { - switch (event.key.key) { - case SDLK_ESCAPE: - case SDLK_KP_ENTER: - case SDLK_RETURN: - case SDLK_SPACE: - state->playing = false; - return true; - default: + auto is_skip_key = [](SDL_Keycode key) { + return key == SDLK_ESCAPE || key == SDLK_KP_ENTER || key == SDLK_RETURN || key == SDLK_SPACE; + }; + // Only records presses and passes them on to the other key listeners. It is registered ahead + // of them so that none can consume a press before it is seen. Auto-repeat is not a press. + auto key_down_listener = [state, is_skip_key](const SDL_Event& event) { + if (is_skip_key(event.key.key) && !event.key.repeat) { + state->skip_keys_pressed.insert(event.key.key); + } + return false; + }; + // Consumes only the release that stops playback. Any other release is passed on, so the key + // state stays right for a key that was already held when the movie started. + auto key_up_listener = [state, is_skip_key](const SDL_Event& event) { + if (!is_skip_key(event.key.key) || state->skip_keys_pressed.erase(event.key.key) == 0) { return false; } + state->playing = false; + return true; }; - // Use a dedicated listener here since we want to listen for the KEYUP event - auto key_handle = os::events::addEventListener(SDL_EVENT_KEY_UP, os::events::DEFAULT_LISTENER_WEIGHT - 10, listener); + auto key_down_handle = + os::events::addEventListener(SDL_EVENT_KEY_DOWN, os::events::DEFAULT_LISTENER_WEIGHT - 20, key_down_listener); + auto key_up_handle = + os::events::addEventListener(SDL_EVENT_KEY_UP, os::events::DEFAULT_LISTENER_WEIGHT - 10, key_up_listener); // slight hack to make sure that game_set_frametime() doesn't also try to cap the framerate auto fpsCapSave = Cmdline_NoFPSCap; @@ -263,7 +276,8 @@ void movie_display_loop(Player* player, PlaybackState* state) { Cmdline_NoFPSCap = fpsCapSave; - os::events::removeEventListener(key_handle); + os::events::removeEventListener(key_down_handle); + os::events::removeEventListener(key_up_handle); // flush keys so we don't pass anything to the current state key_flush(); diff --git a/code/osapi/osapi.cpp b/code/osapi/osapi.cpp index 6379346e2f4..1ddbfbb8472 100644 --- a/code/osapi/osapi.cpp +++ b/code/osapi/osapi.cpp @@ -884,7 +884,9 @@ void os_remove_deferred_cutscene_key_events() { deferred_events.erase( std::remove_if(deferred_events.begin(), deferred_events.end(), [](const SDL_Event &event) { - return (event.type == SDL_EVENT_KEY_UP) && ( + // Remove the whole press: a deferred key-down replayed into the movie would + // count as a press during playback, and its live release would then skip. + return (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) && ( event.key.key == SDLK_KP_ENTER || event.key.key == SDLK_RETURN || event.key.key == SDLK_SPACE From 1a0aa74ae7187c6fcd20343117d1e340807161ca Mon Sep 17 00:00:00 2001 From: Saga port Date: Wed, 18 Nov 2026 08:19:10 +0100 Subject: [PATCH 2/2] Run the movie release listener ahead of scripted UI too Run the key-up listener at -20, before the scripted UI listener at -10 can consume the release. Equal weights have no defined order, so the old tie could hide a skip release from movie playback. Document the ordering beside the registration so the weight is not mistaken for an interchangeable priority. --- code/cutscene/movie.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/cutscene/movie.cpp b/code/cutscene/movie.cpp index 003d8411aee..129e9ebadb4 100644 --- a/code/cutscene/movie.cpp +++ b/code/cutscene/movie.cpp @@ -232,8 +232,9 @@ void movie_display_loop(Player* player, PlaybackState* state) { }; auto key_down_handle = os::events::addEventListener(SDL_EVENT_KEY_DOWN, os::events::DEFAULT_LISTENER_WEIGHT - 20, key_down_listener); + // Run at -20 before the scripted UI at -10 can consume the release; equal weights have no defined order. auto key_up_handle = - os::events::addEventListener(SDL_EVENT_KEY_UP, os::events::DEFAULT_LISTENER_WEIGHT - 10, key_up_listener); + os::events::addEventListener(SDL_EVENT_KEY_UP, os::events::DEFAULT_LISTENER_WEIGHT - 20, key_up_listener); // slight hack to make sure that game_set_frametime() doesn't also try to cap the framerate auto fpsCapSave = Cmdline_NoFPSCap;