diff options
author | Paul Gilbert | 2014-02-01 15:04:18 -0500 |
---|---|---|
committer | Paul Gilbert | 2014-02-01 15:04:18 -0500 |
commit | 517df376a2d96b68e3a7b9f5c078be48cb12a211 (patch) | |
tree | bdf5afb5d591ce288c37108e30d24bbaf0a9089f /engines/voyeur | |
parent | 3b414f10ba9e79fca6a920240435c1531ec6db1b (diff) | |
download | scummvm-rg350-517df376a2d96b68e3a7b9f5c078be48cb12a211.tar.gz scummvm-rg350-517df376a2d96b68e3a7b9f5c078be48cb12a211.tar.bz2 scummvm-rg350-517df376a2d96b68e3a7b9f5c078be48cb12a211.zip |
VOYEUR: Refactored hotspot time arrays into a cleaner template
Diffstat (limited to 'engines/voyeur')
-rw-r--r-- | engines/voyeur/data.cpp | 22 | ||||
-rw-r--r-- | engines/voyeur/data.h | 53 | ||||
-rw-r--r-- | engines/voyeur/files_threads.cpp | 57 |
3 files changed, 78 insertions, 54 deletions
diff --git a/engines/voyeur/data.cpp b/engines/voyeur/data.cpp index 5d311a8385..800d9d15c1 100644 --- a/engines/voyeur/data.cpp +++ b/engines/voyeur/data.cpp @@ -66,24 +66,10 @@ void SVoy::synchronize(Common::Serializer &s) { s.syncAsSint16LE(_RTVNum); s.syncAsSint16LE(_switchBGNum); - for (int v1 = 0; v1 < 8; ++v1) { - for (int v2 = 0; v2 < 20; ++v2) { - s.syncAsSint16LE(_arr1[v1][v2]); - s.syncAsSint16LE(_arr2[v1][v2]); - } - } - for (int v1 = 0; v1 < 4; ++v1) { - for (int v2 = 0; v2 < 20; ++v2) { - s.syncAsSint16LE(_arr3[v1][v2]); - s.syncAsSint16LE(_arr4[v1][v2]); - } - } - for (int v1 = 0; v1 < 4; ++v1) { - for (int v2 = 0; v2 < 20; ++v2) { - s.syncAsSint16LE(_arr5[v1][v2]); - s.syncAsSint16LE(_arr6[v1][v2]); - } - } + _videoHotspotTimes.synchronize(s); + _audioHotspotTimes.synchronize(s); + _evidenceHotspotTimes.synchronize(s); + for (int v1 = 0; v1 < 20; ++v1) { s.syncAsSint16LE(_arr7[20]); } diff --git a/engines/voyeur/data.h b/engines/voyeur/data.h index 37b2671ea7..4e592d8b11 100644 --- a/engines/voyeur/data.h +++ b/engines/voyeur/data.h @@ -49,6 +49,50 @@ struct VoyeurEvent { class VoyeurEngne; +/** + * Encapsulates a list of the time expired ranges that hotspots in the mansion + * view are enabled for in a given time period. + */ +template<int SLOTS> +class HotspotTimes { +public: + int _min[SLOTS][20]; // Min time expired + int _max[SLOTS][20]; // Max time expired + + HotspotTimes() { + reset(); + } + + /** + * Resets the data to an initial state + */ + void reset() { + Common::fill(&_min[0][0], &_min[SLOTS][20], 9999); + Common::fill(&_max[0][0], &_max[SLOTS][20], 0); + } + + /** + * Synchronise the data + */ + void synchronize(Common::Serializer &s) { + for (int slotIndex = 0; slotIndex < SLOTS; ++slotIndex) { + for (int hotspotIndex = 0; hotspotIndex < 20; ++hotspotIndex) { + s.syncAsSint16LE(_min[slotIndex][hotspotIndex]); + s.syncAsSint16LE(_max[slotIndex][hotspotIndex]); + } + } + } + + /** + * Returns true if the given value is in the range specified by the + * min and max at the given hotspot and slot indexes + */ + bool isInRange(int slotIndex, int hotspotIndex, int v) const { + return _min[slotIndex][hotspotIndex] <= v && + v < _max[slotIndex][hotspotIndex]; + } +}; + class SVoy { private: VoyeurEngine *_vm; @@ -57,12 +101,9 @@ public: int _RTANum; int _RTVNum; int _switchBGNum; - int _arr1[8][20]; - int _arr2[8][20]; - int _arr3[3][20]; - int _arr4[3][20]; - int _arr5[3][20]; - int _arr6[3][20]; + HotspotTimes<8> _videoHotspotTimes; + HotspotTimes<3> _audioHotspotTimes; + HotspotTimes<3> _evidenceHotspotTimes; int _arr7[20]; int _field468; diff --git a/engines/voyeur/files_threads.cpp b/engines/voyeur/files_threads.cpp index 0892de1494..134a064b42 100644 --- a/engines/voyeur/files_threads.cpp +++ b/engines/voyeur/files_threads.cpp @@ -344,12 +344,10 @@ void ThreadResource::parsePlayCommands() { _vm->_voy._field478 &= ~8; _vm->_eventsManager._videoDead = -1; - Common::fill(&_vm->_voy._arr1[0][0], &_vm->_voy._arr1[8][20], 9999); - Common::fill(&_vm->_voy._arr2[0][0], &_vm->_voy._arr2[8][20], 0); - Common::fill(&_vm->_voy._arr3[0][0], &_vm->_voy._arr3[3][20], 9999); - Common::fill(&_vm->_voy._arr4[0][0], &_vm->_voy._arr4[3][20], 0); - Common::fill(&_vm->_voy._arr5[0][0], &_vm->_voy._arr5[3][20], 9999); - Common::fill(&_vm->_voy._arr6[0][0], &_vm->_voy._arr6[3][20], 0); + // Reset hotspot times data + _vm->_voy._videoHotspotTimes.reset(); + _vm->_voy._audioHotspotTimes.reset(); + _vm->_voy._evidenceHotspotTimes.reset(); Common::fill(&_vm->_voy._arr7[0], &_vm->_voy._arr7[20], 0); byte *dataP = _playCommandsPtr; @@ -542,52 +540,54 @@ void ThreadResource::parsePlayCommands() { break; case 7: + // Load the video event scene hotspot times data v2 = READ_LE_UINT16(dataP); v3 = READ_LE_UINT16(dataP + 2) - 1; if (v2 == 0 || READ_LE_UINT16(_vm->_controlPtr->_ptr + 4) == 0) { int idx = 0; - while (_vm->_voy._arr1[idx][v3] != 9999) + while (_vm->_voy._videoHotspotTimes._min[idx][v3] != 9999) ++idx; v2 = READ_LE_UINT16(dataP + 4); - _vm->_voy._arr1[idx][v3] = v2; - _vm->_voy._arr2[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; + _vm->_voy._videoHotspotTimes._min[idx][v3] = v2; + _vm->_voy._videoHotspotTimes._max[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; } dataP += 8; break; case 8: + // Load the audio event scene hotspot times data v2 = READ_LE_UINT16(dataP); v3 = READ_LE_UINT16(dataP + 2) - 1; if (v2 == 0 || READ_LE_UINT16(_vm->_controlPtr->_ptr + 4) == 0) { int idx = 0; - while (_vm->_voy._arr3[idx][v3] != 9999) + while (_vm->_voy._audioHotspotTimes._min[idx][v3] != 9999) ++idx; v2 = READ_LE_UINT16(dataP + 4); - _vm->_voy._arr3[idx][v3] = v2; - _vm->_voy._arr4[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; + _vm->_voy._audioHotspotTimes._min[idx][v3] = v2; + _vm->_voy._audioHotspotTimes._max[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; } dataP += 8; break; case 9: - // Load up initial timeframese for third set of hotspots + // Load up evidence event scene hotspot times data v2 = READ_LE_UINT16(dataP); v3 = READ_LE_UINT16(dataP + 2) - 1; if (v2 == 0 || READ_LE_UINT16(_vm->_controlPtr->_ptr + 4) == 0) { int idx = 0; - while (_vm->_voy._arr5[idx][v3] != 9999) + while (_vm->_voy._evidenceHotspotTimes._min[idx][v3] != 9999) ++idx; v2 = READ_LE_UINT16(dataP + 4); - _vm->_voy._arr5[idx][v3] = v2; - _vm->_voy._arr6[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; + _vm->_voy._evidenceHotspotTimes._min[idx][v3] = v2; + _vm->_voy._evidenceHotspotTimes._max[idx][v3] = v2 + READ_LE_UINT16(dataP + 6) - 2; } dataP += 8; @@ -1417,31 +1417,28 @@ int ThreadResource::doInterface() { Common::Point(pt.x - MANSION_VIEW_X, pt.y - MANSION_VIEW_Y); regionIndex = -1; - for (int idx = 0; idx < (int)hotspots->size(); ++idx) { - if ((*hotspots)[idx].contains(pt)) { + for (int hotspotIdx = 0; hotspotIdx < (int)hotspots->size(); ++hotspotIdx) { + if ((*hotspots)[hotspotIdx].contains(pt)) { // Rect check done for (int arrIndex = 0; arrIndex < 3; ++arrIndex) { - if (_vm->_voy._arr3[arrIndex][idx] <= _vm->_voy._RTVNum && - _vm->_voy._arr4[arrIndex][idx] > _vm->_voy._RTVNum) { - // Found a hotspot - switch to the magnifying glass cursor + if (_vm->_voy._audioHotspotTimes.isInRange(arrIndex, hotspotIdx, _vm->_voy._RTVNum)) { + // Set the ear cursor for an audio event _vm->_eventsManager.setCursor(listenCursor); - regionIndex = idx; + regionIndex = hotspotIdx; } - if (_vm->_voy._arr5[arrIndex][idx] <= _vm->_voy._RTVNum && - _vm->_voy._arr6[arrIndex][idx] > _vm->_voy._RTVNum) { - // Set unk? cursor + if (_vm->_voy._evidenceHotspotTimes.isInRange(arrIndex, hotspotIdx, _vm->_voy._RTVNum)) { + // Set the magnifier cursor for an evidence event _vm->_eventsManager.setCursor(mangifyCursor); - regionIndex = idx; + regionIndex = hotspotIdx; } } for (int arrIndex = 0; arrIndex < 8; ++arrIndex) { - if (_vm->_voy._arr1[arrIndex][idx] <= _vm->_voy._RTVNum && - _vm->_voy._arr2[arrIndex][idx] > _vm->_voy._RTVNum) { - // Draw the picture + if (_vm->_voy._videoHotspotTimes.isInRange(arrIndex, hotspotIdx, _vm->_voy._RTVNum)) { + // Set the eye cursor for a video event _vm->_eventsManager.setCursor(eyeCursor); - regionIndex = idx; + regionIndex = hotspotIdx; } } } |