[Scummvm-cvs-logs] CVS: scummvm/sword2/driver animation.cpp,1.41,1.42 d_draw.h,1.31,1.32 palette.cpp,1.31,1.32 render.cpp,1.63,1.64 sprite.cpp,1.43,1.44

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Tue Jun 8 23:34:06 CEST 2004


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20377/driver

Modified Files:
	animation.cpp d_draw.h palette.cpp render.cpp sprite.cpp 
Log Message:
Cleaned up the palette handling a bit. Renamed _palCopy to _palette since I
found the old name misleading (there is only one array that stores the
palette in the engine, though it could be argued that it's a copy of the
one used by the backend), and removed some code that I'm almost certain was
never used. (I've added assert()s to trigger in the cases where it would
have been used.)


Index: animation.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/animation.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- animation.cpp	9 May 2004 13:32:04 -0000	1.41
+++ animation.cpp	9 Jun 2004 06:33:28 -0000	1.42
@@ -178,8 +178,8 @@
 	uint32 flags = SoundMixer::FLAG_16BITS;
 	bool startNextText = false;
 
-	byte oldPal[1024];
-	memcpy(oldPal, _vm->_graphics->_palCopy, 1024);
+	byte oldPal[256 * 4];
+	memcpy(oldPal, _vm->_graphics->_palette, sizeof(oldPal));
 
 	AnimationState *anim = new AnimationState(_vm);
 
@@ -345,8 +345,8 @@
 int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], byte *musicOut) {
 	int frameCounter = 0, textCounter = 0;
 	if (text) {
-		byte oldPal[1024];
-		byte tmpPal[1024];
+		byte oldPal[256 * 4];
+		byte tmpPal[256 * 4];
 
 		_vm->_graphics->clearScene();
 
@@ -384,8 +384,8 @@
 		// In the opening cutscene it seems to use colours 1 (black?)
 		// and 255 (white?).
 
-		memcpy(oldPal, _vm->_graphics->_palCopy, 1024);
-		memset(tmpPal, 0, 1024);
+		memcpy(oldPal, _vm->_graphics->_palette, sizeof(oldPal));
+		memset(tmpPal, 0, sizeof(tmpPal));
 		tmpPal[255 * 4 + 0] = 255;
 		tmpPal[255 * 4 + 1] = 255;
 		tmpPal[255 * 4 + 2] = 255;

Index: d_draw.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_draw.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- d_draw.h	6 Jun 2004 15:40:31 -0000	1.31
+++ d_draw.h	9 Jun 2004 06:33:28 -0000	1.32
@@ -93,7 +93,6 @@
 
 	byte _paletteMatch[PALTABLESIZE];
 
-	byte _fadePalette[256][4];
 	uint8 _fadeStatus;
 
 	int32 _fadeStartTime;
@@ -150,7 +149,6 @@
 
 	void decompressMouse(byte *decomp, byte *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0);
 
-	uint8 getMatch(uint8 r, uint8 g, uint8 b);
 	void fadeServer(void);
 
 	void scaleImageFast(byte *dst, uint16 dstPitch, uint16 dstWidth,
@@ -178,7 +176,7 @@
 	int16 _screenWide;
 	int16 _screenDeep;
 
-	byte _palCopy[256][4];
+	byte _palette[256 * 4];
 
 	byte *getScreen(void) { return _buffer; }
 

Index: palette.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/palette.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- palette.cpp	23 Apr 2004 07:02:10 -0000	1.31
+++ palette.cpp	9 Jun 2004 06:33:28 -0000	1.32
@@ -23,68 +23,15 @@
 
 namespace Sword2 {
 
-uint8 Graphics::getMatch(uint8 r, uint8 g, uint8 b) {
-	int32 diff;
-	int32 min;
-	int16 diffred, diffgreen, diffblue;
-	int16 i;
-	uint8 minIndex;
-
-	diffred = _palCopy[0][0] - r;
-	diffgreen = _palCopy[0][1] - g;
-	diffblue = _palCopy[0][2] - b;
-
-	diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue;
-	min = diff;
-	minIndex = 0;
-	if (diff > 0) {
-		for (i = 1; i < 256; i++) {
-			diffred = _palCopy[i][0] - r;
-			diffgreen = _palCopy[i][1] - g;
-			diffblue = _palCopy[i][2] - b;
-
-			diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue;
-			if (diff < min) {
-				min = diff;
-				minIndex = (uint8) i;
-				if (min == 0)
-					break;
-			}
-		}
-	}
-
-	// Here, minIndex is the index of the matchpalette which is closest.
-	return minIndex;
-}
-
 /**
- * Sets or creates a table of palette indices which will be searched later for
- * a quick palette match.
- * @param data either the palette match table, or NULL to create a new table
- * from the current palCopy
+ * Sets a table of palette indices which will be searched later for a quick
+ * palette match.
+ * @param data the palette match table
  */
 
 void Graphics::updatePaletteMatchTable(byte *data) {
-	if (!data) {
-		int16 red, green, blue;
-		byte *p;
-
-		// Create palette match table
-
-		// FIXME: Does this case ever happen?
-
-		p = &_paletteMatch[0];
-		for (red = 0; red < 256; red += 4) {
-			for (green = 0; green < 256; green += 4) {
-				for (blue = 0; blue < 256; blue += 4) {
-					*p++ = getMatch((uint8) red, (uint8) green, (uint8) blue);
-				}
-			}
-		}
-	} else {
-		// The provided data is the new palette match table
-		memcpy(_paletteMatch, data, PALTABLESIZE);
-	}
+	assert(data);
+	memcpy(_paletteMatch, data, PALTABLESIZE);
 }
 
 /**
@@ -110,23 +57,24 @@
  */
 
 void Graphics::setPalette(int16 startEntry, int16 noEntries, byte *colourTable, uint8 fadeNow) {
-	if (noEntries) {
-		memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4);
-		if (fadeNow == RDPAL_INSTANT) {
-			_vm->_system->setPalette((const byte *) _palCopy, startEntry, noEntries);
-			setNeedFullRedraw();
-		}
-	} else {
-		_vm->_system->setPalette((const byte *) _palCopy, 0, 256);
+	assert(noEntries > 0);
+
+	memcpy(&_palette[4 * startEntry], colourTable, noEntries * 4);
+
+	if (fadeNow == RDPAL_INSTANT) {
+		_vm->_system->setPalette(_palette, startEntry, noEntries);
 		setNeedFullRedraw();
 	}
 }
 
 void Graphics::dimPalette(void) {
-	byte *p = (byte *) _palCopy;
+	byte *p = _palette;
 
-	for (int i = 0; i < 256 * 4; i++)
-		p[i] /= 2;
+	for (int i = 0; i < 256; i++) {
+		p[i * 4 + 0] /= 2;
+		p[i * 4 + 1] /= 2;
+		p[i * 4 + 2] /= 2;
+	}
 
 	_vm->_system->setPalette(p, 0, 256);
 	setNeedFullRedraw();
@@ -183,15 +131,12 @@
 
 void Graphics::fadeServer(void) {
 	static int32 previousTime = 0;
-	const byte *newPalette = (const byte *) _fadePalette;
+	byte fadePalette[256 * 4];
+	byte *newPalette = fadePalette;
 	int32 currentTime;
 	int16 fadeMultiplier;
 	int16 i;
 
-	// This used to be called through a timer, but is now called from
-	// ServiceWindows() instead, since that's the only place where we
-	// actually update the screen.
-
 	// If we're not in the process of fading, do nothing.
 	if (getFadeStatus() != RDFADE_UP && getFadeStatus() != RDFADE_DOWN)
 		return;
@@ -207,25 +152,25 @@
 	if (getFadeStatus() == RDFADE_UP) {
 		if (currentTime >= _fadeStartTime + _fadeTotalTime) {
 			_fadeStatus = RDFADE_NONE;
-			newPalette = (const byte *) _palCopy;
+			newPalette = _palette;
 		} else {
 			fadeMultiplier = (int16) (((int32) (currentTime - _fadeStartTime) * 256) / _fadeTotalTime);
 			for (i = 0; i < 256; i++) {
-				_fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8;
-				_fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8;
-				_fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 2] = (_palette[i * 4 + 2] * fadeMultiplier) >> 8;
 			}
 		}
 	} else {
 		if (currentTime >= _fadeStartTime + _fadeTotalTime) {
 			_fadeStatus = RDFADE_BLACK;
-			memset(_fadePalette, 0, sizeof(_fadePalette));
+			memset(newPalette, 0, sizeof(fadePalette));
 		} else {
 			fadeMultiplier = (int16) (((int32) (_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime);
 			for (i = 0; i < 256; i++) {
-				_fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8;
-				_fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8;
-				_fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8;
+				newPalette[i * 4 + 2] = (_palette[i * 4 + 2] * fadeMultiplier) >> 8;
 			}
 		}
 	}

Index: render.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/render.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- render.cpp	6 Jun 2004 15:40:31 -0000	1.63
+++ render.cpp	9 Jun 2004 06:33:28 -0000	1.64
@@ -152,21 +152,21 @@
 				c4 = c3;
 
 			if (!transparent) {
-				uint32 r1 = _palCopy[c1][0];
-				uint32 g1 = _palCopy[c1][1];
-				uint32 b1 = _palCopy[c1][2];
+				uint32 r1 = _palette[c1 * 4 + 0];
+				uint32 g1 = _palette[c1 * 4 + 1];
+				uint32 b1 = _palette[c1 * 4 + 2];
 
-				uint32 r2 = _palCopy[c2][0];
-				uint32 g2 = _palCopy[c2][1];
-				uint32 b2 = _palCopy[c2][2];
+				uint32 r2 = _palette[c2 * 4 + 0];
+				uint32 g2 = _palette[c2 * 4 + 1];
+				uint32 b2 = _palette[c2 * 4 + 2];
 
-				uint32 r3 = _palCopy[c3][0];
-				uint32 g3 = _palCopy[c3][1];
-				uint32 b3 = _palCopy[c3][2];
+				uint32 r3 = _palette[c3 * 4 + 0];
+				uint32 g3 = _palette[c3 * 4 + 1];
+				uint32 b3 = _palette[c3 * 4 + 2];
 
-				uint32 r4 = _palCopy[c4][0];
-				uint32 g4 = _palCopy[c4][1];
-				uint32 b4 = _palCopy[c4][2];
+				uint32 r4 = _palette[c4 * 4 + 0];
+				uint32 g4 = _palette[c4 * 4 + 1];
+				uint32 b4 = _palette[c4 * 4 + 2];
 
 				uint32 r5 = (r1 * xFrac + r2 * (dstWidth - xFrac)) / dstWidth;
 				uint32 g5 = (g1 * xFrac + g2 * (dstWidth - xFrac)) / dstWidth;

Index: sprite.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/sprite.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- sprite.cpp	7 Jun 2004 05:57:00 -0000	1.43
+++ sprite.cpp	9 Jun 2004 06:33:29 -0000	1.44
@@ -522,9 +522,9 @@
 		for (i = 0; i < rs.height(); i++) {
 			for (j = 0; j < rs.width(); j++) {
 				if (src[j] && lightMap[j]) {
-					uint8 r = ((32 - lightMap[j]) * _palCopy[src[j]][0]) >> 5;
-					uint8 g = ((32 - lightMap[j]) * _palCopy[src[j]][1]) >> 5;
-					uint8 b = ((32 - lightMap[j]) * _palCopy[src[j]][2]) >> 5;
+					uint8 r = ((32 - lightMap[j]) * _palette[src[j] * 4 + 0]) >> 5;
+					uint8 g = ((32 - lightMap[j]) * _palette[src[j] * 4 + 1]) >> 5;
+					uint8 b = ((32 - lightMap[j]) * _palette[src[j] * 4 + 2]) >> 5;
 					src[j] = quickMatch(r, g, b);
 				}
 			}
@@ -562,12 +562,12 @@
 			for (i = 0; i < rs.height(); i++) {
 				for (j = 0; j < rs.width(); j++) {
 					if (src[j]) {
-						uint8 r1 = _palCopy[src[j]][0];
-						uint8 g1 = _palCopy[src[j]][1];
-						uint8 b1 = _palCopy[src[j]][2];
-						uint8 r2 = _palCopy[dst[j]][0];
-						uint8 g2 = _palCopy[dst[j]][1];
-						uint8 b2 = _palCopy[dst[j]][2];
+						uint8 r1 = _palette[src[j] * 4 + 0];
+						uint8 g1 = _palette[src[j] * 4 + 1];
+						uint8 b1 = _palette[src[j] * 4 + 2];
+						uint8 r2 = _palette[dst[j] * 4 + 0];
+						uint8 g2 = _palette[dst[j] * 4 + 1];
+						uint8 b2 = _palette[dst[j] * 4 + 2];
 
 						uint8 r = (r1 * n + r2 * (8 - n)) >> 3;
 						uint8 g = (g1 * n + g2 * (8 - n)) >> 3;





More information about the Scummvm-git-logs mailing list