[Scummvm-cvs-logs] SF.net SVN: scummvm: [22554] scummvm/trunk/graphics

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sun May 21 06:28:01 CEST 2006


Revision: 22554
Author:   eriktorbjorn
Date:     2006-05-21 06:27:18 -0700 (Sun, 21 May 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22554&view=rev

Log Message:
-----------
Make it so that if the new cursor palette to be set has zero colours, the
cursor palette is disabled.

Also, when replacing a cursor palette, try to re-use the old palette buffer, as
a minor optimization. (Not that these functions should need any optimization,
but it's simple and shouldn't hurt.)

Modified Paths:
--------------
    scummvm/trunk/graphics/paletteman.cpp
    scummvm/trunk/graphics/paletteman.h
Modified: scummvm/trunk/graphics/paletteman.cpp
===================================================================
--- scummvm/trunk/graphics/paletteman.cpp	2006-05-21 13:04:49 UTC (rev 22553)
+++ scummvm/trunk/graphics/paletteman.cpp	2006-05-21 13:27:18 UTC (rev 22554)
@@ -41,15 +41,13 @@
 	if (!g_system->hasFeature(OSystem::kFeatureCursorHasPalette))
 		return;
 
-	Palette *pal = new Palette;
+	Palette *pal = new Palette(colors, start, num);
+	_cursorPaletteStack.push(pal);
 
-	pal->colors = new byte[4 * num];
-	pal->start = start;
-	pal->num = num;
-	memcpy(pal->colors, colors, 4 * num);
-
-	_cursorPaletteStack.push(pal);
-	g_system->setCursorPalette(colors, start, num);
+	if (num)
+		g_system->setCursorPalette(colors, start, num);
+	else
+		g_system->disableCursorPalette(true);
 }
 
 void PaletteManager::popCursorPalette() {
@@ -70,7 +68,11 @@
 	}
 
 	pal = _cursorPaletteStack.top();
-	g_system->setCursorPalette(pal->colors, pal->start, pal->num);
+
+	if (pal->_num)
+		g_system->setCursorPalette(pal->_colors, pal->_start, pal->_num);
+	else
+		g_system->disableCursorPalette(true);
 }
 
 void PaletteManager::replaceCursorPalette(const byte *colors, uint start, uint num) {
@@ -82,16 +84,24 @@
 		return;
 	}
 
-	Palette *pal = _cursorPaletteStack.pop();
+	Palette *pal = _cursorPaletteStack.top();
 
-	delete pal->colors;
-	pal->colors = new byte[4 * num];
-	pal->start = start;
-	pal->num = num;
-	memcpy(pal->colors, colors, 4 * num);
+	if (pal->_size < 4 * num) {
+		delete pal->_colors;
+		pal->_colors = new byte[4 * num];
+	} else {
+		pal->_size = 4 * num;
+	}
 
-	_cursorPaletteStack.push(pal);
-	g_system->setCursorPalette(pal->colors, pal->start, pal->num);
+	pal->_start = start;
+	pal->_num = num;
+
+	if (num) {
+		memcpy(pal->_colors, colors, 4 * num);
+		g_system->setCursorPalette(pal->_colors, pal->_start, pal->_num);
+	} else {
+		g_system->disableCursorPalette(true);
+	}
 }
 
 } // End of namespace Graphics

Modified: scummvm/trunk/graphics/paletteman.h
===================================================================
--- scummvm/trunk/graphics/paletteman.h	2006-05-21 13:04:49 UTC (rev 22553)
+++ scummvm/trunk/graphics/paletteman.h	2006-05-21 13:27:18 UTC (rev 22554)
@@ -42,6 +42,8 @@
 	 * @param colors	the new palette data, in interleaved RGB format
 	 * @param start		the first palette entry to be updated
 	 * @param num		the number of palette entries to be updated
+	 *
+	 * @note If num is zero, the cursor palette is disabled.
 	 */
 	void pushCursorPalette(const byte *colors, uint start, uint num);
 
@@ -54,11 +56,14 @@
 
 	/**
 	 * Replace the current cursor palette on the stack. If the stack is
-	 * empty, the palette is pushed instead.
+	 * empty, the palette is pushed instead. It's a slightly more optimized
+	 * way of popping the old palette before pushing the new one.
 	 *
 	 * @param colors	the new palette data, in interleaved RGB format
 	 * @param start		the first palette entry to be updated
 	 * @param num		the number of palette entries to be updated
+	 *
+	 * @note If num is zero, the cursor palette is disabled.
 	 */
 	void replaceCursorPalette(const byte *colors, uint start, uint num);
 
@@ -67,18 +72,26 @@
 	PaletteManager();
 
 	struct Palette {
-		byte *colors;
-		uint start;
-		uint num;
+		byte *_colors;
+		uint _start;
+		uint _num;
+		uint _size;
 
-		Palette() {
-			colors = NULL;
-			start = 0;
-			num = 0;
+		Palette(const byte *colors, uint start, uint num) {
+			_start = start;
+			_num = num;
+			_size = 4 * num;
+
+			if (num) {
+				_colors = new byte[_size];
+				memcpy(_colors, colors, _size);
+			} else {
+				_colors = NULL;
+			}
 		}
 
 		~Palette() {
-			delete [] colors;
+			delete [] _colors;
 		}
 	};
 


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