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

yinsimei roseline.yin at gmail.com
Mon Aug 21 10:20:27 CEST 2017


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

Summary:
d9a6791500 SLUDGE: Add support for some windows-only games
a9ee51d6ce SLUDGE: Some code cleaning
516c24e8c3 SLUDGE: Change game file to be loaded
cae614a4dc SLUDGE: Use common hashmap instead of array table


Commit: d9a6791500eef13d64d7b3d11136b9c901af7f2f
    https://github.com/scummvm/scummvm/commit/d9a6791500eef13d64d7b3d11136b9c901af7f2f
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-08-21T10:19:19+02:00

Commit Message:
SLUDGE: Add support for some windows-only games

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/event.h
    engines/sludge/imgloader.cpp
    engines/sludge/main_loop.cpp
    engines/sludge/main_loop.h
    engines/sludge/region.cpp
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp
    engines/sludge/sludger.h


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index d63eb97..9b4c1b7 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "common/config-manager.h"
 #include "common/savefile.h"
 
 #include "sludge/allfiles.h"
@@ -2412,11 +2413,29 @@ builtIn(_rem_launchWith) {
 	UNUSEDALL
 
 	trimStack(fun->stack);
+
+	// To support some windows only games
+	Common::String filename = getTextFromAnyVar(fun->stack->thisVar);
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, false);
 
-	return BR_CONTINUE;
+	if (filename.hasSuffix(".exe")) {
+		const Common::FSNode gameDataDir(ConfMan.get("path"));
+		Common::FSList files;
+		gameDataDir.getChildren(files, Common::FSNode::kListFilesOnly);
+
+		for (Common::FSList::const_iterator file = files.begin(); file != files.end(); ++file) {
+			Common::String fileName = file->getName();
+			fileName.toLowercase();
+			if (fileName.hasSuffix(".dat") || fileName == "data") {
+				g_sludge->launchNext = file->getName();
+				return BR_CONTINUE;
+			}
+		}
+	}
 
+	g_sludge->launchNext.clear();
+	setVariable(fun->reg, SVT_INT, false);
+	return BR_CONTINUE;
 }
 
 builtIn(getFramesPerSecond) {
@@ -2577,8 +2596,9 @@ BuiltReturn callBuiltIn(int whichFunc, int numParams, LoadedFunction *fun) {
 		}
 
 		if (builtInFunctionArray[whichFunc].func) {
-			debugC(1, kSludgeDebugBuiltin, "Run built-in function : %s",
-					(whichFunc < numBIFNames) ? allBIFNames[whichFunc].c_str() : "Unknown");
+			debugC(3, kSludgeDebugBuiltin,
+					"Run built-in function %i : %s",
+					whichFunc, (whichFunc < numBIFNames) ? allBIFNames[whichFunc].c_str() : "Unknown");
 			return builtInFunctionArray[whichFunc].func(numParams, fun);
 		}
 	}
diff --git a/engines/sludge/event.h b/engines/sludge/event.h
index 691a0da..878d363 100644
--- a/engines/sludge/event.h
+++ b/engines/sludge/event.h
@@ -73,6 +73,7 @@ public:
 	void restore(FrozenStuffStruct *frozenStuff);
 
 	// Quit
+	void startGame() { _weAreDoneSoQuit = false; }
 	void quitGame() { _weAreDoneSoQuit = true; /* _reallyWantToQuit = true; */ }
 	bool quit() { return _weAreDoneSoQuit; }
 
diff --git a/engines/sludge/imgloader.cpp b/engines/sludge/imgloader.cpp
index 64c8d78..c909ad5 100644
--- a/engines/sludge/imgloader.cpp
+++ b/engines/sludge/imgloader.cpp
@@ -33,7 +33,7 @@
 namespace Sludge {
 
 bool ImgLoader::loadImage(Common::SeekableReadStream *stream, Graphics::Surface *dest, int reserve) {
-	debugC(3, kSludgeDebugDataLoad, "Loading image at position: %i", stream->pos());
+	debugC(3, kSludgeDebugGraphics, "Loading image at position: %i", stream->pos());
 	int32 start_ptr = stream->pos();
 	if (!loadPNGImage(stream, dest)) {
 		stream->seek(start_ptr);
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 708d4df..4524d02 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -34,6 +34,7 @@
 #include "sludge/newfatal.h"
 #include "sludge/objtypes.h"
 #include "sludge/people.h"
+#include "sludge/region.h"
 #include "sludge/statusba.h"
 #include "sludge/sound.h"
 #include "sludge/sludge.h"
@@ -48,7 +49,7 @@ extern VariableStack *noStack;
 
 int dialogValue = 0;
 
-int main_loop(const char *filename) {
+int main_loop(Common::String filename) {
 
 	if (!initSludge(filename)) {
 		return 0;
@@ -75,6 +76,7 @@ int main_loop(const char *filename) {
 
 	startNewFunctionNum(0, 0, NULL, noStack);
 
+	g_sludge->_evtMan->startGame();
 	g_sludge->_timer.init();
 
 	while (!g_sludge->_evtMan->quit()) {
@@ -88,8 +90,17 @@ int main_loop(const char *filename) {
 		g_sludge->_timer.waitFrame();
 	}
 
+	killAllFunctions();
+	killAllRegions();
 	g_sludge->_soundMan->killSoundStuff();
 
+	// Load next game
+	if (!g_sludge->launchNext.empty()) {
+		Common::String name = g_sludge->launchNext;
+		g_sludge->launchNext.clear();
+		main_loop(name);
+	}
+
 	return (0);
 }
 
diff --git a/engines/sludge/main_loop.h b/engines/sludge/main_loop.h
index b287c81..3fe522c 100644
--- a/engines/sludge/main_loop.h
+++ b/engines/sludge/main_loop.h
@@ -24,7 +24,7 @@
 
 namespace Sludge {
 
-int main_loop(const char *filename);
+int main_loop(Common::String filename);
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index af9e2b8..7593fe4 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -33,8 +33,9 @@
 
 namespace Sludge {
 
-ScreenRegion *allScreenRegions = NULL;
-ScreenRegion *overRegion = NULL;
+ScreenRegion *allScreenRegions = nullptr;
+ScreenRegion *overRegion = nullptr;
+ScreenRegion *lastRegion = nullptr;
 
 void showBoxes() {
 	ScreenRegion*huntRegion = allScreenRegions;
@@ -121,7 +122,8 @@ void killAllRegions() {
 		g_sludge->_objMan->removeObjectType(killRegion->thisType);
 		delete killRegion;
 	}
-	overRegion = NULL;
+	overRegion = nullptr;
+	lastRegion = nullptr;
 }
 
 bool addScreenRegion(int x1, int y1, int x2, int y2, int sX, int sY, int di,
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 9976652..97904e1 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -55,7 +55,8 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 	DebugMan.addDebugChannel(kSludgeDebugZBuffer, "ZBuffer", "ZBuffer debug level");
 	DebugMan.addDebugChannel(kSludgeDebugSound, "Sound", "Sound debug level");
 
-	DebugMan.enableDebugChannel("Sound");
+	DebugMan.enableDebugChannel("Data Load");
+	DebugMan.enableDebugChannel("Built-in");
 
 	// init graphics
 	_origFormat = new Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);
@@ -63,10 +64,10 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 
 	// Init Strings
 	launchMe = "";
+	launchNext = "";
 	loadNow = "";
 	gamePath = "";
 	bundleFolder = "";
-
 	fatalMessage = "";
 	fatalInfo = "Initialisation error! Something went wrong before we even got started!";
 
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index d868754..240045d 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -67,6 +67,7 @@ protected:
 public:
 	// global String variables
 	Common::String launchMe;
+	Common::String launchNext;
 	Common::String loadNow;
 	Common::String gamePath;
 	Common::String bundleFolder;
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 8e49b32..a63b8b9 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -54,7 +54,6 @@
 namespace Sludge {
 
 extern int dialogValue;
-extern Variable *launchResult;
 
 int numBIFNames = 0;
 Common::String *allBIFNames;
@@ -74,7 +73,6 @@ extern SpeechStruct *speech;
 extern LoadedFunction *saverFunc;
 
 LoadedFunction *allRunningFunctions = NULL;
-ScreenRegion *lastRegion = NULL;
 VariableStack *noStack = NULL;
 Variable *globalVars;
 
@@ -913,6 +911,15 @@ bool runSludge() {
 	return true;
 }
 
+void killAllFunctions() {
+	LoadedFunction *ptr = allRunningFunctions;
+	while (ptr) {
+		LoadedFunction *kill = ptr;
+		ptr = ptr->next;
+		abortFunction(kill);
+	}
+}
+
 bool loadFunctionCode(LoadedFunction *newFunc) {
 	uint numLines, numLinesRead;
 
diff --git a/engines/sludge/sludger.h b/engines/sludge/sludger.h
index 91efb24..0ab3eb7 100644
--- a/engines/sludge/sludger.h
+++ b/engines/sludge/sludger.h
@@ -66,6 +66,7 @@ int startNewFunctionNum(uint, uint, LoadedFunction *, VariableStack*&, bool = tr
 bool handleInput();
 void restartFunction(LoadedFunction *fun);
 bool loadFunctionCode(LoadedFunction *newFunc);
+void killAllFunctions();
 
 void finishFunction(LoadedFunction *fun);
 void abortFunction(LoadedFunction *fun);


Commit: a9ee51d6ce79a6510a6f11b090e167e1047dd60d
    https://github.com/scummvm/scummvm/commit/a9ee51d6ce79a6510a6f11b090e167e1047dd60d
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-08-21T10:19:19+02:00

Commit Message:
SLUDGE: Some code cleaning

Changed paths:
    engines/sludge/main_loop.cpp
    engines/sludge/moreio.cpp
    engines/sludge/newfatal.cpp
    engines/sludge/newfatal.h
    engines/sludge/sludger.cpp
    engines/sludge/variable.cpp


diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 4524d02..d00f6e4 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -57,8 +57,6 @@ int main_loop(Common::String filename) {
 
 	g_sludge->_gfxMan->init();
 
-	registerWindowForFatal();
-
 	g_sludge->_gfxMan->blankAllScreen();
 	if (!initPeople())
 		return fatal("Couldn't initialise people stuff");
diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp
index 4a57000..1512574 100644
--- a/engines/sludge/moreio.cpp
+++ b/engines/sludge/moreio.cpp
@@ -46,7 +46,6 @@ Common::String readString(Common::SeekableReadStream *stream) {
 	for (int a = 0; a < len; a++) {
 		res += (char)(stream->readByte() - 1);
 	}
-	debugC(3, kSludgeDebugDataLoad, "Read string of length %i: %s", len, res.c_str());
 	return res;
 }
 
diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp
index 673fc02..70f6bd9 100644
--- a/engines/sludge/newfatal.cpp
+++ b/engines/sludge/newfatal.cpp
@@ -53,10 +53,6 @@ bool hasFatal() {
 	return false;
 }
 
-void registerWindowForFatal() {
-	g_sludge->fatalInfo = "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.";
-}
-
 int inFatal(const Common::String &str) {
 	g_sludge->_soundMan->killSoundStuff();
 	error("%s", str.c_str());
diff --git a/engines/sludge/newfatal.h b/engines/sludge/newfatal.h
index eb65db0..fc91110 100644
--- a/engines/sludge/newfatal.h
+++ b/engines/sludge/newfatal.h
@@ -33,7 +33,6 @@ bool hasFatal();
 int fatal(const Common::String &str);
 int fatal(const Common::String &str1, const Common::String &str2);
 int checkNew(const void *mem);
-void registerWindowForFatal();
 void setFatalInfo(const Common::String &userFunc, const Common::String &BIF);
 void setResourceForFatal(int n);
 const Common::String resourceNameFromNum(int i);
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index a63b8b9..91c78b0 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -405,27 +405,16 @@ bool continueFunction(LoadedFunction *fun) {
 		return true;
 	}
 
-//	if (numBIFNames) newDebug ("*** Function:", allUserFunc[fun->originalNumber]);
-
-	//debugOut ("SLUDGER: continueFunction\n");
-
 	while (keepLooping) {
 		advanceNow = true;
 		debugC(1, kSludgeDebugStackMachine, "Executing command line %i : ", fun->runThisLine);
 		param = fun->compiledLines[fun->runThisLine].param;
 		com = fun->compiledLines[fun->runThisLine].theCommand;
-//		fprintf (stderr, "com: %d param: %d (%s)\n", com, param,
-//				(com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE); fflush(stderr);
 
 		if (numBIFNames) {
 			setFatalInfo((fun->originalNumber < numUserFunc) ? allUserFunc[fun->originalNumber] : "Unknown user function", (com < numSludgeCommands) ? sludgeText[com] : ERROR_UNKNOWN_MCODE);
-//			newDebug (
-//				(com < numSludgeCommands) ? sludgeText[com] : "Unknown SLUDGE machine code",
-//				param);
 		}
 
-		//debugOut ("SLUDGER: continueFunction - in da loop: %s\n", sludgeText[com]);
-
 		switch (com) {
 		case SLU_RETURN:
 			if (fun->calledBy) {
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index fb4f191..510c6f4 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -430,14 +430,6 @@ bool makeFastArrayFromStack(Variable &to, const StackHandler *stacky) {
 	return true;
 }
 
-/*
- bool moveVariable (Variable & from, Variable & to) {
- unlinkVar (to);
- memcpy (& to, & from, sizeof (variable));
- from.varType = SVT_NULL;
- }
- */
-
 bool addVarToStack(const Variable &va, VariableStack *&thisStack) {
 	VariableStack *newStack = new VariableStack;
 	if (!checkNew(newStack))


Commit: 516c24e8c3bdcfd2e5e6240fd61508945c43a9ae
    https://github.com/scummvm/scummvm/commit/516c24e8c3bdcfd2e5e6240fd61508945c43a9ae
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-08-21T10:19:19+02:00

Commit Message:
SLUDGE: Change game file to be loaded

Changed paths:
    engines/sludge/detection_tables.h


diff --git a/engines/sludge/detection_tables.h b/engines/sludge/detection_tables.h
index abdfde5..b61d541 100644
--- a/engines/sludge/detection_tables.h
+++ b/engines/sludge/detection_tables.h
@@ -127,15 +127,26 @@ static const SludgeGameDescription gameDescriptions[] = {
 		0
 	},
 
-	// TODO: the games down here are windows-only and can't be successfully run by
-	// sludge engine nor scummvm, need to solve it
+//	{
+//		{
+//			"tgttpoacs",
+//			"",
+//			AD_ENTRY1s("gamedata", "d5ec4d7d8440f7744335d25d25e1e943", 40368),
+//			Common::EN_ANY,
+//			Common::kPlatformWindows,
+//			ADGF_NO_FLAGS,
+//			GUIO0()
+//		},
+//		0
+//	},
+
 	{
 		{
 			"tgttpoacs",
 			"",
-			AD_ENTRY1s("gamedata", "d5ec4d7d8440f7744335d25d25e1e943", 40368),
+			AD_ENTRY1s("tgttpoacs.dat", "e61d3d050793689d55487d3ad01b6693", 23817174),
 			Common::EN_ANY,
-			Common::kPlatformUnknown,
+			Common::kPlatformLinux,
 			ADGF_NO_FLAGS,
 			GUIO0()
 		},
@@ -146,9 +157,9 @@ static const SludgeGameDescription gameDescriptions[] = {
 		{
 			"mandy",
 			"",
-			AD_ENTRY1s("gamedata", "bb51eea418d87071c98f4e050ccf6387", 589),
-			Common::EN_ANY,
-			Common::kPlatformUnknown,
+			AD_ENTRY1s("data", "705f6ca5f5da0c40c1f547231dd5139f", 7141292),
+			Common::CZ_CZE,
+			Common::kPlatformLinux,
 			ADGF_NO_FLAGS,
 			GUIO0()
 		},
@@ -157,17 +168,108 @@ static const SludgeGameDescription gameDescriptions[] = {
 
 	{
 		{
+			"mandy",
+			"",
+			AD_ENTRY1s("data", "705f6ca5f5da0c40c1f547231dd5139f", 7141292),
+			Common::EN_ANY,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		1
+	},
+
+	{
+		{
+			"mandy",
+			"",
+			AD_ENTRY1s("data", "705f6ca5f5da0c40c1f547231dd5139f", 7141292),
+			Common::IT_ITA,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		2
+	},
+
+	{
+		{
+			"mandy",
+			"",
+			AD_ENTRY1s("data", "705f6ca5f5da0c40c1f547231dd5139f", 7141292),
+			Common::PL_POL,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		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::kPlatformUnknown,
+			AD_ENTRY1s("cubert.dat", "e70050692a0ab96e8753109793157ccd", 19677815),
+			Common::EN_ANY,
+			Common::kPlatformLinux,
 			ADGF_NO_FLAGS,
 			GUIO0()
 		},
 		0
 	},
 
+	{
+		{
+			"cubert",
+			"",
+			AD_ENTRY1s("cubert.dat", "e70050692a0ab96e8753109793157ccd", 19677815),
+			Common::IT_ITA,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		1
+	},
+
+	{
+		{
+			"cubert",
+			"",
+			AD_ENTRY1s("cubert.dat", "e70050692a0ab96e8753109793157ccd", 19677815),
+			Common::SE_SWE,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		2
+	},
+
+	{
+		{
+			"cubert",
+			"",
+			AD_ENTRY1s("cubert.dat", "e70050692a0ab96e8753109793157ccd", 19677815),
+			Common::DE_DEU,
+			Common::kPlatformLinux,
+			ADGF_NO_FLAGS,
+			GUIO0()
+		},
+		3
+	},
+
 	{ AD_TABLE_END_MARKER, 0 }
 };
 


Commit: cae614a4dc883fc27ddf0af718088af65c4651e3
    https://github.com/scummvm/scummvm/commit/cae614a4dc883fc27ddf0af718088af65c4651e3
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2017-08-21T10:19:19+02:00

Commit Message:
SLUDGE: Use common hashmap instead of array table

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


diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 4c273fe..664c843 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -40,20 +40,15 @@ TextManager::TextManager() {
 	_loadedFontNum = 0;
 	_fontSpace = -1;
 
-	_fontTable = nullptr;
-	_fontTableSize = 0;
+	_fontTable.clear();
 }
 
 TextManager::~TextManager() {
-	if (_fontTable) {
-		delete []_fontTable;
-		_fontTable = nullptr;
-	}
-
+	g_sludge->_gfxMan->forgetSpriteBank(_theFont);
 }
 
 bool TextManager::isInFont(const Common::String &theText) {
-	if (!_fontTableSize)
+	if (_fontTable.empty())
 		return 0;
 	if (theText.empty())
 		return 0;
@@ -78,7 +73,7 @@ int TextManager::stringLength(const Common::String &theText) {
 int TextManager::stringWidth(const Common::String &theText) {
 	int xOff = 0;
 
-	if (!_fontTableSize)
+	if (_fontTable.empty())
 		return 0;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
@@ -92,7 +87,7 @@ int TextManager::stringWidth(const Common::String &theText) {
 }
 
 void TextManager::pasteString(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!_fontTableSize)
+	if (_fontTable.empty())
 		return;
 
 	xOff += (int)((float)(_fontSpace >> 1) / g_sludge->_gfxMan->getCamZoom());
@@ -108,7 +103,7 @@ void TextManager::pasteString(const Common::String &theText, int xOff, int y, Sp
 }
 
 void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!_fontTableSize)
+	if (_fontTable.empty())
 		return;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
@@ -123,7 +118,7 @@ void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff,
 }
 
 void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
-	if (!_fontTableSize)
+	if (_fontTable.empty())
 		return;
 
 	Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
@@ -152,25 +147,10 @@ bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h)
 
 	// get max value among all utf8 chars
 	Common::U32String fontOrderString = _fontOrder.getU32String();
-	_fontTableSize = 0;
-	for (uint32 i = 0; i < fontOrderString.size(); ++i) {
-		uint32 c = fontOrderString[i];
-		if (c > _fontTableSize)
-			_fontTableSize = c;
-	}
-	_fontTableSize++;
 
 	// create an index table from utf8 char to the index
-	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;
+	if (!_fontTable.empty()) {
+		_fontTable.clear();
 	}
 
 	for (uint i = 0; i < fontOrderString.size(); ++i) {
@@ -190,8 +170,8 @@ bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h)
 
 // load & save
 void TextManager::saveFont(Common::WriteStream *stream) {
-	stream->writeByte(_fontTableSize > 0);
-	if (_fontTableSize > 0) {
+	stream->writeByte(!_fontTable.empty());
+	if (!_fontTable.empty() > 0) {
 		stream->writeUint16BE(_loadedFontNum);
 		stream->writeUint16BE(_fontHeight);
 		writeString(_fontOrder.getUTF8String(), stream);
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
index 3170a3e..9628db6 100644
--- a/engines/sludge/fonttext.h
+++ b/engines/sludge/fonttext.h
@@ -22,6 +22,7 @@
 #ifndef SLUDGE_FONTTEXT_H
 #define SLUDGE_FONTTEXT_H
 
+#include "common/hashmap.h"
 #include "common/ustr.h"
 
 #include "sludge/sprites.h"
@@ -59,10 +60,9 @@ private:
 	UTF8Converter _fontOrder;
 	int16 _fontSpace;
 
-	uint32 *_fontTable;
-	uint _fontTableSize;
+	Common::HashMap<uint32, uint32> _fontTable;
 
-	inline uint32 fontInTable(uint32 x) { return ((x < _fontTableSize) ? _fontTable[x] : 0); }
+	inline uint32 fontInTable(uint32 x) { return _fontTable[x]; }
 
 };
 





More information about the Scummvm-git-logs mailing list