aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sludge/cursors.cpp13
-rw-r--r--engines/sludge/cursors.h3
-rw-r--r--engines/sludge/detection_tables.h48
-rw-r--r--engines/sludge/event.cpp16
-rw-r--r--engines/sludge/event.h3
-rw-r--r--engines/sludge/fileset.cpp24
-rw-r--r--engines/sludge/fileset.h13
-rw-r--r--engines/sludge/floor.cpp20
-rw-r--r--engines/sludge/fonttext.cpp12
-rw-r--r--engines/sludge/fonttext.h3
-rw-r--r--engines/sludge/graphics.cpp37
-rw-r--r--engines/sludge/graphics.h7
-rw-r--r--engines/sludge/language.cpp22
-rw-r--r--engines/sludge/language.h12
-rw-r--r--engines/sludge/main_loop.cpp22
-rw-r--r--engines/sludge/objtypes.cpp14
-rw-r--r--engines/sludge/objtypes.h6
-rw-r--r--engines/sludge/sludger.cpp86
-rw-r--r--engines/sludge/sludger.h4
-rw-r--r--engines/sludge/sound.cpp32
-rw-r--r--engines/sludge/sound.h1
-rw-r--r--engines/sludge/sprites.cpp14
-rw-r--r--engines/sludge/sprites.h29
-rw-r--r--engines/sludge/talk.cpp3
24 files changed, 312 insertions, 132 deletions
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 7c16e8fa19..0c7745e9ff 100644
--- a/engines/sludge/cursors.cpp
+++ b/engines/sludge/cursors.cpp
@@ -36,13 +36,22 @@ namespace Sludge {
CursorManager::CursorManager(SludgeEngine *vm) {
_vm = vm;
+ init();
+}
+
+CursorManager::~CursorManager() {
+ kill();
+}
+
+void CursorManager::init() {
_mouseCursorAnim = makeNullAnim();
_mouseCursorFrameNum = 0;
_mouseCursorCountUp = 0;
}
-CursorManager::~CursorManager() {
-
+void CursorManager::kill() {
+ deleteAnim(_mouseCursorAnim);
+ _mouseCursorAnim = nullptr;
}
void CursorManager::pickAnimCursor(PersonaAnimation *pp) {
diff --git a/engines/sludge/cursors.h b/engines/sludge/cursors.h
index 5fd1885f69..4229900a94 100644
--- a/engines/sludge/cursors.h
+++ b/engines/sludge/cursors.h
@@ -34,6 +34,9 @@ public:
CursorManager(SludgeEngine *vm);
virtual ~CursorManager();
+ void init();
+ void kill();
+
// cursor
void pickAnimCursor(struct PersonaAnimation *pp);
void displayCursor();
diff --git a/engines/sludge/detection_tables.h b/engines/sludge/detection_tables.h
index b61d5413e1..c5bf3d6185 100644
--- a/engines/sludge/detection_tables.h
+++ b/engines/sludge/detection_tables.h
@@ -127,18 +127,18 @@ static const SludgeGameDescription gameDescriptions[] = {
0
},
-// {
-// {
-// "tgttpoacs",
-// "",
-// AD_ENTRY1s("gamedata", "d5ec4d7d8440f7744335d25d25e1e943", 40368),
-// Common::EN_ANY,
-// Common::kPlatformWindows,
-// ADGF_NO_FLAGS,
-// GUIO0()
-// },
-// 0
-// },
+ {
+ {
+ "tgttpoacs",
+ "",
+ AD_ENTRY1s("gamedata", "d5ec4d7d8440f7744335d25d25e1e943", 40368),
+ Common::EN_ANY,
+ Common::kPlatformWindows,
+ ADGF_NO_FLAGS,
+ GUIO0()
+ },
+ 0
+ },
{
{
@@ -205,18 +205,18 @@ static const SludgeGameDescription gameDescriptions[] = {
3
},
-// {
-// {
-// "cubert",
-// "",
-// AD_ENTRY1s("gamedata", "0078eb54f63cc0a22e50f17d904fcfde", 26799),
-// Common::UNK_LANG,
-// Common::kPlatformWindows,
-// ADGF_NO_FLAGS,
-// GUIO0()
-// },
-// 0
-// },
+ {
+ {
+ "cubert",
+ "",
+ AD_ENTRY1s("gamedata", "0078eb54f63cc0a22e50f17d904fcfde", 26799),
+ Common::UNK_LANG,
+ Common::kPlatformWindows,
+ ADGF_NO_FLAGS,
+ GUIO0()
+ },
+ 0
+ },
{
{
diff --git a/engines/sludge/event.cpp b/engines/sludge/event.cpp
index c2997be078..d5c453bdc1 100644
--- a/engines/sludge/event.cpp
+++ b/engines/sludge/event.cpp
@@ -41,21 +41,31 @@ extern ScreenRegion *lastRegion;
EventManager::EventManager(SludgeEngine *vm) {
_vm = vm;
+ _currentEvents = new EventHandlers;
+ init();
+}
+EventManager::~EventManager() {
+ kill();
+ if (_currentEvents) {
+ delete _currentEvents;
+ _currentEvents = nullptr;
+ }
+}
+
+void EventManager::init() {
_weAreDoneSoQuit = 0;
_reallyWantToQuit = false;
_input.leftClick = _input.rightClick = _input.justMoved = _input.leftRelease = _input.rightRelease = false;
_input.keyPressed = 0;
- _currentEvents = new EventHandlers;
for (uint i = 0; i < EVENT_FUNC_NB; ++i) {
_currentEvents->func[i] = 0;
}
}
-EventManager::~EventManager() {
-
+void EventManager::kill() {
}
void EventManager::checkInput() {
diff --git a/engines/sludge/event.h b/engines/sludge/event.h
index 878d363b49..015e9ea1cb 100644
--- a/engines/sludge/event.h
+++ b/engines/sludge/event.h
@@ -56,6 +56,9 @@ public:
EventManager(SludgeEngine *vm);
virtual ~EventManager();
+ void init();
+ void kill();
+
// Input
void checkInput();
bool handleInput();
diff --git a/engines/sludge/fileset.cpp b/engines/sludge/fileset.cpp
index c9cdefd512..b04c68c1cb 100644
--- a/engines/sludge/fileset.cpp
+++ b/engines/sludge/fileset.cpp
@@ -31,6 +31,30 @@
namespace Sludge {
+ResourceManager::ResourceManager() {
+ init();
+}
+
+ResourceManager::~ResourceManager() {
+ kill();
+}
+
+void ResourceManager::init() {
+ _sliceBusy = true;
+ _bigDataFile = nullptr;
+ _startOfDataIndex = 0;
+ _startOfTextIndex = 0;
+ _startOfSubIndex = 0;
+ _startOfObjectIndex = 0;
+ _startIndex = 0;
+}
+void ResourceManager::kill() {
+ if (_bigDataFile) {
+ delete _bigDataFile;
+ _bigDataFile = nullptr;
+ }
+}
+
bool ResourceManager::openSubSlice(int num) {
if (_sliceBusy) {
fatal("Can't read from data file", "I'm already reading something");
diff --git a/engines/sludge/fileset.h b/engines/sludge/fileset.h
index 9cde705a55..3ba0a2bc48 100644
--- a/engines/sludge/fileset.h
+++ b/engines/sludge/fileset.h
@@ -29,14 +29,11 @@ namespace Sludge {
class ResourceManager {
public:
- ResourceManager():
- _sliceBusy(true),
- _bigDataFile(0),
- _startOfDataIndex(0),
- _startOfTextIndex(0),
- _startOfSubIndex(0),
- _startOfObjectIndex(0),
- _startIndex(0) {}
+ ResourceManager();
+ ~ResourceManager();
+
+ void init();
+ void kill();
void setData(Common::File *readStream);
void setFileIndices(uint, uint);
diff --git a/engines/sludge/floor.cpp b/engines/sludge/floor.cpp
index dff6980c7c..45a7501470 100644
--- a/engines/sludge/floor.cpp
+++ b/engines/sludge/floor.cpp
@@ -105,16 +105,18 @@ bool initFloor() {
}
void killFloor() {
- for (int i = 0; i < currentFloor->numPolygons; i++) {
- delete []currentFloor->polygon[i].vertexID;
- delete []currentFloor->matrix[i];
+ if (currentFloor) {
+ for (int i = 0; i < currentFloor->numPolygons; i++) {
+ delete []currentFloor->polygon[i].vertexID;
+ delete []currentFloor->matrix[i];
+ }
+ delete []currentFloor->polygon;
+ currentFloor->polygon = NULL;
+ delete []currentFloor->vertex;
+ currentFloor->vertex = NULL;
+ delete []currentFloor->matrix;
+ currentFloor->matrix = NULL;
}
- delete []currentFloor->polygon;
- currentFloor->polygon = NULL;
- delete []currentFloor->vertex;
- currentFloor->vertex = NULL;
- delete []currentFloor->matrix;
- currentFloor->matrix = NULL;
}
void setFloorNull() {
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 664c843cb0..787e95e6f3 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -32,6 +32,14 @@
namespace Sludge {
TextManager::TextManager() {
+ init();
+}
+
+TextManager::~TextManager() {
+ kill();
+}
+
+void TextManager::init() {
_theFont.total = 0;
_theFont.sprites = nullptr;
@@ -43,8 +51,8 @@ TextManager::TextManager() {
_fontTable.clear();
}
-TextManager::~TextManager() {
- g_sludge->_gfxMan->forgetSpriteBank(_theFont);
+void TextManager::kill() {
+ GraphicsManager::forgetSpriteBank(_theFont);
}
bool TextManager::isInFont(const Common::String &theText) {
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
index 9628db632d..26b12d9f11 100644
--- a/engines/sludge/fonttext.h
+++ b/engines/sludge/fonttext.h
@@ -38,6 +38,9 @@ public:
TextManager();
virtual ~TextManager();
+ void init();
+ void kill();
+
int stringWidth(const Common::String &theText);
int stringLength(const Common::String &theText);
diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp
index eecf52231f..3bcb5aa043 100644
--- a/engines/sludge/graphics.cpp
+++ b/engines/sludge/graphics.cpp
@@ -37,7 +37,14 @@ namespace Sludge {
GraphicsManager::GraphicsManager(SludgeEngine *vm) {
_vm = vm;
+ init();
+}
+GraphicsManager::~GraphicsManager() {
+ kill();
+}
+
+void GraphicsManager::init() {
// Init screen surface
_winWidth = _sceneWidth = 640;
_winHeight = _sceneHeight = 480;
@@ -78,11 +85,13 @@ GraphicsManager::GraphicsManager(SludgeEngine *vm) {
_currentBurnB = 0;
}
-GraphicsManager::~GraphicsManager() {
+void GraphicsManager::kill() {
// kill parallax
- killParallax();
- delete _parallaxStuff;
- _parallaxStuff = nullptr;
+ if (_parallaxStuff) {
+ _parallaxStuff->kill();
+ delete _parallaxStuff;
+ _parallaxStuff = nullptr;
+ }
// kill frozen stuff
FrozenStuffStruct *killMe = _frozenStuff;
@@ -98,9 +107,11 @@ GraphicsManager::~GraphicsManager() {
}
// kill sprite layers
- killSpriteLayers();
- delete _spriteLayers;
- _spriteLayers = nullptr;
+ if (_spriteLayers) {
+ killSpriteLayers();
+ delete _spriteLayers;
+ _spriteLayers = nullptr;
+ }
// kill sprite banks
LoadedSpriteBanks::iterator it;
@@ -111,9 +122,11 @@ GraphicsManager::~GraphicsManager() {
_allLoadedBanks.clear();
// kill zbuffer
- killZBuffer();
- delete _zBuffer;
- _zBuffer = nullptr;
+ if (_zBuffer) {
+ killZBuffer();
+ delete _zBuffer;
+ _zBuffer = nullptr;
+ }
// kill surfaces
if (_renderSurface.getPixels())
@@ -129,13 +142,15 @@ GraphicsManager::~GraphicsManager() {
_origBackdropSurface.free();
}
-bool GraphicsManager::init() {
+bool GraphicsManager::initGfx() {
initGraphics(_winWidth, _winHeight, true, _vm->getScreenPixelFormat());
_renderSurface.create(_winWidth, _winHeight, *_vm->getScreenPixelFormat());
if (!killResizeBackdrop(_winWidth, _winHeight))
return fatal("Couldn't allocate memory for backdrop");
+ blankAllScreen();
+
return true;
}
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index c5914c712b..16973a1658 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -57,9 +57,12 @@ public:
GraphicsManager(SludgeEngine *vm);
virtual ~GraphicsManager();
+ void init();
+ void kill();
+
// graphics
void setWindowSize(uint winWidth, uint winHeight) { _winWidth = winWidth; _winHeight = winHeight; }
- bool init();
+ bool initGfx();
void display();
void clear();
@@ -125,7 +128,7 @@ public:
bool isFrozen() { return (_frozenStuff != nullptr); }
// Sprites
- void forgetSpriteBank(SpriteBank &forgetme);
+ static void forgetSpriteBank(SpriteBank &forgetme);
bool loadSpriteBank(char *filename, SpriteBank &loadhere);
bool loadSpriteBank(int fileNum, SpriteBank &loadhere, bool isFont);
diff --git a/engines/sludge/language.cpp b/engines/sludge/language.cpp
index 858c44dd19..8bd9d51493 100644
--- a/engines/sludge/language.cpp
+++ b/engines/sludge/language.cpp
@@ -32,19 +32,35 @@
namespace Sludge {
+LanguageManager::LanguageManager() {
+ init();
+}
+
LanguageManager::~LanguageManager() {
+ kill();
+}
+
+void LanguageManager::init() {
+ _languageID = 0;
+ _languageIdx = -1;
+ _numLanguages = 0;
+ _languageTable = nullptr;
+ _languageNames = nullptr;
+}
+
+void LanguageManager::kill() {
if (_languageTable) {
delete []_languageTable;
- _languageTable = NULL;
+ _languageTable = nullptr;
}
if (_languageNames) {
delete []_languageNames;
- _languageNames = NULL;
+ _languageNames = nullptr;
}
}
-void LanguageManager::init(Common::File *fp) {
+void LanguageManager::createTable(Common::File *fp) {
// get number of languages
_numLanguages =
(gameVersion >= VERSION(1, 3)) ? (fp->readByte()) : 0;
diff --git a/engines/sludge/language.h b/engines/sludge/language.h
index 9d3f2d2d12..26b57ad76e 100644
--- a/engines/sludge/language.h
+++ b/engines/sludge/language.h
@@ -30,15 +30,13 @@ namespace Sludge {
class LanguageManager {
public:
- LanguageManager() :
- _languageID(0),
- _languageIdx(-1),
- _numLanguages(0),
- _languageTable(0),
- _languageNames(0) {}
+ LanguageManager();
~LanguageManager();
- void init(Common::File *table);
+ void init();
+ void kill();
+
+ void createTable(Common::File *table);
void setLanguageID(uint id);
void saveLanguageSetting(Common::WriteStream *writeStream);
void loadLanguageSetting(Common::SeekableReadStream *readStream);
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index d00f6e42c4..fc164dfd57 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -20,7 +20,6 @@
*
*/
-#include "common/config-manager.h"
#include "common/debug.h"
#include "graphics/surface.h"
@@ -55,22 +54,7 @@ int main_loop(Common::String filename) {
return 0;
}
- g_sludge->_gfxMan->init();
-
- g_sludge->_gfxMan->blankAllScreen();
- if (!initPeople())
- return fatal("Couldn't initialise people stuff");
- if (!initFloor())
- return fatal("Couldn't initialise floor stuff");
- if (!g_sludge->_objMan->initObjectTypes())
- return fatal("Couldn't initialise object type stuff");
- initSpeech();
- initStatusBar();
- resetRandW();
-
- if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
- g_sludge->_soundMan->initSoundStuff();
- }
+ g_sludge->_gfxMan->initGfx();
startNewFunctionNum(0, 0, NULL, noStack);
@@ -88,9 +72,7 @@ int main_loop(Common::String filename) {
g_sludge->_timer.waitFrame();
}
- killAllFunctions();
- killAllRegions();
- g_sludge->_soundMan->killSoundStuff();
+ killSludge();
// Load next game
if (!g_sludge->launchNext.empty()) {
diff --git a/engines/sludge/objtypes.cpp b/engines/sludge/objtypes.cpp
index 3bea21a943..dc41249ab7 100644
--- a/engines/sludge/objtypes.cpp
+++ b/engines/sludge/objtypes.cpp
@@ -32,16 +32,22 @@
namespace Sludge {
ObjectManager::~ObjectManager() {
+ kill();
+}
+
+bool ObjectManager::init() {
+ _allObjectTypes.clear();
+ return true;
+}
+
+void ObjectManager::kill() {
ObjectTypeList::iterator it;
for (it = _allObjectTypes.begin(); it != _allObjectTypes.end(); ++it) {
delete [](*it)->allCombis;
delete (*it);
(*it) = nullptr;
}
-}
-
-bool ObjectManager::initObjectTypes() {
- return true;
+ _allObjectTypes.clear();
}
ObjectType *ObjectManager::findObjectType(int i) {
diff --git a/engines/sludge/objtypes.h b/engines/sludge/objtypes.h
index f0f5125884..a348fa123d 100644
--- a/engines/sludge/objtypes.h
+++ b/engines/sludge/objtypes.h
@@ -44,10 +44,12 @@ typedef Common::List<ObjectType *> ObjectTypeList;
class ObjectManager {
public:
- ObjectManager(SludgeEngine *vm) : _vm(vm) {}
+ ObjectManager(SludgeEngine *vm) : _vm(vm) { init(); }
~ObjectManager();
- bool initObjectTypes();
+ bool init();
+ void kill();
+
ObjectType *findObjectType(int i);
ObjectType *loadObjectType(int i);
int getCombinationFunction(int a, int b);
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 91c78b08f0..69e6966e74 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -20,12 +20,14 @@
*
*/
+#include "common/config-manager.h"
#include "common/debug.h"
#include "sludge/allfiles.h"
#include "sludge/backdrop.h"
#include "sludge/builtin.h"
#include "sludge/cursors.h"
+#include "sludge/event.h"
#include "sludge/fonttext.h"
#include "sludge/freeze.h"
#include "sludge/floor.h"
@@ -76,7 +78,17 @@ LoadedFunction *allRunningFunctions = NULL;
VariableStack *noStack = NULL;
Variable *globalVars;
-int numGlobals;
+int numGlobals = 0;
+
+extern SpritePalette pastePalette;
+extern int speechMode;
+extern float speechSpeed;
+extern Variable *launchResult;
+extern int lastFramesPerSecond, thumbWidth, thumbHeight;
+
+extern bool allowAnyFilename;
+extern byte fadeMode;
+extern uint16 saveEncoding;
const char *sludgeText[] = { "?????", "RETURN", "BRANCH", "BR_ZERO",
"SET_GLOBAL", "SET_LOCAL", "LOAD_GLOBAL", "LOAD_LOCAL", "PLUS", "MINUS",
@@ -136,9 +148,69 @@ Common::File *openAndVerify(const Common::String &filename, char extra1, char ex
return fp;
}
+void initSludge() {
+ g_sludge->_languageMan->init();
+ g_sludge->_gfxMan->init();
+ g_sludge->_resMan->init();
+ initPeople();
+ initFloor();
+ g_sludge->_objMan->init();
+ initSpeech();
+ initStatusBar();
+ resetRandW();
+ g_sludge->_evtMan->init();
+ g_sludge->_txtMan->init();
+ g_sludge->_cursorMan->init();
+
+ g_sludge->_soundMan->init();
+ if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
+ g_sludge->_soundMan->initSoundStuff();
+ }
+
+ // global variables
+ numGlobals = 0;
+ speechMode = 0;
+ launchResult = nullptr;
+
+ lastFramesPerSecond = -1;
+ thumbWidth = thumbHeight = 0;
+ allowAnyFilename = true;
+ captureAllKeys = false;
+ noStack = nullptr;
+ numBIFNames = numUserFunc = 0;
+ allUserFunc = allBIFNames = nullptr;
+ speechSpeed = 1;
+ brightnessLevel = 255;
+ fadeMode = 2;
+ saveEncoding = false;
+}
+
+void killSludge() {
+ killAllFunctions();
+ killAllPeople();
+ killAllRegions();
+ setFloorNull();
+ killAllSpeech();
+ g_sludge->_languageMan->kill();
+ g_sludge->_gfxMan->kill();
+ g_sludge->_resMan->kill();
+ g_sludge->_objMan->kill();
+ g_sludge->_soundMan->killSoundStuff();
+ g_sludge->_evtMan->kill();
+ g_sludge->_txtMan->kill();
+ g_sludge->_cursorMan->kill();
+
+ // global variables
+ pastePalette.reset();
+ numBIFNames = numUserFunc = 0;
+ delete []allUserFunc;
+ delete []allBIFNames;
+}
+
bool initSludge(const Common::String &filename) {
- int a = 0;
+ initSludge();
+ int a = 0;
Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion);
if (!fp)
return false;
@@ -201,7 +273,7 @@ bool initSludge(const Common::String &filename) {
Common::String dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : "";
debugC(2, kSludgeDebugDataLoad, "dataFol : %s", dataFol.c_str());
- g_sludge->_languageMan->init(fp);
+ g_sludge->_languageMan->createTable(fp);
if (gameVersion >= VERSION(1, 6)) {
fp->readByte();
@@ -901,12 +973,8 @@ bool runSludge() {
}
void killAllFunctions() {
- LoadedFunction *ptr = allRunningFunctions;
- while (ptr) {
- LoadedFunction *kill = ptr;
- ptr = ptr->next;
- abortFunction(kill);
- }
+ while (allRunningFunctions)
+ finishFunction(allRunningFunctions);
}
bool loadFunctionCode(LoadedFunction *newFunc) {
diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h
index 0ab3eb7887..8f554f83cb 100644
--- a/engines/sludge/sludger.h
+++ b/engines/sludge/sludger.h
@@ -60,6 +60,10 @@ struct LoadedFunction {
bool initSludge(const Common::String &);
bool runSludge();
+
+void initSludge();
+void killSludge();
+
void displayBase();
void sludgeDisplay();
int startNewFunctionNum(uint, uint, LoadedFunction *, VariableStack*&, bool = true);
diff --git a/engines/sludge/sound.cpp b/engines/sludge/sound.cpp
index 6820ae14be..25caa0b9de 100644
--- a/engines/sludge/sound.cpp
+++ b/engines/sludge/sound.cpp
@@ -43,24 +43,13 @@ const int SoundManager::MAX_SAMPLES = 8;
const int SoundManager::MAX_MODS = 3;
SoundManager::SoundManager() {
- // there's possibility that several sound list played at the same time
- _soundListHandles.clear();
-
- _soundOK = false;
- _silenceIKillYou = false;
- _isHandlingSoundList = false;
-
_soundCache = nullptr;
_soundCache = new SoundThing[MAX_SAMPLES];
_modCache = nullptr;
_modCache = new SoundThing[MAX_MODS];
- _defVol = 128;
- _defSoundVol = 255;
- _modLoudness = 0.95f;
-
- _emptySoundSlot = 0;
+ init();
}
SoundManager::~SoundManager() {
@@ -73,14 +62,29 @@ SoundManager::~SoundManager() {
_modCache = nullptr;
}
+void SoundManager::init() {
+ // there's possibility that several sound list played at the same time
+ _soundListHandles.clear();
+
+ _soundOK = false;
+ _silenceIKillYou = false;
+ _isHandlingSoundList = false;
+
+ _defVol = 128;
+ _defSoundVol = 255;
+ _modLoudness = 0.95f;
+
+ _emptySoundSlot = 0;
+}
+
bool SoundManager::initSoundStuff() {
- for (int a = 0; a < MAX_SAMPLES; a ++) {
+ for (int a = 0; a < MAX_SAMPLES; ++a) {
_soundCache[a].fileLoaded = -1;
_soundCache[a].looping = false;
_soundCache[a].inSoundList = false;
}
- for (int a = 0; a < MAX_MODS; a ++) {
+ for (int a = 0; a < MAX_MODS; ++a) {
_soundCache[a].fileLoaded = -1;
_soundCache[a].looping = false;
_soundCache[a].inSoundList = false;
diff --git a/engines/sludge/sound.h b/engines/sludge/sound.h
index 1e1a2a47e4..dd9a0179d9 100644
--- a/engines/sludge/sound.h
+++ b/engines/sludge/sound.h
@@ -50,6 +50,7 @@ public:
void handleSoundLists(); // to produce the same effects as end of stream call back functions
// GENERAL...
+ void init();
bool initSoundStuff();
void killSoundStuff();
diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp
index c37c4a1905..81769ccb97 100644
--- a/engines/sludge/sprites.cpp
+++ b/engines/sludge/sprites.cpp
@@ -54,13 +54,15 @@ void GraphicsManager::forgetSpriteBank(SpriteBank &forgetme) {
forgetme.myPalette.b = NULL;
}
- for (int i = 0; i < forgetme.total; ++i) {
- forgetme.sprites[i].surface.free();
- forgetme.sprites[i].burnSurface.free();
- }
+ if (forgetme.sprites) {
+ for (int i = 0; i < forgetme.total; ++i) {
+ forgetme.sprites[i].surface.free();
+ forgetme.sprites[i].burnSurface.free();
+ }
- delete []forgetme.sprites;
- forgetme.sprites = NULL;
+ delete []forgetme.sprites;
+ forgetme.sprites = NULL;
+ }
}
bool GraphicsManager::reserveSpritePal(SpritePalette &sP, int n) {
diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h
index 521fb5298d..e138c6f14f 100644
--- a/engines/sludge/sprites.h
+++ b/engines/sludge/sprites.h
@@ -41,15 +41,32 @@ public:
byte *b;
byte originalRed, originalGreen, originalBlue, total;
- SpritePalette() : pal(0), r(0), g(0), b(0), total(0) {
+ SpritePalette() { init(); }
+
+ ~SpritePalette() { kill(); }
+
+ void reset() {
+ kill();
+ init();
+ }
+
+private:
+ void init() {
+ pal = nullptr;
+ r = g = b = nullptr;
+ total = 0;
originalRed = originalGreen = originalBlue = 255;
}
- ~SpritePalette() {
- delete[] pal;
- delete[] r;
- delete[] g;
- delete[] b;
+ void kill() {
+ if (pal)
+ delete[] pal;
+ if (r)
+ delete[] r;
+ if (g)
+ delete[] g;
+ if (b)
+ delete[] b;
}
};
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index 531fb42fd8..4bb1d222b6 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -53,6 +53,9 @@ void initSpeech() {
}
void killAllSpeech() {
+ if (!speech)
+ return;
+
if (speech->lastFile != -1) {
g_sludge->_soundMan->huntKillSound(speech->lastFile);
speech->lastFile = -1;