[Scummvm-git-logs] scummvm master -> fd2cf90bb3eab1050d0513813c72a9e26a8166d5

yinsimei roseline.yin at gmail.com
Fri Jul 21 11:22:05 CEST 2017


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

Summary:
2b538d4376 SLUDGE: Correct uninitialized values
73a81a5089 SLUDGE: Objectify sound manager
4a54a02760 SLUDGE: Objectify text manager
6858d3c6ae SLUDGE: Remove unused files
fd2cf90bb3 SLUDGE: Objectify cursor manager


Commit: 2b538d43767beefbb1e342e8e25191179225aaf5
    https://github.com/scummvm/scummvm/commit/2b538d43767beefbb1e342e8e25191179225aaf5
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-21T11:21:45+02:00

Commit Message:
SLUDGE: Correct uninitialized values

Changed paths:
    engines/sludge/event.cpp
    engines/sludge/event.h


diff --git a/engines/sludge/event.cpp b/engines/sludge/event.cpp
index 5ab237b..2211400 100644
--- a/engines/sludge/event.cpp
+++ b/engines/sludge/event.cpp
@@ -44,11 +44,13 @@ EventManager::EventManager(SludgeEngine *vm) {
 
 	_weAreDoneSoQuit = 0;
 
+	_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) {
-		_mainHandlers.func[i] = 0;
+		_currentEvents->func[i] = 0;
 	}
-	_currentEvents = &_mainHandlers;
 }
 
 EventManager::~EventManager() {
diff --git a/engines/sludge/event.h b/engines/sludge/event.h
index e857529..ddb973f 100644
--- a/engines/sludge/event.h
+++ b/engines/sludge/event.h
@@ -81,7 +81,6 @@ private:
 
 	int _weAreDoneSoQuit;
 
-	EventHandlers _mainHandlers;
 	EventHandlers *_currentEvents;
 };
 


Commit: 73a81a5089627599d9adbedf6d2d4dc0122d48c5
    https://github.com/scummvm/scummvm/commit/73a81a5089627599d9adbedf6d2d4dc0122d48c5
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-21T11:21:45+02:00

Commit Message:
SLUDGE: Objectify sound manager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/main_loop.cpp
    engines/sludge/newfatal.cpp
    engines/sludge/people.cpp
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp
    engines/sludge/sound.cpp
    engines/sludge/sound.h
    engines/sludge/talk.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index d88ecb3..4ae01ab 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -1063,7 +1063,7 @@ builtIn(startMusic) {
 	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	if (!playMOD(fileNumber, musChan, fromTrack))
+	if (!g_sludge->_soundMan->playMOD(fileNumber, musChan, fromTrack))
 		return BR_CONTINUE;  //BR_ERROR;
 	return BR_CONTINUE;
 }
@@ -1074,7 +1074,7 @@ builtIn(stopMusic) {
 	if (!getValueType(v, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	stopMOD(v);
+	g_sludge->_soundMan->stopMOD(v);
 	return BR_CONTINUE;
 }
 
@@ -1087,7 +1087,7 @@ builtIn(setMusicVolume) {
 	if (!getValueType(musChan, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setMusicVolume(musChan, v);
+	g_sludge->_soundMan->setMusicVolume(musChan, v);
 	return BR_CONTINUE;
 }
 
@@ -1097,7 +1097,7 @@ builtIn(setDefaultMusicVolume) {
 	if (!getValueType(v, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setDefaultMusicVolume(v);
+	g_sludge->_soundMan->setDefaultMusicVolume(v);
 	return BR_CONTINUE;
 }
 
@@ -1107,7 +1107,7 @@ builtIn(playSound) {
 	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	if (!startSound(fileNumber, false))
+	if (!g_sludge->_soundMan->startSound(fileNumber, false))
 		return BR_CONTINUE;    // Was BR_ERROR
 	return BR_CONTINUE;
 }
@@ -1123,7 +1123,7 @@ builtIn(loopSound) {
 		if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar))
 			return BR_ERROR;
 		trimStack(fun->stack);
-		if (!startSound(fileNumber, true))
+		if (!g_sludge->_soundMan->startSound(fileNumber, true))
 			return BR_CONTINUE;     // Was BR_ERROR
 		return BR_CONTINUE;
 	} else {
@@ -1165,7 +1165,7 @@ builtIn(loopSound) {
 			s->next = s;
 		}
 		old->vol = -1;
-		playSoundList(old);
+		g_sludge->_soundMan->playSoundList(old);
 		return BR_CONTINUE;
 	}
 }
@@ -1176,7 +1176,7 @@ builtIn(stopSound) {
 	if (!getValueType(v, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	huntKillSound(v);
+	g_sludge->_soundMan->huntKillSound(v);
 	return BR_CONTINUE;
 }
 
@@ -1186,7 +1186,7 @@ builtIn(setDefaultSoundVolume) {
 	if (!getValueType(v, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setDefaultSoundVolume(v);
+	g_sludge->_soundMan->setDefaultSoundVolume(v);
 	return BR_CONTINUE;
 }
 
@@ -1199,7 +1199,7 @@ builtIn(setSoundVolume) {
 	if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setSoundVolume(musChan, v);
+	g_sludge->_soundMan->setSoundVolume(musChan, v);
 	return BR_CONTINUE;
 }
 
@@ -1215,7 +1215,7 @@ builtIn(setSoundLoopPoints) {
 	if (!getValueType(musChan, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setSoundLoop(musChan, theStart, theEnd);
+	g_sludge->_soundMan->setSoundLoop(musChan, theStart, theEnd);
 	return BR_CONTINUE;
 }
 
@@ -2153,7 +2153,7 @@ builtIn(cacheSound) {
 	if (!getValueType(fileNumber, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	if (cacheSound(fileNumber) == -1)
+	if (g_sludge->_soundMan->cacheSound(fileNumber) == -1)
 		return BR_ERROR;
 	return BR_CONTINUE;
 }
@@ -2245,7 +2245,7 @@ builtIn(getSoundCache) {
 	fun->reg.varData.theStack->first = NULL;
 	fun->reg.varData.theStack->last = NULL;
 	fun->reg.varData.theStack->timesUsed = 1;
-	if (!getSoundCacheStack(fun->reg.varData.theStack))
+	if (!g_sludge->_soundMan->getSoundCacheStack(fun->reg.varData.theStack))
 		return BR_ERROR;
 	return BR_CONTINUE;
 }
@@ -2312,7 +2312,7 @@ builtIn(freeSound) {
 	if (!getValueType(v, SVT_FILE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	huntKillFreeSound(v);
+	g_sludge->_soundMan->huntKillFreeSound(v);
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 8eb59fc..da3037e 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -432,7 +432,7 @@ bool saveGame(const Common::String &fname) {
 	fp->writeByte(fadeMode);
 	saveSpeech(speech, fp);
 	saveStatusBars(fp);
-	saveSounds(fp);
+	g_sludge->_soundMan->saveSounds(fp);
 
 	fp->writeUint16BE(saveEncoding);
 
@@ -604,7 +604,7 @@ bool loadGame(const Common::String &fname) {
 	fadeMode = fp->readByte();
 	loadSpeech(speech, fp);
 	loadStatusBars(fp);
-	loadSounds(fp);
+	g_sludge->_soundMan->loadSounds(fp);
 
 	saveEncoding = fp->readUint16BE();
 
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index a4851d7..3a42d6d 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -45,12 +45,6 @@
 
 namespace Sludge {
 
-#ifndef MAX_PATH
-#define MAX_PATH        1024          // maximum size of a path name
-#endif
-
-HWND hMainWindow = NULL;
-
 extern VariableStack *noStack;
 
 int dialogValue = 0;
@@ -77,7 +71,7 @@ int main_loop(const char *filename) {
 	resetRandW();
 
 	if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
-		initSoundStuff(hMainWindow);
+		g_sludge->_soundMan->initSoundStuff();
 	}
 
 	startNewFunctionNum(0, 0, NULL, noStack);
@@ -91,11 +85,11 @@ int main_loop(const char *filename) {
 			runSludge();
 		}
 		sludgeDisplay();
-		handleSoundLists();
+		g_sludge->_soundMan->handleSoundLists();
 		g_sludge->_timer.waitFrame();
 	}
 
-	killSoundStuff();
+	g_sludge->_soundMan->killSoundStuff();
 
 	return (0);
 }
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp
index acbcc14..b86ddb2 100644
--- a/engines/sludge/newfatal.cpp
+++ b/engines/sludge/newfatal.cpp
@@ -58,7 +58,7 @@ void registerWindowForFatal() {
 }
 
 int inFatal(const Common::String &str) {
-	killSoundStuff();
+	g_sludge->_soundMan->killSoundStuff();
 	error("%s", str.c_str());
 	return true;
 }
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index 1021829..1edec12 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -457,7 +457,7 @@ void drawPeople() {
 				thisPerson->frameNum = 0;
 				thisPerson->frameTick = myAnim->frames[0].howMany;
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					g_sludge->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
 					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
 					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
@@ -495,7 +495,7 @@ void drawPeople() {
 			thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 			if (thisPerson->show && myAnim && myAnim->frames) {
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					g_sludge->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
 					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
 					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index fef2ebf..4766356 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -28,6 +28,7 @@
 #include "sludge/event.h"
 #include "sludge/graphics.h"
 #include "sludge/sludge.h"
+#include "sludge/sound.h"
 #include "sludge/main_loop.h"
 
 namespace Sludge {
@@ -69,6 +70,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 	_objMan = new ObjectManager(this);
 	_gfxMan = new GraphicsManager(this);
 	_evtMan = new EventManager(this);
+	_soundMan = new SoundManager();
 }
 
 SludgeEngine::~SludgeEngine() {
@@ -91,6 +93,8 @@ SludgeEngine::~SludgeEngine() {
 	_pixelFormat = nullptr;
 
 	// Dispose managers
+	delete _soundMan;
+	_soundMan = nullptr;
 	delete _evtMan;
 	_evtMan = nullptr;
 	delete _gfxMan;
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 74d5c07..6fb4689 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -40,6 +40,8 @@ extern SludgeEngine *g_sludge;
 
 class EventManager;
 class GraphicsManager;
+class SoundManager;
+
 class SludgeConsole;
 
 struct SludgeGameDescription;
@@ -76,6 +78,7 @@ public:
 	ObjectManager *_objMan;
 	GraphicsManager *_gfxMan;
 	EventManager *_evtMan;
+	SoundManager *_soundMan;
 
 	SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
 	virtual ~SludgeEngine();
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index b890c78..ffcecc9 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -882,8 +882,8 @@ bool runSludge() {
 		if (!thisFunction->freezerLevel) {
 			if (thisFunction->timeLeft) {
 				if (thisFunction->timeLeft < 0) {
-					if (!stillPlayingSound(
-							findInSoundCache(speech->lastFile))) {
+					if (!g_sludge->_soundMan->stillPlayingSound(
+							g_sludge->_soundMan->findInSoundCache(speech->lastFile))) {
 						thisFunction->timeLeft = 0;
 					}
 				} else if (!--(thisFunction->timeLeft)) {
diff --git a/engines/sludge/sound.cpp b/engines/sludge/sound.cpp
index 5d6b426..f25b48f 100644
--- a/engines/sludge/sound.cpp
+++ b/engines/sludge/sound.cpp
@@ -26,7 +26,6 @@
 #include "common/memstream.h"
 
 #include "audio/audiostream.h"
-#include "audio/mixer.h"
 #include "audio/decoders/wave.h"
 #include "audio/decoders/vorbis.h"
 #include "audio/mods/protracker.h"
@@ -38,67 +37,73 @@
 #include "sludge/fileset.h"
 #include "sludge/sludge.h"
 
-#define MAX_SAMPLES 8
-#define MAX_MODS 3
-#define NUM_BUFS 3
-
 namespace Sludge {
 
-bool soundOK = false;
-bool SilenceIKillYou = false;
-bool isHandlingSoundList = false;
-// there's possibility that several sound list played at the same time
-typedef Common::List<SoundList*> SoundListHandles;
-SoundListHandles soundListHandles;
-
-struct soundThing {
-	Audio::SoundHandle handle;
-	int fileLoaded, vol;    //Used for sounds only. (sound saving/loading)
-	bool looping;      		//Used for sounds only. (sound saving/loading)
-	bool inSoundList;
-};
-
-soundThing soundCache[MAX_SAMPLES];
-#if 0
-soundThing modCache[MAX_MODS];
-#endif
+const int SoundManager::MAX_SAMPLES = 8;
+const int SoundManager::MAX_MODS = 3;
 
-int defVol = 128;
-int defSoundVol = 255;
-const float modLoudness = 0.95f;
+SoundManager::SoundManager() {
+	// there's possibility that several sound list played at the same time
+	_soundListHandles.clear();
 
-/*
- * Set up, tear down:
- */
+	_soundOK = false;
+	_silenceIKillYou = false;
+	_isHandlingSoundList = false;
+
+	_soundCache = nullptr;
+	_soundCache = new SoundThing[MAX_SAMPLES];
+	#if 0
+	_modCache = nullptr;
+	_modCache = new SoundThing[MAX_MODS];
+	#endif
+
+	_defVol = 128;
+	_defSoundVol = 255;
+	_modLoudness = 0.95f;
 
-bool initSoundStuff(HWND hwnd) {
+	_emptySoundSlot = 0;
+}
+
+SoundManager::~SoundManager() {
+	delete []_soundCache;
+	_soundCache = nullptr;
+
+	#if 0
+	delete []_modCache;
+	_modCache = nullptr;
+	#endif
+
+	killSoundStuff();
+}
+
+bool SoundManager::initSoundStuff() {
 	for (int a = 0; a < MAX_SAMPLES; a ++) {
-		soundCache[a].fileLoaded = -1;
-		soundCache[a].looping = false;
-		soundCache[a].inSoundList = false;
+		_soundCache[a].fileLoaded = -1;
+		_soundCache[a].looping = false;
+		_soundCache[a].inSoundList = false;
 	}
 #if 0
 	for (int a = 0; a < MAX_MODS; a ++) {
-		modCache[a].stream = NULL;
-		modCache[a].playing = false;
+		_modCache[a].stream = NULL;
+		_modCache[a].playing = false;
 	}
 #endif
-	return soundOK = true;
+	return _soundOK = true;
 }
 
-void killSoundStuff() {
-	if (!soundOK)
+void SoundManager::killSoundStuff() {
+	if (!_soundOK)
 		return;
 
-	SilenceIKillYou = true;
+	_silenceIKillYou = true;
 	for (int i = 0; i < MAX_SAMPLES; i ++) {
-		if (g_sludge->_mixer->isSoundHandleActive(soundCache[i].handle)) {
-			g_sludge->_mixer->stopHandle(soundCache[i].handle);
+		if (g_sludge->_mixer->isSoundHandleActive(_soundCache[i].handle)) {
+			g_sludge->_mixer->stopHandle(_soundCache[i].handle);
 		}
 	}
 #if 0
 	for (int i = 0; i < MAX_MODS; i ++) {
-		if (modCache[i].playing) {
+		if (_modCache[i].playing) {
 
 			if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) {
 				debugOut("Failed to stop source: %s\n",
@@ -107,7 +112,7 @@ void killSoundStuff() {
 
 		}
 
-		if (modCache[i].stream != NULL) {
+		if (_modCache[i].stream != NULL) {
 
 			if (! alureDestroyStream(modCache[i].stream, 0, NULL)) {
 				debugOut("Failed to destroy stream: %s\n",
@@ -117,63 +122,59 @@ void killSoundStuff() {
 		}
 	}
 #endif
-	SilenceIKillYou = false;
+	_silenceIKillYou = false;
 }
 
 /*
  * Some setters:
  */
 
-void setMusicVolume(int a, int v) {
-	if (!soundOK)
+void SoundManager::setMusicVolume(int a, int v) {
+	if (!_soundOK)
 		return;
 #if 0
-	if (modCache[a].playing) {
-		alSourcef(modCache[a].playingOnSource, AL_GAIN, (float) modLoudness * v / 256);
+	if (_modCache[a].playing) {
+		alSourcef(modCache[a].playingOnSource, AL_GAIN, (float) _modLoudness * v / 256);
 	}
 #endif
 }
 
-void setDefaultMusicVolume(int v) {
-	defVol = v;
+void SoundManager::setDefaultMusicVolume(int v) {
+	_defVol = v;
 }
 
-void setSoundVolume(int a, int v) {
-	if (!soundOK)
+void SoundManager::setSoundVolume(int a, int v) {
+	if (!_soundOK)
 		return;
 	int ch = findInSoundCache(a);
 	if (ch != -1) {
-		if (g_sludge->_mixer->isSoundHandleActive(soundCache[ch].handle)) {
-			soundCache[ch].vol = v;
-			g_sludge->_mixer->setChannelVolume(soundCache[ch].handle, v);
+		if (g_sludge->_mixer->isSoundHandleActive(_soundCache[ch].handle)) {
+			_soundCache[ch].vol = v;
+			g_sludge->_mixer->setChannelVolume(_soundCache[ch].handle, v);
 		}
 	}
 }
 
-void setDefaultSoundVolume(int v) {
-	defSoundVol = v;
+void SoundManager::setDefaultSoundVolume(int v) {
+	_defSoundVol = v;
 }
 
-void setSoundLoop(int a, int s, int e) {
+void SoundManager::setSoundLoop(int a, int s, int e) {
 //#pragma unused (a,s,e)
 }
 
-/*
- * Stopping things:
- */
-
-int findInSoundCache(int a) {
+int SoundManager::findInSoundCache(int a) {
 	int i;
 	for (i = 0; i < MAX_SAMPLES; i++) {
-		if (soundCache[i].fileLoaded == a) {
+		if (_soundCache[i].fileLoaded == a) {
 			return i;
 		}
 	}
 	return -1;
 }
 
-void stopMOD(int i) {
-	if (!soundOK)
+void SoundManager::stopMOD(int i) {
+	if (!_soundOK)
 		return;
 #if 0
 	alGetError();
@@ -185,41 +186,41 @@ void stopMOD(int i) {
 #endif
 }
 
-void huntKillSound(int filenum) {
-	if (!soundOK)
+void SoundManager::huntKillSound(int filenum) {
+	if (!_soundOK)
 		return;
 
 	int gotSlot = findInSoundCache(filenum);
 	if (gotSlot == -1) return;
 
-	SilenceIKillYou = true;
+	_silenceIKillYou = true;
 
-	if (g_sludge->_mixer->isSoundHandleActive(soundCache[gotSlot].handle)) {
-		g_sludge->_mixer->stopHandle(soundCache[gotSlot].handle);
+	if (g_sludge->_mixer->isSoundHandleActive(_soundCache[gotSlot].handle)) {
+		g_sludge->_mixer->stopHandle(_soundCache[gotSlot].handle);
 	}
 
-	SilenceIKillYou = false;
+	_silenceIKillYou = false;
 }
 
-void freeSound(int a) {
-	if (!soundOK)
+void SoundManager::freeSound(int a) {
+	if (!_soundOK)
 		return;
 
-	SilenceIKillYou = true;
+	_silenceIKillYou = true;
 
-	if (g_sludge->_mixer->isSoundHandleActive(soundCache[a].handle)) {
-		g_sludge->_mixer->stopHandle(soundCache[a].handle);
-		if (soundCache[a].inSoundList)
+	if (g_sludge->_mixer->isSoundHandleActive(_soundCache[a].handle)) {
+		g_sludge->_mixer->stopHandle(_soundCache[a].handle);
+		if (_soundCache[a].inSoundList)
 			handleSoundLists();
 	}
 
-	soundCache[a].fileLoaded = -1;
+	_soundCache[a].fileLoaded = -1;
 
-	SilenceIKillYou = false;
+	_silenceIKillYou = false;
 }
 
-void huntKillFreeSound(int filenum) {
-	if (!soundOK)
+void SoundManager::huntKillFreeSound(int filenum) {
+	if (!_soundOK)
 		return;
 	int gotSlot = findInSoundCache(filenum);
 	if (gotSlot == -1)
@@ -230,7 +231,7 @@ void huntKillFreeSound(int filenum) {
 /*
  * Loading and playing:
  */
-bool playMOD(int f, int a, int fromTrack) {
+bool SoundManager::playMOD(int f, int a, int fromTrack) {
 #if 0
 	// load sound
 	setResourceForFatal(f);
@@ -253,9 +254,8 @@ bool playMOD(int f, int a, int fromTrack) {
 	Audio::SoundHandle soundHandle;
 	g_sludge->_mixer->playStream(Audio::Mixer::kSFXSoundType, &soundHandle,
 			stream, -1, Audio::Mixer::kMaxChannelVolume);
-#endif
-#if 0
-	if (!soundOK)
+
+	if (!_soundOK)
 		return true;
 	stopMOD(a);
 
@@ -271,11 +271,11 @@ bool playMOD(int f, int a, int fromTrack) {
 	memImage = (byte *) loadEntireFileToMemory(bigDataFile, length);
 	if (! memImage) return fatal(ERROR_MUSIC_MEMORY_LOW);
 
-	modCache[a].stream = alureCreateStreamFromMemory(memImage, length, 19200, 0, NULL);
+	_modCache[a].stream = alureCreateStreamFromMemory(memImage, length, 19200, 0, NULL);
 
 	delete memImage;
 
-	if (modCache[a].stream != NULL) {
+	if (_modCache[a].stream != NULL) {
 		setMusicVolume(a, defVol);
 
 		if (! alureSetStreamOrder(modCache[a].stream, fromTrack)) {
@@ -291,28 +291,28 @@ bool playMOD(int f, int a, int fromTrack) {
 				alureGetErrorString());
 
 		warning(ERROR_MUSIC_ODDNESS);
-		soundCache[a].stream = NULL;
-		soundCache[a].playing = false;
-		soundCache[a].playingOnSource = 0;
+		_soundCache[a].stream = NULL;
+		_soundCache[a].playing = false;
+		_soundCache[a].playingOnSource = 0;
 	}
 	setResourceForFatal(-1);
 #endif
 	return true;
 }
 
-bool stillPlayingSound(int ch) {
-	if (soundOK)
+bool SoundManager::stillPlayingSound(int ch) {
+	if (_soundOK)
 		if (ch != -1)
-			if (soundCache[ch].fileLoaded != -1)
-				if (g_sludge->_mixer->isSoundHandleActive(soundCache[ch].handle))
+			if (_soundCache[ch].fileLoaded != -1)
+				if (g_sludge->_mixer->isSoundHandleActive(_soundCache[ch].handle))
 					return true;
 
 	return false;
 }
 
-bool forceRemoveSound() {
+bool SoundManager::forceRemoveSound() {
 	for (int a = 0; a < MAX_SAMPLES; a++) {
-		if (soundCache[a].fileLoaded != -1 && !stillPlayingSound(a)) {
+		if (_soundCache[a].fileLoaded != -1 && !stillPlayingSound(a)) {
 //			soundWarning ("Deleting silent sound", a);
 			freeSound(a);
 			return 1;
@@ -320,7 +320,7 @@ bool forceRemoveSound() {
 	}
 
 	for (int a = 0; a < MAX_SAMPLES; a++) {
-		if (soundCache[a].fileLoaded != -1) {
+		if (_soundCache[a].fileLoaded != -1) {
 //			soundWarning ("Deleting playing sound", a);
 			freeSound(a);
 			return 1;
@@ -330,46 +330,44 @@ bool forceRemoveSound() {
 	return 0;
 }
 
-int emptySoundSlot = 0;
-
-int findEmptySoundSlot() {
+int SoundManager::findEmptySoundSlot() {
 	for (int t = 0; t < MAX_SAMPLES; t++) {
-		emptySoundSlot++;
-		emptySoundSlot %= MAX_SAMPLES;
-		if (!g_sludge->_mixer->isSoundHandleActive(soundCache[emptySoundSlot].handle) && !soundCache[emptySoundSlot].inSoundList)
-			return emptySoundSlot;
+		_emptySoundSlot++;
+		_emptySoundSlot %= MAX_SAMPLES;
+		if (!g_sludge->_mixer->isSoundHandleActive(_soundCache[_emptySoundSlot].handle) && !_soundCache[_emptySoundSlot].inSoundList)
+			return _emptySoundSlot;
 	}
 
 	// Argh! They're all playing! Let's trash the oldest that's not looping...
 
 	for (int t = 0; t < MAX_SAMPLES; t++) {
-		emptySoundSlot++;
-		emptySoundSlot %= MAX_SAMPLES;
-		if (!soundCache[emptySoundSlot].looping && !soundCache[emptySoundSlot].inSoundList)
-			return emptySoundSlot;
+		_emptySoundSlot++;
+		_emptySoundSlot %= MAX_SAMPLES;
+		if (!_soundCache[_emptySoundSlot].looping && !_soundCache[_emptySoundSlot].inSoundList)
+			return _emptySoundSlot;
 	}
 
 	// Holy crap, they're all looping! What's this twat playing at?
 
-	emptySoundSlot++;
-	emptySoundSlot %= MAX_SAMPLES;
-	return emptySoundSlot;
+	_emptySoundSlot++;
+	_emptySoundSlot %= MAX_SAMPLES;
+	return _emptySoundSlot;
 }
 
-int cacheSound(int f) {
+int SoundManager::cacheSound(int f) {
 	return 0; // don't load source in advance
 }
 
-int makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy) {
-	if (!soundOK)
+int SoundManager::makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy) {
+	if (!_soundOK)
 		return -1;
 
 	int a = findInSoundCache(f);
 	if (a != -1) { // if this sound has been loaded before
 		// still playing
-		if (g_sludge->_mixer->isSoundHandleActive(soundCache[a].handle)) {
-			g_sludge->_mixer->stopHandle(soundCache[a].handle); // stop it
-			if (soundCache[a].inSoundList) {
+		if (g_sludge->_mixer->isSoundHandleActive(_soundCache[a].handle)) {
+			g_sludge->_mixer->stopHandle(_soundCache[a].handle); // stop it
+			if (_soundCache[a].inSoundList) {
 				handleSoundLists();
 			}
 		}
@@ -399,21 +397,21 @@ int makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy) {
 
 	if (stream) {
 		audiostream = Audio::makeLoopingAudioStream(stream, loopy ? 0 : 1);
-		soundCache[a].fileLoaded = f;
+		_soundCache[a].fileLoaded = f;
 		setResourceForFatal(-1);
 	} else {
 		audiostream = nullptr;
 		warning(ERROR_SOUND_ODDNESS);
-		soundCache[a].fileLoaded = -1;
-		soundCache[a].looping = false;
+		_soundCache[a].fileLoaded = -1;
+		_soundCache[a].looping = false;
 		return -1;
 	}
 
 	return a;
 }
 
-bool startSound(int f, bool loopy) {
-	if (soundOK) {
+bool SoundManager::startSound(int f, bool loopy) {
+	if (_soundOK) {
 		// Load sound
 		Audio::AudioStream *stream = nullptr;
 		int a = makeSoundAudioStream(f, stream, loopy);
@@ -423,49 +421,49 @@ bool startSound(int f, bool loopy) {
 		}
 
 		// play sound
-		soundCache[a].looping = loopy;
-		soundCache[a].vol = defSoundVol;
-		g_sludge->_mixer->playStream(Audio::Mixer::kSFXSoundType, &soundCache[a].handle, stream, -1, soundCache[a].vol);
+		_soundCache[a].looping = loopy;
+		_soundCache[a].vol = _defSoundVol;
+		g_sludge->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundCache[a].handle, stream, -1, _soundCache[a].vol);
 	}
 	return true;
 }
 
-void saveSounds(Common::WriteStream *stream) {
-	if (soundOK) {
+void SoundManager::saveSounds(Common::WriteStream *stream) {
+	if (_soundOK) {
 		for (int i = 0; i < MAX_SAMPLES; i++) {
-			if (soundCache[i].looping) {
+			if (_soundCache[i].looping) {
 				stream->writeByte(1);
-				stream->writeUint16BE(soundCache[i].fileLoaded);
-				stream->writeUint16BE(soundCache[i].vol);
+				stream->writeUint16BE(_soundCache[i].fileLoaded);
+				stream->writeUint16BE(_soundCache[i].vol);
 			}
 		}
 	}
 	stream->writeByte(0);
-	stream->writeUint16BE(defSoundVol);
-	stream->writeUint16BE(defVol);
+	stream->writeUint16BE(_defSoundVol);
+	stream->writeUint16BE(_defVol);
 }
 
-void loadSounds(Common::SeekableReadStream *stream) {
+void SoundManager::loadSounds(Common::SeekableReadStream *stream) {
 	for (int i = 0; i < MAX_SAMPLES; i++)
 		freeSound(i);
 
 	while (stream->readByte()) {
 		int fileLoaded = stream->readUint16BE();
-		defSoundVol = stream->readUint16BE();
+		_defSoundVol = stream->readUint16BE();
 		startSound(fileLoaded, 1);
 	}
 
-	defSoundVol = stream->readUint16BE();
-	defVol = stream->readUint16BE();
+	_defSoundVol = stream->readUint16BE();
+	_defVol = stream->readUint16BE();
 }
 
-bool getSoundCacheStack(StackHandler *sH) {
+bool SoundManager::getSoundCacheStack(StackHandler *sH) {
 	Variable newFileHandle;
 	newFileHandle.varType = SVT_NULL;
 
 	for (int a = 0; a < MAX_SAMPLES; a++) {
-		if (soundCache[a].fileLoaded != -1) {
-			setVariable(newFileHandle, SVT_FILE, soundCache[a].fileLoaded);
+		if (_soundCache[a].fileLoaded != -1) {
+			setVariable(newFileHandle, SVT_FILE, _soundCache[a].fileLoaded);
 			if (!addVarToStackQuick(newFileHandle, sH->first))
 				return false;
 			if (sH->last == NULL)
@@ -475,7 +473,7 @@ bool getSoundCacheStack(StackHandler *sH) {
 	return true;
 }
 
-bool deleteSoundFromList(SoundList*&s) {
+bool SoundManager::deleteSoundFromList(SoundList*&s) {
 	// Don't delete a playing sound.
 	if (s->cacheIndex)
 		return false;
@@ -500,33 +498,33 @@ bool deleteSoundFromList(SoundList*&s) {
 	return (s != NULL);
 }
 
-void handleSoundLists() {
-	if (isHandlingSoundList)
+void SoundManager::handleSoundLists() {
+	if (_isHandlingSoundList)
 		return;
-	isHandlingSoundList = true;
-	for (SoundListHandles::iterator it = soundListHandles.begin(); it != soundListHandles.end(); ++it) {
+	_isHandlingSoundList = true;
+	for (SoundListHandles::iterator it = _soundListHandles.begin(); it != _soundListHandles.end(); ++it) {
 		SoundList*s = (*it);
 		int a = s->cacheIndex;
 		bool remove = false;
-		if (!g_sludge->_mixer->isSoundHandleActive(soundCache[a].handle)) { // reach the end of stream
+		if (!g_sludge->_mixer->isSoundHandleActive(_soundCache[a].handle)) { // reach the end of stream
 			s->cacheIndex = false;
-			soundCache[a].inSoundList = false;
-			if (SilenceIKillYou) {
+			_soundCache[a].inSoundList = false;
+			if (_silenceIKillYou) {
 				while (deleteSoundFromList(s))
 					;
 				remove = (s == NULL); // s not null if still playing
 			} else {
 				if (s->next) {
 					if (s->next == s) { // loop the same sound
-						int v = defSoundVol;
-						defSoundVol = soundCache[a].vol;
+						int v = _defSoundVol;
+						_defSoundVol = _soundCache[a].vol;
 						startSound(s->sound, true);
-						defSoundVol = v;
+						_defSoundVol = v;
 						while (deleteSoundFromList(s))
 							;
 						remove = (s == NULL); // s not null if still playing
 					} else { // repush the next sound list
-						s->next->vol = soundCache[a].vol;
+						s->next->vol = _soundCache[a].vol;
 						playSoundList(s->next);
 						remove = true; // remove this one
 					}
@@ -539,15 +537,15 @@ void handleSoundLists() {
 			}
 		}
 		if (remove) {
-			it = soundListHandles.reverse_erase(it);
+			it = _soundListHandles.reverse_erase(it);
 		}
 	}
-	isHandlingSoundList = false;
+	_isHandlingSoundList = false;
 }
 
 // loop a list of sound
-void playSoundList(SoundList*s) {
-	if (soundOK) {
+void SoundManager::playSoundList(SoundList*s) {
+	if (_soundOK) {
 		// Load sound
 		Audio::AudioStream *stream;
 		int a = makeSoundAudioStream(s->sound, stream, false);
@@ -557,17 +555,17 @@ void playSoundList(SoundList*s) {
 		}
 
 		// Play sound
-		soundCache[a].looping = false;
+		_soundCache[a].looping = false;
 		if (s->vol < 0)
-			soundCache[a].vol = defSoundVol;
+			_soundCache[a].vol = _defSoundVol;
 		else
-			soundCache[a].vol = s->vol;
+			_soundCache[a].vol = s->vol;
 		s-> cacheIndex = a;
-		g_sludge->_mixer->playStream(Audio::Mixer::kSFXSoundType, &soundCache[a].handle, stream, -1, soundCache[a].vol);
-		soundCache[a].inSoundList = true;
+		g_sludge->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundCache[a].handle, stream, -1, _soundCache[a].vol);
+		_soundCache[a].inSoundList = true;
 
 		// push sound list
-		soundListHandles.push_back(s);
+		_soundListHandles.push_back(s);
 
 	}
 }
@@ -642,7 +640,7 @@ int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
 }
 #endif
 
-uint getSoundSource(int index) {
+uint SoundManager::getSoundSource(int index) {
 	return 0; /*soundCache[index].playingOnSource;*/ //TODO:false value
 }
 
diff --git a/engines/sludge/sound.h b/engines/sludge/sound.h
index 8e9038d..cdd76b3 100644
--- a/engines/sludge/sound.h
+++ b/engines/sludge/sound.h
@@ -23,10 +23,10 @@
 #ifndef SLUDGE_SOUND_H
 #define SLUDGE_SOUND_H
 
-#define HWND void *
-
 #include "common/file.h"
 
+#include "audio/mixer.h"
+
 #include "sludge/variable.h"
 
 namespace Sludge {
@@ -39,37 +39,80 @@ struct SoundList{
 	int cacheIndex;
 	int vol;
 };
-bool deleteSoundFromList(SoundList*&s);
-void playSoundList(SoundList*s);
-void handleSoundLists(); // to produce the same effects as end of stream call back functions
-
-// GENERAL...
-bool initSoundStuff(HWND);
-void killSoundStuff();
-
-// MUSIC...
-bool playMOD(int, int, int);
-void stopMOD(int);
-void setMusicVolume(int a, int v);
-void setDefaultMusicVolume(int v);
-
-// SAMPLES...
-int cacheSound(int f);
-bool startSound(int, bool = false);
-void huntKillSound(int a);
-void huntKillFreeSound(int filenum);
-void setSoundVolume(int a, int v);
-void setDefaultSoundVolume(int v);
-void setSoundLoop(int a, int s, int e);
-bool stillPlayingSound(int ch);
-bool getSoundCacheStack(StackHandler *sH);
-int findInSoundCache(int a);
-
-void debugSounds();
-void loadSounds(Common::SeekableReadStream *stream);
-void saveSounds(Common::WriteStream *stream);
-
-uint getSoundSource(int index);
+
+class SoundManager {
+public:
+	SoundManager();
+	virtual ~SoundManager();
+
+	// Sound list
+	void playSoundList(SoundList*s);
+	void handleSoundLists(); // to produce the same effects as end of stream call back functions
+
+	// GENERAL...
+	bool initSoundStuff();
+	void killSoundStuff();
+
+	// MUSIC...
+	bool playMOD(int, int, int);
+	void stopMOD(int);
+	void setMusicVolume(int a, int v);
+	void setDefaultMusicVolume(int v);
+
+	// SAMPLES...
+	int cacheSound(int f);
+	bool startSound(int, bool = false);
+	void huntKillSound(int a);
+	void huntKillFreeSound(int filenum);
+	void setSoundVolume(int a, int v);
+	void setDefaultSoundVolume(int v);
+	void setSoundLoop(int a, int s, int e);
+	bool stillPlayingSound(int ch);
+	bool getSoundCacheStack(StackHandler *sH);
+	int findInSoundCache(int a);
+
+	// Load & save
+	void loadSounds(Common::SeekableReadStream *stream);
+	void saveSounds(Common::WriteStream *stream);
+
+	uint getSoundSource(int index);
+
+private:
+	const static int MAX_SAMPLES;
+	const static int MAX_MODS;
+
+	struct SoundThing {
+		Audio::SoundHandle handle;
+		int fileLoaded, vol;    //Used for sounds only. (sound saving/loading)
+		bool looping;      		//Used for sounds only. (sound saving/loading)
+		bool inSoundList;
+	};
+	typedef Common::List<SoundList *> SoundListHandles;
+
+	// there's possibility that several sound list played at the same time
+	SoundListHandles _soundListHandles;
+
+	bool _soundOK;
+	bool _silenceIKillYou;
+	bool _isHandlingSoundList;
+
+	SoundThing *_soundCache;
+	#if 0
+	SoundThing *_modCache;
+	#endif
+
+	int _defVol;
+	int _defSoundVol;
+	float _modLoudness;
+
+	int _emptySoundSlot;
+
+	void freeSound(int a);
+	bool forceRemoveSound();
+	bool deleteSoundFromList(SoundList*&s);
+	int findEmptySoundSlot();
+	int makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, bool loopy);
+};
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index 4e8cd3f..23ebc5f 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -54,7 +54,7 @@ void initSpeech() {
 
 void killAllSpeech() {
 	if (speech->lastFile != -1) {
-		huntKillSound(speech->lastFile);
+		g_sludge->_soundMan->huntKillSound(speech->lastFile);
 		speech->lastFile = -1;
 	}
 
@@ -114,7 +114,7 @@ int wrapSpeechXY(const Common::String &theText, int x, int y, int wrap, int samp
 		speechTime = 1;
 	if (sampleFile != -1) {
 		if (speechMode >= 1) {
-			if (startSound(sampleFile, false)) {
+			if (g_sludge->_soundMan->startSound(sampleFile, false)) {
 				speechTime = -10;
 				speech->lastFile = sampleFile;
 				if (speechMode == 2) return -10;


Commit: 4a54a027607cd41255406b8d82d0bf54ecd5fa14
    https://github.com/scummvm/scummvm/commit/4a54a027607cd41255406b8d82d0bf54ecd5fa14
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-21T11:21:45+02:00

Commit Message:
SLUDGE: Objectify text manager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/fonttext.cpp
    engines/sludge/fonttext.h
    engines/sludge/loadsave.cpp
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sprbanks.cpp
    engines/sludge/sprbanks.h
    engines/sludge/statusba.cpp
    engines/sludge/talk.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 4ae01ab..5156aa5 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -63,7 +63,6 @@ Variable *launchResult = NULL;
 extern int lastFramesPerSecond, thumbWidth, thumbHeight;
 extern bool allowAnyFilename;
 extern bool captureAllKeys;
-extern int16 fontSpace;
 extern VariableStack *noStack;
 extern StatusStuff  *nowStatus;
 extern ScreenRegion *overRegion;
@@ -534,7 +533,7 @@ builtIn(stringLength) {
 	UNUSEDALL
 	Common::String newText = getTextFromAnyVar(fun->stack->thisVar);
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, stringLength(newText));
+	setVariable(fun->reg, SVT_INT, g_sludge->_txtMan->stringLength(newText));
 	return BR_CONTINUE;
 }
 
@@ -826,7 +825,7 @@ builtIn(setFont) {
 		return BR_ERROR;
 	//              newDebug ("  File:", fileNumber);
 	trimStack(fun->stack);
-	if (!loadFont(fileNumber, newText, newHeight))
+	if (!g_sludge->_txtMan->loadFont(fileNumber, newText, newHeight))
 		return BR_ERROR;
 	//              newDebug ("  Done!");
 	return BR_CONTINUE;
@@ -838,7 +837,7 @@ builtIn(inFont) {
 	trimStack(fun->stack);
 
 	// Return value
-	setVariable(fun->reg, SVT_INT, isInFont(newText));
+	setVariable(fun->reg, SVT_INT, g_sludge->_txtMan->isInFont(newText));
 	return BR_CONTINUE;
 }
 
@@ -854,8 +853,8 @@ builtIn(pasteString) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE)
-		x = g_sludge->_gfxMan->getCenterX(stringWidth(newText));
-	pasteStringToBackdrop(newText, x, y, pastePalette);
+		x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText));
+	g_sludge->_txtMan->pasteStringToBackdrop(newText, x, y, pastePalette);
 	return BR_CONTINUE;
 }
 
@@ -1937,7 +1936,7 @@ builtIn(stringWidth) {
 	trimStack(fun->stack);
 
 	// Return value
-	setVariable(fun->reg, SVT_INT, stringWidth(theText));
+	setVariable(fun->reg, SVT_INT, g_sludge->_txtMan->stringWidth(theText));
 	return BR_CONTINUE;
 }
 
@@ -1977,7 +1976,7 @@ builtIn(setFontSpacing) {
 	int fontSpaceI;
 	if (!getValueType(fontSpaceI, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
-	fontSpace = fontSpaceI;
+	g_sludge->_txtMan->setFontSpace(fontSpaceI);
 	trimStack(fun->stack);
 	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
@@ -2170,8 +2169,8 @@ builtIn(burnString) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE)
-		x = g_sludge->_gfxMan->getCenterX(stringWidth(newText));
-	burnStringToBackdrop(newText, x, y, pastePalette);
+		x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText));
+	g_sludge->_txtMan->burnStringToBackdrop(newText, x, y, pastePalette);
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 9d38b27..4c273fe 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -27,22 +27,33 @@
 #include "sludge/newfatal.h"
 #include "sludge/moreio.h"
 #include "sludge/sludge.h"
-#include "sludge/utf8.h"
+#include "sludge/version.h"
 
 namespace Sludge {
 
-SpriteBank theFont;
-int fontHeight = 0, numFontColours, loadedFontNum;
-UTF8Converter fontOrder;
-int16 fontSpace = -1;
+TextManager::TextManager() {
+	_theFont.total = 0;
+	_theFont.sprites = nullptr;
 
-uint32 *fontTable = NULL;
-uint fontTableSize = 0;
+	_fontHeight = 0;
+	_numFontColours = 0;
+	_loadedFontNum = 0;
+	_fontSpace = -1;
 
-#define fontInTable(x) ((x<fontTableSize) ? fontTable[(uint32) x] : 0)
+	_fontTable = nullptr;
+	_fontTableSize = 0;
+}
+
+TextManager::~TextManager() {
+	if (_fontTable) {
+		delete []_fontTable;
+		_fontTable = nullptr;
+	}
 
-bool isInFont(const Common::String &theText) {
-	if (!fontTableSize)
+}
+
+bool TextManager::isInFont(const Common::String &theText) {
+	if (!_fontTableSize)
 		return 0;
 	if (theText.empty())
 		return 0;
@@ -56,73 +67,73 @@ bool isInFont(const Common::String &theText) {
 	uint32 c = str32[0];
 
 	// check if font order contains the utf8 char
-	return fontOrder.getU32String().contains(c);
+	return _fontOrder.getU32String().contains(c);
 }
 
-int stringLength(const Common::String &theText) {
+int TextManager::stringLength(const Common::String &theText) {
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
 	return str32.size();
 }
 
-int stringWidth(const Common::String &theText) {
+int TextManager::stringWidth(const Common::String &theText) {
 	int xOff = 0;
 
-	if (!fontTableSize)
+	if (!_fontTableSize)
 		return 0;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
 
 	for (uint i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
-		xOff += theFont.sprites[fontInTable(c)].surface.w + fontSpace;
+		xOff += _theFont.sprites[fontInTable(c)].surface.w + _fontSpace;
 	}
 
 	return xOff;
 }
 
-void pasteString(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!fontTableSize)
+void TextManager::pasteString(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
+	if (!_fontTableSize)
 		return;
 
-	xOff += (int)((float)(fontSpace >> 1) / g_sludge->_gfxMan->getCamZoom());
+	xOff += (int)((float)(_fontSpace >> 1) / g_sludge->_gfxMan->getCamZoom());
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
 
 	for (uint32 i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
-		Sprite *mySprite = &theFont.sprites[fontInTable(c)];
+		Sprite *mySprite = &_theFont.sprites[fontInTable(c)];
 		g_sludge->_gfxMan->fontSprite(xOff, y, *mySprite, thePal);
-		xOff += (int)((double)(mySprite->surface.w + fontSpace) / g_sludge->_gfxMan->getCamZoom());
+		xOff += (int)((double)(mySprite->surface.w + _fontSpace) / g_sludge->_gfxMan->getCamZoom());
 	}
 }
 
-void pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!fontTableSize)
+void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
+	if (!_fontTableSize)
 		return;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
 
-	xOff += fontSpace >> 1;
+	xOff += _fontSpace >> 1;
 	for (uint32 i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
-		Sprite *mySprite = &theFont.sprites[fontInTable(c)];
+		Sprite *mySprite = &_theFont.sprites[fontInTable(c)];
 		g_sludge->_gfxMan->pasteSpriteToBackDrop(xOff, y, *mySprite, thePal);
-		xOff += mySprite->surface.w + fontSpace;
+		xOff += mySprite->surface.w + _fontSpace;
 	}
 }
 
-void burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!fontTableSize)
+void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
+	if (!_fontTableSize)
 		return;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
 
-	xOff += fontSpace >> 1;
+	xOff += _fontSpace >> 1;
 	for (uint i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
-		Sprite *mySprite = &theFont.sprites[fontInTable(c)];
+		Sprite *mySprite = &_theFont.sprites[fontInTable(c)];
 		g_sludge->_gfxMan->burnSpriteToBackDrop(xOff, y, *mySprite, thePal);
-		xOff += mySprite->surface.w + fontSpace;
+		xOff += mySprite->surface.w + _fontSpace;
 	}
 }
 
@@ -132,46 +143,86 @@ void setFontColour(SpritePalette &sP, byte r, byte g, byte b) {
 	sP.originalBlue = b;
 }
 
-bool loadFont(int filenum, const Common::String &charOrder, int h) {
-	fontOrder.setUTF8String(charOrder);
+bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h) {
+	_fontOrder.setUTF8String(charOrder);
 
-	g_sludge->_gfxMan->forgetSpriteBank(theFont);
+	g_sludge->_gfxMan->forgetSpriteBank(_theFont);
 
-	loadedFontNum = filenum;
+	_loadedFontNum = filenum;
 
 	// get max value among all utf8 chars
-	Common::U32String fontOrderString = fontOrder.getU32String();
-	fontTableSize = 0;
+	Common::U32String fontOrderString = _fontOrder.getU32String();
+	_fontTableSize = 0;
 	for (uint32 i = 0; i < fontOrderString.size(); ++i) {
 		uint32 c = fontOrderString[i];
-		if (c > fontTableSize)
-			fontTableSize = c;
+		if (c > _fontTableSize)
+			_fontTableSize = c;
 	}
-	fontTableSize++;
+	_fontTableSize++;
 
 	// create an index table from utf8 char to the index
-	delete[] fontTable;
-	fontTable = new uint32[fontTableSize];
-	if (!checkNew(fontTable))
+	if (_fontTable) {
+		delete []_fontTable;
+		_fontTable = nullptr;
+	}
+	_fontTable = new uint32[_fontTableSize];
+	if (!checkNew(_fontTable))
 		return false;
 
-	for (uint i = 0; i < fontTableSize; i++) {
-		fontTable[i] = 0;
+	for (uint i = 0; i < _fontTableSize; i++) {
+		_fontTable[i] = 0;
 	}
 
 	for (uint i = 0; i < fontOrderString.size(); ++i) {
 		uint32 c = fontOrderString[i];
-		fontTable[c] = i;
+		_fontTable[c] = i;
 	}
 
-	if (!g_sludge->_gfxMan->loadSpriteBank(filenum, theFont, true)) {
+	if (!g_sludge->_gfxMan->loadSpriteBank(filenum, _theFont, true)) {
 		fatal("Can't load font");
 		return false;
 	}
 
-	numFontColours = theFont.myPalette.total;
-	fontHeight = h;
+	_numFontColours = _theFont.myPalette.total;
+	_fontHeight = h;
 	return true;
 }
 
+// load & save
+void TextManager::saveFont(Common::WriteStream *stream) {
+	stream->writeByte(_fontTableSize > 0);
+	if (_fontTableSize > 0) {
+		stream->writeUint16BE(_loadedFontNum);
+		stream->writeUint16BE(_fontHeight);
+		writeString(_fontOrder.getUTF8String(), stream);
+	}
+	stream->writeSint16LE(_fontSpace);
+}
+
+void TextManager::loadFont(int ssgVersion, Common::SeekableReadStream *stream) {
+	bool fontLoaded = stream->readByte();
+	int fontNum = 0;
+	Common::String charOrder = "";
+	if (fontLoaded) {
+		fontNum = stream->readUint16BE();
+		_fontHeight = stream->readUint16BE();
+
+		if (ssgVersion < VERSION(2, 2)) {
+			char *tmp = new char[257];
+			for (int a = 0; a < 256; a++) {
+				int x = stream->readByte();
+				tmp[x] = a;
+			}
+			tmp[256] = 0;
+			charOrder = tmp;
+			delete []tmp;
+		} else {
+			charOrder = readString(stream);
+		}
+	}
+	loadFont(fontNum, charOrder, _fontHeight);
+
+	_fontSpace = stream->readSint16LE();
+}
+
 } // End of namespace Sludge
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
index 06cadfd..c8038cb 100644
--- a/engines/sludge/fonttext.h
+++ b/engines/sludge/fonttext.h
@@ -24,18 +24,49 @@
 
 #include "common/ustr.h"
 
+#include "sludge/sprites.h"
+#include "sludge/utf8.h"
+
 namespace Sludge {
 
+struct SpriteBank;
 struct SpritePalette;
 
-bool loadFont(int filenum, const Common::String &charOrder, int);
-void pasteString(const Common::String &theText, int, int, SpritePalette &);
+class TextManager {
+public:
+	TextManager();
+	virtual ~TextManager();
+
+	int stringWidth(const Common::String &theText);
+	int stringLength(const Common::String &theText);
+
+	bool loadFont(int filenum, const Common::String &charOrder, int);
+	void pasteString(const Common::String &theText, int, int, SpritePalette &);
+	void pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal);
+	void burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal);
+	bool isInFont(const Common::String &theText);
+
+	void setFontSpace(int fontSpace) { _fontSpace = fontSpace; }
+	int getFontHeight() const { return _fontHeight; }
+
+	// load & save
+	void saveFont(Common::WriteStream *stream);
+	void loadFont(int ssgVersion, Common::SeekableReadStream *stream);
+
+private:
+	SpriteBank _theFont;
+	int _fontHeight, _numFontColours, _loadedFontNum;
+	UTF8Converter _fontOrder;
+	int16 _fontSpace;
+
+	uint32 *_fontTable;
+	uint _fontTableSize;
+
+	inline uint32 fontInTable(uint32 x) { return ((x < _fontTableSize) ? _fontTable[x] : 0); }
+
+};
+
 void setFontColour(SpritePalette &sP, byte r, byte g, byte b);
-int stringWidth(const Common::String &theText);
-int stringLength(const Common::String &theText);
-void pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal);
-void burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal);
-bool isInFont(const Common::String &theText);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index da3037e..494c767 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -63,13 +63,9 @@ extern Floor *currentFloor;                          // In floor.cpp
 extern SpeechStruct *speech;                        // In talk.cpp
 extern PersonaAnimation  *mouseCursorAnim;           // In cursor.cpp
 extern int mouseCursorFrameNum;                     // "    "   "
-extern int loadedFontNum, fontHeight;				// In fonttext.cpp
-extern uint fontTableSize;							// 
-extern UTF8Converter fontOrder;                       // "    "   "
 extern FILETIME fileTime;                           // In sludger.cpp
 extern int speechMode;                              // "    "   "
 extern byte brightnessLevel;               // "    "   "
-extern int16 fontSpace;                             // in textfont.cpp
 extern byte fadeMode;                      // In transition.cpp
 extern bool captureAllKeys;
 extern bool allowAnyFilename;
@@ -370,14 +366,7 @@ bool saveGame(const Common::String &fname) {
 	fp->writeByte(allowAnyFilename);
 	fp->writeByte(captureAllKeys);
 	fp->writeByte(true);
-	fp->writeByte(fontTableSize > 0);
-
-	if (fontTableSize > 0) {
-		fp->writeUint16BE(loadedFontNum);
-		fp->writeUint16BE(fontHeight);
-		writeString(fontOrder.getUTF8String(), fp);
-	}
-	fp->writeSint16LE(fontSpace);
+	g_sludge->_txtMan->saveFont(fp);
 
 	// Save backdrop
 	fp->writeUint16BE(g_sludge->_gfxMan->getCamX());
@@ -520,29 +509,7 @@ bool loadGame(const Common::String &fname) {
 	captureAllKeys = fp->readByte();
 	fp->readByte();  // updateDisplay (part of movie playing)
 
-	bool fontLoaded = fp->readByte();
-	int fontNum = 0;
-	Common::String charOrder = "";
-	if (fontLoaded) {
-		fontNum = fp->readUint16BE();
-		fontHeight = fp->readUint16BE();
-
-		if (ssgVersion < VERSION(2, 2)) {
-			char *tmp = new char[257];
-			for (int a = 0; a < 256; a++) {
-				int x = fp->readByte();
-				tmp[x] = a;
-			}
-			tmp[256] = 0;
-			charOrder = tmp;
-			delete []tmp;
-		} else {
-			charOrder = readString(fp);
-		}
-	}
-	loadFont(fontNum, charOrder, fontHeight);
-
-	fontSpace = fp->readSint16LE();
+	g_sludge->_txtMan->loadFont(ssgVersion, fp);
 
 	killAllPeople();
 	killAllRegions();
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 4766356..12b6a8b 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -29,6 +29,7 @@
 #include "sludge/graphics.h"
 #include "sludge/sludge.h"
 #include "sludge/sound.h"
+#include "sludge/fonttext.h"
 #include "sludge/main_loop.h"
 
 namespace Sludge {
@@ -71,6 +72,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 	_gfxMan = new GraphicsManager(this);
 	_evtMan = new EventManager(this);
 	_soundMan = new SoundManager();
+	_txtMan = new TextManager();
 }
 
 SludgeEngine::~SludgeEngine() {
@@ -93,6 +95,8 @@ SludgeEngine::~SludgeEngine() {
 	_pixelFormat = nullptr;
 
 	// Dispose managers
+	delete _txtMan;
+	_txtMan = nullptr;
 	delete _soundMan;
 	_soundMan = nullptr;
 	delete _evtMan;
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index 6fb4689..844d6d0 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -41,6 +41,7 @@ extern SludgeEngine *g_sludge;
 class EventManager;
 class GraphicsManager;
 class SoundManager;
+class TextManager;
 
 class SludgeConsole;
 
@@ -79,6 +80,7 @@ public:
 	GraphicsManager *_gfxMan;
 	EventManager *_evtMan;
 	SoundManager *_soundMan;
+	TextManager *_txtMan;
 
 	SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
 	virtual ~SludgeEngine();
diff --git a/engines/sludge/sprbanks.cpp b/engines/sludge/sprbanks.cpp
index d1d63c7..265764b 100644
--- a/engines/sludge/sprbanks.cpp
+++ b/engines/sludge/sprbanks.cpp
@@ -32,9 +32,6 @@
 namespace Sludge {
 
 LoadedSpriteBank *allLoadedBanks = NULL;
-extern SpriteBank theFont;
-extern int loadedFontNum;
-extern uint fontTableSize;
 
 LoadedSpriteBank *loadBankForAnim(int ID) {
 	LoadedSpriteBank *returnMe = allLoadedBanks;
@@ -62,20 +59,4 @@ LoadedSpriteBank *loadBankForAnim(int ID) {
 		return NULL;
 }
 
-void reloadSpriteTextures() {
-	LoadedSpriteBank *spriteBank = allLoadedBanks;
-	while (spriteBank) {
-		//fprintf (stderr, "Reloading bank %d: %s.\n", spriteBank->ID, resourceNameFromNum (spriteBank->ID));
-		delete spriteBank->bank.sprites;
-		spriteBank->bank.sprites = NULL;
-		g_sludge->_gfxMan->loadSpriteBank(spriteBank->ID, spriteBank->bank, false);
-		spriteBank = spriteBank->next;
-	}
-	if (fontTableSize) {
-		delete theFont.sprites;
-		theFont.sprites = NULL;
-		g_sludge->_gfxMan->loadSpriteBank(loadedFontNum, theFont, true);
-	}
-}
-
 } // End of namespace Sludge
diff --git a/engines/sludge/sprbanks.h b/engines/sludge/sprbanks.h
index bbf046a..99651b7 100644
--- a/engines/sludge/sprbanks.h
+++ b/engines/sludge/sprbanks.h
@@ -33,7 +33,6 @@ struct LoadedSpriteBank {
 };
 
 LoadedSpriteBank *loadBankForAnim(int ID);
-void reloadSpriteTextures();
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp
index e46736a..9e8546a 100644
--- a/engines/sludge/statusba.cpp
+++ b/engines/sludge/statusba.cpp
@@ -39,7 +39,6 @@ SpritePalette litVerbLinePalette;
 
 StatusStuff  mainStatus;
 StatusStuff  *nowStatus = & mainStatus;
-extern int fontHeight;
 
 void setLitStatus(int i) {
 	nowStatus->litStatus = i;
@@ -93,18 +92,24 @@ void drawStatusBar() {
 	while (stat) {
 		switch (nowStatus->alignStatus) {
 		case IN_THE_CENTRE:
-			pasteString(stat->text, ((g_system->getWidth() - stringWidth(stat->text)) >> 1) / cameraZoom, y / cameraZoom, (n++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
+			g_sludge->_txtMan->pasteString(stat->text,
+					((g_system->getWidth() - g_sludge->_txtMan->stringWidth(stat->text)) >> 1) / cameraZoom, y / cameraZoom,
+					(n++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 			break;
 
 		case 1001:
-			pasteString(stat->text, (g_system->getWidth() - stringWidth(stat->text)) - nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
+			g_sludge->_txtMan->pasteString(stat->text,
+					(g_system->getWidth() - g_sludge->_txtMan->stringWidth(stat->text)) - nowStatus->statusX / cameraZoom, y / cameraZoom,
+					(n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 			break;
 
 		default:
-			pasteString(stat->text, nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
+			g_sludge->_txtMan->pasteString(stat->text,
+					nowStatus->statusX / cameraZoom, y / cameraZoom,
+					(n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
 		}
 		stat = stat->next;
-		y -= fontHeight;
+		y -= g_sludge->_txtMan->getFontHeight();
 	}
 }
 
@@ -122,7 +127,7 @@ void statusBarLitColour(byte r, byte g, byte b) {
 	nowStatus->statusLB = b;
 }
 
-StatusStuff  *copyStatusBarStuff(StatusStuff  *here) {
+StatusStuff *copyStatusBarStuff(StatusStuff  *here) {
 
 	// Things we want to keep
 	here->statusLR = nowStatus->statusLR;
@@ -145,7 +150,7 @@ StatusStuff  *copyStatusBarStuff(StatusStuff  *here) {
 	return old;
 }
 
-void restoreBarStuff(StatusStuff  *here) {
+void restoreBarStuff(StatusStuff *here) {
 	delete nowStatus;
 	setFontColour(verbLinePalette, here->statusR, here->statusG, here->statusB);
 	setFontColour(litVerbLinePalette, here->statusLR, here->statusLG, here->statusLB);
diff --git a/engines/sludge/talk.cpp b/engines/sludge/talk.cpp
index 23ebc5f..531fb42 100644
--- a/engines/sludge/talk.cpp
+++ b/engines/sludge/talk.cpp
@@ -38,7 +38,7 @@
 
 namespace Sludge {
 
-extern int fontHeight, speechMode;
+extern int speechMode;
 SpeechStruct *speech;
 float speechSpeed = 1;
 
@@ -78,7 +78,7 @@ inline void setObjFontColour(ObjectType *t) {
 
 void addSpeechLine(const Common::String &theLine, int x, int &offset) {
 	float cameraZoom = g_sludge->_gfxMan->getCamZoom();
-	int halfWidth = (stringWidth(theLine) >> 1) / cameraZoom;
+	int halfWidth = (g_sludge->_txtMan->stringWidth(theLine) >> 1) / cameraZoom;
 	int xx1 = x - (halfWidth);
 	int xx2 = x + (halfWidth);
 	SpeechLine *newLine = new SpeechLine;
@@ -103,6 +103,7 @@ int isThereAnySpeechGoingOn() {
 
 int 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;
@@ -206,10 +207,11 @@ int wrapSpeech(const Common::String &theText, int objT, int sampleFile, bool ani
 
 void viewSpeech() {
 	float cameraZoom = g_sludge->_gfxMan->getCamZoom();
+	int fontHeight = g_sludge->_txtMan->getFontHeight();
 	int viewY = speech->speechY;
 	SpeechLine *viewLine = speech->allSpeech;
 	while (viewLine) {
-		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;
 	}


Commit: 6858d3c6aefe1f39089a56ef3f2521b86d8abeb0
    https://github.com/scummvm/scummvm/commit/6858d3c6aefe1f39089a56ef3f2521b86d8abeb0
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-21T11:21:45+02:00

Commit Message:
SLUDGE: Remove unused files

Changed paths:
  R engines/sludge/helpers.cpp
  R engines/sludge/helpers.h
    engines/sludge/main_loop.cpp
    engines/sludge/module.mk


diff --git a/engines/sludge/helpers.cpp b/engines/sludge/helpers.cpp
deleted file mode 100644
index 9cc44ab..0000000
--- a/engines/sludge/helpers.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "common/file.h"
-
-#include "sludge/allfiles.h"
-#include "sludge/helpers.h"
-
-namespace Sludge {
-
-bool fileExists(const char *file) {
-	bool retval = false;
-
-	Common::File tester;
-	if (tester.open(file)) {
-		retval = true;
-		tester.close();
-	}
-
-	return retval;
-}
-
-} // End of namespace Sludge
diff --git a/engines/sludge/helpers.h b/engines/sludge/helpers.h
deleted file mode 100644
index 27625d2..0000000
--- a/engines/sludge/helpers.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-#ifndef SLUDGE_HELPERS_H
-#define SLUDGE_HELPERS_H
-
-namespace Sludge {
-
-bool fileExists(const char *file);
-
-} // End of namespace Sludge
-
-#endif
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 3a42d6d..708d4df 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -30,7 +30,6 @@
 #include "sludge/event.h"
 #include "sludge/floor.h"
 #include "sludge/graphics.h"
-#include "sludge/helpers.h"
 #include "sludge/language.h"
 #include "sludge/newfatal.h"
 #include "sludge/objtypes.h"
diff --git a/engines/sludge/module.mk b/engines/sludge/module.mk
index 4d05e82..07f1af3 100644
--- a/engines/sludge/module.mk
+++ b/engines/sludge/module.mk
@@ -13,7 +13,6 @@ MODULE_OBJS := \
 	freeze.o \
 	fonttext.o \
 	graphics.o \
-	helpers.o \
 	hsi.o \
 	imgloader.o \
 	language.o \


Commit: fd2cf90bb3eab1050d0513813c72a9e26a8166d5
    https://github.com/scummvm/scummvm/commit/fd2cf90bb3eab1050d0513813c72a9e26a8166d5
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-07-21T11:21:45+02:00

Commit Message:
SLUDGE: Objectify cursor manager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/cursors.cpp
    engines/sludge/cursors.h
    engines/sludge/freeze.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 5156aa5..a27fcb4 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 87a2bf7..7c16e8f 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 9bc5b82..5fd1885 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 1bc2ad9..3e8cdef 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 494c767..1588ffd 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 12b6a8b..36b1fa2 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 844d6d0..d1dcb92 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 ffcecc9..880c808 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
 }





More information about the Scummvm-git-logs mailing list