diff options
author | Simei Yin | 2017-07-21 08:16:17 +0200 |
---|---|---|
committer | Simei Yin | 2017-07-21 11:21:45 +0200 |
commit | fd2cf90bb3eab1050d0513813c72a9e26a8166d5 (patch) | |
tree | 3179a75e87527fffaec880b2876beec2b88ddfb6 | |
parent | 6858d3c6aefe1f39089a56ef3f2521b86d8abeb0 (diff) | |
download | scummvm-rg350-fd2cf90bb3eab1050d0513813c72a9e26a8166d5.tar.gz scummvm-rg350-fd2cf90bb3eab1050d0513813c72a9e26a8166d5.tar.bz2 scummvm-rg350-fd2cf90bb3eab1050d0513813c72a9e26a8166d5.zip |
SLUDGE: Objectify cursor manager
-rw-r--r-- | engines/sludge/builtin.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/cursors.cpp | 91 | ||||
-rw-r--r-- | engines/sludge/cursors.h | 32 | ||||
-rw-r--r-- | engines/sludge/freeze.cpp | 12 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 12 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/sludge.h | 2 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 4 |
8 files changed, 108 insertions, 53 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 5156aa59ef..a27fcb4153 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -201,7 +201,7 @@ builtIn(howFrozen) { builtIn(setCursor) { UNUSEDALL PersonaAnimation *aa = getAnimationFromVar(fun->stack->thisVar); - pickAnimCursor(aa); + g_sludge->_cursorMan->pickAnimCursor(aa); trimStack(fun->stack); return BR_CONTINUE; } @@ -416,7 +416,7 @@ builtIn(pasteImage) { if (pp == NULL) return BR_CONTINUE; - pasteCursor(x, y, pp); + g_sludge->_cursorMan->pasteCursor(x, y, pp); return BR_CONTINUE; } diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp index 87a2bf7179..7c16e8fa19 100644 --- a/engines/sludge/cursors.cpp +++ b/engines/sludge/cursors.cpp @@ -23,7 +23,9 @@ #include "sludge/allfiles.h" #include "sludge/cursors.h" #include "sludge/event.h" +#include "sludge/freeze.h" #include "sludge/graphics.h" +#include "sludge/newfatal.h" #include "sludge/people.h" #include "sludge/sprites.h" #include "sludge/sprbanks.h" @@ -32,58 +34,93 @@ namespace Sludge { -PersonaAnimation *mouseCursorAnim; -int mouseCursorFrameNum = 0; -int mouseCursorCountUp = 0; +CursorManager::CursorManager(SludgeEngine *vm) { + _vm = vm; + _mouseCursorAnim = makeNullAnim(); + _mouseCursorFrameNum = 0; + _mouseCursorCountUp = 0; +} + +CursorManager::~CursorManager() { + +} -void pickAnimCursor(PersonaAnimation *pp) { - deleteAnim(mouseCursorAnim); - mouseCursorAnim = pp; - mouseCursorFrameNum = 0; - mouseCursorCountUp = 0; +void CursorManager::pickAnimCursor(PersonaAnimation *pp) { + deleteAnim(_mouseCursorAnim); + _mouseCursorAnim = pp; + _mouseCursorFrameNum = 0; + _mouseCursorCountUp = 0; } -void displayCursor() { - if (mouseCursorAnim && mouseCursorAnim->numFrames) { +void CursorManager::displayCursor() { + if (_mouseCursorAnim && _mouseCursorAnim->numFrames) { - int spriteNum = mouseCursorAnim->frames[mouseCursorFrameNum].frameNum; + int spriteNum = _mouseCursorAnim->frames[_mouseCursorFrameNum].frameNum; int flipMe = 0; if (spriteNum < 0) { spriteNum = -spriteNum; flipMe = 1; - if (spriteNum >= mouseCursorAnim->theSprites->bank.total) + if (spriteNum >= _mouseCursorAnim->theSprites->bank.total) spriteNum = 0; } else { - if (spriteNum >= mouseCursorAnim->theSprites->bank.total) + if (spriteNum >= _mouseCursorAnim->theSprites->bank.total) flipMe = 2; } if (flipMe != 2) { if (flipMe) { - g_sludge->_gfxMan->flipFontSprite( - g_sludge->_evtMan->mouseX(), g_sludge->_evtMan->mouseY(), - mouseCursorAnim->theSprites->bank.sprites[spriteNum], - mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/); + _vm->_gfxMan->flipFontSprite( + _vm->_evtMan->mouseX(), _vm->_evtMan->mouseY(), + _mouseCursorAnim->theSprites->bank.sprites[spriteNum], + _mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/); } else { - g_sludge->_gfxMan->fontSprite( - g_sludge->_evtMan->mouseX(), g_sludge->_evtMan->mouseY(), - mouseCursorAnim->theSprites->bank.sprites[spriteNum], - mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/); + _vm->_gfxMan->fontSprite( + _vm->_evtMan->mouseX(), _vm->_evtMan->mouseY(), + _mouseCursorAnim->theSprites->bank.sprites[spriteNum], + _mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/); } } - if (++mouseCursorCountUp >= mouseCursorAnim->frames[mouseCursorFrameNum].howMany) { - mouseCursorCountUp = 0; - mouseCursorFrameNum++; - mouseCursorFrameNum %= mouseCursorAnim->numFrames; + if (++_mouseCursorCountUp >= _mouseCursorAnim->frames[_mouseCursorFrameNum].howMany) { + _mouseCursorCountUp = 0; + _mouseCursorFrameNum++; + _mouseCursorFrameNum %= _mouseCursorAnim->numFrames; } } } -void pasteCursor(int x, int y, PersonaAnimation *c) { +void CursorManager::pasteCursor(int x, int y, PersonaAnimation *c) { if (c->numFrames) - g_sludge->_gfxMan->pasteSpriteToBackDrop(x, y, c->theSprites->bank.sprites[c->frames[0].frameNum], c->theSprites->bank.myPalette); + _vm->_gfxMan->pasteSpriteToBackDrop(x, y, c->theSprites->bank.sprites[c->frames[0].frameNum], c->theSprites->bank.myPalette); +} + +void CursorManager::freeze(FrozenStuffStruct *frozenStuff) { + frozenStuff->mouseCursorAnim = _mouseCursorAnim; + frozenStuff->mouseCursorFrameNum = _mouseCursorFrameNum; + _mouseCursorAnim = makeNullAnim(); + _mouseCursorFrameNum = 0; +} + +void CursorManager::resotre(FrozenStuffStruct *frozenStuff) { + deleteAnim(_mouseCursorAnim); + _mouseCursorAnim = frozenStuff->mouseCursorAnim; + _mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum; +} + +void CursorManager::saveCursor(Common::WriteStream *stream) { + saveAnim(_mouseCursorAnim, stream); + stream->writeUint16BE(_mouseCursorFrameNum); +} + +bool CursorManager::loadCursor(Common::SeekableReadStream *stream) { + _mouseCursorAnim = new PersonaAnimation; + if (!checkNew(_mouseCursorAnim)) + return false; + if (!loadAnim(_mouseCursorAnim, stream)) + return false; + _mouseCursorFrameNum = stream->readUint16BE(); + return true; } } // End of namespace Sludge diff --git a/engines/sludge/cursors.h b/engines/sludge/cursors.h index 9bc5b82806..5fd1885f69 100644 --- a/engines/sludge/cursors.h +++ b/engines/sludge/cursors.h @@ -25,9 +25,35 @@ namespace Sludge { -void pickAnimCursor(struct PersonaAnimation *pp); -void displayCursor(); -void pasteCursor(int x, int y, struct PersonaAnimation *c); +class SludgeEngine; + +struct FrozenStuffStruct; + +class CursorManager { +public: + CursorManager(SludgeEngine *vm); + virtual ~CursorManager(); + + // cursor + void pickAnimCursor(struct PersonaAnimation *pp); + void displayCursor(); + void pasteCursor(int x, int y, struct PersonaAnimation *c); + + // freeze + void freeze(FrozenStuffStruct *frozenStuff); + void resotre(FrozenStuffStruct *frozenStuff); + + // load & save + void saveCursor(Common::WriteStream *stream); + bool loadCursor(Common::SeekableReadStream *stream); + +private: + SludgeEngine *_vm; + + PersonaAnimation *_mouseCursorAnim; + int _mouseCursorFrameNum; + int _mouseCursorCountUp; +}; } // End of namespace Sludge diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp index 1bc2ad96f7..3e8cdef0d0 100644 --- a/engines/sludge/freeze.cpp +++ b/engines/sludge/freeze.cpp @@ -20,6 +20,7 @@ * */ #include "sludge/allfiles.h" +#include "sludge/cursors.h" #include "sludge/backdrop.h" #include "sludge/event.h" #include "sludge/fonttext.h" @@ -43,8 +44,6 @@ extern OnScreenPerson *allPeople; extern ScreenRegion *allScreenRegions; extern ScreenRegion *overRegion; extern SpeechStruct *speech; -extern PersonaAnimation *mouseCursorAnim; -extern int mouseCursorFrameNum; void GraphicsManager::freezeGraphics() { @@ -100,10 +99,7 @@ bool GraphicsManager::freeze() { allScreenRegions = NULL; overRegion = NULL; - newFreezer->mouseCursorAnim = mouseCursorAnim; - newFreezer->mouseCursorFrameNum = mouseCursorFrameNum; - mouseCursorAnim = makeNullAnim(); - mouseCursorFrameNum = 0; + _vm->_cursorMan->freeze(newFreezer); newFreezer->speech = speech; initSpeech(); @@ -173,9 +169,7 @@ void GraphicsManager::unfreeze(bool killImage) { killParallax(); _parallaxStuff = _frozenStuff->parallaxStuff; - deleteAnim(mouseCursorAnim); - mouseCursorAnim = _frozenStuff->mouseCursorAnim; - mouseCursorFrameNum = _frozenStuff->mouseCursorFrameNum; + _vm->_cursorMan->resotre(_frozenStuff); restoreBarStuff(_frozenStuff->frozenStatus); diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 494c767684..1588ffdc01 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -61,8 +61,6 @@ extern int numGlobals; // In sludger.cpp extern Variable *globalVars; // In sludger.cpp extern Floor *currentFloor; // In floor.cpp extern SpeechStruct *speech; // In talk.cpp -extern PersonaAnimation *mouseCursorAnim; // In cursor.cpp -extern int mouseCursorFrameNum; // " " " extern FILETIME fileTime; // In sludger.cpp extern int speechMode; // " " " extern byte brightnessLevel; // " " " @@ -382,8 +380,7 @@ bool saveGame(const Common::String &fname) { // Save regions saveRegions(fp); - saveAnim(mouseCursorAnim, fp); - fp->writeUint16BE(mouseCursorFrameNum); + g_sludge->_cursorMan->saveCursor(fp); // Save functions LoadedFunction *thisFunction = allRunningFunctions; @@ -529,12 +526,9 @@ bool loadGame(const Common::String &fname) { g_sludge->_evtMan->loadHandlers(fp); loadRegions(fp); - mouseCursorAnim = new PersonaAnimation ; - if (!checkNew(mouseCursorAnim)) + if (!g_sludge->_cursorMan->loadCursor(fp)) { return false; - if (!loadAnim(mouseCursorAnim, fp)) - return false; - mouseCursorFrameNum = fp->readUint16BE(); + } LoadedFunction *rFunc; LoadedFunction **buildList = &allRunningFunctions; diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index 12b6a8b058..36b1fa27ac 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -25,6 +25,7 @@ #include "common/debug-channels.h" #include "common/error.h" +#include "sludge/cursors.h" #include "sludge/event.h" #include "sludge/graphics.h" #include "sludge/sludge.h" @@ -73,6 +74,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) _evtMan = new EventManager(this); _soundMan = new SoundManager(); _txtMan = new TextManager(); + _cursorMan = new CursorManager(this); } SludgeEngine::~SludgeEngine() { @@ -95,6 +97,8 @@ SludgeEngine::~SludgeEngine() { _pixelFormat = nullptr; // Dispose managers + delete _cursorMan; + _cursorMan = nullptr; delete _txtMan; _txtMan = nullptr; delete _soundMan; diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 844d6d0d3f..d1dcb92a92 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -38,6 +38,7 @@ namespace Sludge { extern SludgeEngine *g_sludge; +class CursorManager; class EventManager; class GraphicsManager; class SoundManager; @@ -81,6 +82,7 @@ public: EventManager *_evtMan; SoundManager *_soundMan; TextManager *_txtMan; + CursorManager *_cursorMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index ffcecc9865..880c808a96 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -53,7 +53,6 @@ namespace Sludge { -extern PersonaAnimation *mouseCursorAnim; extern int dialogValue; extern Variable *launchResult; @@ -143,7 +142,6 @@ Common::File *openAndVerify(const Common::String &filename, char extra1, char ex bool initSludge(const Common::String &filename) { int a = 0; - mouseCursorAnim = makeNullAnim(); Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion); if (!fp) @@ -279,7 +277,7 @@ void sludgeDisplay() { displayBase(); viewSpeech();// ...and anything being said drawStatusBar(); - displayCursor(); + g_sludge->_cursorMan->displayCursor(); g_sludge->_gfxMan->display(); if (brightnessLevel < 255) fixBrightness();// This is for transitionLevel special effects } |