aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche
diff options
context:
space:
mode:
authoruruk2013-09-03 23:41:15 +0200
committeruruk2013-09-03 23:41:15 +0200
commit212391f337a3beee1fa4d987b62fe8494ab1fc02 (patch)
tree208ba796982921ee08252ca86a63c754ff489b23 /engines/avalanche
parent3fe9c6d90b6e5b416e0fa2d6db78044d066aaedf (diff)
downloadscummvm-rg350-212391f337a3beee1fa4d987b62fe8494ab1fc02.tar.gz
scummvm-rg350-212391f337a3beee1fa4d987b62fe8494ab1fc02.tar.bz2
scummvm-rg350-212391f337a3beee1fa4d987b62fe8494ab1fc02.zip
AVALANCHE: Refactor Celer.
Diffstat (limited to 'engines/avalanche')
-rw-r--r--engines/avalanche/celer2.cpp119
-rw-r--r--engines/avalanche/celer2.h51
2 files changed, 80 insertions, 90 deletions
diff --git a/engines/avalanche/celer2.cpp b/engines/avalanche/celer2.cpp
index 4eefe3c47e..daec21c294 100644
--- a/engines/avalanche/celer2.cpp
+++ b/engines/avalanche/celer2.cpp
@@ -44,16 +44,18 @@ namespace Avalanche {
const int16 Celer::kOnDisk = -1;
+
Celer::Celer(AvalancheEngine *vm) {
_vm = vm;
- _chunkNum = 0;
+ _spriteNum = 0;
}
Celer::~Celer() {
- for (byte i = 0; i < 40; i++)
- _memory[i].free();
+ forgetBackgroundSprites();
}
+
+
void Celer::refreshBackgroundSprites() {
if (_vm->_gyro->ddmnow)
return; // No animation when the menus are up.
@@ -272,11 +274,11 @@ void Celer::loadBackgroundSprites(byte number) {
}
f.seek(44);
- _chunkNum = f.readByte();
- for (byte i = 0; i < _chunkNum; i++)
+ _spriteNum = f.readByte();
+ for (byte i = 0; i < _spriteNum; i++)
_offsets[i] = f.readSint32LE();
- for (byte i = 0; i < _chunkNum; i++) {
+ for (byte i = 0; i < _spriteNum; i++) {
f.seek(_offsets[i]);
SpriteType sprite;
@@ -286,61 +288,38 @@ void Celer::loadBackgroundSprites(byte number) {
sprite._xl = f.readSint16LE();
sprite._yl = f.readSint16LE();
sprite._size = f.readSint32LE();
- sprite._natural = f.readByte();
- sprite._memorise = f.readByte();
+ bool natural = f.readByte();
+ bool memorise = f.readByte();
- if (sprite._memorise) {
- _memos[i]._x = sprite._x;
- _memos[i]._xl = sprite._xl;
- _memos[i]._y = sprite._y;
- _memos[i]._yl = sprite._yl;
- _memos[i]._type = sprite._type;
-
- if (sprite._natural) {
- _memos[i]._type = kNaturalImage; // We simply read from the screen and later, in display_it() we draw it right back.
- _memos[i]._size = _memos[i]._xl * 8 * _memos[i]._yl + 1;
- _memory[i].create(_memos[i]._xl * 8, _memos[i]._yl + 1, ::Graphics::PixelFormat::createFormatCLUT8());
-
- for (uint16 y = 0; y < _memos[i]._yl + 1; y++)
- for (uint16 x = 0; x < _memos[i]._xl * 8; x++)
- *(byte *)_memory[i].getBasePtr(x, y) = *_vm->_graphics->getPixel(_memos[i]._x * 8 + x, _memos[i]._y + y);
+ if (memorise) {
+ _sprites[i]._x = sprite._x;
+ _sprites[i]._xl = sprite._xl;
+ _sprites[i]._y = sprite._y;
+ _sprites[i]._yl = sprite._yl;
+ _sprites[i]._type = sprite._type;
+
+ if (natural) {
+ _sprites[i]._type = kNaturalImage; // We simply read from the screen and later, in display_it() we draw it right back.
+ _sprites[i]._size = _sprites[i]._xl * 8 * _sprites[i]._yl + 1;
+ _sprites[i]._picture.create(_sprites[i]._xl * 8, _sprites[i]._yl + 1, ::Graphics::PixelFormat::createFormatCLUT8());
+
+ for (uint16 y = 0; y < _sprites[i]._yl + 1; y++)
+ for (uint16 x = 0; x < _sprites[i]._xl * 8; x++)
+ *(byte *)_sprites[i]._picture.getBasePtr(x, y) = *_vm->_graphics->getPixel(_sprites[i]._x * 8 + x, _sprites[i]._y + y);
} else {
- _memos[i]._size = sprite._size;
- _memory[i] = _vm->_graphics->loadPictureRow(f, _memos[i]._xl * 8, _memos[i]._yl + 1); // Celer::forget_chunks() deallocates it.
+ _sprites[i]._size = sprite._size;
+ _sprites[i]._picture = _vm->_graphics->loadPictureRow(f, _sprites[i]._xl * 8, _sprites[i]._yl + 1); // Celer::forget_chunks() deallocates it.
}
} else
- _memos[i]._x = kOnDisk;
+ _sprites[i]._x = kOnDisk;
}
f.close();
}
void Celer::forgetBackgroundSprites() {
- for (byte i = 0; i < _chunkNum; i ++)
- if (_memos[i]._x > kOnDisk)
- _memory[i].free();
-
- memset(_memos, 255, sizeof(_memos)); /* x=-1, => on disk. */
-}
-
-void Celer::drawSprite(int16 x, int16 y, int16 xl, int16 yl, PictureType type, const ::Graphics::Surface &picture) {
- _r.x1 = x;
- _r.y1 = y;
- _r.y2 = y + yl;
-
- switch (type) {
- case kNaturalImage: // Allow fallthorugh on purpose.
- case kBgi : {
- _r.x2 = x + xl + 1;
- }
- break;
- case kEga : {
- _r.x2 = x + xl;
- }
- break;
- }
-
- // These pictures are practically parts of the background. -10 is for the drop-down menu.
- _vm->_graphics->drawPicture(_vm->_graphics->_background, picture, x, y - 10);
+ for (byte i = 0; i < _spriteNum; i ++)
+ if (_sprites[i]._x > kOnDisk)
+ _sprites[i]._picture.free();
}
void Celer::drawBackgroundSprite(int16 destX, int16 destY, byte which) {
@@ -348,12 +327,12 @@ void Celer::drawBackgroundSprite(int16 destX, int16 destY, byte which) {
//setactivepage(3);
warning("STUB: Celer::show_one()");
- if (_memos[which]._x > kOnDisk) {
+ if (_sprites[which]._x > kOnDisk) {
if (destX < 0) {
- destX = _memos[which]._x * 8;
- destY = _memos[which]._y;
+ destX = _sprites[which]._x * 8;
+ destY = _sprites[which]._y;
}
- drawSprite(destX, destY, _memos[which]._xl, _memos[which]._yl, _memos[which]._type, _memory[which]);
+ drawSprite(destX, destY, _sprites[which]);
} else {
Common::File f;
if (!f.open(_filename)) { // Filename was set in loadBackgroundSprites().
@@ -370,18 +349,15 @@ void Celer::drawBackgroundSprite(int16 destX, int16 destY, byte which) {
sprite._xl = f.readSint16LE();
sprite._yl = f.readSint16LE();
sprite._size = f.readSint32LE();
- sprite._natural = f.readByte();
- sprite._memorise = f.readByte();
-
- ::Graphics::Surface picture = _vm->_graphics->loadPictureRow(f, sprite._xl * 8, sprite._yl + 1);
+ f.skip(2); // For the now not existing natural and memorise data members of the SpriteType (called chunkblocktype in the original).
+ sprite._picture = _vm->_graphics->loadPictureRow(f, sprite._xl * 8, sprite._yl + 1);
if (destX < 0) {
destX = sprite._x * 8;
destY = sprite._y;
}
- drawSprite(destX, destY, sprite._xl, sprite._yl, sprite._type, picture);
+ drawSprite(destX, destY, sprite);
- picture.free();
f.close();
}
@@ -394,4 +370,23 @@ void Celer::drawBackgroundSprite(int16 destX, int16 destY, byte which) {
+void Celer::drawSprite(int16 x, int16 y, const SpriteType &sprite) {
+ _r.x1 = x;
+ _r.y1 = y;
+ _r.y2 = y + sprite._yl;
+
+ switch (sprite._type) {
+ case kNaturalImage: // Allow fallthorugh on purpose.
+ case kBgi:
+ _r.x2 = x + sprite._xl + 1;
+ break;
+ case kEga:
+ _r.x2 = x + sprite._xl;
+ break;
+ }
+
+ // These pictures are practically parts of the background. -10 is for the drop-down menu.
+ _vm->_graphics->drawPicture(_vm->_graphics->_background, sprite._picture, x, y - 10);
+}
+
} // End of namespace Avalanche.
diff --git a/engines/avalanche/celer2.h b/engines/avalanche/celer2.h
index 8f0a489b50..aac4c88850 100644
--- a/engines/avalanche/celer2.h
+++ b/engines/avalanche/celer2.h
@@ -43,37 +43,12 @@ class AvalancheEngine;
class Celer {
public:
- enum PictureType {kEga, kBgi, kNaturalImage};
-
- struct SpriteType {
- PictureType _type;
- int16 _x, _y;
- int16 _xl, _yl;
- int32 _size;
- bool _natural;
-
- bool _memorise; /* Hold it in memory? */
- };
-
- struct MemoType {
- int16 _x, _y;
- int16 _xl, _yl;
- PictureType _type;
- uint16 _size;
- };
-
- int32 _offsets[40];
- byte _chunkNum;
- MemoType _memos[40];
- ::Graphics::Surface _memory[40]; // .free() is called in ~Celer()
- bytefield _r;
-
-
-
Celer(AvalancheEngine *vm);
~Celer();
+
+
void refreshBackgroundSprites();
void loadBackgroundSprites(byte number);
@@ -86,13 +61,33 @@ public:
void drawBackgroundSprite(int16 destX, int16 destY, byte which);
private:
+ enum PictureType {kEga, kBgi, kNaturalImage};
+
+ struct SpriteType {
+ PictureType _type;
+ int16 _x, _y;
+ int16 _xl, _yl;
+ int32 _size;
+ ::Graphics::Surface _picture;
+ };
+
+
+
AvalancheEngine *_vm;
+ int32 _offsets[40];
+ byte _spriteNum;
+ SpriteType _sprites[40];
+ bytefield _r;
Common::String _filename;
+
+
static const int16 kOnDisk; /* Value of memos[fv].x when it's not in memory. */
- void drawSprite(int16 x, int16 y, int16 xl, int16 yl, PictureType type, const ::Graphics::Surface &picture);
+
+
+ void drawSprite(int16 x, int16 y, const SpriteType &sprite);
};
} // End of namespace Avalanche.