aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2003-10-04 11:50:21 +0000
committerMax Horn2003-10-04 11:50:21 +0000
commitd4734bd4f2963168f794691a618869ba4e558aaa (patch)
tree6881cb61298534a4966533289bb81a2f0332a4c3 /common
parent91da08e1f3f836442c9c2ff39a9d1570f49df24d (diff)
downloadscummvm-rg350-d4734bd4f2963168f794691a618869ba4e558aaa.tar.gz
scummvm-rg350-d4734bd4f2963168f794691a618869ba4e558aaa.tar.bz2
scummvm-rg350-d4734bd4f2963168f794691a618869ba4e558aaa.zip
use namespace Common a bit more; don't zero the RNG in scumm (else the seed gets reset); remove obsolete 256 color blending code
svn-id: r10592
Diffstat (limited to 'common')
-rw-r--r--common/timer.cpp8
-rw-r--r--common/util.cpp95
-rw-r--r--common/util.h16
3 files changed, 24 insertions, 95 deletions
diff --git a/common/timer.cpp b/common/timer.cpp
index cc8bf00efc..c6a139bd54 100644
--- a/common/timer.cpp
+++ b/common/timer.cpp
@@ -54,7 +54,7 @@ Timer::~Timer() {
_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::timer_handler(int t) {
}
int Timer::handler(int t) {
- StackLock lock(_mutex);
+ Common::StackLock lock(_mutex);
uint32 interval, l;
_lastTime = _thisTime;
@@ -102,7 +102,7 @@ int Timer::handler(int t) {
}
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 @@ bool Timer::installProcedure(TimerProc procedure, int32 interval, void *refCon)
}
void Timer::releaseProcedure(TimerProc procedure) {
- StackLock lock(_mutex);
+ Common::StackLock lock(_mutex);
int32 l;
for (l = 0; l < MAX_TIMERS; l++) {
diff --git a/common/util.cpp b/common/util.cpp
index 7732372dbb..5c85e74c70 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -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 @@ void hexdump(const byte * data, int len, int bytes_per_line) {
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 @@ void hexdump(const byte * data, int len, int bytes_per_line) {
c = '.';
printf("%c", c);
}
- for (; i < bytes_per_line; i++)
+ for (; i < bytesPerLine; i++)
printf(" ");
printf("|\n");
}
@@ -187,3 +115,4 @@ void StackLock::unlock() {
_syst->unlock_mutex(_mutex);
}
+} // End of namespace Common
diff --git a/common/util.h b/common/util.h
index 14ab36f4b0..a62511d6da 100644
--- a/common/util.h
+++ b/common/util.h
@@ -35,22 +35,20 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
#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:
@@ -88,6 +86,8 @@ public:
~StackLock();
};
+} // End of namespace Common
+
#if defined(__GNUC__)