[Scummvm-git-logs] scummvm master -> 867b8dbb9277f2cde6c45c107b15edd1a6f73b10

yinsimei roseline.yin at gmail.com
Tue Aug 22 16:20:37 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
867b8dbb92 SLUDGE: Reset engine when launching a new game data file


Commit: 867b8dbb9277f2cde6c45c107b15edd1a6f73b10
    https://github.com/scummvm/scummvm/commit/867b8dbb9277f2cde6c45c107b15edd1a6f73b10
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-08-22T16:20:15+02:00

Commit Message:
SLUDGE: Reset engine when launching a new game data file

Changed paths:
    engines/sludge/cursors.cpp
    engines/sludge/cursors.h
    engines/sludge/detection_tables.h
    engines/sludge/event.cpp
    engines/sludge/event.h
    engines/sludge/fileset.cpp
    engines/sludge/fileset.h
    engines/sludge/floor.cpp
    engines/sludge/fonttext.cpp
    engines/sludge/fonttext.h
    engines/sludge/graphics.cpp
    engines/sludge/graphics.h
    engines/sludge/language.cpp
    engines/sludge/language.h
    engines/sludge/main_loop.cpp
    engines/sludge/objtypes.cpp
    engines/sludge/objtypes.h
    engines/sludge/sludger.cpp
    engines/sludge/sludger.h
    engines/sludge/sound.cpp
    engines/sludge/sound.h
    engines/sludge/sprites.cpp
    engines/sludge/sprites.h
    engines/sludge/talk.cpp


diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 7c16e8f..0c7745e 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 5fd1885..4229900 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 b61d541..c5bf3d6 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 c2997be..d5c453b 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 878d363..015e9ea 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 c9cdefd..b04c68c 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 9cde705..3ba0a2b 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 dff6980..45a7501 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 664c843..787e95e 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 9628db6..26b12d9 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 eecf522..3bcb5aa 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 c5914c7..16973a1 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 858c44d..8bd9d51 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 9d3f2d2..26b57ad 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 d00f6e4..fc164df 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 3bea21a..dc41249 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 f0f5125..a348fa1 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 91c78b0..69e6966 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 0ab3eb7..8f554f8 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 6820ae1..25caa0b 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 1e1a2a4..dd9a017 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 c37c4a1..81769cc 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 521fb52..e138c6f 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 531fb42..4bb1d22 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;





More information about the Scummvm-git-logs mailing list