[Scummvm-cvs-logs] CVS: scummvm/common util.h,1.24,1.25 util.cpp,1.19,1.20 timer.cpp,1.17,1.18

Max Horn fingolfin at users.sourceforge.net
Sat Oct 4 04:51:04 CEST 2003


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv25712/common

Modified Files:
	util.h util.cpp timer.cpp 
Log Message:
use namespace Common a bit more; don't zero the RNG in scumm (else the seed gets reset); remove obsolete 256 color blending code

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- util.h	10 Sep 2003 12:15:12 -0000	1.24
+++ util.h	4 Oct 2003 11:50:20 -0000	1.25
@@ -35,22 +35,20 @@
 
 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
 
-int RGBMatch(byte *palette, int r, int g, int b);
-int Blend(int src, int dst, byte *palette);
-void ClearBlendCache();
+namespace Common {
 
 /**
- * Print a hexdump of the data passed in. The number of bytes per line
- * is customizable.
+ * Print a hexdump of the data passed in. The number of bytes per line is
+ * customizable.
  * @param data	the data to be dumped
  * @param len	the lenght of that data
  * @param bytes_per_line	number of bytes to print per line (default: 16)
  */
-void hexdump(const byte * data, int len, int bytes_per_line = 16);
+void hexdump(const byte * data, int len, int bytesPerLine = 16);
 
 /**
- * A simple random number generator. Although it is definitely not suitable
- * for cryptographic purposes, it serves our purposes just fine.
+ * Simple random number generator. Although it is definitely not suitable for
+ * cryptographic purposes, it serves our purposes just fine.
  */
 class RandomSource {
 private:
@@ -87,6 +85,8 @@
 	StackLock(OSystem::MutexRef mutex, OSystem *syst = 0);
 	~StackLock();
 };
+
+}	// End of namespace Common
 
 
 

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- util.cpp	18 Sep 2003 02:07:17 -0000	1.19
+++ util.cpp	4 Oct 2003 11:50:20 -0000	1.20
@@ -22,106 +22,34 @@
 #include "base/engine.h"
 #include "common/util.h"
 
-//
-// 8-bit alpha blending routines
-//
-#ifndef NEWGUI_256
-static int BlendCache[256][256];
-#endif
-//
-// Find the entry in the given palette which matches the color defined by
-// the tripel (r,b,g) most closely.
-//
-int RGBMatch(byte *palette, int r, int g, int b) {
-	int i, bestidx = 0, besterr = 0xFFFFFF;
-	int error = 0;
-
-	for (i = 0;i < 256;i++) {
-		byte *pal = palette + (i * 3);
-		int r_diff = r - (int)*pal++; 
-		int g_diff = g - (int)*pal++; 
-		int b_diff = b - (int)*pal++; 
-		r_diff *= r_diff; g_diff *= g_diff; b_diff *= b_diff;
-
-		error = r_diff + g_diff + b_diff;
-		if (error < besterr) {
-			besterr = error;
-			bestidx = i;
-		}
-	}
-	return bestidx;
-}
-
-//
-// Blend two 8 bit colors into a third, all colors being defined by palette indices.
-//
-int Blend(int src, int dst, byte *palette) {
-#ifndef NEWGUI_256
-	int r, g, b;
-	int alpha = 128;	// Level of transparency [0-256]
-	byte *srcpal = palette + (dst * 3);
-	byte *dstpal = palette + (src * 3);
-
-	if (BlendCache[dst][src] > -1)
-		return BlendCache[dst][src];
-
-	r =  (*srcpal++ * alpha);
-	r += (*dstpal++ * (256 - alpha));
-	r /= 256;
-
-	g =  (*srcpal++ * alpha);
-	g += (*dstpal++ * (256 - alpha));
-	g /= 256;
-
-	b =  (*srcpal++ * alpha);
-	b += (*dstpal++  * (256 - alpha));
-	b /= 256;
-
-	return (BlendCache[dst][src] = RGBMatch(palette, r , g , b ));
-#else
-	return 0;
-#endif
-}
-
-//
-// Reset the blending cache
-//
-void ClearBlendCache() {
-#ifndef NEWGUI_256
-	for (int i = 0; i < 256; i++)
-		for (int j = 0 ; j < 256 ; j++)
-//			BlendCache[i][j] = i;	// No alphablending
-//			BlendCache[i][j] = j;	// 100% translucent
-			BlendCache[i][j] = -1;	// Enable alphablending
-#endif
-}
+namespace Common {
 
 //
 // Print hexdump of the data passed in
 //
-void hexdump(const byte * data, int len, int bytes_per_line) {
-	assert(1 <= bytes_per_line && bytes_per_line <= 32);
+void hexdump(const byte * data, int len, int bytesPerLine) {
+	assert(1 <= bytesPerLine && bytesPerLine <= 32);
 	int i;
 	byte c;
 	int offset = 0;
-	while (len >= bytes_per_line) {
+	while (len >= bytesPerLine) {
 		printf("%06x: ", offset);
-		for (i = 0; i < bytes_per_line; i++) {
+		for (i = 0; i < bytesPerLine; i++) {
 			printf("%02x ", data[i]);
 			if (i % 4 == 3)
 				printf(" ");
 		}
 		printf(" |");
-		for (i = 0; i < bytes_per_line; i++) {
+		for (i = 0; i < bytesPerLine; i++) {
 			c = data[i];
 			if (c < 32 || c >= 127)
 				c = '.';
 			printf("%c", c);
 		}
 		printf("|\n");
-		data += bytes_per_line;
-		len -= bytes_per_line;
-		offset += bytes_per_line;
+		data += bytesPerLine;
+		len -= bytesPerLine;
+		offset += bytesPerLine;
 	}
 
 	if (len <= 0) 
@@ -133,7 +61,7 @@
 		if (i % 4 == 3)
 			printf(" ");
 	}
-	for (; i < bytes_per_line; i++)
+	for (; i < bytesPerLine; i++)
 		printf("   ");
 	printf(" |");
 	for (i = 0; i < len; i++) {
@@ -142,7 +70,7 @@
 			c = '.';
 		printf("%c", c);
 	}
-	for (; i < bytes_per_line; i++)
+	for (; i < bytesPerLine; i++)
 		printf(" ");
 	printf("|\n");
 }
@@ -187,3 +115,4 @@
 	_syst->unlock_mutex(_mutex);
 }
 
+}	// End of namespace Common

Index: timer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/timer.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- timer.cpp	28 Sep 2003 21:08:47 -0000	1.17
+++ timer.cpp	4 Oct 2003 11:50:20 -0000	1.18
@@ -54,7 +54,7 @@
 	_system->set_timer(0, 0);
 
 	{
-		StackLock lock(_mutex);
+		Common::StackLock lock(_mutex);
 		for (int i = 0; i < MAX_TIMERS; i++) {
 			_timerSlots[i].procedure = NULL;
 			_timerSlots[i].interval = 0;
@@ -81,7 +81,7 @@
 }
 
 int Timer::handler(int t) {
-	StackLock lock(_mutex);
+	Common::StackLock lock(_mutex);
 	uint32 interval, l;
 
 	_lastTime = _thisTime;
@@ -102,7 +102,7 @@
 }
 
 bool Timer::installProcedure(TimerProc procedure, int32 interval, void *refCon) {
-	StackLock lock(_mutex);
+	Common::StackLock lock(_mutex);
 	int32 l;
 	bool found = false;
 
@@ -124,7 +124,7 @@
 }
 
 void Timer::releaseProcedure(TimerProc procedure) {
-	StackLock lock(_mutex);
+	Common::StackLock lock(_mutex);
 	int32 l;
 
 	for (l = 0; l < MAX_TIMERS; l++) {





More information about the Scummvm-git-logs mailing list