diff options
author | Strangerke | 2018-04-20 07:55:46 +0200 |
---|---|---|
committer | Strangerke | 2018-04-20 07:55:46 +0200 |
commit | 56db8c626eb095fc21a4648e7cc79f7ed0bd1260 (patch) | |
tree | a6ff83454fce1cf02795e581d51b8ae274e26cb9 /engines | |
parent | 7af31d6614766c2e53c5b1e6240309e2f9382abe (diff) | |
download | scummvm-rg350-56db8c626eb095fc21a4648e7cc79f7ed0bd1260.tar.gz scummvm-rg350-56db8c626eb095fc21a4648e7cc79f7ed0bd1260.tar.bz2 scummvm-rg350-56db8c626eb095fc21a4648e7cc79f7ed0bd1260.zip |
LILLIPUT: Refactor engine, replace the use of MinMax by Common::Rect
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lilliput/lilliput.cpp | 55 | ||||
-rw-r--r-- | engines/lilliput/lilliput.h | 8 | ||||
-rw-r--r-- | engines/lilliput/script.cpp | 23 |
3 files changed, 31 insertions, 55 deletions
diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp index 97767a6005..cc5247592d 100644 --- a/engines/lilliput/lilliput.cpp +++ b/engines/lilliput/lilliput.cpp @@ -236,12 +236,9 @@ LilliputEngine::LilliputEngine(OSystem *syst, const LilliputGameDescription *gd) _listIndex = nullptr; _listArr = nullptr; _rectNumb = 0; - for (int i = 0; i < 40; ++i) { - _rectXMinMax[i].min = 0; - _rectXMinMax[i].max = 0; - _rectYMinMax[i].min = 0; - _rectYMinMax[i].max = 0; - } + for (int i = 0; i < 40; ++i) + _enclosureRect[i] = Common::Rect(0, 0, 0, 0); + _interfaceHotspotNumb = 0; for (int i = 0; i < 20; ++i) _keyboardMapping[i] = Common::KEYCODE_DOLLAR; @@ -1396,32 +1393,28 @@ void LilliputEngine::homeInPathFinding(int index) { return; } - if ((enclosureDst != -1) && - (_characterTargetPos[index].x >= _rectXMinMax[enclosureSrc].min) && - (_characterTargetPos[index].x <= _rectXMinMax[enclosureSrc].max) && - (_characterTargetPos[index].y >= _rectYMinMax[enclosureSrc].min) && - (_characterTargetPos[index].y <= _rectYMinMax[enclosureSrc].max)) { + if ((enclosureDst != -1) && _enclosureRect->contains(_characterTargetPos[index])) { _characterSubTargetPos[index] = _portalPos[enclosureDst]; return; } _characterSubTargetPos[index] = _portalPos[enclosureSrc]; - if (_rectXMinMax[enclosureSrc].min != _rectXMinMax[enclosureSrc].max) { - if (_portalPos[enclosureSrc].x == _rectXMinMax[enclosureSrc].min) { + if (_enclosureRect[enclosureSrc].left != _enclosureRect[enclosureSrc].right) { + if (_portalPos[enclosureSrc].x == _enclosureRect[enclosureSrc].left) { _characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x - 1, _portalPos[enclosureSrc].y); return; } - if (_portalPos[enclosureSrc].x == _rectXMinMax[enclosureSrc].max) { + if (_portalPos[enclosureSrc].x == _enclosureRect[enclosureSrc].right) { _characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x + 1, _portalPos[enclosureSrc].y); return; } - if (_rectYMinMax[enclosureSrc].min != _rectYMinMax[enclosureSrc].max) { - if (_portalPos[enclosureSrc].y == _rectYMinMax[enclosureSrc].min) + if (_enclosureRect[enclosureSrc].bottom != _enclosureRect[enclosureSrc].top) { + if (_portalPos[enclosureSrc].y == _enclosureRect[enclosureSrc].bottom) _characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x, _portalPos[enclosureSrc].y - 1); - else // CHECKME: Should be a check on y == max + else // CHECKME: Should be a check on y == top _characterSubTargetPos[index] = Common::Point(_portalPos[enclosureSrc].x, _portalPos[enclosureSrc].y + 1); return; @@ -1499,18 +1492,14 @@ byte LilliputEngine::homeInAvoidDeadEnds(int indexb, int indexs) { Common::Point tmpPos = Common::Point(_curCharacterTilePos.x + constDirX[indexb], _curCharacterTilePos.y + constDirY[indexb]); - int16 var2 = checkEnclosure(tmpPos); - if (var2 == -1) + int16 idx = checkEnclosure(tmpPos); + if (idx == -1) return 1; - tmpPos = _curCharacterTilePos; - - if ((tmpPos.x >= _rectXMinMax[var2].min) && (tmpPos.x <= _rectXMinMax[var2].max) && (tmpPos.y >= _rectYMinMax[var2].min) && (tmpPos.y <= _rectYMinMax[var2].max)) + if (_enclosureRect[idx].contains(_curCharacterTilePos)) return 0; - tmpPos = _characterSubTargetPos[indexs]; - - if ((tmpPos.x >= _rectXMinMax[var2].min) && (tmpPos.x <= _rectXMinMax[var2].max) && (tmpPos.y >= _rectYMinMax[var2].min) && (tmpPos.y <= _rectYMinMax[var2].max)) + if (_enclosureRect[idx].contains(_characterSubTargetPos[indexs])) return 0; return 1; @@ -1519,8 +1508,8 @@ byte LilliputEngine::homeInAvoidDeadEnds(int indexb, int indexs) { int16 LilliputEngine::checkEnclosure(Common::Point pos) { debugC(2, kDebugEngine, "checkEnclosure(%d, %d)", pos.x, pos.y); - for (int i = 0; i < _rectNumb; i++) { - if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max)) + for (int i = 0; i < _rectNumb; ++i) { + if (_enclosureRect[i].contains(pos)) return i; } return -1; @@ -1529,8 +1518,8 @@ int16 LilliputEngine::checkEnclosure(Common::Point pos) { int16 LilliputEngine::checkOuterEnclosure(Common::Point pos) { debugC(2, kDebugEngine, "checkOuterEnclosure(%d, %d)", pos.x, pos.y); - for (int i = _rectNumb - 1; i >= 0 ; i--) { - if ((pos.x >= _rectXMinMax[i].min) && (pos.x <= _rectXMinMax[i].max) && (pos.y >= _rectYMinMax[i].min) && (pos.y <= _rectYMinMax[i].max)) + for (int i = _rectNumb - 1; i >= 0 ; --i) { + if (_enclosureRect[i].contains(pos)) return i; } return -1; @@ -2571,10 +2560,10 @@ void LilliputEngine::loadRules() { assert((_rectNumb >= 0) && (_rectNumb <= 40)); for (int i = 0; i < _rectNumb; i++) { - _rectXMinMax[i].max = (int16)f.readByte(); - _rectXMinMax[i].min = (int16)f.readByte(); - _rectYMinMax[i].max = (int16)f.readByte(); - _rectYMinMax[i].min = (int16)f.readByte(); + _enclosureRect[i].right = (int16)f.readByte(); + _enclosureRect[i].left = (int16)f.readByte(); + _enclosureRect[i].top = (int16)f.readByte(); + _enclosureRect[i].bottom = (int16)f.readByte(); int16 tmpValY = (int16)f.readByte(); int16 tmpValX = (int16)f.readByte(); diff --git a/engines/lilliput/lilliput.h b/engines/lilliput/lilliput.h index 6d67021b55..ac33a0f613 100644 --- a/engines/lilliput/lilliput.h +++ b/engines/lilliput/lilliput.h @@ -87,11 +87,6 @@ struct SmallAnim { int16 _frameIndex[8]; }; -struct MinMax { - int16 min; - int16 max; -}; - class LilliputEngine : public Engine { public: LilliputEngine(OSystem *syst, const LilliputGameDescription *gd); @@ -200,8 +195,7 @@ public: int16 *_listIndex; byte *_listArr; int16 _rectNumb; - MinMax _rectXMinMax[40]; - MinMax _rectYMinMax[40]; + Common::Rect _enclosureRect[40]; Common::Point _keyPos[40]; Common::Point _portalPos[40]; int _interfaceHotspotNumb; diff --git a/engines/lilliput/script.cpp b/engines/lilliput/script.cpp index 07911f945f..4202a28f14 100644 --- a/engines/lilliput/script.cpp +++ b/engines/lilliput/script.cpp @@ -1518,36 +1518,29 @@ byte LilliputScript::OC_CompareCharacterVariables() { return compareValues(var1, operation, var2); } -// TODO Rename function to "Check if character pos in rectangle" +// TODO Rename function to "Check if current script character pos is in enclosure" byte LilliputScript::OC_compareCoords_1() { debugC(1, kDebugScript, "OC_compareCoords_1()"); int index = _currScript->readUint16LE(); assert(index < 40); - MinMax xMinMax = _vm->_rectXMinMax[index]; - MinMax yMinMax = _vm->_rectYMinMax[index]; - Common::Point var1 = _vm->_currentScriptCharacterPos; - - if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max)) - return 0; + if (_vm->_enclosureRect[index].contains(_vm->_currentScriptCharacterPos)) + return 1; - return 1; + return 0; } -// TODO Rename function to "Check if character pos in rectangle" +// TODO Rename function to "Check if given character pos is in enclosure" byte LilliputScript::OC_compareCoords_2() { debugC(1, kDebugScript, "OC_compareCoords_2()"); int16 index = getValue1(); - Common::Point var1 = _characterTilePos[index]; index = _currScript->readUint16LE(); - MinMax xMinMax = _vm->_rectXMinMax[index]; - MinMax yMinMax = _vm->_rectYMinMax[index]; - if ((var1.x < xMinMax.min) || (var1.x > xMinMax.max) || (var1.y < yMinMax.min) || (var1.y > yMinMax.max)) - return 0; - return 1; + if (_vm->_enclosureRect[index].contains(_characterTilePos[index])) + return 1; + return 0; } byte LilliputScript::OC_CompareDistanceFromCharacterToPositionWith() { |