[Scummvm-cvs-logs] CVS: scummvm/saga actor.cpp,1.204,1.205 actor.h,1.100,1.101 puzzle.cpp,1.19,1.20

Andrew Kurushin h00ligan at users.sourceforge.net
Thu Dec 1 10:23:11 CET 2005


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv302

Modified Files:
	actor.cpp actor.h puzzle.cpp 
Log Message:
reduce memory usage by 7Megs, CPU usage by 40% 

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.cpp,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- actor.cpp	3 Nov 2005 18:20:10 -0000	1.204
+++ actor.cpp	1 Dec 2005 18:22:29 -0000	1.205
@@ -306,9 +306,6 @@
 	size_t resourceLength;
 	int framesCount;
 	ActorFrameSequence *framesPointer;
-	int lastFrame = 0;
-	int orient;
-	int resourceId;
 	bool gotSomething = false;
 
 	if (actor->_frameListResourceId) {
@@ -326,15 +323,12 @@
 		MemoryReadStreamEndian readS(resourcePointer, resourceLength, _actorContext->isBigEndian);
 
 		for (int i = 0; i < framesCount; i++) {
-			for (orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) {
+			for (int orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) {
 				// Load all four orientations
 				framesPointer[i].directions[orient].frameIndex = readS.readUint16();
 				framesPointer[i].directions[orient].frameCount = readS.readSint16();
 				if (framesPointer[i].directions[orient].frameCount < 0)
 					warning("frameCount < 0 (%d)", framesPointer[i].directions[orient].frameCount);
-				if (framesPointer[i].directions[orient].frameIndex > lastFrame) {
-					lastFrame = framesPointer[i].directions[orient].frameIndex;
-				}
 			}
 		}
 
@@ -351,21 +345,7 @@
 			return true;
 	}
 
-	resourceId = actor->_spriteListResourceId;
-
-	if (resourceId) {
-		debug(9, "Loading sprite resource id %d", resourceId);
-
-		_vm->_sprite->loadList(resourceId, actor->_spriteList);
-
-		if (actor->_flags & kExtended) {
-			while ((lastFrame >= actor->_spriteList.spriteCount)) {
-				resourceId++;
-				debug(9, "Appending to sprite list %d", resourceId);
-				_vm->_sprite->loadList(resourceId, actor->_spriteList);
-			}
-		}
-
+	if (actor->_spriteListResourceId) {
 		gotSomething = true;
 	} else {
 		warning("Sprite List ID = 0 for actor index %d", actor->_index);
@@ -386,6 +366,31 @@
 	_actorsCount = 0;
 }
 
+void Actor::loadActorSpriteList(ActorData *actor) {
+	int lastFrame = 0;
+	int resourceId = actor->_spriteListResourceId;
+
+	for (int i = 0; i < actor->_framesCount; i++) {
+		for (int orient = 0; orient < ACTOR_DIRECTIONS_COUNT; orient++) {
+			if (actor->_frames[i].directions[orient].frameIndex > lastFrame) {
+				lastFrame = actor->_frames[i].directions[orient].frameIndex;
+			}
+		}
+	}
+
+	debug(9, "Loading actor sprite resource id %d", resourceId);
+
+	_vm->_sprite->loadList(resourceId, actor->_spriteList);
+
+	if (actor->_flags & kExtended) {
+		while ((lastFrame >= actor->_spriteList.spriteCount)) {
+			resourceId++;
+			debug(9, "Appending to actor sprite list %d", resourceId);
+			_vm->_sprite->loadList(resourceId, actor->_spriteList);
+		}
+	}
+}
+
 void Actor::loadActorList(int protagonistIdx, int actorCount, int actorsResourceID, int protagStatesCount, int protagStatesResourceID) {
 	int i, j;
 	ActorData *actor;
@@ -774,6 +779,7 @@
 	for (i = 0; i < _actorsCount; i++) {
 		actor = _actors[i];
 		actor->_inScene = false;
+		actor->_spriteList.freeMem();
 		if (actor->_disabled) {
 			continue;
 		}
@@ -1578,8 +1584,12 @@
 		frameNumber = 8;
 		spriteList = &_vm->_sprite->_mainSprites;
 	} else if (validActorId(commonObjectData->_id)) {
-		spriteList = &((ActorData *)commonObjectData)->_spriteList;
-		frameNumber = ((ActorData *)commonObjectData)->_frameNumber;
+		ActorData *actor = (ActorData *)commonObjectData;
+		spriteList = &(actor->_spriteList);
+		frameNumber = actor->_frameNumber;
+		if (spriteList->infoList == NULL)
+			loadActorSpriteList(actor);
+
 	} else if (validObjId(commonObjectData->_id)) {
 		spriteList = &_vm->_sprite->_mainSprites;
 		frameNumber = commonObjectData->_spriteListResourceId;

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.h,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- actor.h	3 Nov 2005 18:20:11 -0000	1.100
+++ actor.h	1 Dec 2005 18:22:29 -0000	1.101
@@ -40,7 +40,7 @@
 class HitZone;
 
 
-#define ACTOR_DEBUG
+//#define ACTOR_DEBUG only for actor pathfinding debug!
 
 #define ACTOR_BARRIERS_MAX 16
 
@@ -473,6 +473,10 @@
 		_walkStepsPoints[_walkStepsCount++] = point;
 	}
 
+	void freeSpriteList() {
+		_spriteList.freeMem();
+	}
+
 	ActorData() {
 		memset(this, 0, sizeof(*this));
 	}
@@ -480,7 +484,7 @@
 		free(_frames);
 		free(_tileDirections);
 		free(_walkStepsPoints);
-		_spriteList.freeMem();
+		freeSpriteList();
 	}
 };
 
@@ -519,6 +523,7 @@
 class Actor {
 	friend class IsoMap;
 	friend class SagaEngine;
+	friend class Puzzle;
 public:
 
 	Actor(SagaEngine *vm);
@@ -606,6 +611,7 @@
 
 private:
 	void stepZoneAction(ActorData *actor, const HitZone *hitZone, bool exit, bool stopped);
+	void loadActorSpriteList(ActorData *actor);
 
 	void createDrawOrderList();
 	bool calcScreenPosition(CommonObjectData *commonObjectData);

Index: puzzle.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/puzzle.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- puzzle.cpp	3 Nov 2005 18:20:12 -0000	1.19
+++ puzzle.cpp	1 Dec 2005 18:22:29 -0000	1.20
@@ -140,11 +140,14 @@
 }
 
 void Puzzle::initPieces(void) {
-	ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE));
 	SpriteInfo *spI;
-
+	ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE));
+	int frameNumber;
+	SpriteList *spriteList;
+	_vm->_actor->getSpriteParams(puzzle, frameNumber, spriteList);
+	
 	for (int i = 0; i < PUZZLE_PIECES; i++) {
-		spI = &puzzle->_spriteList.infoList[i];
+		spI = &(spriteList->infoList[i]);
 		_pieceInfo[i].offX = (byte)(spI->width >> 1);
 		_pieceInfo[i].offY = (byte)(spI->height >> 1);
 
@@ -159,13 +162,16 @@
 
 void Puzzle::showPieces(void) {
 	ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE));
+	int frameNumber;
+	SpriteList *spriteList;
 	Surface *backBuffer = _vm->_gfx->getBackBuffer();
+	_vm->_actor->getSpriteParams(puzzle, frameNumber, spriteList);
 
 	for (int j = PUZZLE_PIECES - 1 ; j >= 0; j--) {
 		int num = _piecePriority[j];
 
 		if (_puzzlePiece != num) {
-			_vm->_sprite->draw(backBuffer, _vm->getDisplayClip(), puzzle->_spriteList, num, Point(_pieceInfo[num].curX, _pieceInfo[num].curY), 256);
+			_vm->_sprite->draw(backBuffer, _vm->getDisplayClip(), *spriteList, num, Point(_pieceInfo[num].curX, _pieceInfo[num].curY), 256);
 		}
 	}
 }
@@ -173,8 +179,11 @@
 void Puzzle::drawCurrentPiece() {
 	ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE));
 	Surface *backBuffer = _vm->_gfx->getBackBuffer();
+	int frameNumber;
+	SpriteList *spriteList;
+	_vm->_actor->getSpriteParams(puzzle, frameNumber, spriteList);
 
-	_vm->_sprite->draw(backBuffer, _vm->_scene->getSceneClip(), puzzle->_spriteList, _puzzlePiece,
+	_vm->_sprite->draw(backBuffer, _vm->_scene->getSceneClip(), *spriteList, _puzzlePiece,
 			   Point(_pieceInfo[_puzzlePiece].curX, _pieceInfo[_puzzlePiece].curY), 256);
 }
 
@@ -302,6 +311,10 @@
 	if (mousePt.x >= boxx && mousePt.x < boxw && mousePt.y >= boxy && mousePt.y <= boxh) {
 		ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE));
 		SpriteInfo *spI;
+		int frameNumber;
+		SpriteList *spriteList;
+		_vm->_actor->getSpriteParams(puzzle, frameNumber, spriteList);
+
 		int newx = mousePt.x - _pieceInfo[_puzzlePiece].offX;
 		int newy = mousePt.y - _pieceInfo[_puzzlePiece].offY;
 
@@ -310,7 +323,7 @@
 		if (newy < boxy)
 			newy = PUZZLE_Y_OFFSET;
 
-		spI = &puzzle->_spriteList.infoList[_puzzlePiece];
+		spI = &(spriteList->infoList[_puzzlePiece]);
 
 		if (newx + spI->width > boxw)
 			newx = boxw - spI->width ;





More information about the Scummvm-git-logs mailing list