[Scummvm-git-logs] scummvm master -> 2ea485579932e9e470cb825ed107eba2a86a85c9

yinsimei roseline.yin at gmail.com
Sun Apr 1 18:02:40 CEST 2018


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

Summary:
2ea4855799 SLUDGE: Move global variable pastePalette to TextManager and refactor a little


Commit: 2ea485579932e9e470cb825ed107eba2a86a85c9
    https://github.com/scummvm/scummvm/commit/2ea485579932e9e470cb825ed107eba2a86a85c9
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-01T18:02:14+02:00

Commit Message:
SLUDGE: Move global variable pastePalette to TextManager and refactor a little

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/fonttext.cpp
    engines/sludge/fonttext.h
    engines/sludge/sludger.cpp
    engines/sludge/speech.cpp
    engines/sludge/sprites.h
    engines/sludge/statusba.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 7385d4d..dba5f01 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -55,7 +55,6 @@
 namespace Sludge {
 
 int speechMode = 0;
-SpritePalette pastePalette;
 
 Variable *launchResult = NULL;
 
@@ -775,7 +774,7 @@ builtIn(setPasteColour) {
 	if (!getRGBParams(red, green, blue, fun))
 		return BR_ERROR;
 
-	setFontColour(pastePalette, (byte)red, (byte)green, (byte)blue);
+	g_sludge->_txtMan->setPasterColor((byte)red, (byte)green, (byte)blue);
 	return BR_CONTINUE;
 }
 
@@ -846,7 +845,7 @@ builtIn(pasteString) {
 	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE)
 		x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText));
-	g_sludge->_txtMan->pasteStringToBackdrop(newText, x, y, pastePalette);
+	g_sludge->_txtMan->pasteStringToBackdrop(newText, x, y);
 	return BR_CONTINUE;
 }
 
@@ -2160,7 +2159,7 @@ builtIn(burnString) {
 	trimStack(fun->stack);
 	if (x == IN_THE_CENTRE)
 		x = g_sludge->_gfxMan->getCenterX(g_sludge->_txtMan->stringWidth(newText));
-	g_sludge->_txtMan->burnStringToBackdrop(newText, x, y, pastePalette);
+	g_sludge->_txtMan->burnStringToBackdrop(newText, x, y);
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp
index 0f63c6e..da380f4 100644
--- a/engines/sludge/fonttext.cpp
+++ b/engines/sludge/fonttext.cpp
@@ -48,11 +48,13 @@ void TextManager::init() {
 	_loadedFontNum = 0;
 	_fontSpace = -1;
 
+	_pastePalette.init();
 	_fontTable.clear();
 }
 
 void TextManager::kill() {
 	GraphicsManager::forgetSpriteBank(_theFont);
+	_pastePalette.kill();
 }
 
 bool TextManager::isInFont(const Common::String &theText) {
@@ -110,7 +112,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) {
+void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff, int y) {
 	if (_fontTable.empty())
 		return;
 
@@ -120,12 +122,12 @@ void TextManager::pasteStringToBackdrop(const Common::String &theText, int xOff,
 	for (uint32 i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
 		Sprite *mySprite = &_theFont.sprites[fontInTable(c)];
-		g_sludge->_gfxMan->pasteSpriteToBackDrop(xOff, y, *mySprite, thePal);
+		g_sludge->_gfxMan->pasteSpriteToBackDrop(xOff, y, *mySprite, _pastePalette);
 		xOff += mySprite->surface.w + _fontSpace;
 	}
 }
 
-void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y, SpritePalette &thePal) {
+void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff, int y) {
 	if (_fontTable.empty())
 		return;
 
@@ -135,17 +137,11 @@ void TextManager::burnStringToBackdrop(const Common::String &theText, int xOff,
 	for (uint i = 0; i < str32.size(); ++i) {
 		uint32 c = str32[i];
 		Sprite *mySprite = &_theFont.sprites[fontInTable(c)];
-		g_sludge->_gfxMan->burnSpriteToBackDrop(xOff, y, *mySprite, thePal);
+		g_sludge->_gfxMan->burnSpriteToBackDrop(xOff, y, *mySprite, _pastePalette);
 		xOff += mySprite->surface.w + _fontSpace;
 	}
 }
 
-void setFontColour(SpritePalette &sP, byte r, byte g, byte b) {
-	sP.originalRed = r;
-	sP.originalGreen = g;
-	sP.originalBlue = b;
-}
-
 bool TextManager::loadFont(int filenum, const Common::String &charOrder, int h) {
 	_fontOrder.setUTF8String(charOrder);
 
diff --git a/engines/sludge/fonttext.h b/engines/sludge/fonttext.h
index 26b12d9..7018c75 100644
--- a/engines/sludge/fonttext.h
+++ b/engines/sludge/fonttext.h
@@ -46,12 +46,14 @@ public:
 
 	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);
+	void pasteStringToBackdrop(const Common::String &theText, int xOff, int y);
+	void burnStringToBackdrop(const Common::String &theText, int xOff, int y);
 	bool isInFont(const Common::String &theText);
 
+	// setter & getter
 	void setFontSpace(int fontSpace) { _fontSpace = fontSpace; }
 	int getFontHeight() const { return _fontHeight; }
+	void setPasterColor(byte r, byte g, byte b) { _pastePalette.setColor(r, g, b); }
 
 	// load & save
 	void saveFont(Common::WriteStream *stream);
@@ -62,6 +64,7 @@ private:
 	int _fontHeight, _numFontColours, _loadedFontNum;
 	UTF8Converter _fontOrder;
 	int16 _fontSpace;
+	SpritePalette _pastePalette;
 
 	Common::HashMap<uint32, uint32> _fontTable;
 
@@ -69,8 +72,6 @@ private:
 
 };
 
-void setFontColour(SpritePalette &sP, byte r, byte g, byte b);
-
 } // End of namespace Sludge
 
 #endif
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 812f42f..9526ddf 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -196,7 +196,6 @@ void killSludge() {
 	g_sludge->_cursorMan->kill();
 
 	// global variables
-	pastePalette.reset();
 	numBIFNames = numUserFunc = 0;
 	delete []allUserFunc;
 	delete []allBIFNames;
diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp
index 1d342a1..b3fedac 100644
--- a/engines/sludge/speech.cpp
+++ b/engines/sludge/speech.cpp
@@ -74,7 +74,7 @@ void SpeechManager::kill() {
 }
 
 void SpeechManager::setObjFontColour(ObjectType *t) {
-	setFontColour(_speech->talkCol, t->r, t->g, t->b);
+	_speech->talkCol.setColor(t->r, t->g, t->b);
 }
 
 void SpeechManager::addSpeechLine(const Common::String &theLine, int x, int &offset) {
@@ -264,8 +264,7 @@ bool SpeechManager::load(Common::SeekableReadStream *stream) {
 	byte r = stream->readByte();
 	byte g = stream->readByte();
 	byte b = stream->readByte();
-	setFontColour(_speech->talkCol, r, g, b);
-
+	_speech->talkCol.setColor(r, g, b);
 	_speechSpeed = stream->readFloatLE();
 
 	// Read y co-ordinate
diff --git a/engines/sludge/sprites.h b/engines/sludge/sprites.h
index e138c6f..e18d16e 100644
--- a/engines/sludge/sprites.h
+++ b/engines/sludge/sprites.h
@@ -42,15 +42,8 @@ public:
 	byte originalRed, originalGreen, originalBlue, total;
 
 	SpritePalette() { init(); }
-
 	~SpritePalette() { kill(); }
 
-	void reset() {
-		kill();
-		init();
-	}
-
-private:
 	void init() {
 		pal = nullptr;
 		r = g = b = nullptr;
@@ -59,15 +52,29 @@ private:
 	}
 
 	void kill() {
-		if (pal)
+		if (pal) {
 			delete[] pal;
-		if (r)
+			pal = nullptr;
+		}
+		if (r) {
 			delete[] r;
-		if (g)
+			r = nullptr;
+		}
+		if (g) {
 			delete[] g;
-		if (b)
+			g = nullptr;
+		}
+		if (b) {
 			delete[] b;
+			b = nullptr;
+		}
 	}
+
+	void setColor(byte red, byte green, byte blue) {
+			originalRed = red;
+			originalGreen = green;
+			originalBlue = blue;
+		}
 };
 
 struct SpriteBank {
diff --git a/engines/sludge/statusba.cpp b/engines/sludge/statusba.cpp
index 1aa2497..04fa18e 100644
--- a/engines/sludge/statusba.cpp
+++ b/engines/sludge/statusba.cpp
@@ -114,14 +114,14 @@ void drawStatusBar() {
 }
 
 void statusBarColour(byte r, byte g, byte b) {
-	setFontColour(verbLinePalette, r, g, b);
+	verbLinePalette.setColor(r, g, b);
 	nowStatus->statusR = r;
 	nowStatus->statusG = g;
 	nowStatus->statusB = b;
 }
 
 void statusBarLitColour(byte r, byte g, byte b) {
-	setFontColour(litVerbLinePalette, r, g, b);
+	litVerbLinePalette.setColor(r, g, b);
 	nowStatus->statusLR = r;
 	nowStatus->statusLG = g;
 	nowStatus->statusLB = b;
@@ -152,8 +152,8 @@ StatusStuff *copyStatusBarStuff(StatusStuff  *here) {
 
 void restoreBarStuff(StatusStuff *here) {
 	delete nowStatus;
-	setFontColour(verbLinePalette, here->statusR, here->statusG, here->statusB);
-	setFontColour(litVerbLinePalette, here->statusLR, here->statusLG, here->statusLB);
+	verbLinePalette.setColor((byte)here->statusR, (byte)here->statusG, (byte)here->statusB);
+	litVerbLinePalette.setColor((byte)here->statusLR, (byte)here->statusLG, (byte)here->statusLB);
 	nowStatus = here;
 }
 
@@ -215,8 +215,8 @@ bool loadStatusBars(Common::SeekableReadStream *stream) {
 	nowStatus->statusLG = stream->readByte();
 	nowStatus->statusLB = stream->readByte();
 
-	setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB);
-	setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB);
+	verbLinePalette.setColor((byte)nowStatus->statusR, (byte)nowStatus->statusG, (byte)nowStatus->statusB);
+	litVerbLinePalette.setColor((byte)nowStatus->statusLR, (byte)nowStatus->statusLG, (byte)nowStatus->statusLB);
 	// Read what's being said
 	StatusBar **viewLine = & (nowStatus->firstStatusBar);
 	StatusBar *newOne;





More information about the Scummvm-git-logs mailing list