[Scummvm-cvs-logs] CVS: scummvm/scumm actor.cpp,1.108,1.109 scummvm.cpp,2.176,2.177 scumm.h,1.209,1.210

Max Horn fingolfin at users.sourceforge.net
Fri May 23 05:49:07 CEST 2003


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv31946

Modified Files:
	actor.cpp scummvm.cpp scumm.h 
Log Message:
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

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/actor.cpp,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- actor.cpp	22 May 2003 10:40:49 -0000	1.108
+++ actor.cpp	23 May 2003 12:48:49 -0000	1.109
@@ -770,42 +770,35 @@
 
 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 @@
 	
 	// 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 @@
 // 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 @@
 
 	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 @@
 			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 @@
 	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 @@
 		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 @@
 	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 @@
 
 	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 @@
 	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;
 	}
 }
 

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scummvm.cpp,v
retrieving revision 2.176
retrieving revision 2.177
diff -u -d -r2.176 -r2.177
--- scummvm.cpp	22 May 2003 05:21:48 -0000	2.176
+++ scummvm.cpp	23 May 2003 12:48:50 -0000	2.177
@@ -655,7 +655,6 @@
 
 void Scumm::scummInit() {
 	int i;
-	Actor *a;
 
 	tempMusic = 0;
 	debug(9, "scummInit");
@@ -696,9 +695,8 @@
 	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 @@
 
 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 @@
 	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 @@
 		}
 	} 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 @@
 	}
 }
 
-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) {

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.209
retrieving revision 1.210
diff -u -d -r1.209 -r1.210
--- scumm.h	22 May 2003 14:10:19 -0000	1.209
+++ scumm.h	23 May 2003 12:48:50 -0000	1.210
@@ -718,7 +718,7 @@
 
 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();
 





More information about the Scummvm-git-logs mailing list