[Scummvm-git-logs] scummvm master -> 657f3f81267eb653172d3607ec20d295f4eb578e

yinsimei roseline.yin at gmail.com
Fri Apr 27 19:49:07 CEST 2018


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:
5ced495769 SLUDGE: Move global variable thumbnailWidth/Height to GraphicsManager
da491601d4 SLUDGE: Move global variable brightnessLevel to GraphicsManager and refactor save&load
7e7d8d769a SLUDGE: Remove global variable speechMode
657f3f8126 SLUDGE: Replace linked list by Common::List in SpeechManager


Commit: 5ced49576924c18dd3d04c08f4e1822f21c52894
    https://github.com/scummvm/scummvm/commit/5ced49576924c18dd3d04c08f4e1822f21c52894
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-27T19:48:29+02:00

Commit Message:
SLUDGE: Move global variable thumbnailWidth/Height to GraphicsManager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/graphics.cpp
    engines/sludge/graphics.h
    engines/sludge/sludger.cpp
    engines/sludge/thumbnail.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 8195fc5..909118a 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -58,7 +58,7 @@ int speechMode = 0;
 
 Variable *launchResult = NULL;
 
-extern int lastFramesPerSecond, thumbWidth, thumbHeight;
+extern int lastFramesPerSecond;
 extern bool allowAnyFilename;
 extern VariableStack *noStack;
 extern StatusStuff  *nowStatus;
@@ -2460,13 +2460,14 @@ builtIn(showThumbnail) {
 
 builtIn(setThumbnailSize) {
 	UNUSEDALL
+	int thumbHeight, thumbWidth;
 	if (!getValueType(thumbHeight, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
 	if (!getValueType(thumbWidth, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	if (!g_sludge->_gfxMan->checkSizeValide(thumbWidth, thumbHeight)) {
+	if (!g_sludge->_gfxMan->setThumbnailSize(thumbWidth, thumbHeight)) {
 		Common::String buff = Common::String::format("%i x %i", thumbWidth, thumbWidth);
 		fatal("Invalid thumbnail size", buff);
 		return BR_ERROR;
diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp
index 578e6f6..580124f 100644
--- a/engines/sludge/graphics.cpp
+++ b/engines/sludge/graphics.cpp
@@ -83,6 +83,10 @@ void GraphicsManager::init() {
 	_currentBurnR = 0;
 	_currentBurnG = 0;
 	_currentBurnB = 0;
+
+	// Thumbnail
+	_thumbWidth = 0;
+	_thumbHeight = 0;
 }
 
 void GraphicsManager::kill() {
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index 16973a1..6c5351c 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -167,7 +167,8 @@ public:
 	void saveColors(Common::WriteStream *stream);
 	void loadColors(Common::SeekableReadStream *stream);
 
-	// Thumb nail
+	// Thumbnail
+	bool setThumbnailSize(int thumbWidth, int thumbHeight);
 	bool saveThumbnail(Common::WriteStream *stream);
 	bool skipThumbnail(Common::SeekableReadStream *stream);
 	void showThumbnail(const Common::String &filename, int x, int y);
@@ -222,6 +223,10 @@ private:
 	// Colors
 	uint _currentBlankColour;
 	byte _currentBurnR, _currentBurnG, _currentBurnB;
+
+	// Thumbnail
+	int _thumbWidth;
+	int _thumbHeight;
 };
 
 } // End of namespace Sludge
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 4f5f204..f616fe6 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -79,7 +79,7 @@ Variable *globalVars;
 int numGlobals = 0;
 
 extern Variable *launchResult;
-extern int lastFramesPerSecond, thumbWidth, thumbHeight;
+extern int lastFramesPerSecond;
 
 extern bool allowAnyFilename;
 extern byte fadeMode;
@@ -167,7 +167,6 @@ void initSludge() {
 	launchResult = nullptr;
 
 	lastFramesPerSecond = -1;
-	thumbWidth = thumbHeight = 0;
 	allowAnyFilename = true;
 	noStack = nullptr;
 	numBIFNames = numUserFunc = 0;
diff --git a/engines/sludge/thumbnail.cpp b/engines/sludge/thumbnail.cpp
index 2c7e007..dcbcd91 100644
--- a/engines/sludge/thumbnail.cpp
+++ b/engines/sludge/thumbnail.cpp
@@ -35,14 +35,23 @@
 
 namespace Sludge {
 
-int thumbWidth = 0, thumbHeight = 0;
+bool GraphicsManager::setThumbnailSize(int thumbWidth, int thumbHeight)
+{
+	if (checkSizeValide(thumbWidth, thumbHeight))
+	{
+		_thumbWidth = thumbWidth;
+		_thumbHeight = thumbHeight;
+		return true;
+	}
+	return false;
+}
 
 bool GraphicsManager::saveThumbnail(Common::WriteStream *stream) {
 
-	stream->writeUint32LE(thumbWidth);
-	stream->writeUint32LE(thumbHeight);
+	stream->writeUint32LE(_thumbWidth);
+	stream->writeUint32LE(_thumbHeight);
 
-	if (thumbWidth && thumbHeight) {
+	if (_thumbWidth && _thumbHeight) {
 		if (!freeze())
 			return false;
 
@@ -117,12 +126,12 @@ void GraphicsManager::showThumbnail(const Common::String &filename, int atX, int
 }
 
 bool GraphicsManager::skipThumbnail(Common::SeekableReadStream *stream) {
-	thumbWidth = stream->readUint32LE();
-	thumbHeight = stream->readUint32LE();
+	_thumbWidth = stream->readUint32LE();
+	_thumbHeight = stream->readUint32LE();
 
 	// Load image
 	Graphics::Surface tmp;
-	if (thumbWidth & thumbHeight) {
+	if (_thumbWidth & _thumbHeight) {
 		if (!ImgLoader::loadPNGImage(stream, &tmp))
 			return false;
 		else


Commit: da491601d4fca4deebe8d1a4a18e67fe48dff55d
    https://github.com/scummvm/scummvm/commit/da491601d4fca4deebe8d1a4a18e67fe48dff55d
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-27T19:48:29+02:00

Commit Message:
SLUDGE: Move global variable brightnessLevel to GraphicsManager and refactor save&load

Changed paths:
    engines/sludge/backdrop.cpp
    engines/sludge/builtin.cpp
    engines/sludge/graphics.h
    engines/sludge/loadsave.cpp
    engines/sludge/transition.cpp


diff --git a/engines/sludge/backdrop.cpp b/engines/sludge/backdrop.cpp
index c1042c7..1c618c7 100644
--- a/engines/sludge/backdrop.cpp
+++ b/engines/sludge/backdrop.cpp
@@ -504,6 +504,27 @@ void GraphicsManager::saveHSI(Common::WriteStream *stream) {
 	Image::writePNG(*stream, _backdropSurface);
 }
 
+void GraphicsManager::saveBackdrop(Common::WriteStream *stream) {
+	stream->writeUint16BE(_cameraX);
+	stream->writeUint16BE(_cameraY);
+	stream->writeFloatLE(_cameraZoom);
+	stream->writeByte(_brightnessLevel);
+	saveHSI(stream);
+}
+
+void GraphicsManager::loadBackdrop(int ssgVersion, Common::SeekableReadStream *stream) {
+	_cameraX = stream->readUint16BE();
+	_cameraY = stream->readUint16BE();
+	if (ssgVersion >= VERSION(2, 0)) {
+		_cameraZoom = stream->readFloatLE();
+	} else {
+		_cameraZoom = 1.0;
+	}
+
+	_brightnessLevel = stream->readByte();
+
+	loadHSI(stream, 0, 0, true);
+}
 
 bool GraphicsManager::getRGBIntoStack(uint x, uint y, StackHandler *sH) {
 	if (x >= _sceneWidth || y >= _sceneHeight) {
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 909118a..bc635f8 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -67,7 +67,6 @@ extern int numBIFNames, numUserFunc;
 extern Common::String *allUserFunc;
 extern Common::String *allBIFNames;
 
-extern byte brightnessLevel;
 extern byte fadeMode;
 extern uint16 saveEncoding;
 
@@ -1971,17 +1970,12 @@ builtIn(setFontSpacing) {
 
 builtIn(transitionLevel) {
 	UNUSEDALL
-	int number;
-	if (!getValueType(number, SVT_INT, fun->stack->thisVar))
+	int brightnessLevel;
+	if (!getValueType(brightnessLevel, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	if (number < 0)
-		brightnessLevel = 0;
-	else if (number > 255)
-		brightnessLevel = 255;
-	else
-		brightnessLevel = number;
+	g_sludge->_gfxMan->setBrightnessLevel(brightnessLevel);
 
 	setVariable(fun->reg, SVT_INT, 1);
 	return BR_CONTINUE;
diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h
index 6c5351c..f7ed7d0 100644
--- a/engines/sludge/graphics.h
+++ b/engines/sludge/graphics.h
@@ -91,6 +91,8 @@ public:
 	void drawVerticalLine(uint, uint, uint);
 	void hardScroll(int distance);
 	bool getRGBIntoStack(uint x, uint y, StackHandler *sH);
+	void saveBackdrop(Common::WriteStream *stream); // To game save
+	void loadBackdrop(int ssgVersion, Common::SeekableReadStream *streamn); // From game save
 
 	// Lightmap
 	int _lightMapMode;
@@ -109,11 +111,6 @@ public:
 	int getCamX() { return _cameraX; }
 	int getCamY() { return _cameraY; }
 	float getCamZoom() { return _cameraZoom; }
-	void setCamera(int camerX, int camerY, float camerZ) {
-		_cameraX = camerX;
-		_cameraY = camerY;
-		_cameraZoom = camerZ;
-	}
 	void aimCamera(int cameraX, int cameraY);
 	void zoomCamera(int z);
 
@@ -173,6 +170,9 @@ public:
 	bool skipThumbnail(Common::SeekableReadStream *stream);
 	void showThumbnail(const Common::String &filename, int x, int y);
 
+	// Transition
+	void setBrightnessLevel(int brightnessLevel);
+
 private:
 	SludgeEngine *_vm;
 
@@ -227,6 +227,9 @@ private:
 	// Thumbnail
 	int _thumbWidth;
 	int _thumbHeight;
+
+	// Transition
+	byte _brightnessLevel;
 };
 
 } // End of namespace Sludge
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 017be43..65ea474 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -60,7 +60,6 @@ extern int numGlobals;                              // In sludger.cpp
 extern Variable *globalVars;                        // In sludger.cpp
 extern Floor *currentFloor;                          // In floor.cpp
 extern FILETIME fileTime;                           // In sludger.cpp
-extern byte brightnessLevel;               // "    "   "
 extern byte fadeMode;                      // In transition.cpp
 extern bool allowAnyFilename;
 extern uint16 saveEncoding;                 // in savedata.cpp
@@ -363,12 +362,7 @@ bool saveGame(const Common::String &fname) {
 	g_sludge->_txtMan->saveFont(fp);
 
 	// Save backdrop
-	fp->writeUint16BE(g_sludge->_gfxMan->getCamX());
-	fp->writeUint16BE(g_sludge->_gfxMan->getCamY());
-	fp->writeFloatLE(g_sludge->_gfxMan->getCamZoom());
-
-	fp->writeByte(brightnessLevel);
-	g_sludge->_gfxMan->saveHSI(fp);
+	g_sludge->_gfxMan->saveBackdrop(fp);
 
 	// Save event handlers
 	g_sludge->_evtMan->saveHandlers(fp);
@@ -504,19 +498,10 @@ bool loadGame(const Common::String &fname) {
 
 	g_sludge->_regionMan->kill();
 
-	int camerX = fp->readUint16BE();
-	int camerY = fp->readUint16BE();
-	float camerZ;
-	if (ssgVersion >= VERSION(2, 0)) {
-		camerZ = fp->readFloatLE();
-	} else {
-		camerZ = 1.0;
-	}
-
-	brightnessLevel = fp->readByte();
+	g_sludge->_gfxMan->loadBackdrop(ssgVersion, fp);
 
-	g_sludge->_gfxMan->loadHSI(fp, 0, 0, true);
 	g_sludge->_evtMan->loadHandlers(fp);
+
 	g_sludge->_regionMan->loadRegions(fp);
 
 	if (!g_sludge->_cursorMan->loadCursor(fp)) {
@@ -598,8 +583,6 @@ bool loadGame(const Common::String &fname) {
 
 	delete fp;
 
-	g_sludge->_gfxMan->setCamera(camerX, camerY, camerZ);
-
 	clearStackLib();
 	return true;
 }
diff --git a/engines/sludge/transition.cpp b/engines/sludge/transition.cpp
index 3a768cb..ddefbe9 100644
--- a/engines/sludge/transition.cpp
+++ b/engines/sludge/transition.cpp
@@ -22,16 +22,25 @@
 
 #include "sludge/allfiles.h"
 #include "sludge/backdrop.h"
+#include "sludge/graphics.h"
 #include "sludge/newfatal.h"
 
 namespace Sludge {
 
-extern byte brightnessLevel;
-
 extern float snapTexW, snapTexH;
 
 byte fadeMode = 2;
 
+void GraphicsManager::setBrightnessLevel(int brightnessLevel)
+{
+	if (brightnessLevel < 0)
+		_brightnessLevel = 0;
+	else if (brightnessLevel > 255)
+		_brightnessLevel = 255;
+	else
+		_brightnessLevel = brightnessLevel;
+}
+
 //----------------------------------------------------
 // PROPER BRIGHTNESS FADING
 //----------------------------------------------------


Commit: 7e7d8d769ad55a996ac8f465ee6656ba30719f51
    https://github.com/scummvm/scummvm/commit/7e7d8d769ad55a996ac8f465ee6656ba30719f51
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-27T19:48:29+02:00

Commit Message:
SLUDGE: Remove global variable speechMode

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/speech.h


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index bc635f8..42fcfcf 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -54,8 +54,6 @@
 
 namespace Sludge {
 
-int speechMode = 0;
-
 Variable *launchResult = NULL;
 
 extern int lastFramesPerSecond;
@@ -1280,6 +1278,7 @@ builtIn(setLightMap) {
 
 builtIn(setSpeechMode) {
 	UNUSEDALL
+	int speechMode;
 	if (!getValueType(speechMode, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
@@ -1287,6 +1286,7 @@ builtIn(setSpeechMode) {
 		fatal("Valid parameters are be SPEECHANDTEXT, SPEECHONLY or TEXTONLY");
 		return BR_ERROR;
 	}
+	g_sludge->_speechMan->setSpeechMode(speechMode);
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/speech.h b/engines/sludge/speech.h
index 98b6035..cd2a6dd 100644
--- a/engines/sludge/speech.h
+++ b/engines/sludge/speech.h
@@ -60,6 +60,7 @@ public:
 	void setObjFontColour(ObjectType *t);
 	void setSpeechSpeed(float speed) { _speechSpeed = speed; }
 	float getSpeechSpeed() { return _speechSpeed; }
+	void setSpeechMode(int speechMode) { _speechMode = speechMode; }
 
 	// load & save
 	void save(Common::WriteStream *stream);


Commit: 657f3f81267eb653172d3607ec20d295f4eb578e
    https://github.com/scummvm/scummvm/commit/657f3f81267eb653172d3607ec20d295f4eb578e
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-27T19:48:29+02:00

Commit Message:
SLUDGE: Replace linked list by Common::List in SpeechManager

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


diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp
index cac4a5e..9c02eda 100644
--- a/engines/sludge/speech.cpp
+++ b/engines/sludge/speech.cpp
@@ -45,7 +45,7 @@ void SpeechManager::init() {
 	_speech = new SpeechStruct;
 	if (checkNew(_speech)) {
 		_speech->currentTalker = NULL;
-		_speech->allSpeech = NULL;
+		_speech->allSpeech.clear();
 		_speech->speechY = 0;
 		_speech->lastFile = -1;
 	}
@@ -65,12 +65,12 @@ void SpeechManager::kill() {
 		_speech->currentTalker = nullptr;
 	}
 
-	SpeechLine *killMe;
-	while (_speech->allSpeech) {
-		killMe = _speech->allSpeech;
-		_speech->allSpeech = _speech->allSpeech->next;
+	for (SpeechLineList::iterator it = _speech->allSpeech.begin(); it != _speech->allSpeech.end(); ++it) {
+		SpeechLine *killMe = *it;
 		delete killMe;
+		killMe = nullptr;
 	}
+	_speech->allSpeech.clear();
 }
 
 void SpeechManager::setObjFontColour(ObjectType *t) {
@@ -82,14 +82,16 @@ void SpeechManager::addSpeechLine(const Common::String &theLine, int x, int &off
 	int halfWidth = (g_sludge->_txtMan->stringWidth(theLine) >> 1) / cameraZoom;
 	int xx1 = x - (halfWidth);
 	int xx2 = x + (halfWidth);
+
+	// Create new speech line
 	SpeechLine *newLine = new SpeechLine;
 	checkNew(newLine);
-
-	newLine->next = _speech->allSpeech;
 	newLine->textLine.clear();
 	newLine->textLine = theLine;
 	newLine->x = xx1;
-	_speech->allSpeech = newLine;
+	_speech->allSpeech.push_front(newLine);
+
+	// Calculate offset
 	if ((xx1 < 5) && (offset < (5 - xx1))) {
 		offset = 5 - xx1;
 	} else if ((xx2 >= ((float) g_system->getWidth() / cameraZoom) - 5)
@@ -99,7 +101,7 @@ void SpeechManager::addSpeechLine(const Common::String &theLine, int x, int &off
 }
 
 int SpeechManager::isThereAnySpeechGoingOn() {
-	return _speech->allSpeech ? _speech->lookWhosTalking : -1;
+	return _speech->allSpeech.empty() ? -1 : _speech->lookWhosTalking;
 }
 
 int SpeechManager::getLastSpeechSound() {
@@ -158,10 +160,8 @@ int SpeechManager::wrapSpeechXY(const Common::String &theText, int x, int y, int
 				+ (float) (g_system->getHeight() - fontHeight / 3) / cameraZoom;
 
 	if (offset) {
-		SpeechLine *viewLine = _speech->allSpeech;
-		while (viewLine) {
-			viewLine->x += offset;
-			viewLine = viewLine->next;
+		for (SpeechLineList::iterator it = _speech->allSpeech.begin(); it != _speech->allSpeech.end(); ++it) {
+			(*it)->x += offset;
 		}
 	}
 	return speechTime;
@@ -214,19 +214,14 @@ void SpeechManager::display() {
 	float cameraZoom = g_sludge->_gfxMan->getCamZoom();
 	int fontHeight = g_sludge->_txtMan->getFontHeight();
 	int viewY = _speech->speechY;
-	SpeechLine *viewLine = _speech->allSpeech;
-	while (viewLine) {
-		g_sludge->_txtMan->pasteString(viewLine->textLine, viewLine->x, viewY, _speech->talkCol);
+	for (SpeechLineList::iterator it = _speech->allSpeech.begin(); it != _speech->allSpeech.end(); ++it) {
+		g_sludge->_txtMan->pasteString((*it)->textLine, (*it)->x, viewY, _speech->talkCol);
 		viewY -= fontHeight / cameraZoom;
-		viewLine = viewLine->next;
 	}
 }
 
 void SpeechManager::save(Common::WriteStream *stream) {
 	stream->writeByte(_speechMode);
-
-	SpeechLine *viewLine = _speech->allSpeech;
-
 	stream->writeByte(_speech->talkCol.originalRed);
 	stream->writeByte(_speech->talkCol.originalGreen);
 	stream->writeByte(_speech->talkCol.originalBlue);
@@ -246,11 +241,10 @@ void SpeechManager::save(Common::WriteStream *stream) {
 	}
 
 	// Write what's being said
-	while (viewLine) {
+	for (SpeechLineList::iterator it = _speech->allSpeech.begin(); it != _speech->allSpeech.end(); ++it) {
 		stream->writeByte(1);
-		writeString(viewLine->textLine, stream);
-		stream->writeUint16BE(viewLine->x);
-		viewLine = viewLine->next;
+		writeString((*it)->textLine, stream);
+		stream->writeUint16BE((*it)->x);
 	}
 	stream->writeByte(0);
 }
@@ -280,18 +274,14 @@ bool SpeechManager::load(Common::SeekableReadStream *stream) {
 	}
 
 	// Read what's being said
-	SpeechLine **viewLine = &_speech->allSpeech;
-	SpeechLine *newOne;
 	_speech->lastFile = -1;
 	while (stream->readByte()) {
-		newOne = new SpeechLine;
+		SpeechLine *newOne = new SpeechLine;
 		if (!checkNew(newOne))
 			return false;
 		newOne->textLine = readString(stream);
 		newOne->x = stream->readUint16BE();
-		newOne->next = NULL;
-		(*viewLine) = newOne;
-		viewLine = &(newOne->next);
+		_speech->allSpeech.push_back(newOne);
 	}
 	return true;
 }
diff --git a/engines/sludge/speech.h b/engines/sludge/speech.h
index cd2a6dd..776a9f5 100644
--- a/engines/sludge/speech.h
+++ b/engines/sludge/speech.h
@@ -30,13 +30,14 @@ struct ObjectType;
 
 struct SpeechLine {
 	Common::String textLine;
-	SpeechLine *next;
 	int x;
 };
 
+typedef Common::List<SpeechLine *> SpeechLineList;
+
 struct SpeechStruct {
 	OnScreenPerson *currentTalker;
-	SpeechLine *allSpeech;
+	SpeechLineList allSpeech;
 	int speechY, lastFile, lookWhosTalking;
 	SpritePalette talkCol;
 };





More information about the Scummvm-git-logs mailing list