Permalink
Browse files

SLUDGE: Objectify cursor manager

  • Loading branch information...
yinsimei committed Jul 21, 2017
1 parent 6858d3c commit fd2cf90bb3eab1050d0513813c72a9e26a8166d5
@@ -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;
}
View
@@ -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
View
@@ -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
View
@@ -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);
@@ -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;
@@ -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;
View
@@ -38,6 +38,7 @@ namespace Sludge {
extern SludgeEngine *g_sludge;
class CursorManager;
class EventManager;
class GraphicsManager;
class SoundManager;
@@ -81,6 +82,7 @@ class SludgeEngine: public Engine {
EventManager *_evtMan;
SoundManager *_soundMan;
TextManager *_txtMan;
CursorManager *_cursorMan;
SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
virtual ~SludgeEngine();
@@ -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
}

0 comments on commit fd2cf90

Please sign in to comment.