[Scummvm-cvs-logs] SF.net SVN: scummvm: [32369] scummvm/trunk/engines/sword2

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Thu May 29 22:32:28 CEST 2008


Revision: 32369
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32369&view=rev
Author:   eriktorbjorn
Date:     2008-05-29 13:32:27 -0700 (Thu, 29 May 2008)

Log Message:
-----------
Rewrote dimPalette() so that the dimming is now a "filter" between the Screen
class and the backend, i.e. as far as the game engine is concerned the palette
remains unchanged. (This is similar how to the SCUMM engine handles the "noir"
mode in Sam & Max.)

This is one small step towards allowing the game to be paused anywhere.

Modified Paths:
--------------
    scummvm/trunk/engines/sword2/palette.cpp
    scummvm/trunk/engines/sword2/screen.cpp
    scummvm/trunk/engines/sword2/screen.h
    scummvm/trunk/engines/sword2/sword2.cpp
    scummvm/trunk/engines/sword2/sword2.h

Modified: scummvm/trunk/engines/sword2/palette.cpp
===================================================================
--- scummvm/trunk/engines/sword2/palette.cpp	2008-05-29 18:18:38 UTC (rev 32368)
+++ scummvm/trunk/engines/sword2/palette.cpp	2008-05-29 20:32:27 UTC (rev 32369)
@@ -156,22 +156,17 @@
 	memcpy(&_palette[4 * startEntry], colourTable, noEntries * 4);
 
 	if (fadeNow == RDPAL_INSTANT) {
-		_vm->_system->setPalette(_palette, startEntry, noEntries);
+		setSystemPalette(_palette, startEntry, noEntries);
 		setNeedFullRedraw();
 	}
 }
 
-void Screen::dimPalette() {
-	byte *p = _palette;
-
-	for (int i = 0; i < 256; i++) {
-		p[i * 4 + 0] /= 2;
-		p[i * 4 + 1] /= 2;
-		p[i * 4 + 2] /= 2;
+void Screen::dimPalette(bool dim) {
+	if (dim != _dimPalette) {
+		_dimPalette = dim;
+		setSystemPalette(_palette, 0, 256);
+		setNeedFullRedraw();
 	}
-
-	_vm->_system->setPalette(p, 0, 256);
-	setNeedFullRedraw();
 }
 
 /**
@@ -269,8 +264,24 @@
 		}
 	}
 
-	_vm->_system->setPalette(newPalette, 0, 256);
+	setSystemPalette(newPalette, 0, 256);
 	setNeedFullRedraw();
 }
 
+void Screen::setSystemPalette(const byte *colors, uint start, uint num) {
+	const byte *palette;
+
+	if (_dimPalette) {
+		byte pal[256 * 4];
+
+		for (uint i = start * 4; i < 4 * (start + num); i++)
+			pal[i] = colors[i] / 2;
+
+		palette = pal;
+	} else
+		palette = colors;
+
+	_vm->_system->setPalette(palette, start, num);
+}
+
 } // End of namespace Sword2

Modified: scummvm/trunk/engines/sword2/screen.cpp
===================================================================
--- scummvm/trunk/engines/sword2/screen.cpp	2008-05-29 18:18:38 UTC (rev 32368)
+++ scummvm/trunk/engines/sword2/screen.cpp	2008-05-29 20:32:27 UTC (rev 32369)
@@ -97,6 +97,8 @@
 	_renderAverageTime = 60;
 
 	_layer = 0;
+
+	_dimPalette = false;
 }
 
 Screen::~Screen() {

Modified: scummvm/trunk/engines/sword2/screen.h
===================================================================
--- scummvm/trunk/engines/sword2/screen.h	2008-05-29 18:18:38 UTC (rev 32368)
+++ scummvm/trunk/engines/sword2/screen.h	2008-05-29 20:32:27 UTC (rev 32369)
@@ -350,6 +350,8 @@
 
 	uint16 _layer;
 
+	bool _dimPalette;
+
 public:
 	Screen(Sword2Engine *vm, int16 width, int16 height);
 	~Screen();
@@ -400,11 +402,12 @@
 
 	void setFullPalette(int32 palRes);
 	void setPalette(int16 startEntry, int16 noEntries, byte *palette, uint8 setNow);
+	void setSystemPalette(const byte *colors, uint start, uint num);
 	uint8 quickMatch(uint8 r, uint8 g, uint8 b);
 	int32 fadeUp(float time = 0.75);
 	int32 fadeDown(float time = 0.75);
 	uint8 getFadeStatus();
-	void dimPalette();
+	void dimPalette(bool dim);
 	void waitForFade();
 	void fadeServer();
 

Modified: scummvm/trunk/engines/sword2/sword2.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sword2.cpp	2008-05-29 18:18:38 UTC (rev 32368)
+++ scummvm/trunk/engines/sword2/sword2.cpp	2008-05-29 20:32:27 UTC (rev 32369)
@@ -225,7 +225,6 @@
 #endif
 
 	_gamePaused = false;
-	_graphicsLevelFudged = false;
 
 	_gameCycle = 0;
 	_gameSpeed = 1;
@@ -701,22 +700,14 @@
 		_sound->pauseAllSound();
 		_mouse->pauseEngine(true);
 
-		// If render level is at max, turn it down because palette-
-		// matching won't work when the palette is dimmed.
-
-		if (_screen->getRenderLevel() == 3) {
-			_screen->setRenderLevel(2);
-			_graphicsLevelFudged = true;
-		}
-
 #ifdef SWORD2_DEBUG
 		// Don't dim it if we're single-stepping through frames
 		// dim the palette during the pause
 
 		if (!_stepOneCycle)
-			_screen->dimPalette();
+			_screen->dimPalette(true);
 #else
-		_screen->dimPalette();
+		_screen->dimPalette(true);
 #endif
 
 		_gamePaused = true;
@@ -724,15 +715,8 @@
 		_mouse->pauseEngine(false);
 		_sound->unpauseAllSound();
 
-		// Put back game screen palette; see screen.cpp
-		_screen->setFullPalette(-1);
+		_screen->dimPalette(false);
 
-		// If graphics level at max, turn up again
-		if (_graphicsLevelFudged) {
-			_screen->setRenderLevel(3);
-			_graphicsLevelFudged = false;
-		}
-
 		_gamePaused = false;
 
 		// If mouse is about or we're in a chooser menu

Modified: scummvm/trunk/engines/sword2/sword2.h
===================================================================
--- scummvm/trunk/engines/sword2/sword2.h	2008-05-29 18:18:38 UTC (rev 32368)
+++ scummvm/trunk/engines/sword2/sword2.h	2008-05-29 20:32:27 UTC (rev 32369)
@@ -207,7 +207,6 @@
 	uint32 findBufferSize();
 
 	bool _gamePaused;
-	bool _graphicsLevelFudged;
 
 	void startGame();
 	void gameCycle();


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