aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/util.cpp27
-rw-r--r--scumm/actor.cpp2
-rw-r--r--scumm/scumm.h1
-rw-r--r--scumm/scummvm.cpp45
4 files changed, 47 insertions, 28 deletions
diff --git a/common/util.cpp b/common/util.cpp
index 86711866c9..cea9d3a8f0 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -21,9 +21,15 @@
#include "stdafx.h"
#include "util.h"
+//
// 8-bit alpha blending routines
-int BlendCache[256][256];
+//
+static int BlendCache[256][256];
+//
+// 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;
@@ -45,6 +51,9 @@ int RGBMatch(byte *palette, int r, int g, int b)
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)
{
int r, g, b;
@@ -70,6 +79,9 @@ int Blend(int src, int dst, byte *palette)
return (BlendCache[dst][src] = RGBMatch(palette, r , g , b ));
}
+//
+// Reset the blending cache
+//
void ClearBlendCache(byte *palette, int weight)
{
for (int i = 0; i < 256; i++)
@@ -80,9 +92,9 @@ void ClearBlendCache(byte *palette, int weight)
}
-/*
- * Print hexdump of the data passed in, 8 bytes a row
- */
+//
+// Print hexdump of the data passed in, 8 bytes a row
+//
void hexdump(const byte * data, int len)
{
int i;
@@ -121,7 +133,12 @@ void hexdump(const byte * data, int len)
printf("|\n");
}
-// Resource string length, supports special chars starting with FF
+//
+// Given a pointer to a Scumm resource, this function returns the length
+// of the (string) data in that resource. To do so it understands certain
+// special chars starting with FF. The reason for this function is that
+// sometimes resource data will contain 0 bytes, thus we can't just use strlen.
+//
int resStrLen(const char *src)
{
int num = 0;
diff --git a/scumm/actor.cpp b/scumm/actor.cpp
index 9790993403..6fad8ae9c1 100644
--- a/scumm/actor.cpp
+++ b/scumm/actor.cpp
@@ -258,7 +258,7 @@ int Actor::updateActorDirection(bool is_walking)
dir = remapDirection(newDirection, is_walking);
shouldInterpolate = (dir & 1024);
to = toSimpleDir(dirType, dir & 1023);
- num = numSimpleDirDirections(dirType);
+ num = dirType ? 8 : 4;
if (shouldInterpolate) {
// Turn left or right, depending on which is shorter.
diff --git a/scumm/scumm.h b/scumm/scumm.h
index 4fa6b212c8..c547a8067d 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -1384,7 +1384,6 @@ int oldDirToNewDir(int dir);
int normalizeAngle(int angle);
int fromSimpleDir(int dirtype, int dir);
int toSimpleDir(int dirtype, int dir);
-int numSimpleDirDirections(int dirType);
#endif
diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp
index 1aac72a417..499e9bab27 100644
--- a/scumm/scummvm.cpp
+++ b/scumm/scummvm.cpp
@@ -1143,15 +1143,9 @@ void Scumm::destroy()
free(_classData);
}
-const int new_dir_table[4] = {
- 270,
- 90,
- 180,
- 0,
-};
-
-const int16 many_direction_tab[16] = {71, 109, 251, 289, -1, -1, -1, -1, 22, 72, 107, 157, 202, 252, 287, 337};
-
+//
+// Convert an old style direction to a new style one (angle),
+//
int newDirToOldDir(int dir)
{
if (dir >= 71 && dir <= 109)
@@ -1163,21 +1157,24 @@ int newDirToOldDir(int dir)
return 3;
}
+//
+// Convert an new style (angle) direction to an old style one.
+//
int oldDirToNewDir(int dir)
{
+ const int new_dir_table[4] = { 270, 90, 180, 0 };
return new_dir_table[dir];
}
-
-int numSimpleDirDirections(int dirType)
-{
- return dirType ? 8 : 4;
-}
-
-
-/* Convert an angle to a simple direction */
+//
+// Convert an angle to a simple direction.
+//
int toSimpleDir(int dirType, int dir)
{
+ const int16 many_direction_tab[16] = {
+ 71, 109, 251, 289, -1, -1, -1, -1,
+ 22, 72, 107, 157, 202, 252, 287, 337
+ };
int num = dirType ? 8 : 4;
const int16 *dirtab = &many_direction_tab[dirType * 8];
for (int i = 1; i < num; i++, dirtab++) {
@@ -1188,16 +1185,22 @@ int toSimpleDir(int dirType, int dir)
}
-/* Convert a simple direction to an angle */
+//
+// Convert a simple direction to an angle
+//
int fromSimpleDir(int dirType, int dir)
{
- if (!dirType)
- return dir * 90;
- else
+ if (dirType)
return dir * 45;
+ else
+ return dir * 90;
}
+//
+// Normalize the given angle - that means, ensure it is positive, and
+// change it to the closest multiple of 45 degree by abusing toSimpleDir.
+//
int normalizeAngle(int angle)
{
int temp;