aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2016-08-13 09:02:28 +0200
committerEugene Sandulenko2017-07-03 08:50:10 +0200
commitc623a767676f8422186933c87b569d39185b5496 (patch)
treebc23dde92851c8278c41a0002c2a8798144c604b
parent9ab0d53cd3d8008b55d64cea832191f5ef2155ce (diff)
downloadscummvm-rg350-c623a767676f8422186933c87b569d39185b5496.tar.gz
scummvm-rg350-c623a767676f8422186933c87b569d39185b5496.tar.bz2
scummvm-rg350-c623a767676f8422186933c87b569d39185b5496.zip
MOHAWK: Ensure constructing and deleting cards does not have side effects
-rw-r--r--engines/mohawk/riven.cpp7
-rw-r--r--engines/mohawk/riven_card.cpp11
-rw-r--r--engines/mohawk/riven_card.h6
-rw-r--r--engines/mohawk/riven_scripts.cpp2
-rw-r--r--engines/mohawk/riven_scripts.h2
5 files changed, 16 insertions, 12 deletions
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index 8b7ee885ae..e6d8a16811 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -384,7 +384,10 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) {
}
}
- delete _card;
+ if (_card) {
+ _card->leave();
+ delete _card;
+ }
_card = new RivenCard(this, dest);
refreshCard(); // Handles hotspots and scripts
@@ -394,7 +397,7 @@ void MohawkEngine_Riven::refreshCard() {
// Clear any timer still floating around
removeTimer();
- _card->open();
+ _card->enter();
if (_showHotspots)
_card->drawHotspotRects();
diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp
index e82e00b7ac..212557b15d 100644
--- a/engines/mohawk/riven_card.cpp
+++ b/engines/mohawk/riven_card.cpp
@@ -42,12 +42,9 @@ RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) :
loadCardSoundList(id);
loadCardHotspotEnableList(id);
loadCardWaterEffectList(id);
- setCurrentCardVariable();
}
RivenCard::~RivenCard() {
- runLeaveScripts();
-
for (uint i = 0; i < _hotspots.size(); i++) {
delete _hotspots[i];
}
@@ -66,7 +63,9 @@ void RivenCard::loadCardResource(uint16 id) {
delete inStream;
}
-void RivenCard::open() {
+void RivenCard::enter() {
+ setCurrentCardVariable();
+
_vm->_activatedPLST = false;
_vm->_activatedSLST = false;
@@ -77,7 +76,7 @@ void RivenCard::open() {
initializeZipMode();
_vm->_gfx->applyScreenUpdate(true);
- runScript(kCardOpenScript);
+ runScript(kCardEnterScript);
}
void RivenCard::initializeZipMode() {
@@ -430,7 +429,7 @@ void RivenCard::updateMouseCursor() {
_vm->_system->updateScreen();
}
-void RivenCard::runLeaveScripts() {
+void RivenCard::leave() {
RivenScriptPtr script(new RivenScript());
if (_pressedHotspot) {
diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h
index d20f63dfd6..626c427444 100644
--- a/engines/mohawk/riven_card.h
+++ b/engines/mohawk/riven_card.h
@@ -56,7 +56,10 @@ public:
};
/** Initialization routine used to draw a card for the first time or to refresh it */
- void open();
+ void enter();
+
+ /** Run the card's leave scripts */
+ void leave();
/** Run one of the card's scripts */
void runScript(uint16 scriptType);
@@ -131,7 +134,6 @@ private:
RivenScriptPtr getScript(uint16 scriptType) const;
void defaultLoadScript();
- void runLeaveScripts();
void updateMouseCursor();
diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp
index 794e8db6cd..c3e92380e2 100644
--- a/engines/mohawk/riven_scripts.cpp
+++ b/engines/mohawk/riven_scripts.cpp
@@ -200,7 +200,7 @@ const char *RivenScript::getTypeName(uint16 type) {
"CardLoad",
"CardLeave",
"CardUnknown",
- "CardOpen",
+ "CardEnter",
"CardUpdate"
};
diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h
index 304c2f312f..cfe0f3a048 100644
--- a/engines/mohawk/riven_scripts.h
+++ b/engines/mohawk/riven_scripts.h
@@ -46,7 +46,7 @@ enum {
kCardLoadScript = 6,
kCardLeaveScript = 7,
- kCardOpenScript = 9,
+ kCardEnterScript = 9,
kCardUpdateScript = 10
};