diff options
-rw-r--r-- | engines/gob/hotspots.cpp | 90 | ||||
-rw-r--r-- | engines/gob/hotspots.h | 3 |
2 files changed, 29 insertions, 64 deletions
diff --git a/engines/gob/hotspots.cpp b/engines/gob/hotspots.cpp index bed9d6a7cb..9d1373d51d 100644 --- a/engines/gob/hotspots.cpp +++ b/engines/gob/hotspots.cpp @@ -93,6 +93,10 @@ uint8 Hotspots::Hotspot::getCursor() const { return (flags & 0xF000) >> 12; } +bool Hotspots::Hotspot::isEnd() const { + return (left == 0xFFFF); +} + bool Hotspots::Hotspot::isIn(uint16 x, uint16 y) const { if (x < left) return false; @@ -164,8 +168,8 @@ uint16 Hotspots::add(const Hotspot &hotspot) { for (int i = 0; i < kHotspotCount; i++) { Hotspot &spot = _hotspots[i]; - // free space => add same id => update - if (! ((spot.left == 0xFFFF) || (spot.id == hotspot.id))) + // free space => add same id => update + if (! (spot.isEnd() || (spot.id == hotspot.id))) continue; // When updating, keep bit 0x4000 intact @@ -204,13 +208,9 @@ void Hotspots::removeState(uint16 state) { } void Hotspots::recalculate(bool force) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - // End reached - break; - if (!force && ((spot.flags & 0x80) != 0)) continue; @@ -277,13 +277,9 @@ void Hotspots::push(uint8 all, bool force) { // Count the hotspots uint32 size = 0; - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - // End reached - break; - // Save all of them if ( (all == 1) || // Don't save the global ones @@ -309,13 +305,9 @@ void Hotspots::push(uint8 all, bool force) { // Copy the hotspots Hotspot *destPtr = backup.hotspots; - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - // End reached - break; - // Save all of them if ( (all == 1) || // Don't save the global ones @@ -328,7 +320,7 @@ void Hotspots::push(uint8 all, bool force) { memcpy(destPtr, &spot, sizeof(Hotspot)); destPtr++; - spot.left = 0xFFFF; + spot.clear(); } } @@ -351,7 +343,7 @@ void Hotspots::pop() { int i; Hotspot *destPtr = _hotspots; for (i = 0; i < kHotspotCount; i++, destPtr++) - if (destPtr->left == 0xFFFF) + if (destPtr->isEnd()) break; if (((uint32) (kHotspotCount - i)) < backup.size) @@ -436,12 +428,9 @@ uint16 Hotspots::checkMouse(Type type, uint16 &id, uint16 &index) const { if (type == kTypeMove) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if (spot.id & 0x4000) continue; @@ -464,12 +453,9 @@ uint16 Hotspots::checkMouse(Type type, uint16 &id, uint16 &index) const { } else if (type == kTypeClick) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if (spot.id & 0x4000) continue; @@ -939,7 +925,7 @@ uint16 Hotspots::handleInput(int16 time, uint16 maxPos, uint16 &curPos, for (int i = 0; i < kHotspotCount; i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) + if (spot.isEnd()) continue; if ((spot.id & 0xC000) != 0x8000) @@ -985,7 +971,7 @@ uint16 Hotspots::handleInput(int16 time, uint16 maxPos, uint16 &curPos, for (int i = 0; i < kHotspotCount; i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) + if (spot.isEnd()) continue; if ((spot.id & 0xC000) != 0x8000) @@ -1025,12 +1011,9 @@ uint16 Hotspots::handleInput(int16 time, uint16 maxPos, uint16 &curPos, return 0; if (_vm->_game->_mouseButtons != kMouseButtonsNone) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if (spot.getWindow() != 0) continue; @@ -1064,7 +1047,7 @@ uint16 Hotspots::handleInput(int16 time, uint16 maxPos, uint16 &curPos, for (int i = 0; i < kHotspotCount; i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) + if (spot.isEnd()) continue; if ((spot.id & 0xC000) != 0x8000) @@ -1133,7 +1116,7 @@ void Hotspots::evaluate() { push(0); uint16 endIndex = 0; - while (_hotspots[endIndex].left != 0xFFFF) + while (!_hotspots[endIndex].isEnd()) endIndex++; _shouldPush = false; @@ -1381,12 +1364,9 @@ void Hotspots::evaluate() { WRITE_VAR(55, curEditIndex); if (key == kKeyReturn) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xC000) != 0x8000) continue; @@ -1412,12 +1392,9 @@ void Hotspots::evaluate() { if (id == 0) { if (key != 0) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xC000) != 0x8000) continue; @@ -1429,12 +1406,9 @@ void Hotspots::evaluate() { } if (id == 0) { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xC000) != 0x8000) continue; @@ -1455,12 +1429,9 @@ void Hotspots::evaluate() { if (stackPos2 != 0) { collStackPos = 0; - for (int i = endIndex; i < kHotspotCount; i++) { + for (int i = endIndex; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xF000) != 0x8000) continue; @@ -1514,12 +1485,9 @@ void Hotspots::evaluate() { if (descIndex != 0) { counter = 0; - for (int i = endIndex; i < kHotspotCount; i++) { + for (int i = endIndex; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xF000) == 0x8000) { if (++counter == descIndex) { id = spot.id; @@ -1532,12 +1500,9 @@ void Hotspots::evaluate() { } else { - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.id & 0xF000) == 0x8000) { id = spot.id; index = i; @@ -1584,7 +1549,7 @@ void Hotspots::evaluate() { for (int i = 0; i < kHotspotCount; i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) + if (spot.isEnd()) continue; if ((spot.id & 0xC000) != 0x8000) @@ -1678,12 +1643,9 @@ void Hotspots::evaluate() { int16 Hotspots::findCursor(uint16 x, uint16 y) const { int16 cursor = 0; - for (int i = 0; i < kHotspotCount; i++) { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { Hotspot &spot = _hotspots[i]; - if (spot.left == 0xFFFF) - break; - if ((spot.getWindow() != 0) || (spot.id & 0x4000)) continue; diff --git a/engines/gob/hotspots.h b/engines/gob/hotspots.h index 0bafb94937..b8cd883ffd 100644 --- a/engines/gob/hotspots.h +++ b/engines/gob/hotspots.h @@ -108,6 +108,9 @@ private: uint8 getWindow() const; uint8 getCursor() const; + /** Is this hotspot the block end marker? */ + bool isEnd() const; + /** Are the specified coordinates in the hotspot? */ bool isIn(uint16 x, uint16 y) const; /** Does the specified button trigger the hotspot? */ |