diff options
author | Simei Yin | 2018-04-15 00:21:17 +0200 |
---|---|---|
committer | Simei Yin | 2018-04-15 00:21:17 +0200 |
commit | af9d07a241732be834df43a0d2a36c31bd6311b5 (patch) | |
tree | 67e0ab75545b750df639e41aa350ed2ddb35fd97 /engines | |
parent | 825331c8735d88e113474952d6eb01e97a48cf50 (diff) | |
download | scummvm-rg350-af9d07a241732be834df43a0d2a36c31bd6311b5.tar.gz scummvm-rg350-af9d07a241732be834df43a0d2a36c31bd6311b5.tar.bz2 scummvm-rg350-af9d07a241732be834df43a0d2a36c31bd6311b5.zip |
SLUDGE: Objectify Region Manager
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sludge/builtin.cpp | 20 | ||||
-rw-r--r-- | engines/sludge/event.cpp | 15 | ||||
-rw-r--r-- | engines/sludge/freeze.cpp | 10 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 6 | ||||
-rw-r--r-- | engines/sludge/people.cpp | 15 | ||||
-rw-r--r-- | engines/sludge/region.cpp | 78 | ||||
-rw-r--r-- | engines/sludge/region.h | 48 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/sludge.h | 2 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/speech.cpp | 2 |
11 files changed, 125 insertions, 77 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index dba5f01694..4d4726a165 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -1312,9 +1312,9 @@ builtIn(skipSpeech) { builtIn(getOverObject) { UNUSEDALL - if (overRegion) + if (g_sludge->_regionMan->getOverRegion()) // Return value - setVariable(fun->reg, SVT_OBJTYPE, overRegion->thisType->objectNum); + setVariable(fun->reg, SVT_OBJTYPE, g_sludge->_regionMan->getOverRegion()->thisType->objectNum); else // Return value setVariable(fun->reg, SVT_INT, 0); @@ -1346,7 +1346,7 @@ builtIn(getObjectX) { if (pers) { setVariable(fun->reg, SVT_INT, pers->x); } else { - ScreenRegion *la = getRegionForObject(objectNumber); + ScreenRegion *la = g_sludge->_regionMan->getRegionForObject(objectNumber); if (la) { setVariable(fun->reg, SVT_INT, la->sX); } else { @@ -1367,7 +1367,7 @@ builtIn(getObjectY) { if (pers) { setVariable(fun->reg, SVT_INT, pers->y); } else { - ScreenRegion *la = getRegionForObject(objectNumber); + ScreenRegion *la = g_sludge->_regionMan->getRegionForObject(objectNumber); if (la) { setVariable(fun->reg, SVT_INT, la->sY); } else { @@ -1404,7 +1404,7 @@ builtIn(addScreenRegion) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - if (addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) + if (g_sludge->_regionMan->addScreenRegion(x1, y1, x2, y2, sX, sY, di, objectNumber)) return BR_CONTINUE; return BR_ERROR; @@ -1416,19 +1416,19 @@ builtIn(removeScreenRegion) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - removeScreenRegion(objectNumber); + g_sludge->_regionMan->removeScreenRegion(objectNumber); return BR_CONTINUE; } builtIn(showBoxes) { UNUSEDALL - showBoxes(); + g_sludge->_regionMan->showBoxes(); return BR_CONTINUE; } builtIn(removeAllScreenRegions) { UNUSEDALL - killAllRegions(); + g_sludge->_regionMan->killAll(); return BR_CONTINUE; } @@ -1708,7 +1708,7 @@ static BuiltReturn moveChr(int numParams, LoadedFunction *fun, bool force, bool if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - reggie = getRegionForObject(toObj); + reggie = g_sludge->_regionMan->getRegionForObject(toObj); if (reggie == NULL) return BR_CONTINUE; @@ -1945,7 +1945,7 @@ builtIn(isScreenRegion) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setVariable(fun->reg, SVT_INT, getRegionForObject(objectNumber) != NULL); + setVariable(fun->reg, SVT_INT, g_sludge->_regionMan->getRegionForObject(objectNumber) != NULL); return BR_CONTINUE; } diff --git a/engines/sludge/event.cpp b/engines/sludge/event.cpp index d5c453bdc1..b553702710 100644 --- a/engines/sludge/event.cpp +++ b/engines/sludge/event.cpp @@ -36,8 +36,6 @@ namespace Sludge { extern Variable *launchResult; extern VariableStack *noStack; -extern ScreenRegion *overRegion; -extern ScreenRegion *lastRegion; EventManager::EventManager(SludgeEngine *vm) { _vm = vm; @@ -152,14 +150,14 @@ void EventManager::checkInput() { bool EventManager::handleInput() { static int l = 0; - if (!g_sludge->launchMe.empty()) { + if (!_vm->launchMe.empty()) { if (l) { // Still paused because of spawned thingy... } else { l = 1; setVariable(*launchResult, SVT_INT, 0/*launch(launchMe) > 31*/); //TODO:false value - g_sludge->launchMe.clear(); + _vm->launchMe.clear(); launchResult = nullptr; } return true; @@ -167,8 +165,8 @@ bool EventManager::handleInput() { l = 0; } - if (!overRegion) - getOverRegion(); + if (!_vm->_regionMan->getOverRegion()) + _vm->_regionMan->updateOverRegion(); if (_input.justMoved) { if (_currentEvents->func[kMoveMouse]) { @@ -178,12 +176,13 @@ bool EventManager::handleInput() { } _input.justMoved = false; - if (lastRegion != overRegion && _currentEvents->func[kFocus]) { + if (_vm-> _regionMan->isRegionChanged()&& _currentEvents->func[kFocus]) { VariableStack *tempStack = new VariableStack; if (!checkNew(tempStack)) return false; initVarNew(tempStack->thisVar); + ScreenRegion *overRegion = _vm->_regionMan->getOverRegion(); if (overRegion) { setVariable(tempStack->thisVar, SVT_OBJTYPE, overRegion->thisType->objectNum); } else { @@ -333,7 +332,7 @@ bool EventManager::handleInput() { _input.rightRelease = false; _input.leftRelease = false; _input.keyPressed = 0; - lastRegion = overRegion; + _vm->_regionMan->updateLastRegion(); return true; } diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp index e90f2700d8..2df8f553ea 100644 --- a/engines/sludge/freeze.cpp +++ b/engines/sludge/freeze.cpp @@ -95,10 +95,7 @@ bool GraphicsManager::freeze() { return false; newFreezer->frozenStatus = copyStatusBarStuff(newStatusStuff); - newFreezer->allScreenRegions = allScreenRegions; - allScreenRegions = NULL; - overRegion = NULL; - + _vm->_regionMan->freeze(newFreezer); _vm->_cursorMan->freeze(newFreezer); _vm->_speechMan->freeze(newFreezer); _vm->_evtMan->freeze(newFreezer); @@ -139,8 +136,8 @@ void GraphicsManager::unfreeze(bool killImage) { killAllPeople(); allPeople = _frozenStuff->allPeople; - killAllRegions(); - allScreenRegions = _frozenStuff->allScreenRegions; + g_sludge->_regionMan->killAll(); + g_sludge->_regionMan->resotre(_frozenStuff); killLightMap(); @@ -171,7 +168,6 @@ void GraphicsManager::unfreeze(bool killImage) { _vm->_speechMan->restore(_frozenStuff); _frozenStuff = _frozenStuff->next; - overRegion = NULL; // free current frozen screen struct if (killMe->backdropSurface.getPixels()) diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 4cabbc79da..bd4b38343a 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -375,7 +375,7 @@ bool saveGame(const Common::String &fname) { g_sludge->_evtMan->saveHandlers(fp); // Save regions - saveRegions(fp); + g_sludge->_regionMan->saveRegions(fp); g_sludge->_cursorMan->saveCursor(fp); @@ -504,7 +504,7 @@ bool loadGame(const Common::String &fname) { g_sludge->_txtMan->loadFont(ssgVersion, fp); killAllPeople(); - killAllRegions(); + g_sludge->_regionMan->killAll(); int camerX = fp->readUint16BE(); int camerY = fp->readUint16BE(); @@ -519,7 +519,7 @@ bool loadGame(const Common::String &fname) { g_sludge->_gfxMan->loadHSI(fp, 0, 0, true); g_sludge->_evtMan->loadHandlers(fp); - loadRegions(fp); + g_sludge->_regionMan->loadRegions(fp); if (!g_sludge->_cursorMan->loadCursor(fp)) { return false; diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index 4aec5fa8b7..d0694795c3 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -51,13 +51,11 @@ extern VariableStack *noStack; extern int ssgVersion; ScreenRegion personRegion; -extern ScreenRegion *lastRegion; extern Floor *currentFloor; OnScreenPerson *allPeople = NULL; int16 scaleHorizon = 75; int16 scaleDivide = 150; -extern ScreenRegion *allScreenRegions; void setFrames(OnScreenPerson &m, int a) { m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction]; @@ -161,8 +159,6 @@ bool initPeople() { personRegion.sX = 0; personRegion.sY = 0; personRegion.di = -1; - allScreenRegions = NULL; - return true; } @@ -410,8 +406,6 @@ void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) { moveMe->colourmix = colourmix; } -extern ScreenRegion *overRegion; - void shufflePeople() { OnScreenPerson **thisReference = &allPeople; OnScreenPerson *A, *B; @@ -445,7 +439,7 @@ void drawPeople() { OnScreenPerson *thisPerson = allPeople; PersonaAnimation *myAnim = NULL; - overRegion = NULL; + g_sludge->_regionMan->resetOverRegion(); while (thisPerson) { if (thisPerson->show) { @@ -480,9 +474,9 @@ void drawPeople() { if (r) { if (!thisPerson->thisType->screenName.empty()) { if (personRegion.thisType != thisPerson->thisType) - lastRegion = NULL; + g_sludge->_regionMan->resetLastRegion(); personRegion.thisType = thisPerson->thisType; - overRegion = &personRegion; + g_sludge->_regionMan->setOverRegion(&personRegion); } } } @@ -943,8 +937,9 @@ void removeOneCharacter(int i) { OnScreenPerson *p = findPerson(i); if (p) { + ScreenRegion *overRegion = g_sludge->_regionMan->getOverRegion(); if (overRegion == &personRegion && overRegion->thisType == p->thisType) { - overRegion = NULL; + overRegion = nullptr; } if (p->continueAfterWalking) diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp index 7593fe4aee..3ce4d92c74 100644 --- a/engines/sludge/region.cpp +++ b/engines/sludge/region.cpp @@ -33,12 +33,21 @@ namespace Sludge { -ScreenRegion *allScreenRegions = nullptr; -ScreenRegion *overRegion = nullptr; -ScreenRegion *lastRegion = nullptr; +RegionManager::RegionManager(SludgeEngine *vm) +{ + _vm = vm; + _allScreenRegions = nullptr; + _lastRegion = nullptr; + _overRegion = nullptr; +} + +RegionManager::~RegionManager() +{ + +} -void showBoxes() { - ScreenRegion*huntRegion = allScreenRegions; +void RegionManager::showBoxes() { + ScreenRegion*huntRegion = _allScreenRegions; while (huntRegion) { g_sludge->_gfxMan->drawVerticalLine(huntRegion->x1, huntRegion->y1, huntRegion->y2); @@ -49,8 +58,8 @@ void showBoxes() { } } -void removeScreenRegion(int objectNum) { - ScreenRegion **huntRegion = &allScreenRegions; +void RegionManager::removeScreenRegion(int objectNum) { + ScreenRegion **huntRegion = &_allScreenRegions; ScreenRegion *killMe; while (*huntRegion) { @@ -58,8 +67,8 @@ void removeScreenRegion(int objectNum) { killMe = *huntRegion; *huntRegion = killMe->next; g_sludge->_objMan->removeObjectType(killMe->thisType); - if (killMe == overRegion) - overRegion = NULL; + if (killMe == _overRegion) + _overRegion = NULL; delete killMe; killMe = NULL; } else { @@ -68,15 +77,15 @@ void removeScreenRegion(int objectNum) { } } -void saveRegions(Common::WriteStream *stream) { +void RegionManager::saveRegions(Common::WriteStream *stream) { int numRegions = 0; - ScreenRegion *thisRegion = allScreenRegions; + ScreenRegion *thisRegion = _allScreenRegions; while (thisRegion) { thisRegion = thisRegion->next; numRegions++; } stream->writeUint16BE(numRegions); - thisRegion = allScreenRegions; + thisRegion = _allScreenRegions; while (thisRegion) { stream->writeUint16BE(thisRegion->x1); stream->writeUint16BE(thisRegion->y1); @@ -91,11 +100,11 @@ void saveRegions(Common::WriteStream *stream) { } } -void loadRegions(Common::SeekableReadStream *stream) { +void RegionManager::loadRegions(Common::SeekableReadStream *stream) { int numRegions = stream->readUint16BE(); ScreenRegion *newRegion; - ScreenRegion **pointy = &allScreenRegions; + ScreenRegion **pointy = &_allScreenRegions; while (numRegions--) { newRegion = new ScreenRegion; @@ -114,19 +123,19 @@ void loadRegions(Common::SeekableReadStream *stream) { *pointy = NULL; } -void killAllRegions() { +void RegionManager::killAll() { ScreenRegion *killRegion; - while (allScreenRegions) { - killRegion = allScreenRegions; - allScreenRegions = allScreenRegions->next; + while (_allScreenRegions) { + killRegion = _allScreenRegions; + _allScreenRegions = _allScreenRegions->next; g_sludge->_objMan->removeObjectType(killRegion->thisType); delete killRegion; } - overRegion = nullptr; - lastRegion = nullptr; + _overRegion = nullptr; + _lastRegion = nullptr; } -bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, +bool RegionManager::addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, int objectNum) { ScreenRegion *newRegion = new ScreenRegion; if (!checkNew(newRegion)) @@ -139,31 +148,31 @@ bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di, newRegion->sX = sX; newRegion->sY = sY; newRegion->thisType = g_sludge->_objMan->loadObjectType(objectNum); - newRegion->next = allScreenRegions; - allScreenRegions = newRegion; + newRegion->next = _allScreenRegions; + _allScreenRegions = newRegion; return (bool) (newRegion->thisType != NULL); } -void getOverRegion() { +void RegionManager::updateOverRegion() { int cameraX = g_sludge->_gfxMan->getCamX(); int cameraY = g_sludge->_gfxMan->getCamY(); - ScreenRegion *thisRegion = allScreenRegions; + ScreenRegion *thisRegion = _allScreenRegions; while (thisRegion) { if ((g_sludge->_evtMan->mouseX() >= thisRegion->x1 - cameraX) && (g_sludge->_evtMan->mouseY() >= thisRegion->y1 - cameraY) && (g_sludge->_evtMan->mouseX() <= thisRegion->x2 - cameraX) && (g_sludge->_evtMan->mouseY() <= thisRegion->y2 - cameraY)) { - overRegion = thisRegion; + _overRegion = thisRegion; return; } thisRegion = thisRegion->next; } - overRegion = NULL; + _overRegion = NULL; return; } -ScreenRegion *getRegionForObject(int obj) { - ScreenRegion *thisRegion = allScreenRegions; +ScreenRegion *RegionManager::getRegionForObject(int obj) { + ScreenRegion *thisRegion = _allScreenRegions; while (thisRegion) { if (obj == thisRegion->thisType->objectNum) { @@ -175,4 +184,15 @@ ScreenRegion *getRegionForObject(int obj) { return NULL; } +void RegionManager::freeze(FrozenStuffStruct *frozenStuff) { + frozenStuff->allScreenRegions = _allScreenRegions; + _allScreenRegions = nullptr; + _overRegion = nullptr; +} + +void RegionManager::resotre(FrozenStuffStruct *frozenStuff) { + _allScreenRegions = frozenStuff->allScreenRegions; + _overRegion = nullptr; +} + } // End of namespace Sludge diff --git a/engines/sludge/region.h b/engines/sludge/region.h index 74294814f6..3a7414979e 100644 --- a/engines/sludge/region.h +++ b/engines/sludge/region.h @@ -23,6 +23,7 @@ #define SLUDGE_REGION_H #include "sludge/objtypes.h" +#include "sludge/freeze.h" namespace Sludge { @@ -32,15 +33,46 @@ struct ScreenRegion { ScreenRegion *next; }; -bool addScreenRegion(int x1, int y1, int x2, int y2, int, int, int, int objectNum); -void getOverRegion(); -ScreenRegion *getRegionForObject(int obj); -void removeScreenRegion(int objectNum); -void loadRegions(Common::SeekableReadStream *stream); -void saveRegions(Common::WriteStream *stream); -void killAllRegions(); +class RegionManager { +public: + RegionManager(SludgeEngine *vm); + ~RegionManager(); -void showBoxes(); + // Kill + void killAll(); + + // Add & remove region + bool addScreenRegion(int x1, int y1, int x2, int y2, int, int, int, int objectNum); + void removeScreenRegion(int objectNum); + + // Save & load + void loadRegions(Common::SeekableReadStream *stream); + void saveRegions(Common::WriteStream *stream); + + // Draw + void showBoxes(); + + // Setter & getter + ScreenRegion *getRegionForObject(int obj); + ScreenRegion *getOverRegion() const { return _overRegion; } + void setOverRegion(ScreenRegion *newRegion) { _overRegion = newRegion; } + void updateOverRegion(); + bool isRegionChanged() const { return _lastRegion != _overRegion; } + void updateLastRegion() { _lastRegion = _overRegion; } + void resetOverRegion() { _overRegion = nullptr; } + void resetLastRegion() { _lastRegion = nullptr; } + + // Freeze + void freeze(FrozenStuffStruct *frozenStuff); + void resotre(FrozenStuffStruct *frozenStuff); + +private: + SludgeEngine *_vm; + + ScreenRegion *_allScreenRegions; + ScreenRegion *_overRegion; + ScreenRegion *_lastRegion; +}; } // End of namespace Sludge diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index d14f92202f..483fb53d7d 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -29,6 +29,7 @@ #include "sludge/event.h" #include "sludge/fonttext.h" #include "sludge/graphics.h" +#include "sludge/region.h" #include "sludge/sludge.h" #include "sludge/sound.h" #include "sludge/speech.h" @@ -82,6 +83,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) _txtMan = new TextManager(); _cursorMan = new CursorManager(this); _speechMan = new SpeechManager(this); + _regionMan = new RegionManager(this); } SludgeEngine::~SludgeEngine() { @@ -122,6 +124,8 @@ SludgeEngine::~SludgeEngine() { _resMan = nullptr; delete _speechMan; _speechMan = nullptr; + delete _regionMan; + _regionMan = nullptr; } Common::Error SludgeEngine::run() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 83c6359f52..fa1038231a 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -41,6 +41,7 @@ extern SludgeEngine *g_sludge; class CursorManager; class EventManager; class GraphicsManager; +class RegionManager; class SoundManager; class SpeechManager; class TextManager; @@ -88,6 +89,7 @@ public: TextManager *_txtMan; CursorManager *_cursorMan; SpeechManager *_speechMan; + RegionManager *_regionMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 9526ddf4df..9eb0eb82db 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -183,7 +183,7 @@ void initSludge() { void killSludge() { killAllFunctions(); killAllPeople(); - killAllRegions(); + g_sludge->_regionMan->killAll(); setFloorNull(); g_sludge->_speechMan->kill(); g_sludge->_languageMan->kill(); diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp index b3fedac70e..6324da88cc 100644 --- a/engines/sludge/speech.cpp +++ b/engines/sludge/speech.cpp @@ -193,7 +193,7 @@ int SpeechManager::wrapSpeech(const Common::String &theText, int objT, int sampl setObjFontColour(thisPerson->thisType); i = wrapSpeechPerson(theText, *thisPerson, sampleFile, animPerson); } else { - ScreenRegion *thisRegion = getRegionForObject(objT); + ScreenRegion *thisRegion = g_sludge->_regionMan->getRegionForObject(objT); if (thisRegion) { setObjFontColour(thisRegion->thisType); i = wrapSpeechXY(theText, |