aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kurushin2005-12-01 18:22:29 +0000
committerAndrew Kurushin2005-12-01 18:22:29 +0000
commit81eed2207555ed60f04d183bce4e79f29a3a650c (patch)
tree89f3233d07cc7f1e8bf1462b92174764c25a87e9
parentda65d3c08f56c1dd6d935b94ee9218d702160814 (diff)
downloadscummvm-rg350-81eed2207555ed60f04d183bce4e79f29a3a650c.tar.gz
scummvm-rg350-81eed2207555ed60f04d183bce4e79f29a3a650c.tar.bz2
scummvm-rg350-81eed2207555ed60f04d183bce4e79f29a3a650c.zip
reduce memory usage by 7Megs, CPU usage by 40%
svn-id: r19724
-rw-r--r--saga/actor.cpp58
-rw-r--r--saga/actor.h10
-rw-r--r--saga/puzzle.cpp25
3 files changed, 61 insertions, 32 deletions
diff --git a/saga/actor.cpp b/saga/actor.cpp
index 86fbe71265..46c99a5685 100644
--- a/saga/actor.cpp
+++ b/saga/actor.cpp
@@ -306,9 +306,6 @@ bool Actor::loadActorResources(ActorData *actor) {
size_t resourceLength;
int framesCount;
ActorFrameSequence *framesPointer;
- int lastFrame = 0;
- int orient;
- int resourceId;
bool gotSomething = false;
if (actor->_frameListResourceId) {
@@ -326,15 +323,12 @@ bool Actor::loadActorResources(ActorData *actor) {
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 @@ bool Actor::loadActorResources(ActorData *actor) {
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 @@ void Actor::freeActorList() {
_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 @@ void Actor::updateActorsScene(int actorsEntrance) {
for (i = 0; i < _actorsCount; i++) {
actor = _actors[i];
actor->_inScene = false;
+ actor->_spriteList.freeMem();
if (actor->_disabled) {
continue;
}
@@ -1578,8 +1584,12 @@ bool Actor::getSpriteParams(CommonObjectData *commonObjectData, int &frameNumber
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;
diff --git a/saga/actor.h b/saga/actor.h
index 949bfd7b58..fd05f8efee 100644
--- a/saga/actor.h
+++ b/saga/actor.h
@@ -40,7 +40,7 @@ namespace Saga {
class HitZone;
-#define ACTOR_DEBUG
+//#define ACTOR_DEBUG only for actor pathfinding debug!
#define ACTOR_BARRIERS_MAX 16
@@ -473,6 +473,10 @@ public:
_walkStepsPoints[_walkStepsCount++] = point;
}
+ void freeSpriteList() {
+ _spriteList.freeMem();
+ }
+
ActorData() {
memset(this, 0, sizeof(*this));
}
@@ -480,7 +484,7 @@ public:
free(_frames);
free(_tileDirections);
free(_walkStepsPoints);
- _spriteList.freeMem();
+ freeSpriteList();
}
};
@@ -519,6 +523,7 @@ struct SpeechData {
class Actor {
friend class IsoMap;
friend class SagaEngine;
+ friend class Puzzle;
public:
Actor(SagaEngine *vm);
@@ -606,6 +611,7 @@ protected:
private:
void stepZoneAction(ActorData *actor, const HitZone *hitZone, bool exit, bool stopped);
+ void loadActorSpriteList(ActorData *actor);
void createDrawOrderList();
bool calcScreenPosition(CommonObjectData *commonObjectData);
diff --git a/saga/puzzle.cpp b/saga/puzzle.cpp
index 025e280021..46dc84a787 100644
--- a/saga/puzzle.cpp
+++ b/saga/puzzle.cpp
@@ -140,11 +140,14 @@ void Puzzle::exitPuzzle(void) {
}
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::initPieces(void) {
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::showPieces(void) {
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 @@ void Puzzle::dropPiece(Point mousePt) {
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 @@ void Puzzle::dropPiece(Point mousePt) {
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 ;