diff options
-rw-r--r-- | engines/sludge/backdrop.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/builtin.cpp | 9 | ||||
-rw-r--r-- | engines/sludge/freeze.cpp | 18 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 12 | ||||
-rw-r--r-- | engines/sludge/main_loop.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/module.mk | 2 | ||||
-rw-r--r-- | engines/sludge/people.cpp | 6 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 6 | ||||
-rw-r--r-- | engines/sludge/sludge.h | 2 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 19 | ||||
-rw-r--r-- | engines/sludge/speech.cpp (renamed from engines/sludge/talk.cpp) | 179 | ||||
-rw-r--r-- | engines/sludge/speech.h (renamed from engines/sludge/talk.h) | 45 |
12 files changed, 169 insertions, 135 deletions
diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp index dab10be8b3..c1042c7f05 100644 --- a/engines/sludge/backdrop.cpp +++ b/engines/sludge/backdrop.cpp @@ -35,11 +35,11 @@ #include "sludge/imgloader.h" #include "sludge/moreio.h" #include "sludge/newfatal.h" +#include "sludge/speech.h" #include "sludge/statusba.h" #include "sludge/zbuffer.h" #include "sludge/sludge.h" #include "sludge/sludger.h" -#include "sludge/talk.h" #include "sludge/variable.h" #include "sludge/version.h" @@ -185,7 +185,7 @@ bool GraphicsManager::snapshot() { // draw snapshot to rendersurface displayBase(); - viewSpeech(); // ...and anything being said + _vm->_speechMan->display(); drawStatusBar(); // copy backdrop to snapshot diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 9b4c1b7622..1a538fdb6b 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -40,7 +40,6 @@ #include "sludge/objtypes.h" #include "sludge/floor.h" #include "sludge/zbuffer.h" -#include "sludge/talk.h" #include "sludge/region.h" #include "sludge/language.h" #include "sludge/moreio.h" @@ -49,6 +48,7 @@ #include "sludge/freeze.h" #include "sludge/language.h" #include "sludge/sludge.h" +#include "sludge/speech.h" #include "sludge/utf8.h" #include "sludge/graphics.h" #include "sludge/event.h" @@ -71,7 +71,6 @@ extern int numBIFNames, numUserFunc; extern Common::String *allUserFunc; extern Common::String *allBIFNames; -extern float speechSpeed; extern byte brightnessLevel; extern byte fadeMode; extern uint16 saveEncoding; @@ -153,7 +152,7 @@ static BuiltReturn sayCore(int numParams, LoadedFunction *fun, bool sayIt) { if (!getValueType(objT, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - p = wrapSpeech(newText, objT, fileNum, sayIt); + p = g_sludge->_speechMan->wrapSpeech(newText, objT, fileNum, sayIt); fun->timeLeft = p; //debugOut ("BUILTIN: sayCore: %s (%i)\n", newText, p); fun->isSpeech = true; @@ -1298,7 +1297,7 @@ builtIn(setSpeechMode) { builtIn(somethingSpeaking) { UNUSEDALL - int i = isThereAnySpeechGoingOn(); + int i = g_sludge->_speechMan->isThereAnySpeechGoingOn(); if (i == -1) { setVariable(fun->reg, SVT_INT, 0); } else { @@ -1958,7 +1957,7 @@ builtIn(setSpeechSpeed) { if (!getValueType(number, SVT_INT, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - speechSpeed = number * 0.01; + g_sludge->_speechMan->setSpeechSpeed(number * 0.01); setVariable(fun->reg, SVT_INT, 1); return BR_CONTINUE; } diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp index 3e8cdef0d0..9f55564502 100644 --- a/engines/sludge/freeze.cpp +++ b/engines/sludge/freeze.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ + #include "sludge/allfiles.h" #include "sludge/cursors.h" #include "sludge/backdrop.h" @@ -30,12 +31,12 @@ #include "sludge/objtypes.h" #include "sludge/people.h" #include "sludge/region.h" +#include "sludge/speech.h" #include "sludge/sprites.h" #include "sludge/sprbanks.h" #include "sludge/sludge.h" #include "sludge/sludger.h" #include "sludge/statusba.h" -#include "sludge/talk.h" #include "sludge/zbuffer.h" namespace Sludge { @@ -43,7 +44,6 @@ namespace Sludge { extern OnScreenPerson *allPeople; extern ScreenRegion *allScreenRegions; extern ScreenRegion *overRegion; -extern SpeechStruct *speech; void GraphicsManager::freezeGraphics() { @@ -100,10 +100,7 @@ bool GraphicsManager::freeze() { overRegion = NULL; _vm->_cursorMan->freeze(newFreezer); - - newFreezer->speech = speech; - initSpeech(); - + _vm->_speechMan->freeze(newFreezer); _vm->_evtMan->freeze(newFreezer); newFreezer->next = _frozenStuff; @@ -168,19 +165,12 @@ void GraphicsManager::unfreeze(bool killImage) { killParallax(); _parallaxStuff = _frozenStuff->parallaxStuff; - _vm->_cursorMan->resotre(_frozenStuff); - restoreBarStuff(_frozenStuff->frozenStatus); - _vm->_evtMan->restore(_frozenStuff); + _vm->_speechMan->restore(_frozenStuff); - killAllSpeech(); - delete speech; - - speech = _frozenStuff->speech; _frozenStuff = _frozenStuff->next; - overRegion = NULL; // free current frozen screen struct diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 21c80f7e25..dc593a47de 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -33,7 +33,6 @@ #include "sludge/sludge.h" #include "sludge/sludger.h" #include "sludge/people.h" -#include "sludge/talk.h" #include "sludge/objtypes.h" #include "sludge/backdrop.h" #include "sludge/region.h" @@ -44,6 +43,7 @@ #include "sludge/sound.h" #include "sludge/loadsave.h" #include "sludge/bg_effects.h" +#include "sludge/speech.h" #include "sludge/utf8.h" #include "sludge/version.h" #include "sludge/graphics.h" @@ -59,9 +59,7 @@ extern const char *typeName[]; // In variable.cpp 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 FILETIME fileTime; // In sludger.cpp -extern int speechMode; // " " " extern byte brightnessLevel; // " " " extern byte fadeMode; // In transition.cpp extern bool captureAllKeys; @@ -410,12 +408,11 @@ bool saveGame(const Common::String &fname) { } g_sludge->_gfxMan->saveZBuffer(fp); - g_sludge->_gfxMan->saveLightMap(fp); - fp->writeByte(speechMode); fp->writeByte(fadeMode); - saveSpeech(speech, fp); + + g_sludge->_speechMan->save(fp); saveStatusBars(fp); g_sludge->_soundMan->saveSounds(fp); @@ -559,9 +556,8 @@ bool loadGame(const Common::String &fname) { return false; } - speechMode = fp->readByte(); fadeMode = fp->readByte(); - loadSpeech(speech, fp); + g_sludge->_speechMan->load(fp); loadStatusBars(fp); g_sludge->_soundMan->loadSounds(fp); diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp index fc164dfd57..905d91d9c2 100644 --- a/engines/sludge/main_loop.cpp +++ b/engines/sludge/main_loop.cpp @@ -38,7 +38,7 @@ #include "sludge/sound.h" #include "sludge/sludge.h" #include "sludge/sludger.h" -#include "sludge/talk.h" +#include "sludge/speech.h" #include "sludge/transition.h" #include "sludge/timing.h" diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk index 07f1af36c0..a083ec4a95 100644 --- a/engines/sludge/module.mk +++ b/engines/sludge/module.mk @@ -28,10 +28,10 @@ MODULE_OBJS := \ sludge.o \ sludger.o \ sound.o \ + speech.o \ sprbanks.o \ sprites.o \ statusba.o \ - talk.o \ thumbnail.o \ timing.o \ transition.o \ diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index a6adc4ebfb..c4c0cfe4ea 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -28,7 +28,6 @@ #include "sludge/objtypes.h" #include "sludge/region.h" #include "sludge/people.h" -#include "sludge/talk.h" #include "sludge/newfatal.h" #include "sludge/variable.h" #include "sludge/moreio.h" @@ -37,6 +36,7 @@ #include "sludge/zbuffer.h" #include "sludge/sludge.h" #include "sludge/sound.h" +#include "sludge/speech.h" #include "sludge/version.h" #define ANGLEFIX (180.0 / 3.14157) @@ -46,8 +46,6 @@ namespace Sludge { -extern SpeechStruct *speech; - extern VariableStack *noStack; extern int ssgVersion; @@ -202,7 +200,7 @@ bool turnPersonToFace(int thisNum, int direc) { thisPerson->walking = false; thisPerson->spinning = false; turnMeAngle(thisPerson, direc); - setFrames(*thisPerson, (thisPerson == speech->currentTalker) ? ANI_TALK : ANI_STAND); + setFrames(*thisPerson, g_sludge->_speechMan->isCurrentTalker(thisPerson) ? ANI_TALK : ANI_STAND); return true; } return false; diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index 97904e191f..d14f92202f 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -27,10 +27,11 @@ #include "sludge/cursors.h" #include "sludge/event.h" +#include "sludge/fonttext.h" #include "sludge/graphics.h" #include "sludge/sludge.h" #include "sludge/sound.h" -#include "sludge/fonttext.h" +#include "sludge/speech.h" #include "sludge/main_loop.h" namespace Sludge { @@ -80,6 +81,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) _soundMan = new SoundManager(); _txtMan = new TextManager(); _cursorMan = new CursorManager(this); + _speechMan = new SpeechManager(this); } SludgeEngine::~SludgeEngine() { @@ -118,6 +120,8 @@ SludgeEngine::~SludgeEngine() { _languageMan = nullptr; delete _resMan; _resMan = nullptr; + delete _speechMan; + _speechMan = nullptr; } Common::Error SludgeEngine::run() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index 240045db57..83c6359f52 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -42,6 +42,7 @@ class CursorManager; class EventManager; class GraphicsManager; class SoundManager; +class SpeechManager; class TextManager; class SludgeConsole; @@ -86,6 +87,7 @@ public: SoundManager *_soundMan; TextManager *_txtMan; CursorManager *_cursorMan; + SpeechManager *_speechMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 69e6966e74..812f42fb5d 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -47,7 +47,7 @@ #include "sludge/sound.h" #include "sludge/sludge.h" #include "sludge/sludger.h" -#include "sludge/talk.h" +#include "sludge/speech.h" #include "sludge/transition.h" #include "sludge/variable.h" #include "sludge/version.h" @@ -71,7 +71,6 @@ bool captureAllKeys = false; byte brightnessLevel = 255; -extern SpeechStruct *speech; extern LoadedFunction *saverFunc; LoadedFunction *allRunningFunctions = NULL; @@ -81,8 +80,6 @@ Variable *globalVars; int numGlobals = 0; extern SpritePalette pastePalette; -extern int speechMode; -extern float speechSpeed; extern Variable *launchResult; extern int lastFramesPerSecond, thumbWidth, thumbHeight; @@ -155,7 +152,7 @@ void initSludge() { initPeople(); initFloor(); g_sludge->_objMan->init(); - initSpeech(); + g_sludge->_speechMan->init(); initStatusBar(); resetRandW(); g_sludge->_evtMan->init(); @@ -169,7 +166,6 @@ void initSludge() { // global variables numGlobals = 0; - speechMode = 0; launchResult = nullptr; lastFramesPerSecond = -1; @@ -179,7 +175,6 @@ void initSludge() { noStack = nullptr; numBIFNames = numUserFunc = 0; allUserFunc = allBIFNames = nullptr; - speechSpeed = 1; brightnessLevel = 255; fadeMode = 2; saveEncoding = false; @@ -190,7 +185,7 @@ void killSludge() { killAllPeople(); killAllRegions(); setFloorNull(); - killAllSpeech(); + g_sludge->_speechMan->kill(); g_sludge->_languageMan->kill(); g_sludge->_gfxMan->kill(); g_sludge->_resMan->kill(); @@ -345,7 +340,7 @@ void displayBase() { void sludgeDisplay() { displayBase(); - viewSpeech();// ...and anything being said + g_sludge->_speechMan->display(); drawStatusBar(); g_sludge->_cursorMan->displayCursor(); g_sludge->_gfxMan->display(); @@ -381,7 +376,7 @@ void killSpeechTimers() { thisFunction = thisFunction->next; } - killAllSpeech(); + g_sludge->_speechMan->kill(); } void completeTimers() { @@ -940,7 +935,7 @@ bool runSludge() { if (thisFunction->timeLeft) { if (thisFunction->timeLeft < 0) { if (!g_sludge->_soundMan->stillPlayingSound( - g_sludge->_soundMan->findInSoundCache(speech->lastFile))) { + g_sludge->_speechMan->getLastSpeechSound())) { thisFunction->timeLeft = 0; } } else if (!--(thisFunction->timeLeft)) { @@ -948,7 +943,7 @@ bool runSludge() { } else { if (thisFunction->isSpeech) { thisFunction->isSpeech = false; - killAllSpeech(); + g_sludge->_speechMan->kill(); } if (!continueFunction(thisFunction)) return false; diff --git a/engines/sludge/talk.cpp b/engines/sludge/speech.cpp index 4bb1d222b6..1d342a1b65 100644 --- a/engines/sludge/talk.cpp +++ b/engines/sludge/speech.cpp @@ -22,64 +22,62 @@ #include "sludge/allfiles.h" #include "sludge/backdrop.h" +#include "sludge/fonttext.h" +#include "sludge/freeze.h" #include "sludge/graphics.h" -#include "sludge/sprites.h" -#include "sludge/sludger.h" +#include "sludge/moreio.h" +#include "sludge/newfatal.h" #include "sludge/objtypes.h" -#include "sludge/region.h" -#include "sludge/sprbanks.h" #include "sludge/people.h" -#include "sludge/talk.h" +#include "sludge/region.h" #include "sludge/sludge.h" +#include "sludge/sludger.h" #include "sludge/sound.h" -#include "sludge/fonttext.h" -#include "sludge/newfatal.h" -#include "sludge/moreio.h" +#include "sludge/speech.h" +#include "sludge/sprbanks.h" +#include "sludge/sprites.h" namespace Sludge { -extern int speechMode; -SpeechStruct *speech; -float speechSpeed = 1; - -void initSpeech() { - speech = new SpeechStruct; - if (checkNew(speech)) { - speech->currentTalker = NULL; - speech->allSpeech = NULL; - speech->speechY = 0; - speech->lastFile = -1; +void SpeechManager::init() { + _speechMode = 0; + _speechSpeed = 1; + _speech = new SpeechStruct; + if (checkNew(_speech)) { + _speech->currentTalker = NULL; + _speech->allSpeech = NULL; + _speech->speechY = 0; + _speech->lastFile = -1; } } -void killAllSpeech() { - if (!speech) +void SpeechManager::kill() { + if (!_speech) return; - if (speech->lastFile != -1) { - g_sludge->_soundMan->huntKillSound(speech->lastFile); - speech->lastFile = -1; + if (_speech->lastFile != -1) { + _vm->_soundMan->huntKillSound(_speech->lastFile); + _speech->lastFile = -1; } - if (speech->currentTalker) { - makeSilent(*(speech->currentTalker)); - speech->currentTalker = NULL; + if (_speech->currentTalker) { + makeSilent(*(_speech->currentTalker)); + _speech->currentTalker = NULL; } SpeechLine *killMe; - - while (speech->allSpeech) { - killMe = speech->allSpeech; - speech->allSpeech = speech->allSpeech->next; + while (_speech->allSpeech) { + killMe = _speech->allSpeech; + _speech->allSpeech = _speech->allSpeech->next; delete killMe; } } -inline void setObjFontColour(ObjectType *t) { - setFontColour(speech->talkCol, t->r, t->g, t->b); +void SpeechManager::setObjFontColour(ObjectType *t) { + setFontColour(_speech->talkCol, t->r, t->g, t->b); } -void addSpeechLine(const Common::String &theLine, int x, int &offset) { +void SpeechManager::addSpeechLine(const Common::String &theLine, int x, int &offset) { float cameraZoom = g_sludge->_gfxMan->getCamZoom(); int halfWidth = (g_sludge->_txtMan->stringWidth(theLine) >> 1) / cameraZoom; int xx1 = x - (halfWidth); @@ -87,11 +85,11 @@ void addSpeechLine(const Common::String &theLine, int x, int &offset) { SpeechLine *newLine = new SpeechLine; checkNew(newLine); - newLine->next = speech->allSpeech; + newLine->next = _speech->allSpeech; newLine->textLine.clear(); newLine->textLine = theLine; newLine->x = xx1; - speech->allSpeech = newLine; + _speech->allSpeech = newLine; if ((xx1 < 5) && (offset < (5 - xx1))) { offset = 5 - xx1; } else if ((xx2 >= ((float) g_system->getWidth() / cameraZoom) - 5) @@ -100,33 +98,37 @@ void addSpeechLine(const Common::String &theLine, int x, int &offset) { } } -int isThereAnySpeechGoingOn() { - return speech->allSpeech ? speech->lookWhosTalking : -1; +int SpeechManager::isThereAnySpeechGoingOn() { + return _speech->allSpeech ? _speech->lookWhosTalking : -1; } -int wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int sampleFile) { +int SpeechManager::getLastSpeechSound() { + return _vm->_soundMan->findInSoundCache(_speech->lastFile); +} + +int SpeechManager::wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int sampleFile) { float cameraZoom = g_sludge->_gfxMan->getCamZoom(); int fontHeight = g_sludge->_txtMan->getFontHeight(); int cameraY = g_sludge->_gfxMan->getCamY(); int a, offset = 0; - killAllSpeech(); + kill(); - int speechTime = (theText.size() + 20) * speechSpeed; + int speechTime = (theText.size() + 20) * _speechSpeed; if (speechTime < 1) speechTime = 1; if (sampleFile != -1) { - if (speechMode >= 1) { + if (_speechMode >= 1) { if (g_sludge->_soundMan->startSound(sampleFile, false)) { speechTime = -10; - speech->lastFile = sampleFile; - if (speechMode == 2) return -10; + _speech->lastFile = sampleFile; + if (_speechMode == 2) return -10; } } } - speech->speechY = y; + _speech->speechY = y; char *tmp, *txt; tmp = txt = createCString(theText); @@ -150,13 +152,13 @@ int wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int samp delete []tmp; if (y < 0) - speech->speechY -= y; - else if (speech->speechY > cameraY + (float) (g_system->getHeight() - fontHeight / 3) / cameraZoom) - speech->speechY = cameraY + _speech->speechY -= y; + else if (_speech->speechY > cameraY + (float) (g_system->getHeight() - fontHeight / 3) / cameraZoom) + _speech->speechY = cameraY + (float) (g_system->getHeight() - fontHeight / 3) / cameraZoom; if (offset) { - SpeechLine *viewLine = speech->allSpeech; + SpeechLine *viewLine = _speech->allSpeech; while (viewLine) { viewLine->x += offset; viewLine = viewLine->next; @@ -165,7 +167,7 @@ int wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int samp return speechTime; } -int wrapSpeechPerson(const Common::String &theText, OnScreenPerson &thePerson, int sampleFile, bool animPerson) { +int SpeechManager::wrapSpeechPerson(const Common::String &theText, OnScreenPerson &thePerson, int sampleFile, bool animPerson) { int cameraX = g_sludge->_gfxMan->getCamX(); int cameraY = g_sludge->_gfxMan->getCamY(); int i = wrapSpeechXY(theText, thePerson.x - cameraX, @@ -175,17 +177,17 @@ int wrapSpeechPerson(const Common::String &theText, OnScreenPerson &thePerson, i thePerson.thisType->wrapSpeech, sampleFile); if (animPerson) { makeTalker(thePerson); - speech->currentTalker = &thePerson; + _speech->currentTalker = &thePerson; } return i; } -int wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool animPerson) { +int SpeechManager::wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool animPerson) { int i; int cameraX = g_sludge->_gfxMan->getCamX(); int cameraY = g_sludge->_gfxMan->getCamY(); - speech->lookWhosTalking = objT; + _speech->lookWhosTalking = objT; OnScreenPerson *thisPerson = findPerson(objT); if (thisPerson) { setObjFontColour(thisPerson->thisType); @@ -208,35 +210,37 @@ int wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool ani return i; } -void viewSpeech() { +void SpeechManager::display() { float cameraZoom = g_sludge->_gfxMan->getCamZoom(); int fontHeight = g_sludge->_txtMan->getFontHeight(); - int viewY = speech->speechY; - SpeechLine *viewLine = speech->allSpeech; + int viewY = _speech->speechY; + SpeechLine *viewLine = _speech->allSpeech; while (viewLine) { - g_sludge->_txtMan->pasteString(viewLine->textLine, viewLine->x, viewY, speech->talkCol); + g_sludge->_txtMan->pasteString(viewLine->textLine, viewLine->x, viewY, _speech->talkCol); viewY -= fontHeight / cameraZoom; viewLine = viewLine->next; } } -void saveSpeech(SpeechStruct *sS, Common::WriteStream *stream) { - SpeechLine *viewLine = sS->allSpeech; +void SpeechManager::save(Common::WriteStream *stream) { + stream->writeByte(_speechMode); + + SpeechLine *viewLine = _speech->allSpeech; - stream->writeByte(sS->talkCol.originalRed); - stream->writeByte(sS->talkCol.originalGreen); - stream->writeByte(sS->talkCol.originalBlue); + stream->writeByte(_speech->talkCol.originalRed); + stream->writeByte(_speech->talkCol.originalGreen); + stream->writeByte(_speech->talkCol.originalBlue); - stream->writeFloatLE(speechSpeed); + stream->writeFloatLE(_speechSpeed); // Write y co-ordinate - stream->writeUint16BE(sS->speechY); + stream->writeUint16BE(_speech->speechY); // Write which character's talking - stream->writeUint16BE(sS->lookWhosTalking); - if (sS->currentTalker) { + stream->writeUint16BE(_speech->lookWhosTalking); + if (_speech->currentTalker) { stream->writeByte(1); - stream->writeUint16BE(sS->currentTalker->thisType->objectNum); + stream->writeUint16BE(_speech->currentTalker->thisType->objectNum); } else { stream->writeByte(0); } @@ -251,42 +255,57 @@ void saveSpeech(SpeechStruct *sS, Common::WriteStream *stream) { stream->writeByte(0); } -bool loadSpeech(SpeechStruct *sS, Common::SeekableReadStream *stream) { - speech->currentTalker = NULL; - killAllSpeech(); +bool SpeechManager::load(Common::SeekableReadStream *stream) { + // read speech mode + _speechMode = stream->readByte(); + + _speech->currentTalker = nullptr; + kill(); byte r = stream->readByte(); byte g = stream->readByte(); byte b = stream->readByte(); - setFontColour(sS->talkCol, r, g, b); + setFontColour(_speech->talkCol, r, g, b); - speechSpeed = stream->readFloatLE(); + _speechSpeed = stream->readFloatLE(); // Read y co-ordinate - sS->speechY = stream->readUint16BE(); + _speech->speechY = stream->readUint16BE(); // Read which character's talking - sS->lookWhosTalking = stream->readUint16BE(); + _speech->lookWhosTalking = stream->readUint16BE(); if (stream->readByte()) { - sS->currentTalker = findPerson(stream->readUint16BE()); + _speech->currentTalker = findPerson(stream->readUint16BE()); } else { - sS->currentTalker = NULL; + _speech->currentTalker = NULL; } // Read what's being said - SpeechLine **viewLine = &sS->allSpeech; + SpeechLine **viewLine = &_speech->allSpeech; SpeechLine *newOne; - speech->lastFile = -1; + _speech->lastFile = -1; while (stream->readByte()) { newOne = new SpeechLine; - if (! checkNew(newOne)) return false; + if (!checkNew(newOne)) + return false; newOne->textLine = readString(stream); newOne->x = stream->readUint16BE(); newOne->next = NULL; - (* viewLine) = newOne; + (*viewLine) = newOne; viewLine = &(newOne->next); } return true; } +void SpeechManager::freeze(FrozenStuffStruct *frozenStuff) { + frozenStuff->speech = _speech; + init(); +} + +void SpeechManager::restore(FrozenStuffStruct *frozenStuff) { + kill(); + delete _speech; + _speech = frozenStuff->speech; +} + } // End of namespace Sludge diff --git a/engines/sludge/talk.h b/engines/sludge/speech.h index 0d7fa80f0f..b33a52889c 100644 --- a/engines/sludge/talk.h +++ b/engines/sludge/speech.h @@ -39,13 +39,44 @@ struct SpeechStruct { SpritePalette talkCol; }; -int wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool); -void viewSpeech(); -void killAllSpeech(); -int isThereAnySpeechGoingOn(); -void initSpeech(); -void saveSpeech(SpeechStruct *sS, Common::WriteStream *stream); -bool loadSpeech(SpeechStruct *sS, Common::SeekableReadStream *stream); +class SpeechManager { +public: + SpeechManager(SludgeEngine *vm) : _vm(vm) { init(); } + ~SpeechManager() { kill(); } + + void init(); + void kill(); + + int wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool); + void display(); + + int isThereAnySpeechGoingOn(); + bool isCurrentTalker(OnScreenPerson *person) { return person == _speech->currentTalker; } + int getLastSpeechSound(); + + // setters & getters + void setObjFontColour(ObjectType *t); + void setSpeechSpeed(float speed) { _speechSpeed = speed; } + float getSpeechSpeed() { return _speechSpeed; } + + // load & save + void save(Common::WriteStream *stream); + bool load(Common::SeekableReadStream *stream); + + // freeze & restore + void freeze(FrozenStuffStruct *frozenStuff); + void restore(FrozenStuffStruct *frozenStuff); + +private: + SludgeEngine *_vm; + int _speechMode; + SpeechStruct *_speech; + float _speechSpeed; + + void addSpeechLine(const Common::String &theLine, int x, int &offset); + int wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int sampleFile); + int wrapSpeechPerson(const Common::String &theText, OnScreenPerson &thePerson, int sampleFile, bool animPerson); +}; } // End of namespace Sludge |