diff options
| author | Max Horn | 2003-05-23 12:48:50 +0000 |
|---|---|---|
| committer | Max Horn | 2003-05-23 12:48:50 +0000 |
| commit | 28eade1da4e1811a230feb6c30d3abcf31deb0c2 (patch) | |
| tree | a7150fe7b617b795816284811978e2356d90ce83 | |
| parent | f802c2a7ba65e5625d9946aa8c42dd40127c2fee (diff) | |
| download | scummvm-rg350-28eade1da4e1811a230feb6c30d3abcf31deb0c2.tar.gz scummvm-rg350-28eade1da4e1811a230feb6c30d3abcf31deb0c2.tar.bz2 scummvm-rg350-28eade1da4e1811a230feb6c30d3abcf31deb0c2.zip | |
when iterating from 1 to _numActors over all actors, use _actors[] directly instead of derefActor() (unnecessary overhead); added range check to derefActor, and error out if invalid actor is accessed
svn-id: r7858
| -rw-r--r-- | scumm/actor.cpp | 70 | ||||
| -rw-r--r-- | scumm/scumm.h | 2 | ||||
| -rw-r--r-- | scumm/scummvm.cpp | 24 |
3 files changed, 40 insertions, 56 deletions
diff --git a/scumm/actor.cpp b/scumm/actor.cpp index 542ff7a1a8..b0b5a94f5c 100644 --- a/scumm/actor.cpp +++ b/scumm/actor.cpp @@ -770,42 +770,35 @@ void Actor::showActor() { void Scumm::showActors() { int i; - Actor *a; for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if (a->isInCurrentRoom()) - a->showActor(); + if (_actors[i].isInCurrentRoom()) + _actors[i].showActor(); } } void Scumm::walkActors() { int i; - Actor *a; for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if (a->isInCurrentRoom()) + if (_actors[i].isInCurrentRoom()) if (_features & GF_AFTER_V2 || _features & GF_AFTER_V3) - a->walkActorOld(); + _actors[i].walkActorOld(); else - a->walkActor(); + _actors[i].walkActor(); } } /* Used in Scumm v5 only. Play sounds associated with actors */ void Scumm::playActorSounds() { int i; - Actor *a; for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if (a->cost.animCounter2 && a->isInCurrentRoom() && a->sound) { + if (_actors[i].cost.animCounter2 && _actors[i].isInCurrentRoom() && _actors[i].sound) { _currentScript = 0xFF; - _sound->addSoundToQueue(a->sound[0]); + _sound->addSoundToQueue(_actors[i].sound[0]); for (i = 1; i < _numActors; i++) { - a = derefActor(i); - a->cost.animCounter2 = 0; + _actors[i].cost.animCounter2 = 0; } return; } @@ -824,11 +817,10 @@ void Scumm::processActors() { // Make a list of all actors in this room for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if ((_features & GF_AFTER_V8) && a->layer < 0) + if ((_features & GF_AFTER_V8) && _actors[i].layer < 0) continue; - if (a->isInCurrentRoom()) - actors[numactors++] = a; + if (_actors[i].isInCurrentRoom()) + actors[numactors++] = &_actors[i]; } if (!numactors) { delete [] actors; @@ -866,16 +858,14 @@ void Scumm::processActors() { // Used in Scumm v8, to allow the verb coin to be drawn over the inventory // chest. I'm assuming that draw order won't matter here. void Scumm::processUpperActors() { - Actor *a; int i; for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if (a->isInCurrentRoom() && a->costume && a->layer < 0) { + if (_actors[i].isInCurrentRoom() && _actors[i].costume && _actors[i].layer < 0) { CHECK_HEAP - a->drawActorCostume(); + _actors[i].drawActorCostume(); CHECK_HEAP - a->animateCostume(); + _actors[i].animateCostume(); } } } @@ -1038,9 +1028,8 @@ void Scumm::setActorRedrawFlags(bool fg, bool bg) { if (_fullRedraw) { for (j = 1; j < _numActors; j++) { - Actor *a = derefActor(j); - a->needRedraw |= fg; - a->needBgReset |= bg; + _actors[j].needRedraw |= fg; + _actors[j].needBgReset |= bg; } } else { for (i = 0; i < gdi._numStrips; i++) { @@ -1048,10 +1037,8 @@ void Scumm::setActorRedrawFlags(bool fg, bool bg) { if (testGfxAnyUsageBits(strip)) { for (j = 1; j < _numActors; j++) { if (testGfxUsageBit(strip, j) && testGfxOtherUsageBits(strip, j)) { - Actor *a = derefActor(j); - assert(a->number == j); - a->needRedraw |= fg; - a->needBgReset |= bg; + _actors[j].needRedraw |= fg; + _actors[j].needBgReset |= bg; } } } @@ -1065,10 +1052,8 @@ int Scumm::getActorFromPos(int x, int y) { if (!testGfxAnyUsageBits(x >> 3)) return 0; for (i = 1; i < _numActors; i++) { - Actor *a = derefActor(i); - assert(a->number == i); if (testGfxUsageBit(x >> 3, i) && !getClass(i, kObjectClassUntouchable) - && y >= a->top && y <= a->bottom) { + && y >= _actors[i].top && y <= _actors[i].bottom) { return i; } } @@ -1088,8 +1073,7 @@ void Scumm::actorTalk() { VAR(VAR_TALK_ACTOR) = 0xFF; } else { int oldact; - a = derefActorSafe(_actorToPrintStrFor, "actorTalk"); - assert(a); + a = derefActor(_actorToPrintStrFor, "actorTalk"); if (!a->isInCurrentRoom() && !(_features & GF_NEW_COSTUMES)) { oldact = 0xFF; } else { @@ -1109,7 +1093,7 @@ void Scumm::actorTalk() { if (VAR(VAR_TALK_ACTOR) > 0x7F) { _charsetColor = (byte)_string[0].color; } else { - a = derefActorSafe(VAR(VAR_TALK_ACTOR), "actorTalk(2)"); + a = derefActor(VAR(VAR_TALK_ACTOR), "actorTalk(2)"); _charsetColor = a->talkColor; } _charsetBufPos = 0; @@ -1131,7 +1115,7 @@ void Scumm::stopTalk() { act = VAR(VAR_TALK_ACTOR); if (act && act < 0x80) { - Actor *a = derefActorSafe(act, "stopTalk"); + Actor *a = derefActor(act, "stopTalk"); if ((a->isInCurrentRoom() && _useTalkAnims) || (_features & GF_NEW_COSTUMES)) { a->startAnimActor(a->talkStopFrame); _useTalkAnims = false; @@ -1506,18 +1490,16 @@ void Scumm::resetActorBgs() { for (i = 0; i < gdi._numStrips; i++) { int strip = _screenStartStrip + i; for (j = 1; j < _numActors; j++) { - a = derefActor(j); - if (testGfxUsageBit(strip, j) && a->top != 0xFF && a->needBgReset) { + if (testGfxUsageBit(strip, j) && _actors[j].top != 0xFF && _actors[j].needBgReset) { clearGfxUsageBit(strip, j); - if ((a->bottom - a->top) >= 0) - gdi.resetBackground(a->top, a->bottom, i); + if ((_actors[j].bottom - _actors[j].top) >= 0) + gdi.resetBackground(_actors[j].top, _actors[j].bottom, i); } } } for (i = 1; i < _numActors; i++) { - a = derefActor(i); - a->needBgReset = false; + _actors[i].needBgReset = false; } } diff --git a/scumm/scumm.h b/scumm/scumm.h index c7d1eabbe4..1fc1fcbf0f 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -718,7 +718,7 @@ protected: public: /* Should be in Actor class */ - Actor *derefActor(int id); + Actor *derefActor(int id, const char *errmsg = 0); Actor *derefActorSafe(int id, const char *errmsg); void showActors(); diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 68fc040632..391d8dece1 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -655,7 +655,6 @@ Scumm::~Scumm () void Scumm::scummInit() { int i; - Actor *a; tempMusic = 0; debug(9, "scummInit"); @@ -696,9 +695,8 @@ void Scumm::scummInit() { Actor::initActorClass(this); _actors = new Actor[_numActors]; for (i = 1; i < _numActors; i++) { - a = derefActor(i); - a->number = i; - a->initActor(1); + _actors[i].number = i; + _actors[i].initActor(1); } _numNestedScripts = 0; @@ -1085,7 +1083,6 @@ load_game: void Scumm::startScene(int room, Actor * a, int objectNr) { int i, where; - Actor *at; CHECK_HEAP; debug(1, "Loading room %d", room); @@ -1119,8 +1116,7 @@ void Scumm::startScene(int room, Actor * a, int objectNr) { stopCycle(0); for (i = 1; i < _numActors; i++) { - at = derefActor(i); - at->hideActor(); + _actors[i].hideActor(); } if (!(_features & GF_AFTER_V7)) { @@ -1218,7 +1214,7 @@ void Scumm::startScene(int room, Actor * a, int objectNr) { } } else { if (camera._follows) { - a = derefActorSafe(camera._follows, "startScene: follows"); + a = derefActor(camera._follows, "startScene: follows"); setCameraAt(a->x, a->y); } } @@ -1892,17 +1888,23 @@ void Scumm::convertKeysToClicks() { } } -Actor *Scumm::derefActor(int id) { +Actor *Scumm::derefActor(int id, const char *errmsg) { + if (id < 1 || id >= _numActors || _actors[id].number != id) { + if (errmsg) + error("Invalid actor %d in %s", id, errmsg); + else + error("Invalid actor %d", id); + } return &_actors[id]; } Actor *Scumm::derefActorSafe(int id, const char *errmsg) { - if (id < 1 || id >= _numActors) { + if (id < 1 || id >= _numActors || _actors[id].number != id) { debug(2, "Invalid actor %d in %s (script %d, opcode 0x%x) - This is potentially a BIG problem.", id, errmsg, vm.slot[_curExecScript].number, _opcode); return NULL; } - return derefActor(id); + return &_actors[id]; } void Scumm::setStringVars(int slot) { |
