moved Actor SaveLoadEntry definition to actor.cpp; made findPathTowards/findPathTowardsOld members of Actor; cleanup

svn-id: r7988
This commit is contained in:
Max Horn 2003-05-26 02:26:13 +00:00
parent c2d065d896
commit 2f9ff35bad
5 changed files with 130 additions and 115 deletions

View file

@ -27,6 +27,7 @@
#include "charset.h" #include "charset.h"
#include "costume.h" #include "costume.h"
#include "resource.h" #include "resource.h"
#include "saveload.h"
#include "sound.h" #include "sound.h"
#include "usage_bits.h" #include "usage_bits.h"
@ -592,7 +593,7 @@ void Actor::putActor(int dstX, int dstY, byte newRoom) {
} }
} }
int Actor::getActorXYPos(int &xPos, int &yPos) { int Actor::getActorXYPos(int &xPos, int &yPos) const {
if (!isInCurrentRoom()) if (!isInCurrentRoom())
return -1; return -1;
@ -1308,7 +1309,7 @@ void Actor::walkActor() {
walkdata.curbox = box; walkdata.curbox = box;
if (_vm->findPathTowards(this, walkbox, box, walkdata.destbox, foundPathX, foundPathY)) if (findPathTowards(walkbox, box, walkdata.destbox, foundPathX, foundPathY))
break; break;
if (calcMovementFactor(foundPathX, foundPathY)) if (calcMovementFactor(foundPathX, foundPathY))
@ -1389,7 +1390,7 @@ void Actor::walkActorOld() {
walkdata.curbox = next_box; walkdata.curbox = next_box;
_vm->findPathTowardsOld(this, walkbox, next_box, walkdata.destbox, gateLoc); findPathTowardsOld(walkbox, next_box, walkdata.destbox, gateLoc);
if (gateLoc[2].x == 32000 && gateLoc[3].x == 32000) { if (gateLoc[2].x == 32000 && gateLoc[3].x == 32000) {
break; break;
} }
@ -1521,3 +1522,84 @@ bool Actor::isPlayer() {
} }
const SaveLoadEntry *Actor::getSaveLoadEntries() {
static const SaveLoadEntry actorEntries[] = {
MKLINE(Actor, x, sleInt16, VER_V8),
MKLINE(Actor, y, sleInt16, VER_V8),
MKLINE(Actor, top, sleInt16, VER_V8),
MKLINE(Actor, bottom, sleInt16, VER_V8),
MKLINE(Actor, elevation, sleInt16, VER_V8),
MKLINE(Actor, width, sleUint16, VER_V8),
MKLINE(Actor, facing, sleUint16, VER_V8),
MKLINE(Actor, costume, sleUint16, VER_V8),
MKLINE(Actor, room, sleByte, VER_V8),
MKLINE(Actor, talkColor, sleByte, VER_V8),
MKLINE(Actor, talkFrequency, sleInt16, VER_V16),
MKLINE(Actor, scalex, sleByte, VER_V8),
MKLINE(Actor, scaley, sleByte, VER_V8),
MKLINE(Actor, charset, sleByte, VER_V8),
MKARRAY(Actor, sound[0], sleByte, 8, VER_V8),
MKARRAY(Actor, animVariable[0], sleUint16, 8, VER_V8),
MKLINE(Actor, newDirection, sleUint16, VER_V8),
MKLINE(Actor, moving, sleByte, VER_V8),
MKLINE(Actor, ignoreBoxes, sleByte, VER_V8),
MKLINE(Actor, forceClip, sleByte, VER_V8),
MKLINE(Actor, initFrame, sleByte, VER_V8),
MKLINE(Actor, walkFrame, sleByte, VER_V8),
MKLINE(Actor, standFrame, sleByte, VER_V8),
MKLINE(Actor, talkStartFrame, sleByte, VER_V8),
MKLINE(Actor, talkStopFrame, sleByte, VER_V8),
MKLINE(Actor, speedx, sleUint16, VER_V8),
MKLINE(Actor, speedy, sleUint16, VER_V8),
MKLINE(Actor, cost.animCounter1, sleUint16, VER_V8),
MKLINE(Actor, cost.animCounter2, sleByte, VER_V8),
// Actor palette grew from 64 to 256 bytes
MKARRAY_OLD(Actor, palette[0], sleByte, 64, VER_V8, VER_V9),
MKARRAY(Actor, palette[0], sleByte, 256, VER_V10),
MK_OBSOLETE(Actor, mask, sleByte, VER_V8, VER_V9),
MKLINE(Actor, shadow_mode, sleByte, VER_V8),
MKLINE(Actor, visible, sleByte, VER_V8),
MKLINE(Actor, frame, sleByte, VER_V8),
MKLINE(Actor, animSpeed, sleByte, VER_V8),
MKLINE(Actor, animProgress, sleByte, VER_V8),
MKLINE(Actor, walkbox, sleByte, VER_V8),
MKLINE(Actor, needRedraw, sleByte, VER_V8),
MKLINE(Actor, needBgReset, sleByte, VER_V8),
MKLINE(Actor, costumeNeedsInit, sleByte, VER_V8),
MKLINE(Actor, talkPosY, sleInt16, VER_V8),
MKLINE(Actor, talkPosX, sleInt16, VER_V8),
MKLINE(Actor, ignoreTurns, sleByte, VER_V8),
MKLINE(Actor, layer, sleByte, VER_V8),
MKLINE(Actor, talk_script, sleUint16, VER_V8),
MKLINE(Actor, walk_script, sleUint16, VER_V8),
MKLINE(Actor, walkdata.destx, sleInt16, VER_V8),
MKLINE(Actor, walkdata.desty, sleInt16, VER_V8),
MKLINE(Actor, walkdata.destbox, sleByte, VER_V8),
MKLINE(Actor, walkdata.destdir, sleUint16, VER_V8),
MKLINE(Actor, walkdata.curbox, sleByte, VER_V8),
MKLINE(Actor, walkdata.x, sleInt16, VER_V8),
MKLINE(Actor, walkdata.y, sleInt16, VER_V8),
MKLINE(Actor, walkdata.newx, sleInt16, VER_V8),
MKLINE(Actor, walkdata.newy, sleInt16, VER_V8),
MKLINE(Actor, walkdata.deltaXFactor, sleInt32, VER_V8),
MKLINE(Actor, walkdata.deltaYFactor, sleInt32, VER_V8),
MKLINE(Actor, walkdata.xfrac, sleUint16, VER_V8),
MKLINE(Actor, walkdata.yfrac, sleUint16, VER_V8),
MKARRAY(Actor, cost.active[0], sleByte, 16, VER_V8),
MKLINE(Actor, cost.stopped, sleUint16, VER_V8),
MKARRAY(Actor, cost.curpos[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.start[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.end[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.frame[0], sleUint16, 16, VER_V8),
MKEND()
};
return actorEntries;
}

View file

@ -67,6 +67,8 @@ struct CostumeData {
} }
}; };
class SaveLoadEntry;
class Actor { class Actor {
public: public:
@ -102,12 +104,13 @@ public:
uint16 talk_script, walk_script; uint16 talk_script, walk_script;
bool ignoreTurns; // TODO - we do not honor this flag at all currently! bool ignoreTurns; // TODO - we do not honor this flag at all currently!
int8 layer; int8 layer;
ActorWalkData walkdata;
int16 animVariable[16];
uint16 sound[8]; uint16 sound[8];
CostumeData cost; CostumeData cost;
byte palette[256]; byte palette[256];
protected: protected:
ActorWalkData walkdata;
int16 animVariable[16];
static Scumm *_vm; static Scumm *_vm;
public: public:
@ -173,17 +176,17 @@ public:
void animateActor(int anim); void animateActor(int anim);
bool isInCurrentRoom() { bool isInCurrentRoom() const {
return room == _vm->_currentRoom; return room == _vm->_currentRoom;
} }
int getActorXYPos(int &x, int &y); int getActorXYPos(int &x, int &y) const ;
int getRoom() { int getRoom() const {
return room; return room;
} }
int getAnimVar(byte var) { int getAnimVar(byte var) const {
return animVariable[var]; return animVariable[var];
} }
void setAnimVar(byte var, int value) { void setAnimVar(byte var, int value) {
@ -192,10 +195,16 @@ public:
void classChanged(int cls, bool value); void classChanged(int cls, bool value);
// Used by the save/load syste:
static const SaveLoadEntry *getSaveLoadEntries();
protected: protected:
bool isInClass(int cls); bool isInClass(int cls);
bool isPlayer(); bool isPlayer();
bool findPathTowards(byte box, byte box2, byte box3, int16 &foundPathX, int16 &foundPathY);
void findPathTowardsOld(byte box, byte box2, byte box3, ScummVM::Point gateLoc[5]);
}; };
#endif #endif

View file

@ -86,7 +86,9 @@ struct PathVertex { /* Linked list of walkpath nodes */
#define BOX_MATRIX_SIZE 2000 #define BOX_MATRIX_SIZE 2000
PathVertex *unkMatrixProc1(PathVertex *vtx, PathNode *node); static bool compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3);
static ScummVM::Point closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int y);
static PathVertex *unkMatrixProc1(PathVertex *vtx, PathNode *node);
byte Scumm::getMaskFromBox(int box) { byte Scumm::getMaskFromBox(int box) {
@ -397,7 +399,12 @@ uint Scumm::distanceFromPt(int x, int y, int ptx, int pty) {
return diffx + diffy; return diffx + diffy;
} }
ScummVM::Point Scumm::closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int y) {
bool compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3) {
return (Y2 - Y1) * (X3 - X1) <= (Y3 - Y1) * (X2 - X1);
}
ScummVM::Point closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int y) {
int lydiff, lxdiff; int lydiff, lxdiff;
int32 dist, a, b, c; int32 dist, a, b, c;
int x2, y2; int x2, y2;
@ -611,7 +618,7 @@ int Scumm::getPathToDestBox(byte from, byte to) {
* Computes the next point actor a has to walk towards in a straight * Computes the next point actor a has to walk towards in a straight
* line in order to get from box1 to box3 via box2. * line in order to get from box1 to box3 via box2.
*/ */
bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int16 &foundPathX, int16 &foundPathY) { bool Actor::findPathTowards(byte box1nr, byte box2nr, byte box3nr, int16 &foundPathX, int16 &foundPathY) {
BoxCoords box1; BoxCoords box1;
BoxCoords box2; BoxCoords box2;
ScummVM::Point tmp; ScummVM::Point tmp;
@ -619,8 +626,8 @@ bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int
int flag; int flag;
int q, pos; int q, pos;
getBoxCoordinates(box1nr, &box1); _vm->getBoxCoordinates(box1nr, &box1);
getBoxCoordinates(box2nr, &box2); _vm->getBoxCoordinates(box2nr, &box2);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
@ -644,11 +651,11 @@ bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int
if (flag & 2) if (flag & 2)
SWAP(box2.ul.y, box2.ur.y); SWAP(box2.ul.y, box2.ur.y);
} else { } else {
pos = a->y; pos = y;
if (box2nr == box3nr) { if (box2nr == box3nr) {
int diffX = a->walkdata.destx - a->x; int diffX = walkdata.destx - x;
int diffY = a->walkdata.desty - a->y; int diffY = walkdata.desty - y;
int boxDiffX = box1.ul.x - a->x; int boxDiffX = box1.ul.x - x;
if (diffX != 0) { if (diffX != 0) {
int t; int t;
@ -658,7 +665,7 @@ bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int
if (t == 0 && (diffY <= 0 || diffX <= 0) if (t == 0 && (diffY <= 0 || diffX <= 0)
&& (diffY >= 0 || diffX >= 0)) && (diffY >= 0 || diffX >= 0))
t = -1; t = -1;
pos = a->y + t; pos = y + t;
} }
} }
@ -701,16 +708,16 @@ bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int
} else { } else {
if (box2nr == box3nr) { if (box2nr == box3nr) {
int diffX = a->walkdata.destx - a->x; int diffX = walkdata.destx - x;
int diffY = a->walkdata.desty - a->y; int diffY = walkdata.desty - y;
int boxDiffY = box1.ul.y - a->y; int boxDiffY = box1.ul.y - y;
pos = a->x; pos = x;
if (diffY != 0) { if (diffY != 0) {
pos += diffX * boxDiffY / diffY; pos += diffX * boxDiffY / diffY;
} }
} else { } else {
pos = a->x; pos = x;
} }
q = pos; q = pos;
@ -1053,24 +1060,24 @@ PathVertex *Scumm::addPathVertex() {
return (PathVertex *)addToBoxVertexHeap(sizeof(PathVertex)); return (PathVertex *)addToBoxVertexHeap(sizeof(PathVertex));
} }
void Scumm::findPathTowardsOld(Actor *actor, byte trap1, byte trap2, byte final_trap, ScummVM::Point gateLoc[5]) { void Actor::findPathTowardsOld(byte trap1, byte trap2, byte final_trap, ScummVM::Point gateLoc[5]) {
ScummVM::Point pt; ScummVM::Point pt;
ScummVM::Point gateA[2]; ScummVM::Point gateA[2];
ScummVM::Point gateB[2]; ScummVM::Point gateB[2];
getGates(trap1, trap2, gateA, gateB); _vm->getGates(trap1, trap2, gateA, gateB);
gateLoc[1].x = actor->x; gateLoc[1].x = x;
gateLoc[1].y = actor->y; gateLoc[1].y = y;
gateLoc[2].x = 32000; gateLoc[2].x = 32000;
gateLoc[3].x = 32000; gateLoc[3].x = 32000;
gateLoc[4].x = 32000; gateLoc[4].x = 32000;
if (trap2 == final_trap) { /* next = final box? */ if (trap2 == final_trap) { /* next = final box? */
gateLoc[4].x = actor->walkdata.destx; gateLoc[4].x = walkdata.destx;
gateLoc[4].y = actor->walkdata.desty; gateLoc[4].y = walkdata.desty;
if (getMaskFromBox(trap1) == getMaskFromBox(trap2) || 1) { if (_vm->getMaskFromBox(trap1) == _vm->getMaskFromBox(trap2) || 1) {
if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[0].x, gateA[0].y) != if (compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[0].x, gateA[0].y) !=
compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateB[0].x, gateB[0].y) && compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateB[0].x, gateB[0].y) &&
compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[1].x, gateA[1].y) != compareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gateA[1].x, gateA[1].y) !=
@ -1200,6 +1207,3 @@ void Scumm::getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Poi
} }
} }
bool Scumm::compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3) {
return (Y2 - Y1) * (X3 - X1) <= (Y3 - Y1) * (X2 - X1);
}

View file

@ -272,83 +272,7 @@ void Scumm::saveOrLoad(Serializer *s, uint32 savegameVersion) {
MKEND() MKEND()
}; };
const SaveLoadEntry actorEntries[] = { const SaveLoadEntry *actorEntries = Actor::getSaveLoadEntries();
MKLINE(Actor, x, sleInt16, VER_V8),
MKLINE(Actor, y, sleInt16, VER_V8),
MKLINE(Actor, top, sleInt16, VER_V8),
MKLINE(Actor, bottom, sleInt16, VER_V8),
MKLINE(Actor, elevation, sleInt16, VER_V8),
MKLINE(Actor, width, sleUint16, VER_V8),
MKLINE(Actor, facing, sleUint16, VER_V8),
MKLINE(Actor, costume, sleUint16, VER_V8),
MKLINE(Actor, room, sleByte, VER_V8),
MKLINE(Actor, talkColor, sleByte, VER_V8),
MKLINE(Actor, talkFrequency, sleInt16, VER_V16),
MKLINE(Actor, scalex, sleByte, VER_V8),
MKLINE(Actor, scaley, sleByte, VER_V8),
MKLINE(Actor, charset, sleByte, VER_V8),
MKARRAY(Actor, sound[0], sleByte, 8, VER_V8),
MKARRAY(Actor, animVariable[0], sleUint16, 8, VER_V8),
MKLINE(Actor, newDirection, sleUint16, VER_V8),
MKLINE(Actor, moving, sleByte, VER_V8),
MKLINE(Actor, ignoreBoxes, sleByte, VER_V8),
MKLINE(Actor, forceClip, sleByte, VER_V8),
MKLINE(Actor, initFrame, sleByte, VER_V8),
MKLINE(Actor, walkFrame, sleByte, VER_V8),
MKLINE(Actor, standFrame, sleByte, VER_V8),
MKLINE(Actor, talkStartFrame, sleByte, VER_V8),
MKLINE(Actor, talkStopFrame, sleByte, VER_V8),
MKLINE(Actor, speedx, sleUint16, VER_V8),
MKLINE(Actor, speedy, sleUint16, VER_V8),
MKLINE(Actor, cost.animCounter1, sleUint16, VER_V8),
MKLINE(Actor, cost.animCounter2, sleByte, VER_V8),
// Actor palette grew from 64 to 256 bytes
MKARRAY_OLD(Actor, palette[0], sleByte, 64, VER_V8, VER_V9),
MKARRAY(Actor, palette[0], sleByte, 256, VER_V10),
MK_OBSOLETE(Actor, mask, sleByte, VER_V8, VER_V9),
MKLINE(Actor, shadow_mode, sleByte, VER_V8),
MKLINE(Actor, visible, sleByte, VER_V8),
MKLINE(Actor, frame, sleByte, VER_V8),
MKLINE(Actor, animSpeed, sleByte, VER_V8),
MKLINE(Actor, animProgress, sleByte, VER_V8),
MKLINE(Actor, walkbox, sleByte, VER_V8),
MKLINE(Actor, needRedraw, sleByte, VER_V8),
MKLINE(Actor, needBgReset, sleByte, VER_V8),
MKLINE(Actor, costumeNeedsInit, sleByte, VER_V8),
MKLINE(Actor, talkPosY, sleInt16, VER_V8),
MKLINE(Actor, talkPosX, sleInt16, VER_V8),
MKLINE(Actor, ignoreTurns, sleByte, VER_V8),
MKLINE(Actor, layer, sleByte, VER_V8),
MKLINE(Actor, talk_script, sleUint16, VER_V8),
MKLINE(Actor, walk_script, sleUint16, VER_V8),
MKLINE(Actor, walkdata.destx, sleInt16, VER_V8),
MKLINE(Actor, walkdata.desty, sleInt16, VER_V8),
MKLINE(Actor, walkdata.destbox, sleByte, VER_V8),
MKLINE(Actor, walkdata.destdir, sleUint16, VER_V8),
MKLINE(Actor, walkdata.curbox, sleByte, VER_V8),
MKLINE(Actor, walkdata.x, sleInt16, VER_V8),
MKLINE(Actor, walkdata.y, sleInt16, VER_V8),
MKLINE(Actor, walkdata.newx, sleInt16, VER_V8),
MKLINE(Actor, walkdata.newy, sleInt16, VER_V8),
MKLINE(Actor, walkdata.deltaXFactor, sleInt32, VER_V8),
MKLINE(Actor, walkdata.deltaYFactor, sleInt32, VER_V8),
MKLINE(Actor, walkdata.xfrac, sleUint16, VER_V8),
MKLINE(Actor, walkdata.yfrac, sleUint16, VER_V8),
MKARRAY(Actor, cost.active[0], sleByte, 16, VER_V8),
MKLINE(Actor, cost.stopped, sleUint16, VER_V8),
MKARRAY(Actor, cost.curpos[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.start[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.end[0], sleUint16, 16, VER_V8),
MKARRAY(Actor, cost.frame[0], sleUint16, 16, VER_V8),
MKEND()
};
const SaveLoadEntry verbEntries[] = { const SaveLoadEntry verbEntries[] = {
MKLINE(VerbSlot, x, sleInt16, VER_V8), MKLINE(VerbSlot, x, sleInt16, VER_V8),

View file

@ -993,8 +993,6 @@ public:
byte getNumBoxes(); byte getNumBoxes();
byte *getBoxMatrixBaseAddr(); byte *getBoxMatrixBaseAddr();
int getPathToDestBox(byte from, byte to); int getPathToDestBox(byte from, byte to);
bool findPathTowards(Actor *a, byte box, byte box2, byte box3, int16 &foundPathX, int16 &foundPathY);
void findPathTowardsOld(Actor *a, byte box, byte box2, byte box3, ScummVM::Point gateLoc[5]);
void getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Point gateB[2]); void getGates(int trap1, int trap2, ScummVM::Point gateA[2], ScummVM::Point gateB[2]);
bool inBoxQuickReject(int box, int x, int y, int threshold); bool inBoxQuickReject(int box, int x, int y, int threshold);
AdjustBoxResult getClosestPtOnBox(int box, int x, int y); AdjustBoxResult getClosestPtOnBox(int box, int x, int y);
@ -1005,7 +1003,6 @@ public:
bool checkXYInBoxBounds(int box, int x, int y); bool checkXYInBoxBounds(int box, int x, int y);
uint distanceFromPt(int x, int y, int ptx, int pty); uint distanceFromPt(int x, int y, int ptx, int pty);
ScummVM::Point closestPtOnLine(int ulx, int uly, int llx, int lly, int x, int y);
void getBoxCoordinates(int boxnum, BoxCoords *bc); void getBoxCoordinates(int boxnum, BoxCoords *bc);
byte getMaskFromBox(int box); byte getMaskFromBox(int box);
Box *getBoxBaseAddr(int box); Box *getBoxBaseAddr(int box);
@ -1027,7 +1024,6 @@ protected:
void createBoxMatrix(); void createBoxMatrix();
void addToBoxMatrix(byte b); void addToBoxMatrix(byte b);
bool compareSlope(int X1, int Y1, int X2, int Y2, int X3, int Y3);
PathNode *unkMatrixProc2(PathVertex *vtx, int i); PathNode *unkMatrixProc2(PathVertex *vtx, int i);
void *addToBoxVertexHeap(int size); void *addToBoxVertexHeap(int size);
PathVertex *addPathVertex(); PathVertex *addPathVertex();