Skip to content

Commit

Permalink
Move fix for OpenEnroth#1535 and begin test design
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton committed Mar 13, 2024
1 parent 9f2f494 commit 8f7fe64
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/Engine/Components/Control/EngineController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "Engine/SaveLoad.h"
#include "Engine/EngineGlobals.h"
#include "Engine/mm7_data.h"
#include "Engine/Spells/CastSpellInfo.h"

#include "Library/Platform/Application/PlatformApplication.h"

Expand Down Expand Up @@ -117,10 +116,6 @@ void EngineController::goToMainMenu() {
throw Exception("Couldn't return to main menu");
};

// Clear the spell/message queue to fix #1535
CastSpellInfoHelpers::clearSpellQueue(); // TODO(pskelton): move me somewhere more appropriate?
engine->_messageQueue->clear();

// Skip movies.
while (current_screen_type == SCREEN_VIDEO) {
maybeThrow();
Expand Down
8 changes: 8 additions & 0 deletions src/Engine/Spells/CastSpellInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ void CastSpellInfoHelpers::clearSpellQueue() {
}
}

bool CastSpellInfoHelpers::hasQueuedSpells() {
for (const CastSpellInfo& spellInfo : pCastSpellInfo) { // cycle through spell queue
if (spellInfo.uSpellID != SPELL_NONE)
return true;
}
return false;
}

void CastSpellInfoHelpers::castSpell() {
CharacterSkillType which_skill;
AIDirection target_direction;
Expand Down
4 changes: 4 additions & 0 deletions src/Engine/Spells/CastSpellInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace CastSpellInfoHelpers {
* Clear queue
*/
void clearSpellQueue();
/**
* Test for spells in queue
*/
bool hasQueuedSpells();
}; // namespace CastSpellInfoHelpers

class GUIWindow;
Expand Down
23 changes: 23 additions & 0 deletions test/Bin/GameTest/GameTests_1500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include "Testing/Game/GameTest.h"

#include "Engine/Engine.h"
#include "Engine/mm7_data.h"
#include "Engine/Party.h"
#include "Engine/Spells/CastSpellInfo.h"
#include "GUI/GUIWindow.h"
#include "GUI/UI/UIPartyCreation.h"

#include "Utility/Exception.h"

// 1500

GAME_TEST(Issues, Issue1503) {
Expand All @@ -24,3 +28,22 @@ GAME_TEST(Issues, Issue1510) {
EXPECT_LT(partyHealth.back(), partyHealth.front());
EXPECT_LE(actorDistTape.max(), meleeRange);
}

// TODO(pskelton): Rough test idea but need to prove this will catch the issue first
/*
GAME_TEST(Issues, Issue1535a) {
// Queue some messages then throw to 'fail' test
auto queueMessageAndThrow = [] {
engine->_messageQueue->addMessageCurrentFrame(UIMSG_ShowGameOverWindow, 0, 0);
pushSpellOrRangedAttack(SPELL_LIGHT_DAY_OF_THE_GODS, 0, CombinedSkillValue(10, CHARACTER_SKILL_MASTERY_GRANDMASTER), 0, 0);
throw Exception("Failing test on purpose");
};
EXPECT_ANY_THROW(test.playTraceFromTestData("issue_1510.mm7", "issue_1510.json", queueMessageAndThrow););
}
GAME_TEST(Issues, Issue1535b) {
// Queued messages should be cleared if test fails
EXPECT_FALSE(engine->_messageQueue.get()->haveMessages());
EXPECT_FALSE(CastSpellInfoHelpers::hasQueuedSpells());
}
*/

6 changes: 6 additions & 0 deletions test/Testing/Game/TestController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Engine/Components/Deterministic/EngineDeterministicComponent.h"
#include "Engine/EngineGlobals.h"
#include "Engine/Engine.h"
#include "Engine/Spells/CastSpellInfo.h"

#include "Media/Audio/AudioPlayer.h"

Expand Down Expand Up @@ -80,6 +81,11 @@ void TestController::prepareForNextTestInternal() {
_tapeCallbacks.clear();
::application->component<GameKeyboardController>()->reset();
::application->component<EngineDeterministicComponent>()->restart(frameTimeMs, rngType);

// Clear the spell/message queue to fix #1535
CastSpellInfoHelpers::clearSpellQueue();
engine->_messageQueue->clear();

_controller->goToMainMenu();
}

Expand Down

0 comments on commit 8f7fe64

Please sign in to comment.