aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/cine/bg.cpp1
-rw-r--r--engines/cine/gfx.cpp37
-rw-r--r--engines/cine/gfx.h26
3 files changed, 38 insertions, 26 deletions
diff --git a/engines/cine/bg.cpp b/engines/cine/bg.cpp
index cc7e843c2b..08722c42e5 100644
--- a/engines/cine/bg.cpp
+++ b/engines/cine/bg.cpp
@@ -82,7 +82,6 @@ byte loadCtOS(const char *ctName) {
ptr += 2;
if (bpp == 8) {
- memcpy(collisionPage, ptr + 256 * 3, 320 * 200);
renderer->loadCt256(ptr, ctName);
} else {
gfxConvertSpriteToRaw(collisionPage, ptr + 32, 160, 200);
diff --git a/engines/cine/gfx.cpp b/engines/cine/gfx.cpp
index 87e0e0aa5b..ddc2d48152 100644
--- a/engines/cine/gfx.cpp
+++ b/engines/cine/gfx.cpp
@@ -874,35 +874,25 @@ void FWRenderer::fadeToBlack() {
/*! \brief Initialize Operation Stealth renderer
*/
-OSRenderer::OSRenderer() : FWRenderer(), _currentBg(0), _scrollBg(0),
+OSRenderer::OSRenderer() : FWRenderer(), _bgTable(), _currentBg(0), _scrollBg(0),
_bgShift(0) {
- int i;
- for (i = 0; i < 9; i++) {
- _bgTable[i].bg = NULL;
- _bgTable[i].pal.clear();
- memset(_bgTable[i].name, 0, sizeof (_bgTable[i].name));
- }
+ _bgTable.resize(9); // Resize the background table to its required size
}
/*! \brief Destroy Operation Stealth renderer
*/
OSRenderer::~OSRenderer() {
- for (int i = 0; i < 9; i++) {
- delete[] _bgTable[i].bg;
- _bgTable[i].pal.clear();
+ for (uint i = 0; i < _bgTable.size(); i++) {
+ _bgTable[i].clear();
}
}
/*! \brief Reset Operation Stealth renderer state
*/
void OSRenderer::clear() {
- for (int i = 0; i < 9; i++) {
- delete[] _bgTable[i].bg;
-
- _bgTable[i].bg = NULL;
- _bgTable[i].pal.clear();
- memset(_bgTable[i].name, 0, sizeof (_bgTable[i].name));
+ for (uint i = 0; i < _bgTable.size(); i++) {
+ _bgTable[i].clear();
}
_currentBg = 0;
@@ -1172,7 +1162,10 @@ void OSRenderer::loadBg16(const byte *bg, const char *name, unsigned int idx) {
* \param name Background filename
*/
void OSRenderer::loadCt16(const byte *ct, const char *name) {
- loadBg16(ct, name, 8);
+ // Make the 9th background point directly to the collision page
+ // and load the picture into it.
+ _bgTable[kCollisionPageBgIdxAlias].bg = collisionPage;
+ loadBg16(ct, name, kCollisionPageBgIdxAlias);
}
/*! \brief Load 256 color background into renderer
@@ -1199,7 +1192,10 @@ void OSRenderer::loadBg256(const byte *bg, const char *name, unsigned int idx) {
* \param name Background filename
*/
void OSRenderer::loadCt256(const byte *ct, const char *name) {
- loadBg256(ct, name, 8);
+ // Make the 9th background point directly to the collision page
+ // and load the picture into it.
+ _bgTable[kCollisionPageBgIdxAlias].bg = collisionPage;
+ loadBg256(ct, name, kCollisionPageBgIdxAlias);
}
/*! \brief Select active background and load its palette
@@ -1255,10 +1251,7 @@ void OSRenderer::removeBg(unsigned int idx) {
_scrollBg = 0;
}
- delete[] _bgTable[idx].bg;
- _bgTable[idx].bg = NULL;
- _bgTable[idx].pal.clear();
- memset(_bgTable[idx].name, 0, sizeof (_bgTable[idx].name));
+ _bgTable[idx].clear();
}
void OSRenderer::saveBgNames(Common::OutSaveFile &fHandle) {
diff --git a/engines/cine/gfx.h b/engines/cine/gfx.h
index 839f37a0b1..f1503a4c46 100644
--- a/engines/cine/gfx.h
+++ b/engines/cine/gfx.h
@@ -31,12 +31,34 @@
namespace Cine {
+extern byte *collisionPage;
+static const int kCollisionPageBgIdxAlias = 8;
+
/*! \brief Background with palette
*/
struct palBg {
byte *bg; ///< Background data
Cine::Palette pal; ///< Background color palette
char name[15]; ///< Background filename
+
+ /** @brief Default constructor. */
+ palBg() : bg(NULL), pal(), name() {
+ // Make sure the name is empty (Maybe this is not needed?)
+ memset(this->name, 0, sizeof(this->name));
+ }
+
+ /** @brief Clears the struct (Releases allocated memory etc). */
+ void clear() {
+ // In Operation Stealth the 9th background is sometimes aliased to
+ // the collision page so we should take care not to double delete it
+ // (The collision page is deleted elsewhere).
+ if (this->bg != collisionPage) {
+ delete[] this->bg;
+ }
+ this->bg = NULL;
+ this->pal.clear();
+ memset(this->name, 0, sizeof(this->name));
+ }
};
/*! \brief Future Wars renderer
@@ -129,8 +151,7 @@ public:
*/
class OSRenderer : public FWRenderer {
private:
- // FIXME: Background table's size is probably 8 instead of 9. Check to make sure and correct if necessary.
- palBg _bgTable[9]; ///< Table of backgrounds loaded into renderer
+ Common::Array<palBg> _bgTable; ///< Table of backgrounds loaded into renderer (Maximum is 9)
unsigned int _currentBg; ///< Current background
unsigned int _scrollBg; ///< Current scroll background
unsigned int _bgShift; ///< Background shift
@@ -175,7 +196,6 @@ public:
void gfxDrawSprite(byte *src4, uint16 sw, uint16 sh, byte *dst4, int16 sx, int16 sy);
-extern byte *collisionPage;
extern FWRenderer *renderer;
void setMouseCursor(int cursor);