fixed hardcoded number -> constant stuff (patches by janssen)

svn-id: r3483
This commit is contained in:
Ludvig Strigeus 2001-11-10 19:12:32 +00:00
parent 406b5e63c7
commit 595d9534c3
9 changed files with 64 additions and 54 deletions

View file

@ -574,7 +574,7 @@ void Scumm::showActors() {
int i; int i;
Actor *a; Actor *a;
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
if (a->room == _currentRoom) if (a->room == _currentRoom)
showActor(a); showActor(a);
@ -608,7 +608,7 @@ void Scumm::clearMsgQueue() {
void Scumm::walkActors() { void Scumm::walkActors() {
int i; int i;
Actor *a; Actor *a;
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
if (a->room==_currentRoom) if (a->room==_currentRoom)
walkActor(a); walkActor(a);
@ -620,12 +620,12 @@ void Scumm::playActorSounds() {
int i; int i;
Actor *a; Actor *a;
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
if (a->cost.animCounter2 && a->room==_currentRoom && a->sound) { if (a->cost.animCounter2 && a->room==_currentRoom && a->sound) {
_currentScript = 0xFF; _currentScript = 0xFF;
addSoundToQueue(a->sound[0]); addSoundToQueue(a->sound[0]);
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
a->cost.animCounter2 = 0; a->cost.animCounter2 = 0;
} }
@ -708,10 +708,10 @@ void Scumm::walkActor(Actor *a) {
void Scumm::processActors() { void Scumm::processActors() {
int i; int i;
Actor *actors[13],*a,**ac,**ac2,*tmp; Actor *actors[NUM_ACTORS],*a,**ac,**ac2,*tmp;
int numactors = 0, cnt,cnt2; int numactors = 0, cnt,cnt2;
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
if (a->room == _currentRoom) if (a->room == _currentRoom)
actors[numactors++] = a; actors[numactors++] = a;
@ -814,7 +814,7 @@ void Scumm::setActorRedrawFlags() {
for (i=0; i<40; i++) { for (i=0; i<40; i++) {
bits = actorDrawBits[_screenStartStrip+i]; bits = actorDrawBits[_screenStartStrip+i];
if (bits&0x3FFF) { if (bits&0x3FFF) {
for(j=0; j<13; j++) { for(j=0; j<NUM_ACTORS; j++) {
if ((bits&(1<<j)) && bits!=(1<<j)) { if ((bits&(1<<j)) && bits!=(1<<j)) {
Actor *a = derefActor(j); Actor *a = derefActor(j);
a->needRedraw = true; a->needRedraw = true;
@ -832,7 +832,7 @@ int Scumm::getActorFromPos(int x, int y) {
drawbits = actorDrawBits[x>>3]; drawbits = actorDrawBits[x>>3];
if (!(drawbits & 0x3FFF)) if (!(drawbits & 0x3FFF))
return 0; return 0;
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
Actor *a = derefActor(i); Actor *a = derefActor(i);
if (drawbits&(1<<i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) { if (drawbits&(1<<i) && !getClass(i, 32) && y >= a->top && y <= a->bottom) {
return i; return i;
@ -966,7 +966,7 @@ bool Scumm::isCostumeInUse(int cost) {
Actor *a; Actor *a;
if (_roomResource!=0) if (_roomResource!=0)
for (i=1; i<13; i++) { for (i=1; i<NUM_ACTORS; i++) {
a = derefActor(i); a = derefActor(i);
if (a->room == _currentRoom && a->costume == cost) if (a->room == _currentRoom && a->costume == cost)
return true; return true;

View file

@ -165,7 +165,7 @@ void ScummDebugger::printActors(int act) {
printf("+--------------------------------------------------------------+\n"); printf("+--------------------------------------------------------------+\n");
printf("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n"); printf("|# |room| x y |elev|cos|width|box|mov|zp|frame|scale|spd|dir|\n");
printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n"); printf("+--+----+--------+----+---+-----+---+---+--+-----+-----+---+---+\n");
for(i=1; i<13; i++) { for(i=1; i<NUM_ACTORS; i++) {
if (act==-1 || act==i) { if (act==-1 || act==i) {
a = &_s->actor[i]; a = &_s->actor[i];
if (a->visible) if (a->visible)

View file

@ -295,7 +295,7 @@ void Scumm::setCameraFollows(Actor *a) {
t-_screenStartStrip > cd->_rightTrigger) t-_screenStartStrip > cd->_rightTrigger)
setCameraAt(a->x); setCameraAt(a->x);
for (i=1,a=getFirstActor(); ++a,i<13; i++) { for (i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
if (a->room==_currentRoom) if (a->room==_currentRoom)
a->needRedraw = true; a->needRedraw = true;
} }
@ -1632,7 +1632,7 @@ void Scumm::resetActorBgs() {
} }
} }
for(i=1,a=getFirstActor(); ++a,i<13; i++) { for(i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
a->needBgReset = false; a->needBgReset = false;
} }
} }

5
gui.h
View file

@ -1,3 +1,6 @@
#if !defined(gui_h)
#define gui_h
enum { enum {
GUI_NONE = 0, GUI_NONE = 0,
GUI_TEXT = 1, GUI_TEXT = 1,
@ -73,3 +76,5 @@ struct Gui {
void queryMessage(const char *msg, const char *alts); void queryMessage(const char *msg, const char *alts);
byte getDefaultColor(int color); byte getDefaultColor(int color);
}; };
#endif

View file

@ -175,7 +175,7 @@ void Scumm::readIndexFileV5(int mode) {
switch(blocktype) { switch(blocktype) {
case MKID('DCHR'): case MKID('DCHR'):
readResTypeList(6,MKID('CHAR'),"charset"); readResTypeList(rtCharset,MKID('CHAR'),"charset");
break; break;
case MKID('DOBJ'): case MKID('DOBJ'):
@ -200,15 +200,15 @@ void Scumm::readIndexFileV5(int mode) {
break; break;
case MKID('DROO'): case MKID('DROO'):
readResTypeList(1,MKID('ROOM'),"room"); readResTypeList(rtRoom,MKID('ROOM'),"room");
break; break;
case MKID('DSCR'): case MKID('DSCR'):
readResTypeList(2,MKID('SCRP'),"script"); readResTypeList(rtScript,MKID('SCRP'),"script");
break; break;
case MKID('DCOS'): case MKID('DCOS'):
readResTypeList(3,MKID('COST'),"costume"); readResTypeList(rtCostume,MKID('COST'),"costume");
break; break;
case MKID('MAXS'): case MKID('MAXS'):
@ -224,7 +224,7 @@ void Scumm::readIndexFileV5(int mode) {
break; break;
case MKID('DSOU'): case MKID('DSOU'):
readResTypeList(4,MKID('SOUN'),"sound"); readResTypeList(rtSound,MKID('SOUN'),"sound");
break; break;
default: default:
@ -265,7 +265,7 @@ void Scumm::readIndexFileV6() {
switch(blocktype) { switch(blocktype) {
case MKID('DCHR'): case MKID('DCHR'):
readResTypeList(6,MKID('CHAR'),"charset"); readResTypeList(rtCharset,MKID('CHAR'),"charset");
break; break;
case MKID('DOBJ'): case MKID('DOBJ'):
@ -284,15 +284,15 @@ void Scumm::readIndexFileV6() {
break; break;
case MKID('DROO'): case MKID('DROO'):
readResTypeList(1,MKID('ROOM'),"room"); readResTypeList(rtRoom,MKID('ROOM'),"room");
break; break;
case MKID('DSCR'): case MKID('DSCR'):
readResTypeList(2,MKID('SCRP'),"script"); readResTypeList(rtScript,MKID('SCRP'),"script");
break; break;
case MKID('DCOS'): case MKID('DCOS'):
readResTypeList(3,MKID('COST'),"costume"); readResTypeList(rtCostume,MKID('COST'),"costume");
break; break;
case MKID('MAXS'): case MKID('MAXS'):
@ -300,7 +300,7 @@ void Scumm::readIndexFileV6() {
break; break;
case MKID('DSOU'): case MKID('DSOU'):
readResTypeList(4,MKID('SOUN'),"sound"); readResTypeList(rtSound,MKID('SOUN'),"sound");
break; break;
case MKID('AARY'): case MKID('AARY'):
@ -412,7 +412,7 @@ void Scumm::ensureResourceLoaded(int type, int i) {
debug(9, "ensureResourceLoaded(%d,%d)", type, i); debug(9, "ensureResourceLoaded(%d,%d)", type, i);
if (type==1 && i>127) { if (type==rtRoom && i>127) {
i = _resourceMapper[i&127]; i = _resourceMapper[i&127];
} }
@ -425,7 +425,7 @@ void Scumm::ensureResourceLoaded(int type, int i) {
loadResource(type, i); loadResource(type, i);
if (type==1 && i==_roomResource) if (type==rtRoom && i==_roomResource)
_vars[VAR_ROOM_FLAG] = 1; _vars[VAR_ROOM_FLAG] = 1;
} }
@ -442,7 +442,7 @@ int Scumm::loadResource(int type, int index) {
res.name[type],index); res.name[type],index);
} }
if (type==1) { if (type==rtRoom) {
fileOffs = 0; fileOffs = 0;
} else { } else {
fileOffs = res.roomoffs[type][index]; fileOffs = res.roomoffs[type][index];
@ -455,7 +455,7 @@ int Scumm::loadResource(int type, int index) {
openRoom(roomNr); openRoom(roomNr);
fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET); fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET);
if (type==4) { if (type==rtSound) {
fileReadDwordLE(); fileReadDwordLE();
fileReadDwordLE(); fileReadDwordLE();
return readSoundResource(type, index); return readSoundResource(type, index);
@ -475,7 +475,7 @@ int Scumm::loadResource(int type, int index) {
/* dump the resource */ /* dump the resource */
#ifdef DUMP_SCRIPTS #ifdef DUMP_SCRIPTS
if(type==2) { if(type==rtScript) {
dumpResource("script-", index, getResourceAddress(rtScript, index)); dumpResource("script-", index, getResourceAddress(rtScript, index));
} }
#endif #endif
@ -526,7 +526,7 @@ int Scumm::readSoundResource(int type, int index) {
} }
int Scumm::getResourceRoomNr(int type, int index) { int Scumm::getResourceRoomNr(int type, int index) {
if (type==1) if (type==rtRoom)
return index; return index;
return res.roomno[type][index]; return res.roomno[type][index];
} }
@ -602,7 +602,7 @@ byte *Scumm::createResource(int type, int index, uint32 size) {
} }
void Scumm::validateResource(const char *str, int type, int index) { void Scumm::validateResource(const char *str, int type, int index) {
if (type<1 || type>16 || index<0 || index >= res.num[type]) { if (type<rtFirst || type>rtLast || (uint)index >= (uint)res.num[type]) {
error("%d Illegal Glob type %d num %d", str, type, index); error("%d Illegal Glob type %d num %d", str, type, index);
} }
} }
@ -686,7 +686,7 @@ void Scumm::increaseResourceCounter() {
int i,j; int i,j;
byte counter; byte counter;
for (i=1; i<=16; i++) { for (i=rtFirst; i<=rtLast; i++) {
for(j=res.num[i]; --j>=0;) { for(j=res.num[i]; --j>=0;) {
counter = res.flags[i][j] & 0x7F; counter = res.flags[i][j] & 0x7F;
if (counter && counter < 0x7F) { if (counter && counter < 0x7F) {
@ -717,7 +717,7 @@ void Scumm::expireResources(uint32 size) {
best_type = 0; best_type = 0;
best_counter = 2; best_counter = 2;
for (i=1; i<=16; i++) for (i=rtFirst; i<=rtLast; i++)
if (res.mode[i]) { if (res.mode[i]) {
for(j=res.num[i]; --j>=0;) { for(j=res.num[i]; --j>=0;) {
flag = res.flags[i][j]; flag = res.flags[i][j];
@ -741,7 +741,7 @@ void Scumm::expireResources(uint32 size) {
void Scumm::freeResources() { void Scumm::freeResources() {
int i,j; int i,j;
for (i=1; i<=16; i++) { for (i=rtFirst; i<=rtLast; i++) {
for(j=res.num[i]; --j>=0;) { for(j=res.num[i]; --j>=0;) {
if (isResourceLoaded(i,j)) if (isResourceLoaded(i,j))
nukeResource(i,j); nukeResource(i,j);
@ -786,7 +786,7 @@ void Scumm::resourceStats() {
uint32 lockedSize = 0, lockedNum = 0; uint32 lockedSize = 0, lockedNum = 0;
byte flag; byte flag;
for (i=1; i<=16; i++) for (i=rtFirst; i<=rtLast; i++)
for(j=res.num[i]; --j>=0;) { for(j=res.num[i]; --j>=0;) {
flag = res.flags[i][j]; flag = res.flags[i][j];
if (flag&0x80 && res.address[i][j]) { if (flag&0x80 && res.address[i][j]) {

View file

@ -95,7 +95,7 @@ bool Scumm::loadState(int slot, bool compat) {
memset(_inventory, 0, sizeof(_inventory[0])*_numInventory); memset(_inventory, 0, sizeof(_inventory[0])*_numInventory);
/* Nuke all resources */ /* Nuke all resources */
for (i=1; i<=16; i++) for (i=rtFirst; i<=rtLast; i++)
if (i!=rtTemp && i!=rtBuffer) if (i!=rtTemp && i!=rtBuffer)
for(j=0; j<res.num[i]; j++) { for(j=0; j<res.num[i]; j++) {
nukeResource(i,j); nukeResource(i,j);
@ -452,7 +452,7 @@ void Scumm::saveOrLoad(Serializer *s) {
s->saveLoadArrayOf(string, 6, sizeof(string[0]), stringTabEntries); s->saveLoadArrayOf(string, 6, sizeof(string[0]), stringTabEntries);
s->saveLoadArrayOf(_colorCycle, 16, sizeof(_colorCycle[0]), colorCycleEntries); s->saveLoadArrayOf(_colorCycle, 16, sizeof(_colorCycle[0]), colorCycleEntries);
for (i=1; i<=16; i++) for (i=rtFirst; i<=rtLast; i++)
if (res.mode[i]==0) if (res.mode[i]==0)
for(j=1; j<res.num[i]; j++) for(j=1; j<res.num[i]; j++)
saveLoadResource(s,i,j); saveLoadResource(s,i,j);
@ -464,7 +464,7 @@ void Scumm::saveOrLoad(Serializer *s) {
/* Save or load a list of the locked objects */ /* Save or load a list of the locked objects */
if (s->isSaving()) { if (s->isSaving()) {
for (i=1; i<=16; i++) for (i=rtFirst; i<=rtLast; i++)
for(j=1; j<res.num[i]; j++) { for(j=1; j<res.num[i]; j++) {
if (res.flags[i][j]&0x80) { if (res.flags[i][j]&0x80) {
s->saveByte(i); s->saveByte(i);
@ -486,7 +486,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int index) {
byte flag; byte flag;
/* don't save/load these resource types */ /* don't save/load these resource types */
if (type==13 || type==12 || type==10 || res.mode[type]) if (type==rtFlObject || type==rtTemp || type==rtBuffer || res.mode[type])
return; return;
if (ser->isSaving()) { if (ser->isSaving()) {
@ -501,7 +501,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int index) {
ser->saveUint32(size); ser->saveUint32(size);
ser->saveLoadBytes(ptr+sizeof(ResHeader),size); ser->saveLoadBytes(ptr+sizeof(ResHeader),size);
if (type==5) { if (type==rtInventory) {
ser->saveWord(_inventory[index]); ser->saveWord(_inventory[index]);
} }
} else { } else {
@ -509,7 +509,7 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int index) {
if (size) { if (size) {
createResource(type, index, size); createResource(type, index, size);
ser->saveLoadBytes(getResourceAddress(type, index), size); ser->saveLoadBytes(getResourceAddress(type, index), size);
if (type==5) { if (type==rtInventory) {
_inventory[index] = ser->loadWord(); _inventory[index] = ser->loadWord();
} }
} }

View file

@ -2004,7 +2004,7 @@ void Scumm::o6_miscOps() {
case 6: case 6:
_fullRedraw = 1; _fullRedraw = 1;
redrawBGAreas(); redrawBGAreas();
for (i=0; i<13; i++) for (i=0; i<NUM_ACTORS; i++)
derefActor(i)->needRedraw = true; derefActor(i)->needRedraw = true;
processActors(); processActors();
screenEffect(args[1]); screenEffect(args[1]);

23
scumm.h
View file

@ -29,6 +29,7 @@ struct Actor;
typedef void (Scumm::*OpcodeProc)(); typedef void (Scumm::*OpcodeProc)();
#define NUM_SCRIPT_SLOT 25 #define NUM_SCRIPT_SLOT 25
#define NUM_ACTORS 13
#pragma START_PACK_STRUCTS #pragma START_PACK_STRUCTS
@ -289,6 +290,7 @@ enum ScummVars {
}; };
enum ResTypes { enum ResTypes {
rtFirst = 1,
rtRoom = 1, rtRoom = 1,
rtScript = 2, rtScript = 2,
rtCostume = 3, rtCostume = 3,
@ -305,6 +307,9 @@ enum ResTypes {
rtMatrix = 14, rtMatrix = 14,
rtBox = 15, rtBox = 15,
rtObjectName = 16, rtObjectName = 16,
rtLast = 16,
rtNumTypes = 17,
}; };
@ -759,14 +764,14 @@ struct Scumm {
int16 _palManipCounter; int16 _palManipCounter;
struct { struct {
byte mode[17]; byte mode[rtNumTypes];
uint16 num[17]; uint16 num[rtNumTypes];
uint32 tags[17]; uint32 tags[rtNumTypes];
const char *name[17]; const char *name[rtNumTypes];
byte **address[17]; byte **address[rtNumTypes];
byte *flags[17]; byte *flags[rtNumTypes];
byte *roomno[17]; byte *roomno[rtNumTypes];
uint32 *roomoffs[17]; uint32 *roomoffs[rtNumTypes];
} res; } res;
struct { struct {
@ -784,7 +789,7 @@ struct Scumm {
int16 x,y; int16 x,y;
} mouse; } mouse;
Actor actor[13]; Actor actor[NUM_ACTORS];
uint16 actorDrawBits[200]; uint16 actorDrawBits[200];

View file

@ -72,7 +72,7 @@ void Scumm::scummInit() {
setShake(0); setShake(0);
setupCursor(); setupCursor();
for (i=1,a=getFirstActor(); ++a,i<13; i++) { for (i=1,a=getFirstActor(); ++a,i<NUM_ACTORS; i++) {
a->number = i; a->number = i;
initActor(a, 1); initActor(a, 1);
} }
@ -287,7 +287,7 @@ int Scumm::scummLoop(int delta) {
charset._hasMask = false; charset._hasMask = false;
redrawVerbs(); redrawVerbs();
_fullRedraw = true; _fullRedraw = true;
for (i=0,a=getFirstActor(); i<13; i++,a++) for (i=0,a=getFirstActor(); i<NUM_ACTORS; i++,a++)
a->needRedraw = 1; a->needRedraw = 1;
} }
@ -484,7 +484,7 @@ void Scumm::startScene(int room, Actor *a, int objectNr) {
killScriptsAndResources(); killScriptsAndResources();
stopCycle(0); stopCycle(0);
for(i=1,at=getFirstActor(); ++at,i<13; i++) { for(i=1,at=getFirstActor(); ++at,i<NUM_ACTORS; i++) {
if (at->visible) if (at->visible)
hideActor(at); hideActor(at);
} }
@ -836,7 +836,7 @@ void Scumm::convertKeysToClicks() {
} }
Actor *Scumm::derefActorSafe(int id, const char *errmsg) { Actor *Scumm::derefActorSafe(int id, const char *errmsg) {
if (id<1 || id>=13) if (id<1 || id>=NUM_ACTORS)
error("Invalid actor %d in %s", id, errmsg); error("Invalid actor %d in %s", id, errmsg);
return derefActor(id); return derefActor(id);
} }