diff options
-rw-r--r-- | engines/sludge/builtin.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/graphics.cpp | 12 | ||||
-rw-r--r-- | engines/sludge/graphics.h | 9 | ||||
-rw-r--r-- | engines/sludge/people.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/sprbanks.cpp | 28 | ||||
-rw-r--r-- | engines/sludge/sprbanks.h | 4 | ||||
-rw-r--r-- | engines/sludge/sprites.cpp | 5 |
7 files changed, 39 insertions, 23 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index a27fcb4153..01d58a0815 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -875,7 +875,7 @@ builtIn(anim) { trimStack(fun->stack); // Load the required sprite bank - LoadedSpriteBank *sprBanky = loadBankForAnim(fileNumber); + LoadedSpriteBank *sprBanky = g_sludge->_gfxMan->loadBankForAnim(fileNumber); if (!sprBanky) return BR_ERROR; // File not found, fatal done already setBankFile(ba, sprBanky); diff --git a/engines/sludge/graphics.cpp b/engines/sludge/graphics.cpp index 626c8a20c7..d0333bac8f 100644 --- a/engines/sludge/graphics.cpp +++ b/engines/sludge/graphics.cpp @@ -30,6 +30,7 @@ #include "sludge/sludge.h" #include "sludge/sludger.h" #include "sludge/sprites.h" +#include "sludge/sprbanks.h" #include "sludge/zbuffer.h" namespace Sludge { @@ -62,6 +63,9 @@ GraphicsManager::GraphicsManager(SludgeEngine *vm) { _spriteLayers = new SpriteLayers; _spriteLayers->numLayers = 0; + // Sprite Bank + _allLoadedBanks.clear(); + // ZBuffer _zBuffer = new ZBufferData; _zBuffer->originalNum = -1; @@ -98,6 +102,14 @@ GraphicsManager::~GraphicsManager() { delete _spriteLayers; _spriteLayers = nullptr; + // kill sprite banks + LoadedSpriteBanks::iterator it; + for (it = _allLoadedBanks.begin(); it != _allLoadedBanks.end(); ++it) { + delete (*it); + (*it) = nullptr; + } + _allLoadedBanks.clear(); + // kill zbuffer killZBuffer(); delete _zBuffer; diff --git a/engines/sludge/graphics.h b/engines/sludge/graphics.h index 69d1f5f4ed..ecc2bbc21c 100644 --- a/engines/sludge/graphics.h +++ b/engines/sludge/graphics.h @@ -28,6 +28,8 @@ #include "graphics/surface.h" #include "graphics/transparent_surface.h" +#include "sludge/sprbanks.h" + namespace Sludge { class Parallax; @@ -36,6 +38,7 @@ class SpritePalette; struct StackHandler; struct FrozenStuffStruct; +struct LoadedSpriteBank; struct OnScreenPerson; struct SpriteBank; struct Sprite; @@ -139,6 +142,9 @@ public: void displaySpriteLayers(); void killSpriteLayers(); + // Sprite Bank + LoadedSpriteBank *loadBankForAnim(int ID); + // ZBuffer bool setZBuffer(int y); void killZBuffer(); @@ -195,6 +201,9 @@ private: void fontSprite(bool flip, int x, int y, Sprite &single, const SpritePalette &fontPal); uint32 getDrawColor(OnScreenPerson *thisPerson); + // Sprite banks + LoadedSpriteBanks _allLoadedBanks; + // ZBuffer ZBufferData *_zBuffer; void sortZPal(int *oldpal, int *newpal, int size); diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index 1edec124bb..14d2f0fc5f 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -985,7 +985,7 @@ bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) { p->frames = new AnimFrame [p->numFrames]; if (!checkNew(p->frames)) return false; - p->theSprites = loadBankForAnim(a); + p->theSprites = g_sludge->_gfxMan->loadBankForAnim(a); for (a = 0; a < p->numFrames; a++) { p->frames[a].frameNum = stream->readUint32LE(); diff --git a/engines/sludge/sprbanks.cpp b/engines/sludge/sprbanks.cpp index 265764bfdc..9cb4a58c40 100644 --- a/engines/sludge/sprbanks.cpp +++ b/engines/sludge/sprbanks.cpp @@ -31,32 +31,30 @@ namespace Sludge { -LoadedSpriteBank *allLoadedBanks = NULL; - -LoadedSpriteBank *loadBankForAnim(int ID) { - LoadedSpriteBank *returnMe = allLoadedBanks; - while (returnMe) { - if (returnMe->ID == ID) { - //debugOut ("loadBankForAnim: Found existing sprite bank with ID %d\n", returnMe -> ID); - return returnMe; +LoadedSpriteBank *GraphicsManager::loadBankForAnim(int ID) { + // Check if already exist + LoadedSpriteBanks::iterator it; + for (it = _allLoadedBanks.begin(); it != _allLoadedBanks.end(); ++it) { + if ((*it)->ID == ID) { + return (*it); } - returnMe = returnMe->next; } - returnMe = new LoadedSpriteBank; + + // Else create a new sprite bank + LoadedSpriteBank *returnMe = new LoadedSpriteBank; if (checkNew(returnMe)) { returnMe->ID = ID; - if (g_sludge->_gfxMan->loadSpriteBank(ID, returnMe->bank, false)) { + if (loadSpriteBank(ID, returnMe->bank, false)) { returnMe->timesUsed = 0; - returnMe->next = allLoadedBanks; - allLoadedBanks = returnMe; debug(kSludgeDebugDataLoad, "loadBankForAnim: New sprite bank created OK"); + _allLoadedBanks.push_back(returnMe); return returnMe; } else { debug(kSludgeDebugDataLoad, "loadBankForAnim: I guess I couldn't load the sprites..."); - return NULL; + return nullptr; } } else - return NULL; + return nullptr; } } // End of namespace Sludge diff --git a/engines/sludge/sprbanks.h b/engines/sludge/sprbanks.h index 99651b7c6f..43c59698a8 100644 --- a/engines/sludge/sprbanks.h +++ b/engines/sludge/sprbanks.h @@ -29,10 +29,8 @@ namespace Sludge { struct LoadedSpriteBank { int ID, timesUsed; SpriteBank bank; - LoadedSpriteBank *next; }; - -LoadedSpriteBank *loadBankForAnim(int ID); +typedef Common::List<LoadedSpriteBank *> LoadedSpriteBanks; } // End of namespace Sludge diff --git a/engines/sludge/sprites.cpp b/engines/sludge/sprites.cpp index b35bde4738..ddea0631c7 100644 --- a/engines/sludge/sprites.cpp +++ b/engines/sludge/sprites.cpp @@ -39,7 +39,9 @@ namespace Sludge { +// This function is only used to kill text font void GraphicsManager::forgetSpriteBank(SpriteBank &forgetme) { + // kill the sprite bank if (forgetme.myPalette.pal) { delete[] forgetme.myPalette.pal; forgetme.myPalette.pal = NULL; @@ -58,9 +60,6 @@ void GraphicsManager::forgetSpriteBank(SpriteBank &forgetme) { delete []forgetme.sprites; forgetme.sprites = NULL; - - // TODO: also remove sprite bank from allLoadedBanks - // And add a function call for this function to the scripting language } bool GraphicsManager::reserveSpritePal(SpritePalette &sP, int n) { |