SCUMM: walbox related cleanup

svn-id: r24365
This commit is contained in:
Max Horn 2006-10-18 13:33:42 +00:00
parent ef4e68a8f5
commit dd7e4ff3e7
7 changed files with 41 additions and 47 deletions

View File

@ -702,7 +702,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 (threshold > 0 && _vm->inBoxQuickReject(box, dstX, dstY, threshold))
if (threshold > 0 && inBoxQuickReject(_vm->getBoxCoordinates(box), dstX, dstY, threshold))
continue;
// Check if the point is contained in the box. If it is,
@ -715,7 +715,7 @@ AdjustBoxResult Actor::adjustXYToBeInBox(int dstX, int dstY) {
}
// Find the point in the box which is closest to our point.
tmpDist = _vm->getClosestPtOnBox(box, dstX, dstY, tmpX, tmpY);
tmpDist = getClosestPtOnBox(_vm->getBoxCoordinates(box), dstX, dstY, tmpX, tmpY);
// Check if the box is closer than the previous boxes.
if (tmpDist < bestDist) {
@ -1812,8 +1812,8 @@ void Actor::walkActorV12() {
_walkdata.curbox = next_box;
_vm->getClosestPtOnBox(_walkdata.curbox, x, y, tmp.x, tmp.y);
_vm->getClosestPtOnBox(_walkbox, tmp.x, tmp.y, foundPath.x, foundPath.y);
getClosestPtOnBox(_vm->getBoxCoordinates(_walkdata.curbox), x, y, tmp.x, tmp.y);
getClosestPtOnBox(_vm->getBoxCoordinates(_walkbox), tmp.x, tmp.y, foundPath.x, foundPath.y);
}
calcMovementFactor(foundPath);
}
@ -1896,8 +1896,8 @@ void Actor::walkActorOld() {
_walkdata.curbox = next_box;
if (_vm->_game.version <= 2) {
_vm->getClosestPtOnBox(_walkdata.curbox, _pos.x, _pos.y, p2.x, p2.y);
_vm->getClosestPtOnBox(_walkbox, p2.x, p2.y, p3.x, p3.y);
getClosestPtOnBox(_vm->getBoxCoordinates(_walkdata.curbox), _pos.x, _pos.y, p2.x, p2.y);
getClosestPtOnBox(_vm->getBoxCoordinates(_walkbox), p2.x, p2.y, p3.x, p3.y);
// FIXME: Work in progress
// calcMovementFactor(p3);
// return;

View File

@ -25,6 +25,7 @@
#include "scumm/scumm.h"
#include "scumm/actor.h"
#include "scumm/boxes.h"
#include "scumm/intern.h"
#include "scumm/util.h"
#include "common/util.h"
@ -87,6 +88,7 @@ struct Box { /* Internal walkbox file format */
static bool compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3);
static Common::Point closestPtOnLine(const Common::Point &start, const Common::Point &end, int x, int y);
static uint distanceFromPt(int x, int y, int ptx, int pty);
byte ScummEngine::getMaskFromBox(int box) {
@ -416,7 +418,7 @@ Box *ScummEngine::getBoxBaseAddr(int box) {
return (Box *)(ptr + box * SIZEOF_BOX + 2);
}
int ScummEngine::getSpecialBox(int x, int y) {
int ScummEngine_v6::getSpecialBox(int x, int y) {
int i;
int numOfBoxes;
byte flag;
@ -442,7 +444,7 @@ bool ScummEngine::checkXYInBoxBounds(int b, int x, int y) {
if (b < 0 || b == Actor::kInvalidBox)
return false;
getBoxCoordinates(b, &box);
box = getBoxCoordinates(b);
if (x < box.ul.x && x < box.ur.x && x < box.lr.x && x < box.ll.x)
return false;
@ -480,7 +482,8 @@ bool ScummEngine::checkXYInBoxBounds(int b, int x, int y) {
return true;
}
void ScummEngine::getBoxCoordinates(int boxnum, BoxCoords *box) {
BoxCoords ScummEngine::getBoxCoordinates(int boxnum) {
BoxCoords tmp, *box = &tmp;
Box *bp = getBoxBaseAddr(boxnum);
assert(bp);
@ -543,9 +546,10 @@ void ScummEngine::getBoxCoordinates(int boxnum, BoxCoords *box) {
box->lr.x = (int16)READ_LE_UINT16(&bp->old.lrx);
box->lr.y = (int16)READ_LE_UINT16(&bp->old.lry);
}
return *box;
}
uint ScummEngine::distanceFromPt(int x, int y, int ptx, int pty) {
uint distanceFromPt(int x, int y, int ptx, int pty) {
int diffx, diffy;
diffx = ABS(ptx - x);
@ -639,11 +643,8 @@ Common::Point closestPtOnLine(const Common::Point &start, const Common::Point &e
return pt;
}
bool ScummEngine::inBoxQuickReject(int b, int x, int y, int threshold) {
bool inBoxQuickReject(const BoxCoords &box, int x, int y, int threshold) {
int t;
BoxCoords box;
getBoxCoordinates(b, &box);
t = x - threshold;
if (t > box.ul.x && t > box.ur.x && t > box.lr.x && t > box.ll.x)
@ -664,13 +665,10 @@ bool ScummEngine::inBoxQuickReject(int b, int x, int y, int threshold) {
return false;
}
int ScummEngine::getClosestPtOnBox(int b, int x, int y, int16& outX, int16& outY) {
int getClosestPtOnBox(const BoxCoords &box, int x, int y, int16& outX, int16& outY) {
Common::Point pt;
uint dist;
uint bestdist = 0xFFFFFF;
BoxCoords box;
getBoxCoordinates(b, &box);
pt = closestPtOnLine(box.ul, box.ur, x, y);
dist = distanceFromPt(x, y, pt.x, pt.y);
@ -809,16 +807,13 @@ int ScummEngine::getPathToDestBox(byte from, byte to) {
* line in order to get from box1 to box3 via box2.
*/
bool Actor::findPathTowards(byte box1nr, byte box2nr, byte box3nr, Common::Point &foundPath) {
BoxCoords box1;
BoxCoords box2;
BoxCoords box1 = _vm->getBoxCoordinates(box1nr);
BoxCoords box2 = _vm->getBoxCoordinates(box2nr);
Common::Point tmp;
int i, j;
int flag;
int q, pos;
_vm->getBoxCoordinates(box1nr, &box1);
_vm->getBoxCoordinates(box2nr, &box2);
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (box1.ul.x == box1.ur.x && box1.ul.x == box2.ul.x && box1.ul.x == box2.ur.x) {
@ -1080,8 +1075,8 @@ bool ScummEngine::areBoxesNeighbours(int box1nr, int box2nr) {
if (getBoxFlags(box1nr) & kBoxInvisible || getBoxFlags(box2nr) & kBoxInvisible)
return false;
getBoxCoordinates(box1nr, &box2);
getBoxCoordinates(box2nr, &box);
box2 = getBoxCoordinates(box1nr);
box = getBoxCoordinates(box2nr);
// Roughly, the idea of this algorithm is to check if we can find
// two sides of the two given boxes which touch.
@ -1173,7 +1168,7 @@ void Actor::findPathTowardsOld(byte box1, byte box2, byte finalBox, Common::Poin
Common::Point gateA[2];
Common::Point gateB[2];
_vm->getGates(box1, box2, gateA, gateB);
getGates(_vm->getBoxCoordinates(box1), _vm->getBoxCoordinates(box2), gateA, gateB);
p2.x = 32000;
p3.x = 32000;
@ -1210,34 +1205,31 @@ void Actor::findPathTowardsOld(byte box1, byte box2, byte finalBox, Common::Poin
* This way the lines bound a 'corridor' between the two boxes, through which
* the actor has to walk to get from box1 to box2.
*/
void ScummEngine::getGates(int box1, int box2, Common::Point gateA[2], Common::Point gateB[2]) {
void getGates(const BoxCoords &box1, const BoxCoords &box2, Common::Point gateA[2], Common::Point gateB[2]) {
int i, j;
int dist[8];
int minDist[3];
int closest[3];
int box[3];
BoxCoords coords;
Common::Point closestPoint[8];
Common::Point boxCorner[8];
int line1, line2;
// 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(box1, &coords);
boxCorner[0] = coords.ul;
boxCorner[1] = coords.ur;
boxCorner[2] = coords.lr;
boxCorner[3] = coords.ll;
boxCorner[0] = box1.ul;
boxCorner[1] = box1.ur;
boxCorner[2] = box1.lr;
boxCorner[3] = box1.ll;
for (i = 0; i < 4; i++) {
dist[i] = getClosestPtOnBox(box2, boxCorner[i].x, boxCorner[i].y, closestPoint[i].x, closestPoint[i].y);
}
// Now do the same but with the roles of the first and second box swapped.
getBoxCoordinates(box2, &coords);
boxCorner[4] = coords.ul;
boxCorner[5] = coords.ur;
boxCorner[6] = coords.lr;
boxCorner[7] = coords.ll;
boxCorner[4] = box2.ul;
boxCorner[5] = box2.ur;
boxCorner[6] = box2.lr;
boxCorner[7] = box2.ll;
for (i = 4; i < 8; i++) {
dist[i] = getClosestPtOnBox(box1, boxCorner[i].x, boxCorner[i].y, closestPoint[i].x, closestPoint[i].y);
}

View File

@ -50,6 +50,10 @@ struct BoxCoords { /* Box coordinates */
Common::Point lr;
};
void getGates(const BoxCoords &box1, const BoxCoords &box2, Common::Point gateA[2], Common::Point gateB[2]);
bool inBoxQuickReject(const BoxCoords &box, int x, int y, int threshold);
int getClosestPtOnBox(const BoxCoords &box, int x, int y, int16& outX, int16& outY);
} // End of namespace Scumm
#endif

View File

@ -642,7 +642,7 @@ void ScummDebugger::printBox(int box) {
int mask = _vm->getMaskFromBox(box);
int scale = _vm->getBoxScale(box);
_vm->getBoxCoordinates(box, &coords);
coords = _vm->getBoxCoordinates(box);
// Print out coords, flags, zbuffer mask
DebugPrintf("%d: [%d x %d] [%d x %d] [%d x %d] [%d x %d], flags=0x%02x, mask=%d, scale=%d\n",
@ -748,7 +748,7 @@ void ScummDebugger::drawBox(int box) {
BoxCoords coords;
Common::Point r[4];
_vm->getBoxCoordinates(box, &coords);
coords = _vm->getBoxCoordinates(box);
r[0] = coords.ul;
r[1] = coords.ur;

View File

@ -55,7 +55,6 @@ protected:
const OpcodeEntryv60he *_opcodesv60he;
public:
//Common::File _hFileTable[17];
Common::SeekableReadStream *_hInFileTable[17];
Common::WriteStream *_hOutFileTable[17];

View File

@ -668,6 +668,8 @@ protected:
virtual void processActors();
int getSpecialBox(int x, int y);
/* Version 6 script opcodes */
void o6_setBlastObjectWindow();
void o6_pushByte();

View File

@ -1139,17 +1139,14 @@ public:
byte getNumBoxes();
byte *getBoxMatrixBaseAddr();
int getPathToDestBox(byte from, byte to);
void getGates(int trap1, int trap2, Common::Point gateA[2], Common::Point gateB[2]);
bool inBoxQuickReject(int box, int x, int y, int threshold);
int getClosestPtOnBox(int box, int x, int y, int16& outX, int16& outY);
int getSpecialBox(int param1, int param2);
void setBoxFlags(int box, int val);
void setBoxScale(int box, int b);
bool checkXYInBoxBounds(int box, int x, int y);
uint distanceFromPt(int x, int y, int ptx, int pty);
void getBoxCoordinates(int boxnum, BoxCoords *bc);
BoxCoords getBoxCoordinates(int boxnum);
byte getMaskFromBox(int box);
Box *getBoxBaseAddr(int box);
byte getBoxFlags(int box);