aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2016-02-06 17:55:13 +0100
committerBastien Bouclet2016-02-07 15:27:03 +0100
commit727ee86a443b48d68e22027c7691e5b4c5088641 (patch)
tree13c2fef9a39b0d0ffab889f8fb9bcb175e40d8c8
parent0463e00fb6b776c7774c4e1f06261e78732788f6 (diff)
downloadscummvm-rg350-727ee86a443b48d68e22027c7691e5b4c5088641.tar.gz
scummvm-rg350-727ee86a443b48d68e22027c7691e5b4c5088641.tar.bz2
scummvm-rg350-727ee86a443b48d68e22027c7691e5b4c5088641.zip
MOHAWK: Don't use static_cast to downcast view resources
-rw-r--r--engines/mohawk/myst.h14
-rw-r--r--engines/mohawk/myst_stacks/channelwood.cpp2
-rw-r--r--engines/mohawk/myst_stacks/myst.cpp28
-rw-r--r--engines/mohawk/myst_stacks/selenitic.cpp38
-rw-r--r--engines/mohawk/myst_stacks/stoneship.cpp4
5 files changed, 50 insertions, 36 deletions
diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h
index 4439cb93ca..7fd21455f3 100644
--- a/engines/mohawk/myst.h
+++ b/engines/mohawk/myst.h
@@ -196,6 +196,9 @@ public:
void drawCardBackground();
uint16 getCardBackgroundId();
+ template<class T>
+ T *getViewResource(uint index);
+
void setCacheState(bool state) { _cache.enabled = state; }
bool getCacheState() { return _cache.enabled; }
@@ -242,6 +245,17 @@ private:
uint16 _mainCursor; // Also defines the current page being held (white, blue, red, or none)
};
+template<class T>
+T *MohawkEngine_Myst::getViewResource(uint index) {
+ T *resource = dynamic_cast<T *>(_resources[index]);
+
+ if (!resource) {
+ error("View resource '%d' has unexpected type", index);
+ }
+
+ return resource;
+}
+
} // End of namespace Mohawk
#endif
diff --git a/engines/mohawk/myst_stacks/channelwood.cpp b/engines/mohawk/myst_stacks/channelwood.cpp
index 903632849a..fe93770b9c 100644
--- a/engines/mohawk/myst_stacks/channelwood.cpp
+++ b/engines/mohawk/myst_stacks/channelwood.cpp
@@ -680,7 +680,7 @@ void Channelwood::o_hologramTemple(uint16 op, uint16 var, uint16 argc, uint16 *a
void Channelwood::o_executeMouseUp(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Execute mouse up", op);
- MystAreaAction *resource = static_cast<MystAreaAction *>(_vm->_resources[argv[0]]);
+ MystAreaAction *resource = _vm->getViewResource<MystAreaAction>(argv[0]);
resource->handleMouseUp();
}
diff --git a/engines/mohawk/myst_stacks/myst.cpp b/engines/mohawk/myst_stacks/myst.cpp
index d928887359..c5e151cdf0 100644
--- a/engines/mohawk/myst_stacks/myst.cpp
+++ b/engines/mohawk/myst_stacks/myst.cpp
@@ -3190,7 +3190,7 @@ void Myst::towerRotationMap_run() {
void Myst::o_towerRotationMap_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
_towerRotationMapRunning = true;
_towerRotationMapTower = getInvokingResource<MystAreaDrag>();
- _towerRotationMapLabel = static_cast<MystAreaImageSwitch *>(_vm->_resources[argv[0]]);
+ _towerRotationMapLabel = _vm->getViewResource<MystAreaImageSwitch>(argv[0]);
_tempVar = 0;
_startTime = 0;
_towerRotationMapClicked = false;
@@ -3202,7 +3202,7 @@ void Myst::towerRotationDrawBuildings() {
// Draw other resources
for (uint i = 1; i <= 10; i++) {
- MystAreaImageSwitch *resource = static_cast<MystAreaImageSwitch *>(_vm->_resources[i]);
+ MystAreaImageSwitch *resource = _vm->getViewResource<MystAreaImageSwitch>(i);
_vm->redrawResource(resource, false);
}
}
@@ -3472,16 +3472,16 @@ void Myst::o_observatory_init(uint16 op, uint16 var, uint16 argc, uint16 *argv)
_tempVar = 0;
_observatoryNotInitialized = true;
_observatoryVisualizer = getInvokingResource<MystAreaImageSwitch>();
- _observatoryGoButton = static_cast<MystAreaImageSwitch *>(_vm->_resources[argv[0]]);
+ _observatoryGoButton = _vm->getViewResource<MystAreaImageSwitch>(argv[0]);
if (observatoryIsDDMMYYYY2400()) {
- _observatoryDaySlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[1]]);
- _observatoryMonthSlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[2]]);
+ _observatoryDaySlider = _vm->getViewResource<MystAreaSlider>(argv[1]);
+ _observatoryMonthSlider = _vm->getViewResource<MystAreaSlider>(argv[2]);
} else {
- _observatoryMonthSlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[1]]);
- _observatoryDaySlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[2]]);
+ _observatoryMonthSlider = _vm->getViewResource<MystAreaSlider>(argv[1]);
+ _observatoryDaySlider = _vm->getViewResource<MystAreaSlider>(argv[2]);
}
- _observatoryYearSlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[3]]);
- _observatoryTimeSlider = static_cast<MystAreaSlider *>(_vm->_resources[argv[4]]);
+ _observatoryYearSlider = _vm->getViewResource<MystAreaSlider>(argv[3]);
+ _observatoryTimeSlider = _vm->getViewResource<MystAreaSlider>(argv[4]);
// Set date selection sliders position
_observatoryDaySlider->setPosition(_state.observatoryDaySlider);
@@ -3704,11 +3704,11 @@ void Myst::boilerGaugeInit() {
void Myst::o_rocketSliders_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Rocket sliders init", op);
- _rocketSlider1 = static_cast<MystAreaSlider *>(_vm->_resources[argv[0]]);
- _rocketSlider2 = static_cast<MystAreaSlider *>(_vm->_resources[argv[1]]);
- _rocketSlider3 = static_cast<MystAreaSlider *>(_vm->_resources[argv[2]]);
- _rocketSlider4 = static_cast<MystAreaSlider *>(_vm->_resources[argv[3]]);
- _rocketSlider5 = static_cast<MystAreaSlider *>(_vm->_resources[argv[4]]);
+ _rocketSlider1 = _vm->getViewResource<MystAreaSlider>(argv[0]);
+ _rocketSlider2 = _vm->getViewResource<MystAreaSlider>(argv[1]);
+ _rocketSlider3 = _vm->getViewResource<MystAreaSlider>(argv[2]);
+ _rocketSlider4 = _vm->getViewResource<MystAreaSlider>(argv[3]);
+ _rocketSlider5 = _vm->getViewResource<MystAreaSlider>(argv[4]);
// Initialize sliders position
for (uint i = 0; i < 5; i++)
diff --git a/engines/mohawk/myst_stacks/selenitic.cpp b/engines/mohawk/myst_stacks/selenitic.cpp
index 5fdd37fb0d..034c6c8729 100644
--- a/engines/mohawk/myst_stacks/selenitic.cpp
+++ b/engines/mohawk/myst_stacks/selenitic.cpp
@@ -1058,19 +1058,19 @@ void Selenitic::o_soundReceiver_init(uint16 op, uint16 var, uint16 argc, uint16
// Used for Card 1245 (Sound Receiver)
_soundReceiverRunning = true;
- _soundReceiverRightButton = static_cast<MystAreaImageSwitch *>(_vm->_resources[0]);
- _soundReceiverLeftButton = static_cast<MystAreaImageSwitch *>(_vm->_resources[1]);
- _soundReceiverSigmaButton = static_cast<MystAreaImageSwitch *>(_vm->_resources[2]);
- _soundReceiverSources[4] = static_cast<MystAreaImageSwitch *>(_vm->_resources[3]);
- _soundReceiverSources[3] = static_cast<MystAreaImageSwitch *>(_vm->_resources[4]);
- _soundReceiverSources[2] = static_cast<MystAreaImageSwitch *>(_vm->_resources[5]);
- _soundReceiverSources[1] = static_cast<MystAreaImageSwitch *>(_vm->_resources[6]);
- _soundReceiverSources[0] = static_cast<MystAreaImageSwitch *>(_vm->_resources[7]);
- _soundReceiverViewer = static_cast<MystAreaImageSwitch *>(_vm->_resources[8]);
- _soundReceiverAngle1 = static_cast<MystAreaImageSwitch *>(_vm->_resources[10]);
- _soundReceiverAngle2 = static_cast<MystAreaImageSwitch *>(_vm->_resources[11]);
- _soundReceiverAngle3 = static_cast<MystAreaImageSwitch *>(_vm->_resources[12]);
- _soundReceiverAngle4 = static_cast<MystAreaImageSwitch *>(_vm->_resources[13]);
+ _soundReceiverRightButton = _vm->getViewResource<MystAreaImageSwitch>(0);
+ _soundReceiverLeftButton = _vm->getViewResource<MystAreaImageSwitch>(1);
+ _soundReceiverSigmaButton = _vm->getViewResource<MystAreaImageSwitch>(2);
+ _soundReceiverSources[4] = _vm->getViewResource<MystAreaImageSwitch>(3);
+ _soundReceiverSources[3] = _vm->getViewResource<MystAreaImageSwitch>(4);
+ _soundReceiverSources[2] = _vm->getViewResource<MystAreaImageSwitch>(5);
+ _soundReceiverSources[1] = _vm->getViewResource<MystAreaImageSwitch>(6);
+ _soundReceiverSources[0] = _vm->getViewResource<MystAreaImageSwitch>(7);
+ _soundReceiverViewer = _vm->getViewResource<MystAreaImageSwitch>(8);
+ _soundReceiverAngle1 = _vm->getViewResource<MystAreaImageSwitch>(10);
+ _soundReceiverAngle2 = _vm->getViewResource<MystAreaImageSwitch>(11);
+ _soundReceiverAngle3 = _vm->getViewResource<MystAreaImageSwitch>(12);
+ _soundReceiverAngle4 = _vm->getViewResource<MystAreaImageSwitch>(13);
uint16 currentSource = _state.soundReceiverCurrentSource;
_soundReceiverPosition = &_state.soundReceiverPositions[currentSource];
@@ -1086,28 +1086,28 @@ void Selenitic::o_soundLock_init(uint16 op, uint16 var, uint16 argc, uint16 *arg
if (_vm->_resources[i]->type == kMystAreaSlider) {
switch (_vm->_resources[i]->getImageSwitchVar()) {
case 20:
- _soundLockSlider1 = static_cast<MystAreaSlider *>(_vm->_resources[i]);
+ _soundLockSlider1 = _vm->getViewResource<MystAreaSlider>(i);
_soundLockSlider1->setStep(_state.soundLockSliderPositions[0]);
break;
case 21:
- _soundLockSlider2 = static_cast<MystAreaSlider *>(_vm->_resources[i]);
+ _soundLockSlider2 = _vm->getViewResource<MystAreaSlider>(i);
_soundLockSlider2->setStep(_state.soundLockSliderPositions[1]);
break;
case 22:
- _soundLockSlider3 = static_cast<MystAreaSlider *>(_vm->_resources[i]);
+ _soundLockSlider3 = _vm->getViewResource<MystAreaSlider>(i);
_soundLockSlider3->setStep(_state.soundLockSliderPositions[2]);
break;
case 23:
- _soundLockSlider4 = static_cast<MystAreaSlider *>(_vm->_resources[i]);
+ _soundLockSlider4 = _vm->getViewResource<MystAreaSlider>(i);
_soundLockSlider4->setStep(_state.soundLockSliderPositions[3]);
break;
case 24:
- _soundLockSlider5 = static_cast<MystAreaSlider *>(_vm->_resources[i]);
+ _soundLockSlider5 = _vm->getViewResource<MystAreaSlider>(i);
_soundLockSlider5->setStep(_state.soundLockSliderPositions[4]);
break;
}
} else if (_vm->_resources[i]->type == kMystAreaImageSwitch && _vm->_resources[i]->getImageSwitchVar() == 28) {
- _soundLockButton = static_cast<MystAreaImageSwitch *>(_vm->_resources[i]);
+ _soundLockButton = _vm->getViewResource<MystAreaImageSwitch>(i);
}
}
diff --git a/engines/mohawk/myst_stacks/stoneship.cpp b/engines/mohawk/myst_stacks/stoneship.cpp
index 77a7718e5f..939e84075f 100644
--- a/engines/mohawk/myst_stacks/stoneship.cpp
+++ b/engines/mohawk/myst_stacks/stoneship.cpp
@@ -437,7 +437,7 @@ void Stoneship::o_cabinBookMovie(uint16 op, uint16 var, uint16 argc, uint16 *arg
void Stoneship::o_drawerOpenSirius(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Open drawer", op);
- MystAreaImageSwitch *drawer = static_cast<MystAreaImageSwitch *>(_vm->_resources[argv[0]]);
+ MystAreaImageSwitch *drawer = _vm->getViewResource<MystAreaImageSwitch>(argv[0]);
if (drawer->getImageSwitchVar() == 35) {
drawer->drawConditionalDataToScreen(getVar(102), 0);
@@ -582,7 +582,7 @@ void Stoneship::batteryDeplete_run() {
void Stoneship::o_drawerOpenAchenar(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Open drawer", op);
- MystAreaImageSwitch *drawer = static_cast<MystAreaImageSwitch *>(_vm->_resources[argv[0]]);
+ MystAreaImageSwitch *drawer = _vm->getViewResource<MystAreaImageSwitch>(argv[0]);
drawer->drawConditionalDataToScreen(0, 0);
_vm->_gfx->runTransition(kTransitionTopToBottom, drawer->getRect(), 25, 5);
}