aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/resources.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/xeen/resources.cpp')
-rw-r--r--engines/xeen/resources.cpp80
1 files changed, 55 insertions, 25 deletions
diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp
index 40353c1cdc..4da84c1d38 100644
--- a/engines/xeen/resources.cpp
+++ b/engines/xeen/resources.cpp
@@ -216,19 +216,10 @@ void File::openFile(const Common::String &filename) {
/*------------------------------------------------------------------------*/
-SpriteResource::SpriteResource(const Common::String &filename) {
+GraphicResource::GraphicResource(const Common::String &filename) {
// Open the resource
File f(filename);
- // Read in the index
- int count = f.readUint16LE();
- _index.resize(count);
-
- for (int i = 0; i < count; ++i) {
- _index[i]._offset1 = f.readUint16LE();
- _index[i]._offset2 = f.readUint16LE();
- }
-
// Read in a copy of the file
_filesize = f.size();
_data = new byte[_filesize];
@@ -236,26 +227,15 @@ SpriteResource::SpriteResource(const Common::String &filename) {
f.read(_data, _filesize);
}
-SpriteResource::~SpriteResource() {
+GraphicResource::~GraphicResource() {
delete[] _data;
}
-int SpriteResource::size() const {
- return _index.size();
-}
-
-void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const {
- drawOffset(dest, _index[frame]._offset1, destPos);
- if (_index[frame]._offset2)
- drawOffset(dest, _index[frame]._offset2, destPos);
-}
-
-void SpriteResource::draw(XSurface &dest, int frame) const {
- draw(dest, frame, Common::Point());
+int GraphicResource::size() const {
+ return READ_LE_UINT16(_data);
}
-
-void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const {
+void GraphicResource::drawOffset(XSurface &dest, uint16 offset, const Common::Point &destPos) const {
// Get cell header
Common::MemoryReadStream f(_data, _filesize);
f.seek(offset);
@@ -264,6 +244,9 @@ void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Poi
int yOffset = f.readUint16LE();
int height = f.readUint16LE();
+ if (dest.w < (xOffset + width) || dest.h < (yOffset + height))
+ dest.create(xOffset + width, yOffset + height);
+
// The pattern steps used in the pattern command
const int patternSteps[] = { 0, 1, 1, 1, 2, 2, 3, 3, 0, -1, -1, -1, -2, -2, -3, -3 };
@@ -355,4 +338,51 @@ void SpriteResource::drawOffset(XSurface &dest, uint16 offset, const Common::Poi
destPos.x + xOffset + width, destPos.y + yOffset + height));
}
+/*------------------------------------------------------------------------*/
+
+FramesResource::FramesResource(const Common::String &filename) :
+ GraphicResource(filename) {
+ // Read in the index
+ Common::MemoryReadStream f(_data, _filesize);
+ int count = f.readUint16LE();
+ _index.resize(count);
+
+ for (int i = 0; i < count; ++i) {
+ _index[i] = f.readUint32LE();
+ }
+}
+
+void FramesResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const {
+ drawOffset(dest, _index[frame], destPos);
+}
+
+void FramesResource::draw(XSurface &dest, int frame) const {
+ draw(dest, frame, Common::Point());
+}
+
+/*------------------------------------------------------------------------*/
+
+SpriteResource::SpriteResource(const Common::String &filename) :
+ GraphicResource(filename) {
+ // Read in the index
+ Common::MemoryReadStream f(_data, _filesize);
+ int count = f.readUint16LE();
+ _index.resize(count);
+
+ for (int i = 0; i < count; ++i) {
+ _index[i]._offset1 = f.readUint16LE();
+ _index[i]._offset2 = f.readUint16LE();
+ }
+}
+
+void SpriteResource::draw(XSurface &dest, int frame, const Common::Point &destPos) const {
+ drawOffset(dest, _index[frame]._offset1, destPos);
+ if (_index[frame]._offset2)
+ drawOffset(dest, _index[frame]._offset2, destPos);
+}
+
+void SpriteResource::draw(XSurface &dest, int frame) const {
+ draw(dest, frame, Common::Point());
+}
+
} // End of namespace Xeen