aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorSven Hesse2012-03-11 18:33:10 +0100
committerSven Hesse2012-03-11 21:05:57 +0100
commit4db94f805c0d73b80d93526b5a696fa1248a9754 (patch)
tree5d18864ae4e10e6803523dc0e62c315f391b00e8 /engines
parentb928d6dcb1749a140bf26d23211bfae6f4585ba3 (diff)
downloadscummvm-rg350-4db94f805c0d73b80d93526b5a696fa1248a9754.tar.gz
scummvm-rg350-4db94f805c0d73b80d93526b5a696fa1248a9754.tar.bz2
scummvm-rg350-4db94f805c0d73b80d93526b5a696fa1248a9754.zip
GOB: Use the CMPFile class in ANIFile
Diffstat (limited to 'engines')
-rw-r--r--engines/gob/anifile.cpp78
-rw-r--r--engines/gob/anifile.h22
2 files changed, 23 insertions, 77 deletions
diff --git a/engines/gob/anifile.cpp b/engines/gob/anifile.cpp
index 1a905f1083..2671fe0405 100644
--- a/engines/gob/anifile.cpp
+++ b/engines/gob/anifile.cpp
@@ -28,19 +28,11 @@
#include "gob/dataio.h"
#include "gob/surface.h"
#include "gob/video.h"
+#include "gob/cmpfile.h"
#include "gob/anifile.h"
namespace Gob {
-ANIFile::Layer::Layer() : surface(0), coordinates(0) {
-}
-
-ANIFile::Layer::~Layer() {
- delete coordinates;
- delete surface;
-}
-
-
ANIFile::ANIFile(GobEngine *vm, const Common::String &fileName,
uint16 width, uint8 bpp) : _vm(vm),
_width(width), _bpp(bpp), _hasPadding(false) {
@@ -72,6 +64,8 @@ ANIFile::ANIFile(GobEngine *vm, const Common::String &fileName,
}
ANIFile::~ANIFile() {
+ for (LayerArray::iterator l = _layers.begin(); l != _layers.end(); ++l)
+ delete *l;
}
void ANIFile::load(Common::SeekableSubReadStreamEndian &ani, const Common::String &fileName) {
@@ -90,9 +84,9 @@ void ANIFile::load(Common::SeekableSubReadStreamEndian &ani, const Common::Strin
if (_hasPadding)
ani.skip(1);
- _layers.resize(layerCount - 1);
- for (LayerArray::iterator l = _layers.begin(); l != _layers.end(); ++l)
- loadLayer(*l, ani);
+ _layers.reserve(layerCount - 1);
+ for (int i = 0; i < layerCount - 1; i++)
+ _layers.push_back(loadLayer(ani));
}
_maxWidth = 0;
@@ -158,14 +152,13 @@ void ANIFile::loadAnimation(Animation &animation, FrameArray &frames,
area.right = area.bottom = -0x7FFF;
for (ChunkList::const_iterator c = frame.begin(); c != frame.end(); c++) {
- const Layer *layer;
- const RXYFile::Coordinates *coords;
+ uint16 cL, cT, cR, cB;
- if (!getPart(c->layer, c->part, layer, coords))
+ if (!getCoordinates(c->layer, c->part, cL, cT, cR, cB))
continue;
- const uint16 width = coords->right - coords->left + 1;
- const uint16 height = coords->bottom - coords->top + 1;
+ const uint16 width = cR - cL + 1;
+ const uint16 height = cB - cT + 1;
const uint16 l = c->x;
const uint16 t = c->y;
@@ -233,33 +226,12 @@ void ANIFile::loadFrames(FrameArray &frames, Common::SeekableSubReadStreamEndian
}
}
-void ANIFile::loadLayer(Layer &layer, Common::SeekableSubReadStreamEndian &ani) {
- Common::String file = Util::readString(ani, 13);
+CMPFile *ANIFile::loadLayer(Common::SeekableSubReadStreamEndian &ani) {
+ Common::String file = Util::setExtension(Util::readString(ani, 13), "");
if (_hasPadding)
ani.skip(1);
- if (file.empty())
- return;
-
- Common::String fileRXY = Util::setExtension(file, ".RXY");
- Common::String fileCMP = Util::setExtension(file, ".CMP");
- if (!_vm->_dataIO->hasFile(fileRXY) || !_vm->_dataIO->hasFile(fileCMP))
- return;
-
- loadLayer(layer, fileRXY, fileCMP);
-}
-
-void ANIFile::loadLayer(Layer &layer, const Common::String &fileRXY,
- const Common::String &fileCMP) {
-
- Common::SeekableReadStream *dataRXY = _vm->_dataIO->getFile(fileRXY);
- if (!dataRXY)
- return;
-
- layer.coordinates = new RXYFile(*dataRXY);
- layer.surface = new Surface(_width, layer.coordinates->getHeight(), _bpp);
-
- _vm->_video->drawPackedSprite(fileCMP.c_str(), *layer.surface);
+ return new CMPFile(_vm, file, _width, 0, _bpp);
}
uint16 ANIFile::getAnimationCount() const {
@@ -277,24 +249,13 @@ const ANIFile::Animation &ANIFile::getAnimationInfo(uint16 animation) const {
return _animations[animation];
}
-bool ANIFile::getPart(uint16 layer, uint16 part,
- const Layer *&l, const RXYFile::Coordinates *&c) const {
+bool ANIFile::getCoordinates(uint16 layer, uint16 part,
+ uint16 &left, uint16 &top, uint16 &right, uint16 &bottom) const {
if (layer >= _layers.size())
return false;
- l = &_layers[layer];
- if (!l->surface || !l->coordinates)
- return false;
-
- if (part >= l->coordinates->size())
- return false;
-
- c = &(*l->coordinates)[part];
- if (c->left == 0xFFFF)
- return false;
-
- return true;
+ return _layers[layer]->getCoordinates(part, left, top, right, bottom);
}
void ANIFile::draw(Surface &dest, uint16 animation, uint16 frame, int16 x, int16 y) const {
@@ -314,13 +275,10 @@ void ANIFile::draw(Surface &dest, uint16 animation, uint16 frame, int16 x, int16
void ANIFile::drawLayer(Surface &dest, uint16 layer, uint16 part,
int16 x, int16 y, int32 transp) const {
- const Layer *l;
- const RXYFile::Coordinates *c;
-
- if (!getPart(layer, part, l, c))
+ if (layer >= _layers.size())
return;
- dest.blit(*l->surface, c->left, c->top, c->right, c->bottom, x, y, transp);
+ _layers[layer]->draw(dest, part, x, y, transp);
}
} // End of namespace Gob
diff --git a/engines/gob/anifile.h b/engines/gob/anifile.h
index 1e10da6ff4..b6d9c735b5 100644
--- a/engines/gob/anifile.h
+++ b/engines/gob/anifile.h
@@ -28,8 +28,6 @@
#include "common/array.h"
#include "common/list.h"
-#include "gob/rxyfile.h"
-
namespace Common {
class SeekableSubReadStreamEndian;
}
@@ -38,6 +36,7 @@ namespace Gob {
class GobEngine;
class Surface;
+class CMPFile;
/** An ANI file, describing an animation.
*
@@ -94,16 +93,7 @@ public:
void draw(Surface &dest, uint16 animation, uint16 frame, int16 x, int16 y) const;
private:
- /** A sprite layer. */
- struct Layer {
- Surface *surface; ///< The surface containing the layer sprite.
- RXYFile *coordinates; ///< The coordinates describing the layer sprite parts.
-
- Layer();
- ~Layer();
- };
-
- typedef Common::Array<Layer> LayerArray;
+ typedef Common::Array<CMPFile *> LayerArray;
typedef Common::Array<Animation> AnimationArray;
/** A "chunk" of an animation frame. */
@@ -139,9 +129,7 @@ private:
void load(Common::SeekableSubReadStreamEndian &ani, const Common::String &fileName);
- void loadLayer(Layer &layer, Common::SeekableSubReadStreamEndian &ani);
- void loadLayer(Layer &layer, const Common::String &fileRXY,
- const Common::String &fileCMP);
+ CMPFile *loadLayer(Common::SeekableSubReadStreamEndian &ani);
void loadAnimation(Animation &animation, FrameArray &frames,
Common::SeekableSubReadStreamEndian &ani);
@@ -149,8 +137,8 @@ private:
// Drawing helpers
- bool getPart(uint16 layer, uint16 part,
- const Layer *&l, const RXYFile::Coordinates *&c) const;
+ bool getCoordinates(uint16 layer, uint16 part,
+ uint16 &left, uint16 &top, uint16 &right, uint16 &bottom) const;
void drawLayer(Surface &dest, uint16 layer, uint16 part,
int16 x, int16 y, int32 transp) const;