refactored parts of actor.cpp: many methods are now members of class Actor instead of class Scumm. This is still work in progress!

svn-id: r4319
This commit is contained in:
Max Horn 2002-05-14 19:11:20 +00:00
parent a592de4333
commit fe4230bcbf
11 changed files with 616 additions and 555 deletions

814
actor.cpp

File diff suppressed because it is too large Load Diff

112
actor.h Normal file
View File

@ -0,0 +1,112 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001/2002 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#ifndef ACTOR_H
#define ACTOR_H
struct ActorWalkData {
int16 destx,desty; // Final destination
byte destbox;
int16 destdir;
byte curbox;
int16 x,y; // Current position
int16 newx,newy; // Next position on our way to the destination
int32 XYFactor, YXFactor;
uint16 xfrac,yfrac;
int point3x, point3y;
};
struct CostumeData {
byte active[16];
uint16 animCounter1;
byte animCounter2;
uint16 stopped;
uint16 curpos[16];
uint16 start[16];
uint16 end[16];
uint16 frame[16];
};
struct Actor {
int x, y, top, bottom;
int elevation;
uint width;
byte number;
uint16 facing;
uint16 costume;
byte room;
byte talkColor;
byte scalex,scaley;
byte charset;
int16 newDirection;
byte moving;
byte ignoreBoxes;
byte forceClip;
byte initFrame, walkFrame, standFrame, talkFrame1, talkFrame2;
bool needRedraw, needBgReset, costumeNeedsInit, visible;
byte shadow_mode;
bool flip;
uint speedx,speedy;
byte frame;
byte walkbox;
byte mask;
byte animProgress, animSpeed;
int16 new_1,new_2;
uint16 talk_script, walk_script;
byte new_3;
int8 layer;
ActorWalkData walkdata;
int16 animVariable[16];
uint16 sound[8];
CostumeData cost;
byte palette[64];
void hideActor();
void showActor();
void initActor(int mode);
void setActorWalkSpeed(uint newSpeedX, uint newSpeedY);
int calcMovementFactor(int newx, int newy);
int actorWalkStep();
int remapDirection(int dir);
void setupActorScale();
void stopActorMoving();
void startWalkAnim(int cmd, int angle);
void startAnimActor(int frame);
void setActorBox(int box);
int updateActorDirection();
void setActorDirection(int direction);
void adjustActorPos();
void turnToDirection(int newdir);
void walkActor();
void setActorCostume(int c);
byte *getActorName();
void startWalkActor(int x, int y, int dir);
void remapActor(int b, int c, int d, int e);
void walkActorOld();
};
#endif

View File

@ -871,35 +871,35 @@ int Scumm::findPathTowardsOld(Actor * a, byte trap1, byte trap2,
GetGates(trap1, trap2);
ScummPoint pt;
p[1].x = actor->x;
p[1].y = actor->y;
p[2].x = 32000;
p[3].x = 32000;
p[4].x = 32000;
gateLoc[1].x = actor->x;
gateLoc[1].y = actor->y;
gateLoc[2].x = 32000;
gateLoc[3].x = 32000;
gateLoc[4].x = 32000;
if (trap2 == final_trap) { /* next = final box? */
p[4].x = actor->walkdata.destx;
p[4].y = actor->walkdata.desty;
gateLoc[4].x = actor->walkdata.destx;
gateLoc[4].y = actor->walkdata.desty;
if (getMaskFromBox(trap1) == getMaskFromBox(trap2) || 1) {
if (CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate1ax, gate1ay) !=
CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate1bx, gate1by) &&
CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate2ax, gate2ay) !=
CompareSlope(p[1].x, p[1].y, p[4].x, p[4].y, gate2bx, gate2by)) {
if (CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate1ax, gate1ay) !=
CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate1bx, gate1by) &&
CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate2ax, gate2ay) !=
CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[4].x, gateLoc[4].y, gate2bx, gate2by)) {
return 0; /* same zplane and between both gates? */
}
}
}
pt = closestPtOnLine(gate2ax, gate2ay, gate2bx, gate2by, p[1].x, p[1].y);
p[3].x = pt.x;
p[3].y = pt.y;
pt = closestPtOnLine(gate2ax, gate2ay, gate2bx, gate2by, gateLoc[1].x, gateLoc[1].y);
gateLoc[3].x = pt.x;
gateLoc[3].y = pt.y;
if (CompareSlope(p[1].x, p[1].y, p[3].x, p[3].y, gate1ax, gate1ay) ==
CompareSlope(p[1].x, p[1].y, p[3].x, p[3].y, gate1bx, gate1by)) {
closestPtOnLine(gate1ax, gate1ay, gate1bx, gate1by, p[1].x, p[1].y);
p[2].x = pt.x; /* if point 2 between gates, ignore! */
p[2].y = pt.y;
if (CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gate1ax, gate1ay) ==
CompareSlope(gateLoc[1].x, gateLoc[1].y, gateLoc[3].x, gateLoc[3].y, gate1bx, gate1by)) {
closestPtOnLine(gate1ax, gate1ay, gate1bx, gate1by, gateLoc[1].x, gateLoc[1].y);
gateLoc[2].x = pt.x; /* if point 2 between gates, ignore! */
gateLoc[2].y = pt.y;
}
return 0;

View File

@ -720,7 +720,7 @@ byte *Scumm::getObjOrActorName(int obj)
byte *objptr;
if (obj < NUM_ACTORS)
return getActorName(derefActorSafe(obj, "getObjOrActorName"));
return derefActorSafe(obj, "getObjOrActorName")->getActorName();
if (_features & GF_SMALL_HEADER) {
byte offset = 0;

View File

@ -883,7 +883,7 @@ void Scumm::faceActorToObj(int act, int obj)
return;
dir = (_xPos > x) ? 90 : 270;
turnToDirection(derefActorSafe(act, "faceActorToObj"), dir);
derefActorSafe(act, "faceActorToObj")->turnToDirection(dir);
}
void Scumm::animateActor(int act, int anim)
@ -905,18 +905,18 @@ void Scumm::animateActor(int act, int anim)
switch (cmd) {
case 2:
stopActorMoving(a);
startAnimActor(a, a->standFrame);
a->stopActorMoving();
a->startAnimActor(a->standFrame);
break;
case 3:
a->moving &= ~4;
setActorDirection(a, dir);
a->setActorDirection(dir);
break;
case 4:
turnToDirection(a, dir);
a->turnToDirection(dir);
break;
default:
startAnimActor(a, anim);
a->startAnimActor(anim);
}
} else {
@ -931,18 +931,18 @@ void Scumm::animateActor(int act, int anim)
switch (anim >> 2) {
case 0x3F:
stopActorMoving(a);
startAnimActor(a, a->standFrame);
a->stopActorMoving();
a->startAnimActor(a->standFrame);
break;
case 0x3E:
a->moving &= ~4;
setActorDirection(a, oldDirToNewDir(dir));
a->setActorDirection(oldDirToNewDir(dir));
break;
case 0x3D:
turnToDirection(a, oldDirToNewDir(dir));
a->turnToDirection(oldDirToNewDir(dir));
break;
default:
startAnimActor(a, anim);
a->startAnimActor(anim);
}
}

View File

@ -715,12 +715,12 @@ void Scumm::o5_actorSet()
getVarOrDirectByte(0x80);
break;
case 1: /* costume */
setActorCostume(a, getVarOrDirectByte(0x80));
a->setActorCostume(getVarOrDirectByte(0x80));
break;
case 2: /* walkspeed */
i = getVarOrDirectByte(0x80);
j = getVarOrDirectByte(0x40);
setActorWalkSpeed(a, i, j);
a->setActorWalkSpeed(i, j);
break;
case 3: /* sound */
a->sound[0] = getVarOrDirectByte(0x80);
@ -741,7 +741,7 @@ void Scumm::o5_actorSet()
getVarOrDirectByte(0x20);
break;
case 8: /* init */
initActor(a, 0);
a->initActor(0);
break;
case 9: /* elevation */
a->elevation = getVarOrDirectWord(0x80);
@ -1306,17 +1306,15 @@ void Scumm::o5_getActorWidth()
void Scumm::o5_getActorX()
{
int actor;
int a;
getResultPos();
if(_gameId == GID_INDY3_256)
actor = getVarOrDirectByte(0x80);
a = getVarOrDirectByte(0x80);
else
actor = getVarOrDirectWord(0x80);
a = getVarOrDirectWord(0x80);
setResult(getObjX(actor));
setResult(getObjX(a));
}
void Scumm::o5_getActorY()
@ -1634,7 +1632,7 @@ void Scumm::o5_loadRoomWithEgo()
_fullRedraw = 1;
if (x != -1) {
startWalkActor(a, x, y, -1);
a->startWalkActor(x, y, -1);
}
}
@ -2557,7 +2555,7 @@ void Scumm::o5_walkActorTo()
a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorTo");
x = getVarOrDirectWord(0x40);
y = getVarOrDirectWord(0x20);
startWalkActor(a, x, y, -1);
a->startWalkActor(x, y, -1);
}
void Scumm::o5_walkActorToActor()
@ -2603,7 +2601,7 @@ void Scumm::o5_walkActorToActor()
else
x -= b;
startWalkActor(a, x, y, -1);
a->startWalkActor(x, y, -1);
}
void Scumm::o5_walkActorToObject()
@ -2617,7 +2615,7 @@ void Scumm::o5_walkActorToObject()
obj = getVarOrDirectWord(0x40);
if (whereIsObject(obj) != WIO_NOT_FOUND) {
getObjectXYPos(obj);
startWalkActor(a, _xPos, _yPos, _dir);
a->startWalkActor(_xPos, _yPos, _dir);
}
}

View File

@ -1345,7 +1345,7 @@ void Scumm::o6_walkActorToObj()
if (whereIsObject(obj) == WIO_NOT_FOUND)
return;
getObjectXYPos(obj);
startWalkActor(a, _xPos, _yPos, _dir);
a->startWalkActor(_xPos, _yPos, _dir);
} else {
a2 = derefActorSafe(obj, "o6_walkActorToObj(2)");
if (!a2)
@ -1361,7 +1361,7 @@ void Scumm::o6_walkActorToObj()
x += dist;
else
x -= dist;
startWalkActor(a, x, a2->y, -1);
a->startWalkActor(x, a2->y, -1);
}
}
@ -1370,7 +1370,7 @@ void Scumm::o6_walkActorTo()
int x, y;
y = pop();
x = pop();
startWalkActor(derefActorSafe(pop(), "o6_walkActorTo"), x, y, -1);
derefActorSafe(pop(), "o6_walkActorTo")->startWalkActor(x, y, -1);
}
void Scumm::o6_putActorInRoom()
@ -1508,7 +1508,7 @@ void Scumm::o6_loadRoomWithEgo()
}
_fullRedraw = 1;
if (x != -1) {
startWalkActor(a, x, y, -1);
a->startWalkActor(x, y, -1);
}
}
@ -1920,12 +1920,12 @@ void Scumm::o6_actorSet()
switch (b) {
case 76: /* actor-costume */
setActorCostume(a, pop());
a->setActorCostume(pop());
break;
case 77: /* actor-speed */
j = pop();
i = pop();
setActorWalkSpeed(a, i, j);
a->setActorWalkSpeed(i, j);
break;
case 78: /* actor-sound */
k = getStackList(args, sizeof(args) / sizeof(args[0]));
@ -1948,7 +1948,7 @@ void Scumm::o6_actorSet()
pop();
break;
case 83:
initActor(a, 0);
a->initActor(0);
break;
case 84: /* actor-elevation */
a->elevation = pop();
@ -2026,7 +2026,7 @@ void Scumm::o6_actorSet()
a->new_3 = 0;
break;
case 217:
initActor(a, 2);
a->initActor(2);
break;
case 227: /* actor_layer */
a->layer = pop();
@ -2038,15 +2038,15 @@ void Scumm::o6_actorSet()
a->talk_script = pop();
break;
case 229: /* stand */
stopActorMoving(a);
startAnimActor(a, a->standFrame);
a->stopActorMoving();
a->startAnimActor(a->standFrame);
break;
case 230: /* set direction */
a->moving &= ~4;
setActorDirection(a, pop());
a->setActorDirection(pop());
break;
case 231: /* turn to direction */
turnToDirection(a, pop());
a->turnToDirection(pop());
break;
case 233: /* freeze actor */
a->moving |= 0x80;
@ -2710,11 +2710,11 @@ void Scumm::o6_miscOps()
setCursorImg(args[1], (uint) - 1, args[2]);
break;
case 13:
remapActor(derefActorSafe(args[1], "o6_miscOps:14"), args[2], args[3],
derefActorSafe(args[1], "o6_miscOps:14")->remapActor(args[2], args[3],
args[4], -1);
break;
case 14:
remapActor(derefActorSafe(args[1], "o6_miscOps:14"), args[2], args[3],
derefActorSafe(args[1], "o6_miscOps:14")->remapActor(args[2], args[3],
args[4], args[5]);
break;
case 15:

111
scumm.h
View File

@ -1,5 +1,6 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001/2002 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -19,10 +20,14 @@
*
*/
#ifndef SCUMM_H
#define SCUMM_H
#include "scummsys.h"
#include "system.h"
#include "sound/mixer.h"
#include "config-file.h"
#include "actor.h"
#define SCUMMVM_VERSION "0.2.0 Release"
#define SCUMMVM_CVS "051302"
@ -200,29 +205,6 @@ public:
byte fl_object_index;
};
struct CostumeData {
byte active[16];
uint16 animCounter1;
byte animCounter2;
uint16 stopped;
uint16 curpos[16];
uint16 start[16];
uint16 end[16];
uint16 frame[16];
};
struct ActorWalkData {
int16 destx,desty; // Final destination
byte destbox;
int16 destdir;
byte curbox;
int16 x,y; // Current position
int16 newx,newy; // Next position on our way to the destination
int32 XYFactor, YXFactor;
uint16 xfrac,yfrac;
int point3x, point3y;
};
struct ScriptSlot {
uint32 offs;
int32 delay;
@ -431,41 +413,6 @@ struct CostumeRenderer {
};
struct Actor {
int x,y,top,bottom;
int elevation;
uint width;
byte number;
uint16 facing;
uint16 costume;
byte room;
byte talkColor;
byte scalex,scaley;
byte charset;
int16 newDirection;
byte moving;
byte ignoreBoxes;
byte forceClip;
byte initFrame,walkFrame,standFrame,talkFrame1,talkFrame2;
bool needRedraw, needBgReset,costumeNeedsInit,visible;
byte shadow_mode;
bool flip;
uint speedx,speedy;
byte frame;
byte walkbox;
byte mask;
byte animProgress, animSpeed;
int16 new_1,new_2;
uint16 talk_script, walk_script;
byte new_3;
int8 layer;
ActorWalkData walkdata;
int16 animVariable[16];
uint16 sound[8];
CostumeData cost;
byte palette[64];
};
#define ARRAY_HDR_SIZE 6
struct ArrayHeader {
int16 dim1_size;
@ -1039,21 +986,21 @@ public:
Actor *derefActorSafe(int id, const char *errmsg);
Actor *getFirstActor() {return actor;}
void putActor(Actor *a, int x, int y, byte room);
void hideActor(Actor *a);
void showActor(Actor *a);
// void hideActor(Actor *a);
// void showActor(Actor *a);
void showActors();
void initActor(Actor *a, int mode);
void setActorWalkSpeed(Actor *a, uint speed1, uint speed2);
int calcMovementFactor(Actor *a, int newx, int newy);
int actorWalkStep(Actor *a);
int remapDirection(Actor *a, int dir);
void setupActorScale(Actor *a);
void stopActorMoving(Actor *a);
// void initActor(Actor *a, int mode);
// void setActorWalkSpeed(Actor *a, uint speed1, uint speed2);
// int calcMovementFactor(Actor *a, int newx, int newy);
// int actorWalkStep(Actor *a);
// int remapDirection(Actor *a, int dir);
// void setupActorScale(Actor *a);
// void stopActorMoving(Actor *a);
uint32 *_classData;
void startWalkAnim(Actor *a, int cmd, int angle);
void startAnimActor(Actor *a, int frame);
void setActorBox(Actor *a, int box);
// void startWalkAnim(Actor *a, int cmd, int angle);
// void startAnimActor(Actor *a, int frame);
// void setActorBox(Actor *a, int box);
int newDirToOldDir(int dir);
int oldDirToNewDir(int dir);
@ -1063,34 +1010,34 @@ public:
static int fromSimpleDir(int dirtype, int dir);
static int toSimpleDir(int dirtype, int dir);
static int numSimpleDirDirections(int dirType);
int updateActorDirection(Actor *a);
// int updateActorDirection(Actor *a);
void startAnimActorEx(Actor *a, int frame, int direction);
int getProgrDirChange(Actor *a, int mode);
void initActorCostumeData(Actor *a);
void setActorDirection(Actor *a, int direction);
// void setActorDirection(Actor *a, int direction);
int getActorXYPos(Actor *a);
void adjustActorPos(Actor *a);
void turnToDirection(Actor *a, int newdir);
// void adjustActorPos(Actor *a);
// void turnToDirection(Actor *a, int newdir);
AdjustBoxResult adjustXYToBeInBox(Actor *a, int x, int y, int pathfrom);
void walkActors();
void playActorSounds();
void walkActor(Actor *a);
// void walkActor(Actor *a);
void setActorRedrawFlags();
void resetActorBgs();
void processActors();
void drawActorCostume(Actor *a);
void actorAnimate(Actor *a);
int getActorFromPos(int x, int y);
void setActorCostume(Actor *a, int c);
byte *getActorName(Actor *a);
// void setActorCostume(Actor *a, int c);
// byte *getActorName(Actor *a);
void faceActorToObj(int act, int obj);
void animateActor(int act, int anim);
void actorFollowCamera(int act);
void startWalkActor(Actor *a, int x, int y, int dir);
// void startWalkActor(Actor *a, int x, int y, int dir);
void remapActor(Actor *a, int b, int c, int d, int e);
void walkActorOld(Actor *a);
// void remapActor(Actor *a, int b, int c, int d, int e);
// void walkActorOld(Actor *a);
bool isCostumeInUse(int i);
/* Actor talking stuff */
@ -1261,7 +1208,8 @@ public:
int _maxBoxVertexHeap, _boxPathVertexHeapIndex, _boxMatrixItem;
byte *_boxMatrixPtr4, *_boxMatrixPtr1, *_boxMatrixPtr3;
ScummPoint p[5]; /* Gate locations */
// ScummPoint p[5]; /* Gate locations */
ScummPoint gateLoc[5]; /* Gate locations */
int gate1ax, gate1ay, gate1bx, gate1by, gate2ax, gate2ay, gate2bx, gate2by;
uint16 _extraBoxFlags[65];
int16 _foundPathX, _foundPathY;
@ -1890,3 +1838,4 @@ byte *findResourceSmall(uint32 tag, byte *searchin);
void setWindowName(Scumm *s);
uint16 newTag2Old(uint32 oldTag);
#endif

View File

@ -77,7 +77,7 @@ void Scumm::scummInit()
for (i = 1, a = getFirstActor(); ++a, i < NUM_ACTORS; i++) {
a->number = i;
initActor(a, 1);
a->initActor(1);
}
_vars[VAR_CHARINC] = 4;
@ -408,7 +408,7 @@ void Scumm::startScene(int room, Actor * a, int objectNr)
for (i = 1, at = getFirstActor(); ++at, i < NUM_ACTORS; i++) {
if (at->visible)
hideActor(at);
at->hideActor();
}
if (!(_features & GF_AFTER_V7)) {
@ -484,7 +484,7 @@ void Scumm::startScene(int room, Actor * a, int objectNr)
_currentRoom);
getObjectXYPos(objectNr);
putActor(a, _xPos, _yPos, _currentRoom);
setActorDirection(a, _dir + 180);
a->setActorDirection(_dir + 180);
a->moving = 0;
}

View File

@ -213,7 +213,7 @@ void Scumm::processSfxQueues()
b = isMouthSyncOff(_curSoundPos);
if (_mouthSyncMode != b) {
_mouthSyncMode = b;
startAnimActor(a, b ? a->talkFrame2 : a->talkFrame1);
a->startAnimActor(b ? a->talkFrame2 : a->talkFrame1);
}
}
}

View File

@ -288,7 +288,7 @@ void Scumm::CHARSET_1()
}
if (a && !string[0].no_talk_anim) {
startAnimActor(a, a->talkFrame1);
a->startAnimActor(a->talkFrame1);
_useTalkAnims = true;
}
@ -393,16 +393,16 @@ void Scumm::CHARSET_1()
frme = *buffer++;
frme |= *buffer++ << 8;
if (a)
startAnimActor(a, frme);
a->startAnimActor(frme);
} else if (c == 10) {
uint32 a, b;
uint32 tmpA, tmpB;
a =
tmpA =
buffer[0] | (buffer[1] << 8) | (buffer[4] << 16) | (buffer[5] << 24);
b =
tmpB =
buffer[8] | (buffer[9] << 8) | (buffer[12] << 16) | (buffer[13] <<
24);
talkSound(a, b, 2);
talkSound(tmpA, tmpB, 2);
buffer += 14;
} else if (c == 14) {
int oldy = getResourceAddress(rtCharset, charset._curId)[30];