[Scummvm-cvs-logs] SF.net SVN: scummvm:[50261] scummvm/trunk/engines/sci

m_kiewitz at users.sourceforge.net m_kiewitz at users.sourceforge.net
Fri Jun 25 12:04:33 CEST 2010


Revision: 50261
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50261&view=rev
Author:   m_kiewitz
Date:     2010-06-25 10:04:31 +0000 (Fri, 25 Jun 2010)

Log Message:
-----------
SCI: detect, if SCI1.1 game is merging or copying palette instead of using gameIds. Also prints method used, when using debug command "version"

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/graphics/palette.cpp
    scummvm/trunk/engines/sci/graphics/palette.h
    scummvm/trunk/engines/sci/resource.cpp
    scummvm/trunk/engines/sci/resource.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/console.cpp	2010-06-25 10:04:31 UTC (rev 50261)
@@ -436,6 +436,7 @@
 	DebugPrintf("Move count type: %s\n", (_engine->_features->handleMoveCount()) ? "increment" : "ignore");
 	DebugPrintf("SetCursor type: %s\n", getSciVersionDesc(_engine->_features->detectSetCursorType()));
 	DebugPrintf("View type: %s\n", viewTypeDesc[g_sci->getResMan()->getViewType()]);
+	DebugPrintf("Uses palette merging: %s\n", g_sci->_gfxPalette->isMerging() ? "yes" : "no");
 	DebugPrintf("Resource volume version: %s\n", g_sci->getResMan()->getVolVersionDesc());
 	DebugPrintf("Resource map version: %s\n", g_sci->getResMan()->getMapVersionDesc());
 	DebugPrintf("Contains selector vocabulary (vocab.997): %s\n", hasVocab997 ? "yes" : "no");

Modified: scummvm/trunk/engines/sci/graphics/palette.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/palette.cpp	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/graphics/palette.cpp	2010-06-25 10:04:31 UTC (rev 50261)
@@ -38,7 +38,7 @@
 
 namespace Sci {
 
-GfxPalette::GfxPalette(ResourceManager *resMan, GfxScreen *screen)
+GfxPalette::GfxPalette(ResourceManager *resMan, GfxScreen *screen, bool useMerging)
 	: _resMan(resMan), _screen(screen) {
 	int16 color;
 
@@ -59,7 +59,6 @@
 	_sysPalette.colors[255].b = 255;
 
 	_sysPaletteChanged = false;
-	_alwaysForceRealMerge = false;
 
 	// Pseudo-WORKAROUND
 	// Quest for Glory 3 demo, Eco Quest 1 demo, Laura Bow 2 demo, Police Quest 1 vga and all Nick's Picks
@@ -67,14 +66,7 @@
 	//  It's not using the SCI1.1 palette merging (copying over all the colors) but the real merging
 	//  If we use the copying over, we will get issues because some views have marked all colors as being used
 	//  and those will overwrite the current palette in that case
-	Common::String gameId = g_sci->getGameId();
-	if (g_sci->isDemo()) {
-		if (gameId == "laurabow2" || gameId == "qfg3" || gameId == "ecoquest")
-			_alwaysForceRealMerge = true;
-	} else {
-		if (gameId == "pq1sci" || gameId == "cnick-sq" || gameId == "cnick-longbow" || gameId == "cnick-kq" || gameId == "cnick-laurabow" || gameId == "cnick-lsl")
-			_alwaysForceRealMerge = true;
-	}
+	_useMerging = useMerging;
 
 	palVaryInit();
 }
@@ -82,6 +74,10 @@
 GfxPalette::~GfxPalette() {
 }
 
+bool GfxPalette::isMerging() {
+	return _useMerging;
+}
+
 // meant to get called only once during init of engine
 void GfxPalette::setDefault() {
 	if (_resMan->getViewType() == kViewEga)
@@ -231,7 +227,14 @@
 	uint32 systime = _sysPalette.timestamp;
 
 	if (force || newPalette->timestamp != systime) {
-		_sysPaletteChanged |= merge(newPalette, force, forceRealMerge);
+		// SCI1.1+ doesnt do real merging anymore, but simply copying over the used colors from other palettes
+		//  There are some games with inbetween SCI1.1 interpreters, use real merging for them (e.g. laura bow 2 demo)
+		if ((forceRealMerge) || (_useMerging))
+			_sysPaletteChanged |= merge(newPalette, force, forceRealMerge);
+		else
+			_sysPaletteChanged |= insert(newPalette, &_sysPalette);
+
+		// Adjust timestamp on newPalette, so it wont get merged/inserted w/o need
 		newPalette->timestamp = _sysPalette.timestamp;
 
 		bool updatePalette = _sysPaletteChanged && _screen->_picNotValid == 0;
@@ -265,6 +268,7 @@
 			newPalette->mapping[i] = i;
 		}
 	}
+	// We don't update the timestamp for SCI1.1, it's only updated on kDrawPic calls
 	return paletteChanged;
 }
 
@@ -273,59 +277,50 @@
 	int i,j;
 	bool paletteChanged = false;
 
-	if ((!forceRealMerge) && (!_alwaysForceRealMerge) && (getSciVersion() >= SCI_VERSION_1_1)) {
-		// SCI1.1+ doesnt do real merging anymore, but simply copying over the used colors from other palettes
-		//  There are some games with inbetween SCI1.1 interpreters, use real merging for them (e.g. laura bow 2 demo)
-
-		// We don't update the timestamp for SCI1.1, it's only updated on kDrawPic calls
-		return insert(newPalette, &_sysPalette);
-
-	} else {
-		// colors 0 (black) and 255 (white) are not affected by merging
-		for (i = 1 ; i < 255; i++) {
-			if (!newPalette->colors[i].used)// color is not used - so skip it
-				continue;
-			// forced palette merging or dest color is not used yet
-			if (force || (!_sysPalette.colors[i].used)) {
-				_sysPalette.colors[i].used = newPalette->colors[i].used;
-				if ((newPalette->colors[i].r != _sysPalette.colors[i].r) || (newPalette->colors[i].g != _sysPalette.colors[i].g) || (newPalette->colors[i].b != _sysPalette.colors[i].b)) {
-					_sysPalette.colors[i].r = newPalette->colors[i].r;
-					_sysPalette.colors[i].g = newPalette->colors[i].g;
-					_sysPalette.colors[i].b = newPalette->colors[i].b;
-					paletteChanged = true;
-				}
-				newPalette->mapping[i] = i;
-				continue;
+	// colors 0 (black) and 255 (white) are not affected by merging
+	for (i = 1 ; i < 255; i++) {
+		if (!newPalette->colors[i].used)// color is not used - so skip it
+			continue;
+		// forced palette merging or dest color is not used yet
+		if (force || (!_sysPalette.colors[i].used)) {
+			_sysPalette.colors[i].used = newPalette->colors[i].used;
+			if ((newPalette->colors[i].r != _sysPalette.colors[i].r) || (newPalette->colors[i].g != _sysPalette.colors[i].g) || (newPalette->colors[i].b != _sysPalette.colors[i].b)) {
+				_sysPalette.colors[i].r = newPalette->colors[i].r;
+				_sysPalette.colors[i].g = newPalette->colors[i].g;
+				_sysPalette.colors[i].b = newPalette->colors[i].b;
+				paletteChanged = true;
 			}
-			// is the same color already at the same position? -> match it directly w/o lookup
-			//  this fixes games like lsl1demo/sq5 where the same rgb color exists multiple times and where we would
-			//  otherwise match the wrong one (which would result into the pixels affected (or not) by palette changes)
-			if ((_sysPalette.colors[i].r == newPalette->colors[i].r) && (_sysPalette.colors[i].g == newPalette->colors[i].g) && (_sysPalette.colors[i].b == newPalette->colors[i].b)) {
-				newPalette->mapping[i] = i;
-				continue;
+			newPalette->mapping[i] = i;
+			continue;
+		}
+		// is the same color already at the same position? -> match it directly w/o lookup
+		//  this fixes games like lsl1demo/sq5 where the same rgb color exists multiple times and where we would
+		//  otherwise match the wrong one (which would result into the pixels affected (or not) by palette changes)
+		if ((_sysPalette.colors[i].r == newPalette->colors[i].r) && (_sysPalette.colors[i].g == newPalette->colors[i].g) && (_sysPalette.colors[i].b == newPalette->colors[i].b)) {
+			newPalette->mapping[i] = i;
+			continue;
+		}
+		// check if exact color could be matched
+		res = matchColor(newPalette->colors[i].r, newPalette->colors[i].g, newPalette->colors[i].b);
+		if (res & 0x8000) { // exact match was found
+			newPalette->mapping[i] = res & 0xFF;
+			continue;
+		}
+		// no exact match - see if there is an unused color
+		for (j = 1; j < 256; j++)
+			if (!_sysPalette.colors[j].used) {
+				_sysPalette.colors[j].used = newPalette->colors[i].used;
+				_sysPalette.colors[j].r = newPalette->colors[i].r;
+				_sysPalette.colors[j].g = newPalette->colors[i].g;
+				_sysPalette.colors[j].b = newPalette->colors[i].b;
+				newPalette->mapping[i] = j;
+				paletteChanged = true;
+				break;
 			}
-			// check if exact color could be matched
-			res = matchColor(newPalette->colors[i].r, newPalette->colors[i].g, newPalette->colors[i].b);
-			if (res & 0x8000) { // exact match was found
-				newPalette->mapping[i] = res & 0xFF;
-				continue;
-			}
-			// no exact match - see if there is an unused color
-			for (j = 1; j < 256; j++)
-				if (!_sysPalette.colors[j].used) {
-					_sysPalette.colors[j].used = newPalette->colors[i].used;
-					_sysPalette.colors[j].r = newPalette->colors[i].r;
-					_sysPalette.colors[j].g = newPalette->colors[i].g;
-					_sysPalette.colors[j].b = newPalette->colors[i].b;
-					newPalette->mapping[i] = j;
-					paletteChanged = true;
-					break;
-				}
-			// if still no luck - set an approximate color
-			if (j == 256) {
-				newPalette->mapping[i] = res & 0xFF;
-				_sysPalette.colors[res & 0xFF].used |= 0x10;
-			}
+		// if still no luck - set an approximate color
+		if (j == 256) {
+			newPalette->mapping[i] = res & 0xFF;
+			_sysPalette.colors[res & 0xFF].used |= 0x10;
 		}
 	}
 
@@ -337,7 +332,7 @@
 // This is called for SCI1.1, when kDrawPic got done. We update sysPalette timestamp this way for SCI1.1 and also load
 //  target-palette, if palvary is active
 void GfxPalette::drewPicture(GuiResourceId pictureId) {
-	if (!_alwaysForceRealMerge) // Don't do this on inbetween SCI1.1 games
+	if (!_useMerging) // Don't do this on inbetween SCI1.1 games
 		_sysPalette.timestamp++;
 
 	if (_palVaryResourceId != -1) {

Modified: scummvm/trunk/engines/sci/graphics/palette.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/palette.h	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/graphics/palette.h	2010-06-25 10:04:31 UTC (rev 50261)
@@ -36,9 +36,11 @@
  */
 class GfxPalette {
 public:
-	GfxPalette(ResourceManager *resMan, GfxScreen *screen);
+	GfxPalette(ResourceManager *resMan, GfxScreen *screen, bool useMerging);
 	~GfxPalette();
 
+	bool isMerging();
+
 	void setDefault();
 	void createFromData(byte *data, int bytesLeft, Palette *paletteOut);
 	bool setAmiga();
@@ -88,7 +90,7 @@
 	ResourceManager *_resMan;
 
 	bool _sysPaletteChanged;
-	bool _alwaysForceRealMerge;
+	bool _useMerging;
 
 	Common::Array<PalSchedule> _schedules;
 

Modified: scummvm/trunk/engines/sci/resource.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource.cpp	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/resource.cpp	2010-06-25 10:04:31 UTC (rev 50261)
@@ -1949,6 +1949,21 @@
 	return false;
 }
 
+// detects, if SCI1.1 game uses palette merging or copying - this is supposed to only get used on SCI1.1 games
+bool ResourceManager::detectForPaletteMergingForSci11() {
+	// Load palette 999 (default palette)
+	Resource *res = findResource(ResourceId(kResourceTypePalette, 999), false);
+
+	if ((res) && (res->size > 30)) {
+		byte *data = res->data;
+		// Old palette format used in palette resource? -> it's merging
+		if ((data[0] == 0 && data[1] == 1) || (data[0] == 0 && data[1] == 0 && READ_LE_UINT16(data + 29) == 0))
+			return true;
+		return false;
+	}
+	return false;
+}
+
 // Functions below are based on PD code by Brian Provinciano (SCI Studio)
 bool ResourceManager::hasOldScriptHeader() {
 	Resource *res = findResource(ResourceId(kResourceTypeScript, 0), 0);

Modified: scummvm/trunk/engines/sci/resource.h
===================================================================
--- scummvm/trunk/engines/sci/resource.h	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/resource.h	2010-06-25 10:04:31 UTC (rev 50261)
@@ -328,6 +328,8 @@
 	bool detectHires();
 	// Detects, if standard font of current game includes extended characters (>0x80)
 	bool detectFontExtended();
+	// Detects, if SCI1.1 game uses palette merging
+	bool detectForPaletteMergingForSci11();
 
 	/**
 	 * Finds the internal Sierra ID of the current game from script 0.

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-06-25 09:57:37 UTC (rev 50260)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-06-25 10:04:31 UTC (rev 50261)
@@ -224,7 +224,16 @@
 	if (_resMan->isSci11Mac() && getSciVersion() == SCI_VERSION_1_1)
 		_gfxMacIconBar = new GfxMacIconBar();
 
-	_gfxPalette = new GfxPalette(_resMan, _gfxScreen);
+	bool paletteMerging = true;
+	if (getSciVersion() >= SCI_VERSION_1_1) {
+		// there are some games that use inbetween SCI1.1 interpreter, so we have to detect if it's merging or copying
+		if (getSciVersion() == SCI_VERSION_1_1)
+			paletteMerging = _resMan->detectForPaletteMergingForSci11();
+		else
+			paletteMerging = false;
+	}
+
+	_gfxPalette = new GfxPalette(_resMan, _gfxScreen, paletteMerging);
 	_gfxCache = new GfxCache(_resMan, _gfxScreen, _gfxPalette);
 	_gfxCursor = new GfxCursor(_resMan, _gfxPalette, _gfxScreen);
 


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