Permalink
Browse files

SLUDGE: Move sprite bank to graphics manager

  • Loading branch information...
yinsimei committed Jul 21, 2017
1 parent 5c853fb commit a1be6d4209ce5c0ce8bd3d954de53fdeb3274cc9
@@ -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);
@@ -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;
@@ -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 @@ class GraphicsManager {
void displaySpriteLayers();
void killSpriteLayers();
// Sprite Bank
LoadedSpriteBank *loadBankForAnim(int ID);
// ZBuffer
bool setZBuffer(int y);
void killZBuffer();
@@ -195,6 +201,9 @@ class GraphicsManager {
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);
@@ -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();
@@ -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
@@ -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
@@ -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) {

0 comments on commit a1be6d4

Please sign in to comment.