From 9d1c0026a6e3115a2bf59187001e681a5125e83c Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 11 Nov 2026 00:47:11 -0800 Subject: [PATCH 1/4] qtFRED briefing editor: start fresh on an instant or same-index stage change Icons that moved between two stages vanished after a cut or a jump of more than one stage, until the camera was moved. The engine builds icon movers from the previous stage and divides by the transition time, so a zero-time change needs the previous stage cleared first, as the game does before a cut or a jump. The same reset now also runs when the stage index is unchanged, because Delete Stage and a team switch put a different stage under the same index and the preview kept the old camera. The zero-time part is the #7726 hunk from #7675. Fixes #7726. --- qtfred/src/ui/widgets/BriefingMapWidget.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qtfred/src/ui/widgets/BriefingMapWidget.cpp b/qtfred/src/ui/widgets/BriefingMapWidget.cpp index 2f6389d79ad..8e1e01229c3 100644 --- a/qtfred/src/ui/widgets/BriefingMapWidget.cpp +++ b/qtfred/src/ui/widgets/BriefingMapWidget.cpp @@ -235,6 +235,11 @@ void BriefingMapWidget::applyStageTransition(int stageNum, int transitionTime) { Briefing = briefPtr; auto& stage = briefPtr->stages[stageNum]; + // Start fresh on an instant change, because the engine divides icon movement by the transition time, and on + // an unchanged index, which holds a different stage after a delete or a team switch. + if (transitionTime <= 0 || stageNum == _currentStage) { + brief_reset_last_new_stage(); + } brief_set_new_stage(&stage.camera_pos, &stage.camera_orient, transitionTime, stageNum); // Editor behavior: start highlights as soon as the camera reaches its target // instead of waiting for briefing text wipe timing. From 7165a22e80014168fca481f25a482991a69e634a Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 11 Nov 2026 00:47:18 -0800 Subject: [PATCH 2/4] qtFRED campaign editor: fit the mission graph once its tab is shown Opening a campaign from the Campaign Specs tab fitted the graph to a view that had never been laid out, so the whole flow shrank to a speck and the Campaign Flow tab looked empty until the campaign was opened again. A fit asked for while the view is hidden now runs when the view is shown. --- qtfred/src/ui/widgets/CampaignMissionGraph.cpp | 17 +++++++++++++++++ qtfred/src/ui/widgets/CampaignMissionGraph.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/qtfred/src/ui/widgets/CampaignMissionGraph.cpp b/qtfred/src/ui/widgets/CampaignMissionGraph.cpp index 4e0398b5d14..a91d5655a37 100644 --- a/qtfred/src/ui/widgets/CampaignMissionGraph.cpp +++ b/qtfred/src/ui/widgets/CampaignMissionGraph.cpp @@ -1073,6 +1073,14 @@ void CampaignMissionGraph::applyFocusEmphasis() void CampaignMissionGraph::zoomToFitAll(qreal margin) { + // A view on a hidden tab may not have been laid out yet, so the fit waits until it is shown. + if (!isVisible()) { + m_fitPending = true; + m_pendingFitMargin = margin; + return; + } + m_fitPending = false; + if (!m_scene || m_scene->items().isEmpty()) return; const QRectF itemsRect = m_scene->itemsBoundingRect().adjusted(-margin, -margin, margin, margin); @@ -1082,6 +1090,15 @@ void CampaignMissionGraph::zoomToFitAll(qreal margin) } } +void CampaignMissionGraph::showEvent(QShowEvent* e) +{ + QGraphicsView::showEvent(e); + + if (m_fitPending) { + zoomToFitAll(m_pendingFitMargin); + } +} + void CampaignMissionGraph::setGridVisible(bool on) { if (m_gridVisible == on) diff --git a/qtfred/src/ui/widgets/CampaignMissionGraph.h b/qtfred/src/ui/widgets/CampaignMissionGraph.h index b49000a2d25..0106c00fccb 100644 --- a/qtfred/src/ui/widgets/CampaignMissionGraph.h +++ b/qtfred/src/ui/widgets/CampaignMissionGraph.h @@ -173,6 +173,8 @@ class CampaignMissionGraph final : public QGraphicsView { void mouseReleaseEvent(QMouseEvent* e) override; // Context menu void contextMenuEvent(QContextMenuEvent* e) override; + // Deferred fit + void showEvent(QShowEvent* e) override; private slots: void onNodeMoved(int missionIndex, QPointF sceneTopLeft); @@ -220,6 +222,8 @@ class CampaignMissionGraph final : public QGraphicsView { qreal m_currentScale{1.0}; const qreal kMinScale{0.2}; const qreal kMaxScale{3.0}; + bool m_fitPending{false}; + qreal m_pendingFitMargin{0.0}; bool m_updatingSceneRect{false}; bool m_spawnPending{false}; From 70c2f70863347b33952be5231be65003265fecf8 Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 11 Nov 2026 00:47:25 -0800 Subject: [PATCH 3/4] Let async Lua run in FRED, where there is no game state stack FRED and qtFRED never start the game state machine. Capturing a game state context there, which async.run does by default, asserted in gameseq_get_state_instance_id in Debug builds and read before the start of the state array in Release. The instance id is now 0 without a state stack, like gameseq_get_state returns GS_STATE_INVALID, and a context captured without a stack stays valid while there is still none. Fixes #6521. --- code/executor/GameStateExecutionContext.cpp | 5 ++++ code/gamesequence/gamesequence.cpp | 3 ++ .../test_game_state_execution_context.cpp | 30 +++++++++++++++++++ test/src/scripting/api/async.cpp | 10 +++++++ test/src/source_groups.cmake | 4 +++ .../data/scripts/test.lua | 16 ++++++++++ 6 files changed, 68 insertions(+) create mode 100644 test/src/executor/test_game_state_execution_context.cpp create mode 100644 test/test_data/scripting/async/run/runOnFrameExecutorWithoutGameState/data/scripts/test.lua diff --git a/code/executor/GameStateExecutionContext.cpp b/code/executor/GameStateExecutionContext.cpp index a441ca56cd4..463264266e4 100644 --- a/code/executor/GameStateExecutionContext.cpp +++ b/code/executor/GameStateExecutionContext.cpp @@ -12,6 +12,11 @@ GameStateExecutionContext::~GameStateExecutionContext() = default; IExecutionContext::State GameStateExecutionContext::determineContextState() const { + // FRED never starts the game state machine, so a context captured there has no state to leave. + if (!GameState_Stack_Valid()) { + return m_contextState == GS_STATE_INVALID ? State::Valid : State::Invalid; + } + const auto depth = gameseq_get_state_idx(m_contextState); if (depth < 0) { diff --git a/code/gamesequence/gamesequence.cpp b/code/gamesequence/gamesequence.cpp index 80e7adac2e7..07c91a8d937 100644 --- a/code/gamesequence/gamesequence.cpp +++ b/code/gamesequence/gamesequence.cpp @@ -434,6 +434,9 @@ int gameseq_get_state_idx(int state) } int gameseq_get_state_instance_id(int depth) { + if (!GameState_Stack_Valid()) + return 0; + Assert(depth <= gs_current_stack); return gs[gs_current_stack - depth].instance_id; diff --git a/test/src/executor/test_game_state_execution_context.cpp b/test/src/executor/test_game_state_execution_context.cpp new file mode 100644 index 00000000000..e65a3920efd --- /dev/null +++ b/test/src/executor/test_game_state_execution_context.cpp @@ -0,0 +1,30 @@ +#include "executor/GameStateExecutionContext.h" +#include "gamesequence/gamesequence.h" + +#include + +// The unit tests, like FRED and qtFRED, never call gameseq_init(), so there is no game state stack here. +TEST(GameStateExecutionContextTest, valid_without_state_stack) +{ + ASSERT_FALSE(GameState_Stack_Valid()); + + const auto context = executor::GameStateExecutionContext::captureContext(); + + EXPECT_EQ(executor::IExecutionContext::State::Valid, context->determineContextState()); +} + +TEST(GameStateExecutionContextTest, real_state_invalid_without_state_stack) +{ + ASSERT_FALSE(GameState_Stack_Valid()); + + const executor::GameStateExecutionContext context(GS_STATE_MAIN_MENU, 1); + + EXPECT_EQ(executor::IExecutionContext::State::Invalid, context.determineContextState()); +} + +TEST(GameStateExecutionContextTest, instance_id_without_state_stack) +{ + ASSERT_FALSE(GameState_Stack_Valid()); + + EXPECT_EQ(0, gameseq_get_state_instance_id()); +} diff --git a/test/src/scripting/api/async.cpp b/test/src/scripting/api/async.cpp index 2f52f4266b8..85e39919f5d 100644 --- a/test/src/scripting/api/async.cpp +++ b/test/src/scripting/api/async.cpp @@ -1,4 +1,5 @@ +#include "executor/global_executors.h" #include "scripting/ScriptingTestFixture.h" class ScriptingAsyncTest : public test::scripting::ScriptingTestFixture { @@ -65,3 +66,12 @@ TEST_F(ScriptingAsyncRunTest, runWithErroredAwait) { this->EvalTestScript(); } + +TEST_F(ScriptingAsyncRunTest, runOnFrameExecutorWithoutGameState) +{ + this->EvalTestScript(); + + executor::OnFrameExecutor->process(); + + ASSERT_TRUE(_state->EvalString("assert(function_was_run and asyncPromise:isResolved())")); +} diff --git a/test/src/source_groups.cmake b/test/src/source_groups.cmake index e07770a6367..03df7f01e60 100644 --- a/test/src/source_groups.cmake +++ b/test/src/source_groups.cmake @@ -17,6 +17,10 @@ add_file_folder("CFile" cfile/cfile.cpp ) +add_file_folder("Executor" + executor/test_game_state_execution_context.cpp +) + add_file_folder("Globalincs" globalincs/test_flagset.cpp globalincs/test_safe_strings.cpp diff --git a/test/test_data/scripting/async/run/runOnFrameExecutorWithoutGameState/data/scripts/test.lua b/test/test_data/scripting/async/run/runOnFrameExecutorWithoutGameState/data/scripts/test.lua new file mode 100644 index 00000000000..a5a6ead206a --- /dev/null +++ b/test/test_data/scripting/async/run/runOnFrameExecutorWithoutGameState/data/scripts/test.lua @@ -0,0 +1,16 @@ + +local assert = require("assert") + +local context = async.context.captureGameState() +assert.isTrue(context:determineState() == CONTEXT_VALID) + +function_was_run = false + +asyncPromise = async.run(function() + function_was_run = true + return "FrameReturn" +end, async.OnFrameExecutor) + +-- The body only runs once the executor is processed, which the C++ side of this test does. +assert.isFalse(function_was_run) +assert.isFalse(asyncPromise:isResolved()) From b3d940397457bd72d0297b82f2d11ec0b2195693 Mon Sep 17 00:00:00 2001 From: Dustinspace217 Date: Wed, 11 Nov 2026 01:12:25 -0800 Subject: [PATCH 4/4] Briefing: draw a moved icon at its new position on an instant stage change In the game, a briefing stage with a camera time of 0 and no cut flag lost every icon that had moved from the previous stage. The icon mover divides by the transition time, so its speed became infinite and the icon was never drawn. An icon now gets no mover when the time is exactly 0 and is drawn at its new position instead. Other times, and the fades for icons that appear or disappear, are unchanged. No retail FreeSpace 2 briefing has a stage with a camera time of 0. --- code/mission/missionbriefcommon.cpp | 3 +- code/mission/missionbriefcommon.h | 1 + qtfred/src/ui/widgets/BriefingMapWidget.cpp | 4 +- test/src/mission/test_briefing_move_list.cpp | 57 ++++++++++++++++++++ test/src/source_groups.cmake | 4 ++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 test/src/mission/test_briefing_move_list.cpp diff --git a/code/mission/missionbriefcommon.cpp b/code/mission/missionbriefcommon.cpp index c6920dd8fa8..0d8826573d7 100644 --- a/code/mission/missionbriefcommon.cpp +++ b/code/mission/missionbriefcommon.cpp @@ -1916,7 +1916,8 @@ int brief_set_move_list(int new_stage, int current_stage, float time) for ( j = 0; j < newb->num_icons; j++ ) { if ( ( cb->icons[i].id != 0 ) && ( cb->icons[i].id == newb->icons[j].id ) ) { is_gone=0; - if ( vm_vec_cmp(&cb->icons[i].pos, &newb->icons[j].pos) ) { + // with no time to move in, the icon is drawn at its new position; a mover would divide by zero + if ( (time != 0.0f) && vm_vec_cmp(&cb->icons[i].pos, &newb->icons[j].pos) ) { k = brief_get_free_move_icon(); if ( k == -1 ) { diff --git a/code/mission/missionbriefcommon.h b/code/mission/missionbriefcommon.h index 982e47706d3..05a5b874c12 100644 --- a/code/mission/missionbriefcommon.h +++ b/code/mission/missionbriefcommon.h @@ -355,6 +355,7 @@ void brief_render_icon_line(int stage_num, int line_num); void brief_init_map(); void brief_icons_init(); void brief_move_icon_reset(); +int brief_set_move_list(int new_stage, int current_stage, float time); void brief_common_close(); void brief_reset_icons(int stage_num); void brief_restart_text_wipe(); diff --git a/qtfred/src/ui/widgets/BriefingMapWidget.cpp b/qtfred/src/ui/widgets/BriefingMapWidget.cpp index 8e1e01229c3..8143e259177 100644 --- a/qtfred/src/ui/widgets/BriefingMapWidget.cpp +++ b/qtfred/src/ui/widgets/BriefingMapWidget.cpp @@ -235,8 +235,8 @@ void BriefingMapWidget::applyStageTransition(int stageNum, int transitionTime) { Briefing = briefPtr; auto& stage = briefPtr->stages[stageNum]; - // Start fresh on an instant change, because the engine divides icon movement by the transition time, and on - // an unchanged index, which holds a different stage after a delete or a team switch. + // Start fresh on an instant change, as the game does before a cut or a jump, and on an unchanged index, + // which holds a different stage after a delete or a team switch. if (transitionTime <= 0 || stageNum == _currentStage) { brief_reset_last_new_stage(); } diff --git a/test/src/mission/test_briefing_move_list.cpp b/test/src/mission/test_briefing_move_list.cpp new file mode 100644 index 00000000000..73d0bcb3f90 --- /dev/null +++ b/test/src/mission/test_briefing_move_list.cpp @@ -0,0 +1,57 @@ +#include "mission/missionbriefcommon.h" + +#include + +#include + +class BriefingMoveListTest : public ::testing::Test { + protected: + void SetUp() override + { + _savedBriefing = Briefing; + + for (int i = 0; i < 2; i++) { + memset(&_icons[i], 0, sizeof(brief_icon)); + _icons[i].id = 1; + _briefing.stages[i].icons = &_icons[i]; + _briefing.stages[i].num_icons = 1; + } + _icons[1].pos = vm_vec_new(100.0f, 0.0f, 0.0f); + _briefing.num_stages = 2; + + Briefing = &_briefing; + brief_move_icon_reset(); + } + + void TearDown() override + { + brief_move_icon_reset(); + Briefing = _savedBriefing; + } + + briefing _briefing; + brief_icon _icons[2]; + briefing* _savedBriefing = nullptr; +}; + +TEST_F(BriefingMoveListTest, timed_change_moves_the_icon) +{ + EXPECT_EQ(1, brief_set_move_list(1, 0, 0.5f)); +} + +TEST_F(BriefingMoveListTest, instant_change_builds_no_mover) +{ + EXPECT_EQ(0, brief_set_move_list(1, 0, 0.0f)); +} + +TEST_F(BriefingMoveListTest, negative_time_still_builds_a_mover) +{ + EXPECT_EQ(1, brief_set_move_list(1, 0, -1.0f)); +} + +TEST_F(BriefingMoveListTest, unmoved_icon_builds_no_mover) +{ + _icons[1].pos = _icons[0].pos; + + EXPECT_EQ(0, brief_set_move_list(1, 0, 0.5f)); +} diff --git a/test/src/source_groups.cmake b/test/src/source_groups.cmake index 03df7f01e60..5800479fc49 100644 --- a/test/src/source_groups.cmake +++ b/test/src/source_groups.cmake @@ -47,6 +47,10 @@ add_file_folder("menuui" menuui/test_intel_parse.cpp ) +add_file_folder("mission" + mission/test_briefing_move_list.cpp +) + add_file_folder("missioneditor" missioneditor/test_object_bounds.cpp )