aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2003-07-02 13:47:03 +0000
committerMax Horn2003-07-02 13:47:03 +0000
commit92fd56f9f07a5cefc10f99cdec1e7f490ec2a7d6 (patch)
treeb8b6739e2639e16fa39d6b0e0f32d76f16e92877 /scumm
parent4a3da1a2b74bf9b421ab78005887b33b6191d6ba (diff)
downloadscummvm-rg350-92fd56f9f07a5cefc10f99cdec1e7f490ec2a7d6.tar.gz
scummvm-rg350-92fd56f9f07a5cefc10f99cdec1e7f490ec2a7d6.tar.bz2
scummvm-rg350-92fd56f9f07a5cefc10f99cdec1e7f490ec2a7d6.zip
removed #include "boxes.h" from scumm.h; cleaned up AdjustBoxResult definition & usage; properly deal with larger box distances, thus partially fixing Zak on the airport (but original seems to have used a very different algorithm, so this really is only a partial fix)
svn-id: r8710
Diffstat (limited to 'scumm')
-rw-r--r--scumm/actor.cpp44
-rw-r--r--scumm/actor.h5
-rw-r--r--scumm/boxes.cpp63
-rw-r--r--scumm/boxes.h9
-rw-r--r--scumm/debugger.cpp1
-rw-r--r--scumm/scumm.h6
-rw-r--r--scumm/scummvm.cpp1
7 files changed, 58 insertions, 71 deletions
diff --git a/scumm/actor.cpp b/scumm/actor.cpp
index 08e2be16f3..5dffa37654 100644
--- a/scumm/actor.cpp
+++ b/scumm/actor.cpp
@@ -24,6 +24,7 @@
#include "scumm.h"
#include "actor.h"
#include "akos.h"
+#include "boxes.h"
#include "charset.h"
#include "costume.h"
#include "resource.h"
@@ -605,17 +606,16 @@ int Actor::getActorXYPos(int &xPos, int &yPos) const {
AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
const uint thresholdTable[] = { 30, 80, 0 };
- AdjustBoxResult abr, tmp;
- uint threshold;
- uint bestDist;
- int numBoxes;
- int box;
+ AdjustBoxResult abr;
+ int16 tmpX, tmpY;
+ int tmpDist, bestDist, threshold, numBoxes;
byte flags, bestBox;
+ int box;
const int firstValidBox = (_vm->_features & GF_SMALL_HEADER) ? 0 : 1;
abr.x = dstX;
abr.y = dstY;
- abr.dist = kInvalidBox;
+ abr.box = kInvalidBox;
if (ignoreBoxes)
return abr;
@@ -627,7 +627,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
if (numBoxes < firstValidBox)
return abr;
- bestDist = (uint) 0xFFFF;
+ bestDist = 0xFFFFFF;
bestBox = kInvalidBox;
// We iterate (backwards) over all boxes, searching the one closest
@@ -642,7 +642,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
// For increased performance, we perform a quick test if
// the coordinates can even be within a distance of 'threshold'
// pixels of the box.
- if (!_vm->inBoxQuickReject(box, dstX, dstY, threshold))
+ if (threshold > 0 && _vm->inBoxQuickReject(box, dstX, dstY, threshold))
continue;
// Check if the point is contained in the box. If it is,
@@ -650,23 +650,23 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
if (_vm->checkXYInBoxBounds(box, dstX, dstY)) {
abr.x = dstX;
abr.y = dstY;
- abr.dist = box;
+ abr.box = box;
return abr;
}
// Find the point in the box which is closest to our point.
- tmp = _vm->getClosestPtOnBox(box, dstX, dstY);
+ tmpDist = _vm->getClosestPtOnBox(box, dstX, dstY, tmpX, tmpY);
// Check if the box is closer than the previous boxes.
- if (tmp.dist < bestDist) {
- abr.x = tmp.x;
- abr.y = tmp.y;
+ if (tmpDist < bestDist) {
+ abr.x = tmpX;
+ abr.y = tmpY;
- if (tmp.dist == 0) {
- abr.dist = box;
+ if (tmpDist == 0) {
+ abr.box = box;
return abr;
}
- bestDist = tmp.dist;
+ bestDist = tmpDist;
bestBox = box;
}
}
@@ -674,7 +674,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
// If the closest ('best') box we found is within the threshold, or if
// we are on the last run (i.e. threshold == 0), return that box.
if (threshold == 0 || threshold * threshold >= bestDist) {
- abr.dist = bestBox;
+ abr.box = bestBox;
return abr;
}
}
@@ -689,9 +689,9 @@ void Actor::adjustActorPos() {
x = abr.x;
y = abr.y;
- walkdata.destbox = (byte)abr.dist;
+ walkdata.destbox = abr.box;
- setBox(abr.dist);
+ setBox(abr.box);
walkdata.destx = -1;
@@ -1175,11 +1175,11 @@ void Actor::startWalkActor(int destX, int destY, int dir) {
}
if (ignoreBoxes) {
- abr.dist = kInvalidBox;
+ abr.box = kInvalidBox;
walkbox = kInvalidBox;
} else {
if (_vm->checkXYInBoxBounds(walkdata.destbox, abr.x, abr.y)) {
- abr.dist = walkdata.destbox;
+ abr.box = walkdata.destbox;
} else {
abr = adjustXYToBeInBox(abr.x, abr.y);
}
@@ -1194,7 +1194,7 @@ void Actor::startWalkActor(int destX, int destY, int dir) {
walkdata.destx = abr.x;
walkdata.desty = abr.y;
- walkdata.destbox = (byte)abr.dist; /* a box */
+ walkdata.destbox = abr.box;
walkdata.destdir = dir;
moving = (moving & MF_IN_LEG) | MF_NEW_LEG;
walkdata.point3x = 32000;
diff --git a/scumm/actor.h b/scumm/actor.h
index 7c856c0bd0..6071d301e0 100644
--- a/scumm/actor.h
+++ b/scumm/actor.h
@@ -67,6 +67,11 @@ struct CostumeData {
}
};
+struct AdjustBoxResult { /* Result type of AdjustBox functions */
+ int16 x, y;
+ byte box;
+};
+
struct SaveLoadEntry;
class Actor {
diff --git a/scumm/boxes.cpp b/scumm/boxes.cpp
index 2597a56276..6e430b9d85 100644
--- a/scumm/boxes.cpp
+++ b/scumm/boxes.cpp
@@ -23,6 +23,7 @@
#include "stdafx.h"
#include "scumm.h"
#include "actor.h"
+#include "boxes.h"
#include "common/util.h"
#include <math.h>
@@ -382,13 +383,13 @@ uint Scumm::distanceFromPt(int x, int y, int ptx, int pty) {
diffx = abs(ptx - x);
- if (diffx >= 0x100)
- return 0xFFFF;
+ if (diffx >= 0x1000)
+ return 0xFFFFFF;
diffy = abs(pty - y);
- if (diffy >= 0x100)
- return 0xFFFF;
+ if (diffy >= 0x1000)
+ return 0xFFFFFF;
diffx *= diffx;
diffy *= diffy;
return diffx + diffy;
@@ -484,33 +485,29 @@ bool Scumm::inBoxQuickReject(int b, int x, int y, int threshold) {
getBoxCoordinates(b, &box);
- if (threshold == 0)
- return true;
-
t = x - threshold;
if (t > box.ul.x && t > box.ur.x && t > box.lr.x && t > box.ll.x)
- return false;
+ return true;
t = x + threshold;
if (t < box.ul.x && t < box.ur.x && t < box.lr.x && t < box.ll.x)
- return false;
+ return true;
t = y - threshold;
if (t > box.ul.y && t > box.ur.y && t > box.lr.y && t > box.ll.y)
- return false;
+ return true;
t = y + threshold;
if (t < box.ul.y && t < box.ur.y && t < box.lr.y && t < box.ll.y)
- return false;
+ return true;
- return true;
+ return false;
}
-AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
+int Scumm::getClosestPtOnBox(int b, int x, int y, int16& outX, int16& outY) {
ScummVM::Point pt;
- AdjustBoxResult best;
uint dist;
- uint bestdist = (uint)0xFFFF;
+ uint bestdist = 0xFFFFFF;
BoxCoords box;
getBoxCoordinates(b, &box);
@@ -519,36 +516,35 @@ AdjustBoxResult Scumm::getClosestPtOnBox(int b, int x, int y) {
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
- best.x = pt.x;
- best.y = pt.y;
+ outX = pt.x;
+ outY = pt.y;
}
pt = closestPtOnLine(box.ur.x, box.ur.y, box.lr.x, box.lr.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
- best.x = pt.x;
- best.y = pt.y;
+ outX = pt.x;
+ outY = pt.y;
}
pt = closestPtOnLine(box.lr.x, box.lr.y, box.ll.x, box.ll.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
- best.x = pt.x;
- best.y = pt.y;
+ outX = pt.x;
+ outY = pt.y;
}
pt = closestPtOnLine(box.ll.x, box.ll.y, box.ul.x, box.ul.y, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
if (dist < bestdist) {
bestdist = dist;
- best.x = pt.x;
- best.y = pt.y;
+ outX = pt.x;
+ outY = pt.y;
}
- best.dist = bestdist;
- return best;
+ return bestdist;
}
byte *Scumm::getBoxMatrixBaseAddr() {
@@ -1036,10 +1032,9 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
BoxCoords coords;
ScummVM::Point Clo[8];
ScummVM::Point poly[8];
- AdjustBoxResult abr;
int line1, line2;
- // For all corner coordinates of the first box, compute the point cloest
+ // For all corner coordinates of the first box, compute the point closest
// to them on the second box (and also compute the distance of these points).
getBoxCoordinates(trap1, &coords);
poly[0] = coords.ul;
@@ -1047,10 +1042,7 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
poly[2] = coords.lr;
poly[3] = coords.ll;
for (i = 0; i < 4; i++) {
- abr = getClosestPtOnBox(trap2, poly[i].x, poly[i].y);
- dist[i] = abr.dist;
- Clo[i].x = abr.x;
- Clo[i].y = abr.y;
+ dist[i] = getClosestPtOnBox(trap2, poly[i].x, poly[i].y, Clo[i].x, Clo[i].y);
}
// Now do the same but with the roles of the first and second box swapped.
@@ -1060,10 +1052,7 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
poly[6] = coords.lr;
poly[7] = coords.ll;
for (i = 4; i < 8; i++) {
- abr = getClosestPtOnBox(trap1, poly[i].x, poly[i].y);
- dist[i] = abr.dist;
- Clo[i].x = abr.x;
- Clo[i].y = abr.y;
+ dist[i] = getClosestPtOnBox(trap1, poly[i].x, poly[i].y, Clo[i].x, Clo[i].y);
}
// Find the three closest "close" points between the two boxes.
@@ -1077,7 +1066,7 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
}
dist[closest[j]] = 0xFFFF;
minDist[j] = (int)sqrt((double)minDist[j]);
- box[j] = (closest[j] > 3); // Is the poin on the first or on the second box?
+ box[j] = (closest[j] > 3); // Is the point on the first or on the second box?
}
@@ -1117,7 +1106,6 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
if (line1 < 4) { /* from box 1 to box 2 */
gateA[0] = poly[line1];
gateA[1] = Clo[line1];
-
} else {
gateA[1] = poly[line1];
gateA[0] = Clo[line1];
@@ -1126,7 +1114,6 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
if (line2 < 4) { /* from box */
gateB[0] = poly[line2];
gateB[1] = Clo[line2];
-
} else {
gateB[1] = poly[line2];
gateB[0] = Clo[line2];
diff --git a/scumm/boxes.h b/scumm/boxes.h
index 1fffd7f285..583c3cc889 100644
--- a/scumm/boxes.h
+++ b/scumm/boxes.h
@@ -38,11 +38,6 @@ typedef enum {
kBoxInvisible = 0x80
} BoxFlags;
-struct AdjustBoxResult { /* Result type of AdjustBox functions */
- int16 x, y;
- uint16 dist;
-};
-
struct BoxCoords { /* Box coordinates */
ScummVM::Point ul;
ScummVM::Point ur;
@@ -50,8 +45,4 @@ struct BoxCoords { /* Box coordinates */
ScummVM::Point lr;
};
-struct Box;
-struct PathNode;
-struct PathVertex;
-
#endif
diff --git a/scumm/debugger.cpp b/scumm/debugger.cpp
index dd8415d866..74d3aef13c 100644
--- a/scumm/debugger.cpp
+++ b/scumm/debugger.cpp
@@ -22,6 +22,7 @@
#include "scumm.h"
#include "sound.h"
#include "actor.h"
+#include "boxes.h"
#include "imuse.h"
#include "debugger.h"
#include "common/util.h"
diff --git a/scumm/scumm.h b/scumm/scumm.h
index a86899d091..77a9c3f81c 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -30,7 +30,6 @@
#include "common/str.h"
#include "gfx.h"
-#include "boxes.h"
class Actor;
class BaseCostumeRenderer;
@@ -46,6 +45,9 @@ class Scumm;
class ScummDebugger;
class Serializer;
class Sound;
+
+struct Box;
+struct BoxCoords;
struct FindObjectInRoom;
typedef ScummVM::Map<ScummVM::String, int> ObjectIDMap;
@@ -1012,7 +1014,7 @@ public:
int getPathToDestBox(byte from, byte to);
void getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Point gateB[2]);
bool inBoxQuickReject(int box, int x, int y, int threshold);
- AdjustBoxResult getClosestPtOnBox(int box, int x, int y);
+ int getClosestPtOnBox(int box, int x, int y, int16& outX, int16& outY);
int getSpecialBox(int param1, int param2);
void setBoxFlags(int box, int val);
diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp
index 3aaab63e9a..a663efa91a 100644
--- a/scumm/scummvm.cpp
+++ b/scumm/scummvm.cpp
@@ -23,6 +23,7 @@
#include "stdafx.h"
#include "scumm.h"
#include "actor.h"
+#include "boxes.h"
#include "charset.h"
#include "debugger.h"
#include "dialogs.h"