Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/executor/GameStateExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions code/gamesequence/gamesequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion code/mission/missionbriefcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions code/mission/missionbriefcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions qtfred/src/ui/widgets/BriefingMapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ void BriefingMapWidget::applyStageTransition(int stageNum, int transitionTime) {
Briefing = briefPtr;

auto& stage = briefPtr->stages[stageNum];
// 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();
}
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.
Expand Down
17 changes: 17 additions & 0 deletions qtfred/src/ui/widgets/CampaignMissionGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions qtfred/src/ui/widgets/CampaignMissionGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down
30 changes: 30 additions & 0 deletions test/src/executor/test_game_state_execution_context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "executor/GameStateExecutionContext.h"
#include "gamesequence/gamesequence.h"

#include <gtest/gtest.h>

// 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());
}
57 changes: 57 additions & 0 deletions test/src/mission/test_briefing_move_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "mission/missionbriefcommon.h"

#include <gtest/gtest.h>

#include <cstring>

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));
}
10 changes: 10 additions & 0 deletions test/src/scripting/api/async.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include "executor/global_executors.h"
#include "scripting/ScriptingTestFixture.h"

class ScriptingAsyncTest : public test::scripting::ScriptingTestFixture {
Expand Down Expand Up @@ -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())"));
}
8 changes: 8 additions & 0 deletions test/src/source_groups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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())
Loading