aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorBastien Bouclet2016-02-06 15:59:45 +0100
committerBastien Bouclet2016-02-07 15:27:03 +0100
commit91097d735ef4a1f5645c2918a7d136b64364ef91 (patch)
treee8e74958cd332f0e7b609657931c3d8b5aab14b2 /engines
parentafdcbbae9866d92a434172635d7732b4bb118bdd (diff)
downloadscummvm-rg350-91097d735ef4a1f5645c2918a7d136b64364ef91.tar.gz
scummvm-rg350-91097d735ef4a1f5645c2918a7d136b64364ef91.tar.bz2
scummvm-rg350-91097d735ef4a1f5645c2918a7d136b64364ef91.zip
MOHAWK: Factor the MystAreaActionSwitch switch code
Diffstat (limited to 'engines')
-rw-r--r--engines/mohawk/myst_areas.cpp74
-rw-r--r--engines/mohawk/myst_areas.h4
2 files changed, 18 insertions, 60 deletions
diff --git a/engines/mohawk/myst_areas.cpp b/engines/mohawk/myst_areas.cpp
index 824aa4247b..cfaacccb11 100644
--- a/engines/mohawk/myst_areas.cpp
+++ b/engines/mohawk/myst_areas.cpp
@@ -284,86 +284,40 @@ MystAreaActionSwitch::~MystAreaActionSwitch() {
_subResources.clear();
}
-// TODO: All these functions to switch subresource are very similar.
-// Find way to share code (function pointer pass?)
-void MystAreaActionSwitch::drawDataToScreen() {
+void MystAreaActionSwitch::doSwitch(AreaHandler handler) {
if (_actionSwitchVar == 0xFFFF) {
if (_numSubResources == 1)
- _subResources[0]->drawDataToScreen();
+ (_subResources[0]->*handler)();
else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
+ warning("Action switch resource with _numSubResources of %d, but no control variable", _numSubResources);
} else {
uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->drawDataToScreen();
+ (_subResources[0]->*handler)();
else if (_numSubResources != 0) {
if (varValue < _numSubResources)
- _subResources[varValue]->drawDataToScreen();
+ (_subResources[varValue]->*handler)();
else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
+ warning("Action switch resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
}
}
}
-void MystAreaActionSwitch::handleCardChange() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleCardChange();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
+void MystAreaActionSwitch::drawDataToScreen() {
+ doSwitch(&MystArea::drawDataToScreen);
+}
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleCardChange();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleCardChange();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+void MystAreaActionSwitch::handleCardChange() {
+ doSwitch(&MystArea::handleCardChange);
}
void MystAreaActionSwitch::handleMouseUp() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleMouseUp();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
-
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleMouseUp();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleMouseUp();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+ doSwitch(&MystArea::handleMouseUp);
}
void MystAreaActionSwitch::handleMouseDown() {
- if (_actionSwitchVar == 0xFFFF) {
- if (_numSubResources == 1)
- _subResources[0]->handleMouseDown();
- else if (_numSubResources != 0)
- warning("Type 7 Resource with _numSubResources of %d, but no control variable", _numSubResources);
- } else {
- uint16 varValue = _vm->_scriptParser->getVar(_actionSwitchVar);
-
- if (_numSubResources == 1 && varValue != 0)
- _subResources[0]->handleMouseDown();
- else if (_numSubResources != 0) {
- if (varValue < _numSubResources)
- _subResources[varValue]->handleMouseDown();
- else
- warning("Type 7 Resource Var %d: %d exceeds number of sub resources %d", _actionSwitchVar, varValue, _numSubResources);
- }
- }
+ doSwitch(&MystArea::handleMouseDown);
}
MystAreaImageSwitch::MystAreaImageSwitch(MohawkEngine_Myst *vm, Common::SeekableReadStream *rlstStream, MystArea *parent) :
@@ -407,7 +361,7 @@ MystAreaImageSwitch::~MystAreaImageSwitch() {
}
void MystAreaImageSwitch::drawDataToScreen() {
- // Need to call overidden Type 7 function to ensure
+ // Need to call overridden function to ensure
// switch section is processed correctly.
MystAreaActionSwitch::drawDataToScreen();
diff --git a/engines/mohawk/myst_areas.h b/engines/mohawk/myst_areas.h
index dfaa90e8a3..b4b6fabcb7 100644
--- a/engines/mohawk/myst_areas.h
+++ b/engines/mohawk/myst_areas.h
@@ -140,6 +140,10 @@ public:
MystArea *getSubResource(uint16 index) { return _subResources[index]; }
protected:
+ typedef void (MystArea::*AreaHandler)();
+
+ void doSwitch(AreaHandler handler);
+
uint16 _actionSwitchVar;
uint16 _numSubResources;
Common::Array<MystArea *> _subResources;