[Scummvm-cvs-logs] SF.net SVN: scummvm:[33786] scummvm/trunk/engines/cine

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Tue Aug 12 00:26:29 CEST 2008


Revision: 33786
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33786&view=rev
Author:   buddha_
Date:     2008-08-11 22:26:25 +0000 (Mon, 11 Aug 2008)

Log Message:
-----------
Moved fontParamTable inside TextHandler struct and made it a constant size as that's what it is (No need for using malloc & free anymore). Previously we would've tried to free an array that wasn't heap-allocated in freePoldatDat (Freeing fontParamTable_standard or fontParamTable_alt), that's fixed.

Modified Paths:
--------------
    scummvm/trunk/engines/cine/cine.cpp
    scummvm/trunk/engines/cine/gfx.cpp
    scummvm/trunk/engines/cine/texte.cpp
    scummvm/trunk/engines/cine/texte.h

Modified: scummvm/trunk/engines/cine/cine.cpp
===================================================================
--- scummvm/trunk/engines/cine/cine.cpp	2008-08-11 21:45:47 UTC (rev 33785)
+++ scummvm/trunk/engines/cine/cine.cpp	2008-08-11 22:26:25 UTC (rev 33786)
@@ -69,7 +69,6 @@
 
 CineEngine::~CineEngine() {
 	if (g_cine->getGameType() == Cine::GType_OS) {
-		freePoldatDat();
 		freeErrmessDat();
 	}
 	Common::clearAllSpecialDebugLevels();

Modified: scummvm/trunk/engines/cine/gfx.cpp
===================================================================
--- scummvm/trunk/engines/cine/gfx.cpp	2008-08-11 21:45:47 UTC (rev 33785)
+++ scummvm/trunk/engines/cine/gfx.cpp	2008-08-11 22:26:25 UTC (rev 33786)
@@ -366,8 +366,8 @@
 
 	if (character == ' ') {
 		x += 5;
-	} else if ((width = fontParamTable[(unsigned char)character].characterWidth)) {
-		idx = fontParamTable[(unsigned char)character].characterIdx;
+	} else if ((width = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterWidth)) {
+		idx = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterIdx;
 		drawSpriteRaw(g_cine->_textHandler.textTable[idx][0], g_cine->_textHandler.textTable[idx][1], 16, 8, _backBuffer, x, y);
 		x += width + 1;
 	}
@@ -1023,8 +1023,8 @@
 
 	if (character == ' ') {
 		x += 5;
-	} else if ((width = fontParamTable[(unsigned char)character].characterWidth)) {
-		idx = fontParamTable[(unsigned char)character].characterIdx;
+	} else if ((width = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterWidth)) {
+		idx = g_cine->_textHandler.fontParamTable[(unsigned char)character].characterIdx;
 		drawSpriteRaw2(g_cine->_textHandler.textTable[idx][0], 0, 16, 8, _backBuffer, x, y);
 		x += width + 1;
 	}

Modified: scummvm/trunk/engines/cine/texte.cpp
===================================================================
--- scummvm/trunk/engines/cine/texte.cpp	2008-08-11 21:45:47 UTC (rev 33785)
+++ scummvm/trunk/engines/cine/texte.cpp	2008-08-11 22:26:25 UTC (rev 33786)
@@ -74,9 +74,7 @@
 	fileHandle.close();
 }
 
-const CharacterEntry *fontParamTable;
-
-const CharacterEntry fontParamTable_standard[256] = {
+static const CharacterEntry fontParamTable_standard[NUM_FONT_CHARS] = {
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
@@ -113,7 +111,7 @@
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}
 };
 
-const CharacterEntry fontParamTable_alt[256] = {
+static const CharacterEntry fontParamTable_alt[NUM_FONT_CHARS] = {
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
 	{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0},
@@ -537,9 +535,11 @@
 	}
 
 	if (g_cine->getFeatures() & GF_ALT_FONT) {
-		fontParamTable = fontParamTable_alt;
+		// Copy alternative font parameter table to the current font parameter table
+		Common::copy(fontParamTable_alt, fontParamTable_alt + NUM_FONT_CHARS, g_cine->_textHandler.fontParamTable);
 	} else {
-		fontParamTable = fontParamTable_standard;
+		// Copy standard font parameter to the current font parameter table
+		Common::copy(fontParamTable_standard, fontParamTable_standard + NUM_FONT_CHARS, g_cine->_textHandler.fontParamTable);
 	}
 }
 
@@ -574,25 +574,16 @@
 	in.open(fname);
 
 	if (in.isOpen()) {
-		CharacterEntry *ptr = (CharacterEntry *)malloc(sizeof(CharacterEntry) * 256);
-
-		for (int i = 0; i < 256; i++) {
-			ptr[i].characterIdx = (int)in.readByte();
-			ptr[i].characterWidth = (int)in.readByte();
+		for (int i = 0; i < NUM_FONT_CHARS; i++) {
+			g_cine->_textHandler.fontParamTable[i].characterIdx   = in.readByte();
+			g_cine->_textHandler.fontParamTable[i].characterWidth = in.readByte();
 		}
-		fontParamTable = ptr;
-
 		in.close();
 	} else {
 		error("Cannot open file %s for reading", fname);
 	}
 }
 
-void freePoldatDat() {
-	free(const_cast<Cine::CharacterEntry *>(fontParamTable));
-	fontParamTable = 0;
-}
-
 /*! \brief Fit a substring of text into one line of fixed width text box
  * \param str Text to fit
  * \param maxWidth Text box width
@@ -617,7 +608,7 @@
 			bkpWidth = width;
 			bkpLen = i + 1;
 		} else {
-			charWidth = fontParamTable[(unsigned char)str[i]].characterWidth + 1;
+			charWidth = g_cine->_textHandler.fontParamTable[(unsigned char)str[i]].characterWidth + 1;
 			width += charWidth;
 		}
 

Modified: scummvm/trunk/engines/cine/texte.h
===================================================================
--- scummvm/trunk/engines/cine/texte.h	2008-08-11 21:45:47 UTC (rev 33785)
+++ scummvm/trunk/engines/cine/texte.h	2008-08-11 22:26:25 UTC (rev 33786)
@@ -33,8 +33,17 @@
 
 typedef char CommandeType[20];
 
+// Number of characters in a font
+#define NUM_FONT_CHARS 256
+
+struct CharacterEntry {
+	byte characterIdx;
+	byte characterWidth;
+};
+
 struct TextHandler {
-	byte textTable[256][2][16 * 8];
+	byte textTable[NUM_FONT_CHARS][2][16 * 8];
+	CharacterEntry fontParamTable[NUM_FONT_CHARS];
 };
 
 extern const char **failureMessages;
@@ -44,18 +53,10 @@
 extern const char **otherMessages;
 extern const char *commandPrepositionOn;
 
-struct CharacterEntry {
-	byte characterIdx;
-	byte characterWidth;
-};
-
-extern const CharacterEntry *fontParamTable;
-
 void loadTextData(const char *filename);
 void loadErrmessDat(const char *fname);
 void freeErrmessDat(void);
 void loadPoldatDat(const char *fname);
-void freePoldatDat(void);
 
 int fitLine(const char *ptr, int maxWidth, int &words, int &width);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list