aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2010-07-04 00:38:16 +0000
committerPaul Gilbert2010-07-04 00:38:16 +0000
commit10e7581fe1a281f69875a6d76c9c1bf5aafa939c (patch)
tree14def76f9fbfc1b5b91c792b66804cca203c00f3
parent5872f5bb1fac5a8d4b8ddecf777e22ca23ecca39 (diff)
downloadscummvm-rg350-10e7581fe1a281f69875a6d76c9c1bf5aafa939c.tar.gz
scummvm-rg350-10e7581fe1a281f69875a6d76c9c1bf5aafa939c.tar.bz2
scummvm-rg350-10e7581fe1a281f69875a6d76c9c1bf5aafa939c.zip
Added support for horizontally flipped foreground sprites, which are indicated by setting the high bit of frame numbers
svn-id: r50638
-rw-r--r--engines/m4/graphics.cpp24
-rw-r--r--engines/m4/graphics.h2
-rw-r--r--engines/m4/mads_views.cpp24
3 files changed, 44 insertions, 6 deletions
diff --git a/engines/m4/graphics.cpp b/engines/m4/graphics.cpp
index 107bcbc6f9..c10ea6c9f6 100644
--- a/engines/m4/graphics.cpp
+++ b/engines/m4/graphics.cpp
@@ -65,6 +65,15 @@ void RGBList::setRange(int start, int count, const RGB8 *src) {
Common::copy(&src[0], &src[count], &_data[start]);
}
+/**
+ * Creates a duplicate of the given rgb list
+ */
+RGBList *RGBList::clone() const {
+ RGBList *dest = new RGBList(_size, _data, false);
+ _madsVm->_palette->addRange(dest);
+ return dest;
+}
+
//--------------------------------------------------------------------------
#define VGA_COLOR_TRANS(x) (x == 0x3f ? 255 : x << 2)
@@ -931,6 +940,21 @@ void M4Surface::translate(RGBList *list, bool isTransparent) {
freeData();
}
+M4Surface *M4Surface::flipHorizontal() const {
+ M4Surface *dest = new M4Surface(width(), height());
+ dest->_rgbList = (this->_rgbList == NULL) ? NULL : this->_rgbList->clone();
+
+ byte *destP = dest->getBasePtr();
+
+ for (int y = 0; y < height(); ++y) {
+ const byte *srcP = getBasePtr(width() - 1, y);
+ for (int x = 0; x < width(); ++x)
+ *destP++ = *srcP--;
+ }
+
+ return dest;
+}
+
//--------------------------------------------------------------------------
// Palette class
//
diff --git a/engines/m4/graphics.h b/engines/m4/graphics.h
index c2eb11c575..ecb5048b26 100644
--- a/engines/m4/graphics.h
+++ b/engines/m4/graphics.h
@@ -75,6 +75,7 @@ public:
int size() { return _size; }
RGB8 &operator[](int idx) { return _data[idx]; }
void setRange(int start, int count, const RGB8 *src);
+ RGBList *clone() const;
};
// M4Surface
@@ -203,6 +204,7 @@ public:
void scrollY(int yAmount);
void translate(RGBList *list, bool isTransparent = false);
+ M4Surface *flipHorizontal() const;
};
enum FadeType {FT_TO_GREY, FT_TO_COLOR, FT_TO_BLOCK};
diff --git a/engines/m4/mads_views.cpp b/engines/m4/mads_views.cpp
index 9241774d16..9845db7203 100644
--- a/engines/m4/mads_views.cpp
+++ b/engines/m4/mads_views.cpp
@@ -201,15 +201,23 @@ void MadsSpriteSlots::drawForeground(M4Surface *viewport) {
assert(slot.spriteListIndex < (int)_sprites.size());
SpriteAsset &spriteSet = *_sprites[slot.spriteListIndex];
+ // Get the sprite frame
+ int frameNumber = slot.frameNumber & 0x7fff;
+ bool flipped = (slot.frameNumber & 0x8000) != 0;
+ M4Sprite *sprite = spriteSet.getFrame(frameNumber - 1);
+
+ M4Surface *spr = sprite;
+ if (flipped) {
+ // Create a flipped copy of the sprite temporarily
+ spr = sprite->flipHorizontal();
+ }
+
if ((slot.scale < 100) && (slot.scale != -1)) {
// Minimalised drawing
- assert(slot.spriteListIndex < (int)_sprites.size());
- M4Sprite *spr = spriteSet.getFrame((slot.frameNumber & 0x7fff) - 1);
viewport->copyFrom(spr, slot.xp, slot.yp, slot.depth, _owner._depthSurface, slot.scale,
- spr->getTransparencyIndex());
+ sprite->getTransparencyIndex());
} else {
int xp, yp;
- M4Sprite *spr = spriteSet.getFrame(slot.frameNumber - 1);
if (slot.scale == -1) {
xp = slot.xp - _owner._posAdjust.x;
@@ -221,12 +229,16 @@ void MadsSpriteSlots::drawForeground(M4Surface *viewport) {
if (slot.depth > 1) {
// Draw the frame with depth processing
- viewport->copyFrom(spr, xp, yp, slot.depth, _owner._depthSurface, 100, spr->getTransparencyIndex());
+ viewport->copyFrom(spr, xp, yp, slot.depth, _owner._depthSurface, 100, sprite->getTransparencyIndex());
} else {
// No depth, so simply draw the image
- spr->copyTo(viewport, xp, yp, spr->getTransparencyIndex());
+ spr->copyTo(viewport, xp, yp, sprite->getTransparencyIndex());
}
}
+
+ // Free sprite if it was a flipped one
+ if (flipped)
+ delete spr;
}
}