Only allocate the actor sorting array once

svn-id: r17875
This commit is contained in:
Max Horn 2005-04-30 22:01:16 +00:00
parent 280abe9e91
commit ed4b43df73
3 changed files with 7 additions and 11 deletions

View file

@ -979,30 +979,25 @@ static int compareDrawOrder(const void* a, const void* b)
void ScummEngine::processActors() { void ScummEngine::processActors() {
int numactors = 0; int numactors = 0;
// TODO : put this actors as a member array. It never has to grow or shrink
// since _numActors is constant within a game.
Actor** actors = new Actor * [_numActors];
// Make a list of all actors in this room // Make a list of all actors in this room
for (int i = 1; i < _numActors; i++) { for (int i = 1; i < _numActors; i++) {
if (_version == 8 && _actors[i]._layer < 0) if (_version == 8 && _actors[i]._layer < 0)
continue; continue;
if (_actors[i].isInCurrentRoom() && _actors[i]._costume) if (_actors[i].isInCurrentRoom() && _actors[i]._costume)
actors[numactors++] = &_actors[i]; _sortedActors[numactors++] = &_actors[i];
} }
if (!numactors) { if (!numactors) {
delete [] actors;
return; return;
} }
// Sort actors by position before we draw them (to ensure that actors in // Sort actors by position before we draw them (to ensure that actors in
// front are drawn after those "behind" them). // front are drawn after those "behind" them).
qsort(actors, numactors, sizeof (Actor*), compareDrawOrder); qsort(_sortedActors, numactors, sizeof (Actor*), compareDrawOrder);
Actor** end = actors + numactors; Actor** end = _sortedActors + numactors;
// Finally draw the now sorted actors // Finally draw the now sorted actors
for (Actor** ac = actors; ac != end; ++ac) { for (Actor** ac = _sortedActors; ac != end; ++ac) {
Actor* a = *ac; Actor* a = *ac;
CHECK_HEAP CHECK_HEAP
a->drawActorCostume(); a->drawActorCostume();
@ -1010,8 +1005,6 @@ void ScummEngine::processActors() {
a->animateCostume(); a->animateCostume();
} }
delete [] actors;
if (_features & GF_NEW_COSTUMES) if (_features & GF_NEW_COSTUMES)
akos_processQueue(); akos_processQueue();
} }

View file

@ -1175,6 +1175,7 @@ ScummEngine::~ScummEngine() {
_mixer->stopAll(); _mixer->stopAll();
delete [] _actors; delete [] _actors;
delete [] _sortedActors;
delete _2byteFontPtr; delete _2byteFontPtr;
delete _charset; delete _charset;
@ -1546,6 +1547,7 @@ void ScummEngine::scummInit() {
// Allocate and Initialize actors // Allocate and Initialize actors
Actor::initActorClass(this); Actor::initActorClass(this);
_actors = new Actor[_numActors]; _actors = new Actor[_numActors];
_sortedActors = new Actor * [_numActors];
for (i = 0; i < _numActors; i++) { for (i = 0; i < _numActors; i++) {
_actors[i]._number = i; _actors[i]._number = i;
_actors[i].initActor(1); _actors[i].initActor(1);

View file

@ -462,6 +462,7 @@ protected:
byte _numActors; byte _numActors;
Actor *_actors; // Has _numActors elements Actor *_actors; // Has _numActors elements
Actor **_sortedActors;
byte *_arraySlot; byte *_arraySlot;
uint16 *_inventory; uint16 *_inventory;