Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1543 from captainurist/macos_fixes_485
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton authored Mar 15, 2024
2 parents 00d125f + 9304566 commit a2e1764
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
6 changes: 0 additions & 6 deletions src/Engine/Spells/CastSpellInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2987,12 +2987,6 @@ void CastSpellInfoHelpers::cancelSpellCastInProgress() {
}
}

void CastSpellInfoHelpers::clearSpellQueue() {
for (CastSpellInfo& spellInfo : pCastSpellInfo) { // cycle through spell queue
spellInfo = CastSpellInfo();
}
}

void pushSpellOrRangedAttack(SpellId spell,
int casterIndex,
CombinedSkillValue skill_value,
Expand Down
5 changes: 0 additions & 5 deletions src/Engine/Spells/CastSpellInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ namespace CastSpellInfoHelpers {
* @offset 0x00427D48
*/
void cancelSpellCastInProgress();

/**
* Clear queue
*/
void clearSpellQueue();
}; // namespace CastSpellInfoHelpers

class GUIWindow;
Expand Down
9 changes: 7 additions & 2 deletions src/GUI/GUIMessageQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ void GUIFrameMessageQueue::clear() {
}

void GUIFrameMessageQueue::popMessage(UIMessageType *msg, int *param, int *param2) {
peekMessage(msg, param, param2);
if (!messageQueue.empty())
messageQueue.pop();
}

void GUIFrameMessageQueue::peekMessage(UIMessageType *msg, int *param, int *param2) {
assert(msg != nullptr);

*msg = UIMSG_Invalid;
Expand All @@ -21,8 +27,7 @@ void GUIFrameMessageQueue::popMessage(UIMessageType *msg, int *param, int *param
return;
}

GUIMessage message = messageQueue.front();
messageQueue.pop();
const GUIMessage &message = messageQueue.front();

*msg = message.type;
if (param) {
Expand Down
5 changes: 5 additions & 0 deletions src/GUI/GUIMessageQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct GUIFrameMessageQueue {
void clear();
bool empty() { return messageQueue.empty(); }
void popMessage(UIMessageType *msg, int *param, int *param2);
void peekMessage(UIMessageType *msg, int *param, int *param2);
void addGUIMessage(UIMessageType msg, int param, int param2);

std::queue<GUIMessage> messageQueue;
Expand Down Expand Up @@ -57,6 +58,10 @@ class GUIMessageQueue {
_currentFrameQueue.popMessage(msg, param, param2);
}

void peekMessage(UIMessageType *msg, int *param, int *param2) {
_currentFrameQueue.peekMessage(msg, param, param2);
}

private:
GUIFrameMessageQueue _currentFrameQueue;
GUIFrameMessageQueue _nextFrameQueue;
Expand Down
25 changes: 25 additions & 0 deletions test/Bin/GameTest/GameTests_1500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Testing/Game/GameTest.h"

#include "Engine/Engine.h"
#include "Engine/mm7_data.h"
#include "Engine/Party.h"
#include "GUI/GUIWindow.h"
Expand All @@ -24,3 +25,27 @@ GAME_TEST(Issues, Issue1510) {
EXPECT_LT(partyHealth.back(), partyHealth.front());
EXPECT_LE(actorDistTape.max(), meleeRange);
}

GAME_TEST(Issues, Issue1535) {
// Queued messages stay in the event queue and roll over between tests.
game.startNewGame();
engine->config->debug.AllMagic.setValue(true);

game.pressGuiButton("Game_CastSpell");
game.tick(1);
game.pressGuiButton("SpellBook_Spell8"); // 8 is meteor shower.
game.tick(1);
game.pressGuiButton("SpellBook_Spell8"); // Confirm.
game.tick(1);

// Should have put the spell cast message to queue.
UIMessageType message = UIMSG_Invalid;
int spell = 0;
engine->_messageQueue->peekMessage(&message, &spell, nullptr);
EXPECT_EQ(message, UIMSG_CastSpellFromBook);
EXPECT_EQ(spell, std::to_underlying(SPELL_FIRE_METEOR_SHOWER));

// Then we start a new test.
test.prepareForNextTest(); // This call used to assert.
EXPECT_FALSE(engine->_messageQueue->haveMessages()); // Please don't roll over the messages between tests!
}
3 changes: 1 addition & 2 deletions test/Testing/Game/TestController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ void TestController::prepareForNextTestInternal() {
::application->component<GameKeyboardController>()->reset();
::application->component<EngineDeterministicComponent>()->restart(frameTimeMs, rngType);

// Clear the spell/message queue, otherwise spells can roll over between test runs.
// Clear the message queue, otherwise spells can roll over between test runs.
// TODO(captainurist): this should really happen somewhere in the main loop. When new game is started, or a save is loaded.
CastSpellInfoHelpers::clearSpellQueue();
engine->_messageQueue->clear();

_controller->goToMainMenu();
Expand Down

0 comments on commit a2e1764

Please sign in to comment.