From 568fc31b3090a70aa922479991540d4f5c2e918c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 4 Mar 2014 22:33:27 -0500 Subject: MADS: Beginnings of code support for Scene::drawElements --- engines/mads/sprites.cpp | 239 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 engines/mads/sprites.cpp (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp new file mode 100644 index 0000000000..3cba6989b1 --- /dev/null +++ b/engines/mads/sprites.cpp @@ -0,0 +1,239 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" +#include "engines/util.h" +#include "graphics/palette.h" +#include "mads/mads.h" +#include "mads/graphics.h" +#include "mads/msurface.h" +#include "mads/sprites.h" + +namespace MADS { + +enum { + kEndOfLine = 0, + kEndOfSprite = 1, + kMarker = 2 +}; + +MSprite::MSprite(): MSurface() { + _encoding = 0; +} + +MSprite::MSprite(Common::SeekableReadStream *source, const Common::Point &offset, + int widthVal, int heightVal, bool decodeRle, uint8 encodingVal) + : MSurface(widthVal, heightVal), + _encoding(encodingVal), _offset(offset) { + + // Load the sprite data + loadSprite(source); +} + +MSprite::~MSprite() { +} + + +// TODO: The sprite outlines (pixel value 0xFD) are not shown +void MSprite::loadSprite(Common::SeekableReadStream *source) { + byte *outp, *lineStart; + bool newLine = false; + + outp = getData(); + lineStart = getData(); + + while (1) { + byte cmd1, cmd2, count, pixel; + + if (newLine) { + outp = lineStart + getWidth(); + lineStart = outp; + newLine = false; + } + + cmd1 = source->readByte(); + + if (cmd1 == 0xFC) + break; + else if (cmd1 == 0xFF) + newLine = true; + else if (cmd1 == 0xFD) { + while (!newLine) { + count = source->readByte(); + if (count == 0xFF) { + newLine = true; + } else { + pixel = source->readByte(); + while (count--) + *outp++ = (pixel == 0xFD) ? 0 : pixel; + } + } + } else { + while (!newLine) { + cmd2 = source->readByte(); + if (cmd2 == 0xFF) { + newLine = true; + } else if (cmd2 == 0xFE) { + count = source->readByte(); + pixel = source->readByte(); + while (count--) + *outp++ = (pixel == 0xFD) ? 0 : pixel; + } else { + *outp++ = (cmd2 == 0xFD) ? 0 : cmd2; + } + } + } + } +} + +/*------------------------------------------------------------------------*/ + +MADSEngine *SpriteSlot::_vm = nullptr; + +SpriteSlot::SpriteSlot() { + _spriteType = ST_NONE; + _seqIndex = 0; + _spritesIndex = 0; + _frameNumber = 0; + _depth = 0; + _scale = 0; +} + +SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) { + _spriteType = type; + _seqIndex = seqIndex; + _spritesIndex = 0; + _frameNumber = 0; + _depth = 0; + _scale = 0; +} + +/*------------------------------------------------------------------------*/ + +SpriteSlots::SpriteSlots(MADSEngine *vm) : _vm(vm) { + SpriteSlot::_vm = vm; +} + +void SpriteSlots::clear(bool flag) { + _vm->_game->_scene._textDisplay.clear(); + + if (flag) + _vm->_game->_scene._sprites.clear(); + + Common::Array::clear(); + push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); +} + +/** +* Releases any sprites used by the player +*/ +void SpriteSlots::releasePlayerSprites() { + Player &player = _vm->_game->_player; + + if (player._spritesLoaded && player._numSprites > 0) { + int spriteEnd = player._spritesStart + player._numSprites - 1; + do { + deleteEntry(spriteEnd); + } while (--spriteEnd >= player._spritesStart); + } +} + +void SpriteSlots::deleteEntry(int index) { + remove_at(index); +} + +void SpriteSlots::fullRefresh(bool clearAll) { + if (clearAll) + Common::Array::clear(); + + push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); +} + +void SpriteSlots::drawBackground() { + Scene &scene = _vm->_game->_scene; + + // Initial draw loop for any active sprites in the background + for (uint i = 0; i < scene._spriteSlots.size(); ++i) { + if (scene._spriteSlots[i]._spriteType >= ST_NONE) { + scene._dirtyAreas[i]._active = false; + } + else { + scene._dirtyAreas[i]._active = true; + scene._dirtyAreas[i].setSpriteSlot(&scene._spriteSlots[i]); + + SpriteAsset *asset = scene._sprites[scene._spriteSlots[i]._spritesIndex]; + MSprite *frame = asset->getFrame(scene._spriteSlots[i]._frameNumber); + + if (scene._spriteSlots[i]._spriteType == ST_BACKGROUND) { + Common::Point pt = scene._spriteSlots[i]._position; + if (scene._spriteSlots[i]._scale != -1) { + // Adjust the drawing position + pt.x -= frame->w / 2; + pt.y -= frame->h / 2; + } + + if (scene._spriteSlots[i]._depth <= 1) { + asset->draw(&scene._backgroundSurface, scene._spriteSlots[i]._frameNumber, pt); + } + else if (scene._depthStyle == 0) { + asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, scene._spriteSlots[i]._frameNumber, + pt, scene._spriteSlots[i]._depth); + } else { + error("Unsupported depth style"); + } + } + } + } + + // Mark any remaning dirty areas as inactive + for (uint i = scene._spriteSlots.size(); i < 50; ++i) + scene._dirtyAreas[i]._active = false; + + // Flag any active text display + for (uint i = 50; i < scene._textDisplay.size(); ++i) { + TextDisplay &textDisplay = scene._textDisplay[i - 50]; + if (scene._textDisplay[i]._expire >= 0 || !textDisplay._active) { + scene._dirtyAreas[i]._active = false; + } else { + scene._dirtyAreas[i]._active = true; + scene._dirtyAreas[i].setTextDisplay(&textDisplay); + } + } +} + +/*------------------------------------------------------------------------*/ + +int SpriteSets::add(SpriteAsset *asset, int idx) { + if (!idx) + idx = size(); + + if (idx >= (int)(size() + 1)) + resize(idx + 1); + delete (*this)[idx]; + (*this)[idx] = asset; + + return idx; +} + +/*------------------------------------------------------------------------*/ + +} // End of namespace MADS -- cgit v1.2.3 From 23ebeec600f8210601dd45fc42c21a596fa6d127 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Mar 2014 07:27:39 -0500 Subject: MADS: Further implementation of drawElements --- engines/mads/sprites.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 3cba6989b1..e7349f6c60 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -161,6 +161,19 @@ void SpriteSlots::deleteEntry(int index) { remove_at(index); } +void SpriteSlots::setDirtyAreas() { + Scene &scene = _vm->_game->_scene; + + for (uint i = 0; i < size(); ++i) { + if ((*this)[i]._spriteType >= ST_NONE) { + scene._dirtyAreas[i].setSpriteSlot(&(*this)[i]); + + scene._dirtyAreas[i]._textActive = ((*this)[i]._spriteType <= ST_NONE) ? 0 : 1; + (*this)[i]._spriteType = ST_NONE; + } + } +} + void SpriteSlots::fullRefresh(bool clearAll) { if (clearAll) Common::Array::clear(); @@ -220,6 +233,13 @@ void SpriteSlots::drawBackground() { } } +void SpriteSlots::cleanUp() { + for (int i = (int)size() - 1; i >= 0; --i) { + if ((*this)[i]._spriteType >= ST_NONE) + remove_at(i); + } +} + /*------------------------------------------------------------------------*/ int SpriteSets::add(SpriteAsset *asset, int idx) { -- cgit v1.2.3 From d98f890029936dfa8139cf8dce4756ec92bc2568 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Mar 2014 09:04:53 -0500 Subject: MADS: Completed implementing drawElements and support methods --- engines/mads/sprites.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index e7349f6c60..aa15f665f4 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -36,6 +36,24 @@ enum { kMarker = 2 }; +#define TRANSPARENT_COLOR_INDEX 0xFF + +class DepthEntry { +public: + int depth; + int index; + + DepthEntry(int depthAmt, int indexVal) { depth = depthAmt; index = indexVal; } +}; + +bool sortHelper(const DepthEntry &entry1, const DepthEntry &entry2) { + return entry1.depth < entry2.depth; +} + +typedef Common::List DepthList; + +/*------------------------------------------------------------------------*/ + MSprite::MSprite(): MSurface() { _encoding = 0; } @@ -105,6 +123,10 @@ void MSprite::loadSprite(Common::SeekableReadStream *source) { } } +byte MSprite::getTransparencyIndex() const { + return TRANSPARENT_COLOR_INDEX; +} + /*------------------------------------------------------------------------*/ MADSEngine *SpriteSlot::_vm = nullptr; @@ -233,6 +255,71 @@ void SpriteSlots::drawBackground() { } } +void SpriteSlots::drawForeground(MSurface *s) { + DepthList depthList; + Scene &scene = _vm->_game->_scene; + + // Get a list of sprite object depths for active objects + for (uint i = 0; i < size(); ++i) { + if ((*this)[i]._spriteType >= ST_NONE) { + DepthEntry rec(16 - (*this)[i]._depth, i); + depthList.push_back(rec); + } + } + + // Sort the list in order of the depth + Common::sort(depthList.begin(), depthList.end(), sortHelper); + + // Loop through each of the objects + DepthList::iterator i; + for (i = depthList.begin(); i != depthList.end(); ++i) { + DepthEntry &de = *i; + SpriteSlot &slot = (*this)[de.index]; + assert(slot._spritesIndex < (int)scene._sprites.size()); + SpriteAsset &spriteSet = *scene._sprites[slot._spritesIndex]; + + // Get the sprite frame + int frameNumber = slot._frameNumber & 0x7fff; + bool flipped = (slot._frameNumber & 0x8000) != 0; + MSprite *sprite = spriteSet.getFrame(frameNumber - 1); + + MSurface *spr = sprite; + if (flipped) { + // Create a flipped copy of the sprite temporarily + spr = sprite->flipHorizontal(); + } + + if ((slot._scale < 100) && (slot._scale != -1)) { + // Minimalised drawing + s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, + slot._scale, sprite->getTransparencyIndex()); + } else { + int xp, yp; + + if (slot._scale == -1) { + xp = slot._position.x - scene._posAdjust.x; + yp = slot._position.y - scene._posAdjust.y; + } else { + xp = slot._position.x - (spr->w / 2) - scene._posAdjust.x; + yp = slot._position.y - spr->h - scene._posAdjust.y + 1; + } + + if (slot._depth > 1) { + // Draw the frame with depth processing + s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface, + 100, sprite->getTransparencyIndex()); + } else { + // No depth, so simply draw the image + spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex()); + } + } + + // Free sprite if it was a flipped one + if (flipped) + delete spr; + } +} + void SpriteSlots::cleanUp() { for (int i = (int)size() - 1; i >= 0; --i) { if ((*this)[i]._spriteType >= ST_NONE) @@ -254,6 +341,4 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { return idx; } -/*------------------------------------------------------------------------*/ - } // End of namespace MADS -- cgit v1.2.3 From a0e955d8d327afa83ad96fe1ce765eeba0ce561f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Mar 2014 20:45:02 -0500 Subject: MADS: More Animation class implementation --- engines/mads/sprites.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index aa15f665f4..23360b0a00 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -149,6 +149,20 @@ SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) { _scale = 0; } +bool SpriteSlot::operator==(const SpriteSlotSubset &other) const { + return (_spritesIndex == other._spritesIndex) && (_frameNumber == other._frameNumber) && + (_position == other._position) && (_depth == other._depth) && + (_scale == other._scale); +} + +void SpriteSlot::copy(const SpriteSlotSubset &other) { + _spritesIndex = other._spritesIndex; + _frameNumber = other._frameNumber; + _position = other._position; + _depth = other._depth; + _scale = other._scale; +} + /*------------------------------------------------------------------------*/ SpriteSlots::SpriteSlots(MADSEngine *vm) : _vm(vm) { -- cgit v1.2.3 From a77ed90618664e50705b3e59dd2111faec2f5f39 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 6 Mar 2014 22:31:41 -0500 Subject: MADS: Implementing support methods needed for scene 804 initialisation --- engines/mads/sprites.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 23360b0a00..321acf026d 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -355,4 +355,8 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { return idx; } +int SpriteSets::addSprites(const Common::String &resName, int flags) { + return add(new SpriteAsset(_vm, resName, flags)); +} + } // End of namespace MADS -- cgit v1.2.3 From 3399516c5e4c2931adf76a25944cb3e46f9934ee Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 7 Mar 2014 23:07:36 -0500 Subject: MADS: Implemented remainder of scene 804 setup code and support methods --- engines/mads/sprites.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 321acf026d..9a56ed3895 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -359,4 +359,30 @@ int SpriteSets::addSprites(const Common::String &resName, int flags) { return add(new SpriteAsset(_vm, resName, flags)); } +/*------------------------------------------------------------------------*/ + +ImageInterEntry::ImageInterEntry() { + _field0 = 0; + _field2 = 0; + _field3 = 0; + _field4 = 0; + _field6 = 0; + _field8 = 0; +} + +/*------------------------------------------------------------------------*/ + +int ImageInterEntries::add(int field0, int field2) { + ImageInterEntry ie; + ie._field0 = field0; + ie._field2 = field2; + + push_back(ie); + return size() - 1; +} + +void ImageInterEntries::call(int v1) { + debug("TODO: ImageInterEntries::call"); +} + } // End of namespace MADS -- cgit v1.2.3 From 80bba746406743ab7a7ae6c163c79c652f6d7624 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Mar 2014 08:33:13 -0500 Subject: MADS: Fix sprites loading for scene 804 --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 9a56ed3895..87a23d1296 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -347,7 +347,7 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { if (!idx) idx = size(); - if (idx >= (int)(size() + 1)) + if (idx >= (int)size()) resize(idx + 1); delete (*this)[idx]; (*this)[idx] = asset; -- cgit v1.2.3 From 984099ae2ca9dd53b47e44e7815c560c68acbd61 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Mar 2014 10:53:10 -0500 Subject: MADS: Implemented stubbed SpriteSlots methods --- engines/mads/sprites.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 87a23d1296..82e45deffc 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -70,7 +70,6 @@ MSprite::MSprite(Common::SeekableReadStream *source, const Common::Point &offset MSprite::~MSprite() { } - // TODO: The sprite outlines (pixel value 0xFD) are not shown void MSprite::loadSprite(Common::SeekableReadStream *source) { byte *outp, *lineStart; @@ -217,6 +216,21 @@ void SpriteSlots::fullRefresh(bool clearAll) { push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); } +void SpriteSlots::deleteTimer(int seqIndex) { + for (uint idx = 0; idx < size(); ++idx) { + if ((*this)[idx]._seqIndex == seqIndex) { + remove_at(idx); + return; + } + } +} + +int SpriteSlots::add() { + SpriteSlot ss; + push_back(ss); + return size() - 1; +} + void SpriteSlots::drawBackground() { Scene &scene = _vm->_game->_scene; -- cgit v1.2.3 From 5536b8a933f792f45d08ab5126e826a9a20fa476 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Mar 2014 15:42:07 -0500 Subject: MADS: Fixes for sprite list initialisation --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 82e45deffc..b18efa223b 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -168,7 +168,7 @@ SpriteSlots::SpriteSlots(MADSEngine *vm) : _vm(vm) { SpriteSlot::_vm = vm; } -void SpriteSlots::clear(bool flag) { +void SpriteSlots::reset(bool flag) { _vm->_game->_scene._textDisplay.clear(); if (flag) -- cgit v1.2.3 From 680b5a4487a6c1b08f79c4a657b63715e69240de Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 10 Mar 2014 00:00:39 -0400 Subject: MADS: In progress implementation of PaletteUsage::process --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index b18efa223b..398c1c91b7 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -395,7 +395,7 @@ int ImageInterEntries::add(int field0, int field2) { return size() - 1; } -void ImageInterEntries::call(int v1) { +void ImageInterEntries::call(int v1, int v2) { debug("TODO: ImageInterEntries::call"); } -- cgit v1.2.3 From 408f5e79df5e8a33367fdf2a9c17b424953edace Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 12 Mar 2014 22:45:33 -0400 Subject: MADS: General cleanup and minor fixes --- engines/mads/sprites.cpp | 57 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 398c1c91b7..228071af23 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -235,31 +235,33 @@ void SpriteSlots::drawBackground() { Scene &scene = _vm->_game->_scene; // Initial draw loop for any active sprites in the background - for (uint i = 0; i < scene._spriteSlots.size(); ++i) { - if (scene._spriteSlots[i]._spriteType >= ST_NONE) { - scene._dirtyAreas[i]._active = false; - } - else { - scene._dirtyAreas[i]._active = true; - scene._dirtyAreas[i].setSpriteSlot(&scene._spriteSlots[i]); + for (uint i = 0; i < size(); ++i) { + SpriteSlot &spriteSlot = (*this)[i]; + DirtyArea &dirtyArea = scene._dirtyAreas[i]; + + if (spriteSlot._spriteType >= ST_NONE) { + dirtyArea._active = false; + } else { + dirtyArea._active = true; + dirtyArea.setSpriteSlot(&spriteSlot); - SpriteAsset *asset = scene._sprites[scene._spriteSlots[i]._spritesIndex]; - MSprite *frame = asset->getFrame(scene._spriteSlots[i]._frameNumber); + SpriteAsset *asset = scene._sprites[spriteSlot._spritesIndex]; + MSprite *frame = asset->getFrame(spriteSlot._frameNumber); - if (scene._spriteSlots[i]._spriteType == ST_BACKGROUND) { - Common::Point pt = scene._spriteSlots[i]._position; - if (scene._spriteSlots[i]._scale != -1) { + if (spriteSlot._spriteType == ST_BACKGROUND) { + Common::Point pt = spriteSlot._position; + if (spriteSlot._scale != -1) { // Adjust the drawing position pt.x -= frame->w / 2; pt.y -= frame->h / 2; } - if (scene._spriteSlots[i]._depth <= 1) { - asset->draw(&scene._backgroundSurface, scene._spriteSlots[i]._frameNumber, pt); + if (spriteSlot._depth <= 1) { + asset->draw(&scene._backgroundSurface, spriteSlot._frameNumber, pt); } else if (scene._depthStyle == 0) { - asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, scene._spriteSlots[i]._frameNumber, - pt, scene._spriteSlots[i]._depth); + asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, spriteSlot._frameNumber, + pt, spriteSlot._depth); } else { error("Unsupported depth style"); } @@ -267,18 +269,20 @@ void SpriteSlots::drawBackground() { } } - // Mark any remaning dirty areas as inactive - for (uint i = scene._spriteSlots.size(); i < 50; ++i) + // Mark any remaning sprite slot dirty areas as inactive + for (uint i = size(); i < SPRITE_SLOTS_MAX_SIZE; ++i) scene._dirtyAreas[i]._active = false; // Flag any active text display - for (uint i = 50; i < scene._textDisplay.size(); ++i) { - TextDisplay &textDisplay = scene._textDisplay[i - 50]; - if (scene._textDisplay[i]._expire >= 0 || !textDisplay._active) { - scene._dirtyAreas[i]._active = false; + for (uint i = 0; i < scene._textDisplay.size(); ++i) { + TextDisplay &textDisplay = scene._textDisplay[i]; + DirtyArea &dirtyArea = scene._dirtyAreas[i + SPRITE_SLOTS_MAX_SIZE]; + + if (textDisplay._expire >= 0 || !textDisplay._active) { + dirtyArea._active = false; } else { - scene._dirtyAreas[i]._active = true; - scene._dirtyAreas[i].setTextDisplay(&textDisplay); + dirtyArea._active = true; + dirtyArea.setTextDisplay(&textDisplay); } } } @@ -289,8 +293,9 @@ void SpriteSlots::drawForeground(MSurface *s) { // Get a list of sprite object depths for active objects for (uint i = 0; i < size(); ++i) { - if ((*this)[i]._spriteType >= ST_NONE) { - DepthEntry rec(16 - (*this)[i]._depth, i); + SpriteSlot &spriteSlot = (*this)[i]; + if (spriteSlot._spriteType >= ST_NONE) { + DepthEntry rec(16 - spriteSlot._depth, i); depthList.push_back(rec); } } -- cgit v1.2.3 From 84fb90e7a52daffd862159d54cda4817aa930a6f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 13 Mar 2014 20:56:03 -0400 Subject: MADS: Fix GCC warnings and memory leaks --- engines/mads/sprites.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 228071af23..a7a46ce29f 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -362,6 +362,10 @@ void SpriteSlots::cleanUp() { /*------------------------------------------------------------------------*/ +SpriteSets::~SpriteSets() { + clear(); +} + int SpriteSets::add(SpriteAsset *asset, int idx) { if (!idx) idx = size(); @@ -378,6 +382,13 @@ int SpriteSets::addSprites(const Common::String &resName, int flags) { return add(new SpriteAsset(_vm, resName, flags)); } +void SpriteSets::clear() { + for (uint i = 0; i < size(); ++i) + delete (*this)[i]; + + Common::Array::clear(); +} + /*------------------------------------------------------------------------*/ ImageInterEntry::ImageInterEntry() { -- cgit v1.2.3 From 3f0cd4771c94a83c72f09f74ba351a3905357d1c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 13 Mar 2014 22:25:16 -0400 Subject: MADS: Fixed handling of dirty rects to copy areas to the physical screen --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index a7a46ce29f..6f227fa341 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -24,7 +24,7 @@ #include "engines/util.h" #include "graphics/palette.h" #include "mads/mads.h" -#include "mads/graphics.h" +#include "mads/screen.h" #include "mads/msurface.h" #include "mads/sprites.h" -- cgit v1.2.3 From 12b79e817833fe17da717b88999da96e9bb1ec76 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 14 Mar 2014 21:56:01 -0400 Subject: MADS: Fix for sprite slot cleanup post-frame draw --- engines/mads/sprites.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 6f227fa341..ff953ac21c 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -240,6 +240,7 @@ void SpriteSlots::drawBackground() { DirtyArea &dirtyArea = scene._dirtyAreas[i]; if (spriteSlot._spriteType >= ST_NONE) { + // Foreground sprite, so we can ignore it dirtyArea._active = false; } else { dirtyArea._active = true; @@ -249,6 +250,7 @@ void SpriteSlots::drawBackground() { MSprite *frame = asset->getFrame(spriteSlot._frameNumber); if (spriteSlot._spriteType == ST_BACKGROUND) { + // Background object, so need to draw it Common::Point pt = spriteSlot._position; if (spriteSlot._scale != -1) { // Adjust the drawing position @@ -258,8 +260,7 @@ void SpriteSlots::drawBackground() { if (spriteSlot._depth <= 1) { asset->draw(&scene._backgroundSurface, spriteSlot._frameNumber, pt); - } - else if (scene._depthStyle == 0) { + } else if (scene._depthStyle == 0) { asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, spriteSlot._frameNumber, pt, spriteSlot._depth); } else { @@ -355,7 +356,7 @@ void SpriteSlots::drawForeground(MSurface *s) { void SpriteSlots::cleanUp() { for (int i = (int)size() - 1; i >= 0; --i) { - if ((*this)[i]._spriteType >= ST_NONE) + if ((*this)[i]._spriteType < ST_NONE) remove_at(i); } } -- cgit v1.2.3 From 37bb5150d0d2c901b9bb88ec009a348f1de3d5b0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 14 Mar 2014 22:21:52 -0400 Subject: MADS: Fixes for handling sprite transparency --- engines/mads/sprites.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index ff953ac21c..2d318c5ae2 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -70,15 +70,15 @@ MSprite::MSprite(Common::SeekableReadStream *source, const Common::Point &offset MSprite::~MSprite() { } -// TODO: The sprite outlines (pixel value 0xFD) are not shown void MSprite::loadSprite(Common::SeekableReadStream *source) { byte *outp, *lineStart; bool newLine = false; outp = getData(); lineStart = getData(); + Common::fill(outp, outp + this->w * this->h, getTransparencyIndex()); - while (1) { + for (;;) { byte cmd1, cmd2, count, pixel; if (newLine) { @@ -101,7 +101,7 @@ void MSprite::loadSprite(Common::SeekableReadStream *source) { } else { pixel = source->readByte(); while (count--) - *outp++ = (pixel == 0xFD) ? 0 : pixel; + *outp++ = (pixel == 0xFD) ? getTransparencyIndex() : pixel; } } } else { @@ -113,9 +113,9 @@ void MSprite::loadSprite(Common::SeekableReadStream *source) { count = source->readByte(); pixel = source->readByte(); while (count--) - *outp++ = (pixel == 0xFD) ? 0 : pixel; + *outp++ = (pixel == 0xFD) ? getTransparencyIndex() : pixel; } else { - *outp++ = (cmd2 == 0xFD) ? 0 : cmd2; + *outp++ = (cmd2 == 0xFD) ? getTransparencyIndex() : cmd2; } } } -- cgit v1.2.3 From c9661ca88cbe3554a455c320fe7bcdcb203823a5 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 15 Mar 2014 08:41:17 -0400 Subject: MADS: Fix off by 1 frame references in srite drawing --- engines/mads/sprites.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 2d318c5ae2..78743e6a87 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -246,11 +246,12 @@ void SpriteSlots::drawBackground() { dirtyArea._active = true; dirtyArea.setSpriteSlot(&spriteSlot); - SpriteAsset *asset = scene._sprites[spriteSlot._spritesIndex]; - MSprite *frame = asset->getFrame(spriteSlot._frameNumber); - if (spriteSlot._spriteType == ST_BACKGROUND) { // Background object, so need to draw it + assert(spriteSlot._frameNumber > 0); + SpriteAsset *asset = scene._sprites[spriteSlot._spritesIndex]; + MSprite *frame = asset->getFrame(spriteSlot._frameNumber - 1); + Common::Point pt = spriteSlot._position; if (spriteSlot._scale != -1) { // Adjust the drawing position @@ -315,6 +316,8 @@ void SpriteSlots::drawForeground(MSurface *s) { // Get the sprite frame int frameNumber = slot._frameNumber & 0x7fff; bool flipped = (slot._frameNumber & 0x8000) != 0; + + assert(frameNumber > 0); MSprite *sprite = spriteSet.getFrame(frameNumber - 1); MSurface *spr = sprite; -- cgit v1.2.3 From d2bbdd255a43915267bac8dce6998c8f843979da Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 15 Mar 2014 11:12:31 -0400 Subject: MADS: Implement palette shifting for loaded sprites --- engines/mads/sprites.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 78743e6a87..1b65442b4c 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -58,25 +58,27 @@ MSprite::MSprite(): MSurface() { _encoding = 0; } -MSprite::MSprite(Common::SeekableReadStream *source, const Common::Point &offset, - int widthVal, int heightVal, bool decodeRle, uint8 encodingVal) - : MSurface(widthVal, heightVal), - _encoding(encodingVal), _offset(offset) { - +MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, + const Common::Rect &bounds): + MSurface(bounds.width(), bounds.height()), + _encoding(0), _offset(Common::Point(bounds.left, bounds.top)) { // Load the sprite data - loadSprite(source); + loadSprite(source, palette); } MSprite::~MSprite() { } -void MSprite::loadSprite(Common::SeekableReadStream *source) { +void MSprite::loadSprite(Common::SeekableReadStream *source, + const Common::Array &palette) { byte *outp, *lineStart; bool newLine = false; outp = getData(); lineStart = getData(); - Common::fill(outp, outp + this->w * this->h, getTransparencyIndex()); + int spriteSize = this->w * this->h; + byte transIndex = getTransparencyIndex(); + Common::fill(outp, outp + spriteSize, transIndex); for (;;) { byte cmd1, cmd2, count, pixel; @@ -120,6 +122,13 @@ void MSprite::loadSprite(Common::SeekableReadStream *source) { } } } + + // Do a final iteration over the sprite to convert it's pixels to + // the final positions in the main palette + for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) { + if (*outp != transIndex) + *outp = palette[*outp]._palIndex; + } } byte MSprite::getTransparencyIndex() const { -- cgit v1.2.3 From 49ca357e9ef19aa2650ca42b1f42c8aacf937ec6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 15 Mar 2014 11:22:19 -0400 Subject: MADS: Remove redundant _encoding field from MSprite --- engines/mads/sprites.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 1b65442b4c..8979fdb12c 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -55,13 +55,12 @@ typedef Common::List DepthList; /*------------------------------------------------------------------------*/ MSprite::MSprite(): MSurface() { - _encoding = 0; } MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, const Common::Rect &bounds): MSurface(bounds.width(), bounds.height()), - _encoding(0), _offset(Common::Point(bounds.left, bounds.top)) { + _offset(Common::Point(bounds.left, bounds.top)) { // Load the sprite data loadSprite(source, palette); } -- cgit v1.2.3 From 2fb9edc4ee80c99b5a56a66cf52c614939748bd9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 15 Mar 2014 21:51:40 -0400 Subject: MADS: Added some more ImageInterEntries methods --- engines/mads/sprites.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 8979fdb12c..be066ba2db 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -414,15 +414,34 @@ ImageInterEntry::ImageInterEntry() { /*------------------------------------------------------------------------*/ -int ImageInterEntries::add(int field0, int field2) { +void ImageInterEntries::add(int v1, int v2) { ImageInterEntry ie; - ie._field0 = field0; - ie._field2 = field2; + ie._field0 = -2; + ie._field2 = -1; + + push_back(ie); +} + +void ImageInterEntries::add(int v1, int v2, int v3, int v4) { + assert(size() < 50); + + ImageInterEntry ie; + ie._field0 = -3; + ie._field2 = 201; + ie._field6 = v1; + ie._field8 = v2; + ie._field4 = v3; + ie._field3 = v4; push_back(ie); - return size() - 1; } +ImageInterEntry &ImageInterEntries::add() { + resize(size() + 1); + return (*this)[size() - 1]; +} + + void ImageInterEntries::call(int v1, int v2) { debug("TODO: ImageInterEntries::call"); } -- cgit v1.2.3 From 0c8a3a47e28075bd559be43bde910587af35d8ab Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 17 Mar 2014 21:53:22 -0400 Subject: MADS: Transformed ImageInterEntries to be User Interface UISlots --- engines/mads/sprites.cpp | 70 +++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 52 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index be066ba2db..18f6a642fd 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -139,7 +139,7 @@ byte MSprite::getTransparencyIndex() const { MADSEngine *SpriteSlot::_vm = nullptr; SpriteSlot::SpriteSlot() { - _spriteType = ST_NONE; + _SlotType = ST_NONE; _seqIndex = 0; _spritesIndex = 0; _frameNumber = 0; @@ -147,8 +147,8 @@ SpriteSlot::SpriteSlot() { _scale = 0; } -SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) { - _spriteType = type; +SpriteSlot::SpriteSlot(SlotType type, int seqIndex) { + _SlotType = type; _seqIndex = seqIndex; _spritesIndex = 0; _frameNumber = 0; @@ -208,11 +208,11 @@ void SpriteSlots::setDirtyAreas() { Scene &scene = _vm->_game->_scene; for (uint i = 0; i < size(); ++i) { - if ((*this)[i]._spriteType >= ST_NONE) { + if ((*this)[i]._SlotType >= ST_NONE) { scene._dirtyAreas[i].setSpriteSlot(&(*this)[i]); - scene._dirtyAreas[i]._textActive = ((*this)[i]._spriteType <= ST_NONE) ? 0 : 1; - (*this)[i]._spriteType = ST_NONE; + scene._dirtyAreas[i]._textActive = ((*this)[i]._SlotType <= ST_NONE) ? 0 : 1; + (*this)[i]._SlotType = ST_NONE; } } } @@ -247,14 +247,14 @@ void SpriteSlots::drawBackground() { SpriteSlot &spriteSlot = (*this)[i]; DirtyArea &dirtyArea = scene._dirtyAreas[i]; - if (spriteSlot._spriteType >= ST_NONE) { + if (spriteSlot._SlotType >= ST_NONE) { // Foreground sprite, so we can ignore it dirtyArea._active = false; } else { dirtyArea._active = true; dirtyArea.setSpriteSlot(&spriteSlot); - if (spriteSlot._spriteType == ST_BACKGROUND) { + if (spriteSlot._SlotType == ST_BACKGROUND) { // Background object, so need to draw it assert(spriteSlot._frameNumber > 0); SpriteAsset *asset = scene._sprites[spriteSlot._spritesIndex]; @@ -304,7 +304,7 @@ void SpriteSlots::drawForeground(MSurface *s) { // Get a list of sprite object depths for active objects for (uint i = 0; i < size(); ++i) { SpriteSlot &spriteSlot = (*this)[i]; - if (spriteSlot._spriteType >= ST_NONE) { + if (spriteSlot._SlotType >= ST_NONE) { DepthEntry rec(16 - spriteSlot._depth, i); depthList.push_back(rec); } @@ -367,7 +367,7 @@ void SpriteSlots::drawForeground(MSurface *s) { void SpriteSlots::cleanUp() { for (int i = (int)size() - 1; i >= 0; --i) { - if ((*this)[i]._spriteType < ST_NONE) + if ((*this)[i]._SlotType < ST_NONE) remove_at(i); } } @@ -391,6 +391,7 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { } int SpriteSets::addSprites(const Common::String &resName, int flags) { + ++_assetCount; return add(new SpriteAsset(_vm, resName, flags)); } @@ -398,52 +399,17 @@ void SpriteSets::clear() { for (uint i = 0; i < size(); ++i) delete (*this)[i]; + _assetCount = 0; Common::Array::clear(); } -/*------------------------------------------------------------------------*/ - -ImageInterEntry::ImageInterEntry() { - _field0 = 0; - _field2 = 0; - _field3 = 0; - _field4 = 0; - _field6 = 0; - _field8 = 0; -} - -/*------------------------------------------------------------------------*/ - -void ImageInterEntries::add(int v1, int v2) { - ImageInterEntry ie; - ie._field0 = -2; - ie._field2 = -1; - - push_back(ie); -} +void SpriteSets::remove(int idx) { + if (idx >= 0) { + delete (*this)[idx]; + (*this)[idx] = nullptr; -void ImageInterEntries::add(int v1, int v2, int v3, int v4) { - assert(size() < 50); - - ImageInterEntry ie; - ie._field0 = -3; - ie._field2 = 201; - ie._field6 = v1; - ie._field8 = v2; - ie._field4 = v3; - ie._field3 = v4; - - push_back(ie); -} - -ImageInterEntry &ImageInterEntries::add() { - resize(size() + 1); - return (*this)[size() - 1]; -} - - -void ImageInterEntries::call(int v1, int v2) { - debug("TODO: ImageInterEntries::call"); + --_assetCount; + } } } // End of namespace MADS -- cgit v1.2.3 From d494db888e24c04261a46aa89d946ff3c7db3851 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 17 Mar 2014 23:14:54 -0400 Subject: MADS: Beginnings of code for UI inventory item animation --- engines/mads/sprites.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 18f6a642fd..e519c6966b 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -379,7 +379,9 @@ SpriteSets::~SpriteSets() { } int SpriteSets::add(SpriteAsset *asset, int idx) { - if (!idx) + if (idx) + idx = idx + 49; + else idx = size(); if (idx >= (int)size()) -- cgit v1.2.3 From 2b141aaba681a3c7b848010cd58768f55f4434a3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 21 Mar 2014 09:27:22 -0400 Subject: MADS: Fixes for screen objects loading and checking --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index e519c6966b..ea4dbbbaad 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -177,7 +177,7 @@ SpriteSlots::SpriteSlots(MADSEngine *vm) : _vm(vm) { } void SpriteSlots::reset(bool flag) { - _vm->_game->_scene._textDisplay.clear(); + _vm->_game->_scene._textDisplay.reset(); if (flag) _vm->_game->_scene._sprites.clear(); -- cgit v1.2.3 From 2090987b81615af4cda189a462bc04cd22d7a180 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 21 Mar 2014 22:47:31 -0400 Subject: MADS: Fixes for handling horizontally flipped frames --- engines/mads/sprites.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index ea4dbbbaad..c0467ff95f 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -322,8 +322,8 @@ void SpriteSlots::drawForeground(MSurface *s) { SpriteAsset &spriteSet = *scene._sprites[slot._spritesIndex]; // Get the sprite frame - int frameNumber = slot._frameNumber & 0x7fff; - bool flipped = (slot._frameNumber & 0x8000) != 0; + int frameNumber = ABS(slot._frameNumber); + bool flipped = slot._frameNumber < 0; assert(frameNumber > 0); MSprite *sprite = spriteSet.getFrame(frameNumber - 1); -- cgit v1.2.3 From 195c53a68853db6a77c6a63d392968ba912cf2f4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 30 Mar 2014 22:37:08 -0400 Subject: MADS: Added some missing code for scene change freeing --- engines/mads/sprites.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index c0467ff95f..226835bb23 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -186,20 +186,6 @@ void SpriteSlots::reset(bool flag) { push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); } -/** -* Releases any sprites used by the player -*/ -void SpriteSlots::releasePlayerSprites() { - Player &player = _vm->_game->_player; - - if (player._spritesLoaded && player._numSprites > 0) { - int spriteEnd = player._spritesStart + player._numSprites - 1; - do { - deleteEntry(spriteEnd); - } while (--spriteEnd >= player._spritesStart); - } -} - void SpriteSlots::deleteEntry(int index) { remove_at(index); } -- cgit v1.2.3 From 3f8ee8fafa0166204a6c0b9ec311aa9fb0aa3c39 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 2 Apr 2014 21:24:22 -0400 Subject: MADS: Cleanup of UISlots and flag types --- engines/mads/sprites.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 226835bb23..442125e929 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -139,7 +139,7 @@ byte MSprite::getTransparencyIndex() const { MADSEngine *SpriteSlot::_vm = nullptr; SpriteSlot::SpriteSlot() { - _SlotType = ST_NONE; + _flags = IMG_STATIC; _seqIndex = 0; _spritesIndex = 0; _frameNumber = 0; @@ -147,8 +147,8 @@ SpriteSlot::SpriteSlot() { _scale = 0; } -SpriteSlot::SpriteSlot(SlotType type, int seqIndex) { - _SlotType = type; +SpriteSlot::SpriteSlot(SpriteFlags type, int seqIndex) { + _flags = type; _seqIndex = seqIndex; _spritesIndex = 0; _frameNumber = 0; @@ -183,7 +183,7 @@ void SpriteSlots::reset(bool flag) { _vm->_game->_scene._sprites.clear(); Common::Array::clear(); - push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); + push_back(SpriteSlot(IMG_REFRESH, -1)); } void SpriteSlots::deleteEntry(int index) { @@ -194,11 +194,11 @@ void SpriteSlots::setDirtyAreas() { Scene &scene = _vm->_game->_scene; for (uint i = 0; i < size(); ++i) { - if ((*this)[i]._SlotType >= ST_NONE) { + if ((*this)[i]._flags >= IMG_STATIC) { scene._dirtyAreas[i].setSpriteSlot(&(*this)[i]); - scene._dirtyAreas[i]._textActive = ((*this)[i]._SlotType <= ST_NONE) ? 0 : 1; - (*this)[i]._SlotType = ST_NONE; + scene._dirtyAreas[i]._textActive = ((*this)[i]._flags <= IMG_STATIC) ? 0 : 1; + (*this)[i]._flags = IMG_STATIC; } } } @@ -207,7 +207,7 @@ void SpriteSlots::fullRefresh(bool clearAll) { if (clearAll) Common::Array::clear(); - push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1)); + push_back(SpriteSlot(IMG_REFRESH, -1)); } void SpriteSlots::deleteTimer(int seqIndex) { @@ -233,14 +233,14 @@ void SpriteSlots::drawBackground() { SpriteSlot &spriteSlot = (*this)[i]; DirtyArea &dirtyArea = scene._dirtyAreas[i]; - if (spriteSlot._SlotType >= ST_NONE) { + if (spriteSlot._flags >= IMG_STATIC) { // Foreground sprite, so we can ignore it dirtyArea._active = false; } else { dirtyArea._active = true; dirtyArea.setSpriteSlot(&spriteSlot); - if (spriteSlot._SlotType == ST_BACKGROUND) { + if (spriteSlot._flags == IMG_DELTA) { // Background object, so need to draw it assert(spriteSlot._frameNumber > 0); SpriteAsset *asset = scene._sprites[spriteSlot._spritesIndex]; @@ -290,7 +290,7 @@ void SpriteSlots::drawForeground(MSurface *s) { // Get a list of sprite object depths for active objects for (uint i = 0; i < size(); ++i) { SpriteSlot &spriteSlot = (*this)[i]; - if (spriteSlot._SlotType >= ST_NONE) { + if (spriteSlot._flags >= IMG_STATIC) { DepthEntry rec(16 - spriteSlot._depth, i); depthList.push_back(rec); } @@ -353,7 +353,7 @@ void SpriteSlots::drawForeground(MSurface *s) { void SpriteSlots::cleanUp() { for (int i = (int)size() - 1; i >= 0; --i) { - if ((*this)[i]._SlotType < ST_NONE) + if ((*this)[i]._flags < IMG_STATIC) remove_at(i); } } -- cgit v1.2.3 From 2457905ed42820d27264a4beccc9ae45da746c18 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 Apr 2014 21:24:35 -0400 Subject: MADS: Fixes for switching between scenes --- engines/mads/sprites.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 442125e929..0dd640bca0 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -372,14 +372,18 @@ int SpriteSets::add(SpriteAsset *asset, int idx) { if (idx >= (int)size()) resize(idx + 1); - delete (*this)[idx]; - (*this)[idx] = asset; + if ((*this)[idx]) { + delete (*this)[idx]; + } else { + ++_assetCount; + } + + (*this)[idx] = asset; return idx; } int SpriteSets::addSprites(const Common::String &resName, int flags) { - ++_assetCount; return add(new SpriteAsset(_vm, resName, flags)); } @@ -394,7 +398,14 @@ void SpriteSets::clear() { void SpriteSets::remove(int idx) { if (idx >= 0) { delete (*this)[idx]; - (*this)[idx] = nullptr; + + if (idx < ((int)size() - 1)) + (*this)[idx] = nullptr; + else { + do { + remove_at(size() - 1); + } while (size() > 0 && (*this)[size() - 1] == nullptr); + } --_assetCount; } -- cgit v1.2.3 From f4165c5f8a2a15a6b3cdf1ce46732e2e5efe772a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 12 Apr 2014 22:08:21 -0400 Subject: MADS: Field/method renaming --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 0dd640bca0..83f01430eb 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -283,7 +283,7 @@ void SpriteSlots::drawBackground() { } } -void SpriteSlots::drawForeground(MSurface *s) { +void SpriteSlots::drawSprites(MSurface *s) { DepthList depthList; Scene &scene = _vm->_game->_scene; -- cgit v1.2.3 From 848c94cd0e86bd9f170da7b06371fb0a12d7bb07 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 14 Apr 2014 21:33:58 -0400 Subject: MADS: Fix for sprite refreshes when doing player cutscenes --- engines/mads/sprites.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 83f01430eb..cd838f7dfb 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -212,8 +212,9 @@ void SpriteSlots::fullRefresh(bool clearAll) { void SpriteSlots::deleteTimer(int seqIndex) { for (uint idx = 0; idx < size(); ++idx) { - if ((*this)[idx]._seqIndex == seqIndex) { - remove_at(idx); + SpriteSlot &slot = (*this)[idx]; + if (slot._seqIndex == seqIndex) { + slot._flags = IMG_ERASE; return; } } -- cgit v1.2.3 From 7b907be93775167eab8efab45bea3b9a2776e288 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 15 Apr 2014 19:28:29 -0400 Subject: MADS: General cleanup and minor renamings --- engines/mads/sprites.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index cd838f7dfb..85e36d6c76 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -400,9 +400,9 @@ void SpriteSets::remove(int idx) { if (idx >= 0) { delete (*this)[idx]; - if (idx < ((int)size() - 1)) + if (idx < ((int)size() - 1)) { (*this)[idx] = nullptr; - else { + } else { do { remove_at(size() - 1); } while (size() > 0 && (*this)[size() - 1] == nullptr); -- cgit v1.2.3 From c2bf78848d26d51593ab4f08ad361bbf9fa2d13c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 16 Apr 2014 09:24:10 -0400 Subject: MADS: Fix drawing background sprites --- engines/mads/sprites.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 85e36d6c76..f187295b00 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -254,8 +254,9 @@ void SpriteSlots::drawBackground() { pt.y -= frame->h / 2; } + if (spriteSlot._depth <= 1) { - asset->draw(&scene._backgroundSurface, spriteSlot._frameNumber, pt); + frame->copyTo(&scene._backgroundSurface, frame->getTransparencyIndex()); } else if (scene._depthStyle == 0) { asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, spriteSlot._frameNumber, pt, spriteSlot._depth); -- cgit v1.2.3 From 0023e99621ba91ba87e4241e2a1ef6f97da4e7c0 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 4 May 2014 03:54:54 +0300 Subject: MADS: Fix bugs in SpriteSets::remove() This fixes several crashes when sprites get erased, like for example in death animations --- engines/mads/sprites.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index f187295b00..36cbdbea12 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -399,17 +399,21 @@ void SpriteSets::clear() { void SpriteSets::remove(int idx) { if (idx >= 0) { - delete (*this)[idx]; - if (idx < ((int)size() - 1)) { + delete (*this)[idx]; (*this)[idx] = nullptr; } else { - do { + while (size() > 0 && (*this)[size() - 1] == nullptr) { + delete (*this)[size() - 1]; remove_at(size() - 1); - } while (size() > 0 && (*this)[size() - 1] == nullptr); + } } - --_assetCount; + if (_assetCount > 0) + --_assetCount; + else + // FIXME: This is needed, otherwise scene sprites are not cleared in this case + clear(); } } -- cgit v1.2.3 From 68671d77c2028d41b6b848eb5bf6f40cc2c36f7a Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 4 May 2014 13:57:55 +0300 Subject: MADS: Fix a bug in SequenceList::scan() This resolves the FIXME in SpriteSets::remove() --- engines/mads/sprites.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 36cbdbea12..7bd8407c41 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -404,16 +404,12 @@ void SpriteSets::remove(int idx) { (*this)[idx] = nullptr; } else { while (size() > 0 && (*this)[size() - 1] == nullptr) { - delete (*this)[size() - 1]; remove_at(size() - 1); } } if (_assetCount > 0) --_assetCount; - else - // FIXME: This is needed, otherwise scene sprites are not cleared in this case - clear(); } } -- cgit v1.2.3 From 36a1b66c71543749cdf9276bb18f2e85b98a46e9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 4 May 2014 15:05:31 -0400 Subject: MADS: Fix for scene loading in teleporter scenes --- engines/mads/sprites.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 7bd8407c41..432a0e17df 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -258,8 +258,8 @@ void SpriteSlots::drawBackground() { if (spriteSlot._depth <= 1) { frame->copyTo(&scene._backgroundSurface, frame->getTransparencyIndex()); } else if (scene._depthStyle == 0) { - asset->depthDraw(&scene._backgroundSurface, &scene._depthSurface, spriteSlot._frameNumber, - pt, spriteSlot._depth); + scene._backgroundSurface.copyFrom(frame, pt, spriteSlot._depth, &scene._backgroundSurface, + 100, frame->getTransparencyIndex()); } else { error("Unsupported depth style"); } -- cgit v1.2.3 From b7dd01fdefd910c3c0f6291145ceab4060ae1a70 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 8 May 2014 11:43:23 +0300 Subject: MADS: Remove trailing whitespace --- engines/mads/sprites.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 432a0e17df..b0506fc40a 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -58,8 +58,8 @@ MSprite::MSprite(): MSurface() { } MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, - const Common::Rect &bounds): - MSurface(bounds.width(), bounds.height()), + const Common::Rect &bounds): + MSurface(bounds.width(), bounds.height()), _offset(Common::Point(bounds.left, bounds.top)) { // Load the sprite data loadSprite(source, palette); @@ -158,7 +158,7 @@ SpriteSlot::SpriteSlot(SpriteFlags type, int seqIndex) { bool SpriteSlot::operator==(const SpriteSlotSubset &other) const { return (_spritesIndex == other._spritesIndex) && (_frameNumber == other._frameNumber) && - (_position == other._position) && (_depth == other._depth) && + (_position == other._position) && (_depth == other._depth) && (_scale == other._scale); } @@ -324,7 +324,7 @@ void SpriteSlots::drawSprites(MSurface *s) { if ((slot._scale < 100) && (slot._scale != -1)) { // Minimalised drawing - s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, + s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, slot._scale, sprite->getTransparencyIndex()); } else { int xp, yp; @@ -339,7 +339,7 @@ void SpriteSlots::drawSprites(MSurface *s) { if (slot._depth > 1) { // Draw the frame with depth processing - s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface, + s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface, 100, sprite->getTransparencyIndex()); } else { // No depth, so simply draw the image -- cgit v1.2.3 From ea19581ae30bed434da8c9426c7b6defd702fc88 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 25 May 2014 13:23:05 -0400 Subject: MADS: Standardised on passing depth surfaces as DepthSurface --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index b0506fc40a..e4e57bd07b 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -258,7 +258,7 @@ void SpriteSlots::drawBackground() { if (spriteSlot._depth <= 1) { frame->copyTo(&scene._backgroundSurface, frame->getTransparencyIndex()); } else if (scene._depthStyle == 0) { - scene._backgroundSurface.copyFrom(frame, pt, spriteSlot._depth, &scene._backgroundSurface, + scene._backgroundSurface.copyFrom(frame, pt, spriteSlot._depth, &scene._depthSurface, 100, frame->getTransparencyIndex()); } else { error("Unsupported depth style"); -- cgit v1.2.3 From a01d502d2015b916b61a99ac0dcc0fcf1a289b78 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 25 May 2014 17:42:19 -0400 Subject: MADS: Fix drawing of background elements --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index e4e57bd07b..c98a0963f6 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -256,7 +256,7 @@ void SpriteSlots::drawBackground() { if (spriteSlot._depth <= 1) { - frame->copyTo(&scene._backgroundSurface, frame->getTransparencyIndex()); + frame->copyTo(&scene._backgroundSurface, pt, frame->getTransparencyIndex()); } else if (scene._depthStyle == 0) { scene._backgroundSurface.copyFrom(frame, pt, spriteSlot._depth, &scene._depthSurface, 100, frame->getTransparencyIndex()); -- cgit v1.2.3 From 9866aba2e43da914a17d17b695456ca25a875469 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 27 May 2014 00:58:25 +0200 Subject: MADS: Slight formatting fixes. --- engines/mads/sprites.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index c98a0963f6..89d610f2f1 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -54,13 +54,14 @@ typedef Common::List DepthList; /*------------------------------------------------------------------------*/ -MSprite::MSprite(): MSurface() { +MSprite::MSprite() + : MSurface() { } MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, - const Common::Rect &bounds): - MSurface(bounds.width(), bounds.height()), - _offset(Common::Point(bounds.left, bounds.top)) { + const Common::Rect &bounds) + : MSurface(bounds.width(), bounds.height()), + _offset(Common::Point(bounds.left, bounds.top)) { // Load the sprite data loadSprite(source, palette); } -- cgit v1.2.3 From d0f5184edd101e76dd9ad96a2e68c5cc69a662a7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 27 May 2014 00:58:25 +0200 Subject: MADS: minimise -> minimize --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 89d610f2f1..0dc83d1abc 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -324,7 +324,7 @@ void SpriteSlots::drawSprites(MSurface *s) { } if ((slot._scale < 100) && (slot._scale != -1)) { - // Minimalised drawing + // Minimalized drawing s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, slot._scale, sprite->getTransparencyIndex()); } else { -- cgit v1.2.3 From f8b08874c4819d85d493f42081a336326bff1035 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 28 May 2014 23:18:51 +0200 Subject: MADS: Janitorial - Trim trailing spaces and tabs --- engines/mads/sprites.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 0dc83d1abc..a229fccb89 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -60,7 +60,7 @@ MSprite::MSprite() MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, const Common::Rect &bounds) - : MSurface(bounds.width(), bounds.height()), + : MSurface(bounds.width(), bounds.height()), _offset(Common::Point(bounds.left, bounds.top)) { // Load the sprite data loadSprite(source, palette); -- cgit v1.2.3 From 7d24e1471c445fbf49b3efbb8d046eb26db849cd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 31 May 2014 18:21:11 -0400 Subject: MADS: Merge copyFromScaled into the existing copyFrom method --- engines/mads/sprites.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index a229fccb89..b7688ad417 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -324,7 +324,7 @@ void SpriteSlots::drawSprites(MSurface *s) { } if ((slot._scale < 100) && (slot._scale != -1)) { - // Minimalized drawing + // Scaled drawing s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, slot._scale, sprite->getTransparencyIndex()); } else { @@ -341,7 +341,7 @@ void SpriteSlots::drawSprites(MSurface *s) { if (slot._depth > 1) { // Draw the frame with depth processing s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface, - 100, sprite->getTransparencyIndex()); + -1, sprite->getTransparencyIndex()); } else { // No depth, so simply draw the image spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex()); -- cgit v1.2.3 From 8f20ebb610b9f6be0a4ef8d417318b3e6f0c965f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 31 May 2014 21:10:29 -0400 Subject: MADS: Fix positioning and clipping of flipped scaled images --- engines/mads/sprites.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index b7688ad417..4f5d50db4f 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -317,16 +317,10 @@ void SpriteSlots::drawSprites(MSurface *s) { assert(frameNumber > 0); MSprite *sprite = spriteSet.getFrame(frameNumber - 1); - MSurface *spr = sprite; - if (flipped) { - // Create a flipped copy of the sprite temporarily - spr = sprite->flipHorizontal(); - } - if ((slot._scale < 100) && (slot._scale != -1)) { // Scaled drawing - s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface, - slot._scale, sprite->getTransparencyIndex()); + s->copyFrom(sprite, slot._position, slot._depth, &scene._depthSurface, + slot._scale, flipped, sprite->getTransparencyIndex()); } else { int xp, yp; @@ -334,23 +328,29 @@ void SpriteSlots::drawSprites(MSurface *s) { xp = slot._position.x - scene._posAdjust.x; yp = slot._position.y - scene._posAdjust.y; } else { - xp = slot._position.x - (spr->w / 2) - scene._posAdjust.x; - yp = slot._position.y - spr->h - scene._posAdjust.y + 1; + xp = slot._position.x - (sprite->w / 2) - scene._posAdjust.x; + yp = slot._position.y - sprite->h - scene._posAdjust.y + 1; } if (slot._depth > 1) { // Draw the frame with depth processing - s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface, - -1, sprite->getTransparencyIndex()); + s->copyFrom(sprite, Common::Point(xp, yp), slot._depth, &scene._depthSurface, + -1, flipped, sprite->getTransparencyIndex()); } else { + MSurface *spr = sprite; + if (flipped) { + // Create a flipped copy of the sprite temporarily + spr = sprite->flipHorizontal(); + } + // No depth, so simply draw the image spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex()); + + // Free sprite if it was a flipped one + if (flipped) + delete spr; } } - - // Free sprite if it was a flipped one - if (flipped) - delete spr; } } -- cgit v1.2.3 From 7ab00631dd09fc9822b41b81fb53e06aeac0d5e4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 1 Jun 2014 09:10:49 -0400 Subject: MADS: Add enum for sprite asset loading flags --- engines/mads/sprites.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index 4f5d50db4f..acbb22077f 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -36,8 +36,6 @@ enum { kMarker = 2 }; -#define TRANSPARENT_COLOR_INDEX 0xFF - class DepthEntry { public: int depth; @@ -61,7 +59,7 @@ MSprite::MSprite() MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, const Common::Rect &bounds) : MSurface(bounds.width(), bounds.height()), - _offset(Common::Point(bounds.left, bounds.top)) { + _offset(Common::Point(bounds.left, bounds.top)), _transparencyIndex(0xFF) { // Load the sprite data loadSprite(source, palette); } @@ -123,16 +121,34 @@ void MSprite::loadSprite(Common::SeekableReadStream *source, } } + // Do a first post-sprite generation loop to find a pixel that the sprite + // will not use to designate as the transparency + bool colorUsed[PALETTE_COUNT]; + Common::fill(&colorUsed[0], &colorUsed[PALETTE_COUNT], false); + for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) { + if (*outp != transIndex) + colorUsed[palette[*outp]._palIndex] = true; + } + + _transparencyIndex = PALETTE_COUNT - 1; + while (_transparencyIndex >= 0 && colorUsed[_transparencyIndex]) + --_transparencyIndex; + assert(_transparencyIndex >= 0); + // Do a final iteration over the sprite to convert it's pixels to // the final positions in the main palette + spriteSize = this->w * this->h; for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) { - if (*outp != transIndex) + if (*outp != transIndex) { *outp = palette[*outp]._palIndex; + } else { + *outp = _transparencyIndex; + } } } byte MSprite::getTransparencyIndex() const { - return TRANSPARENT_COLOR_INDEX; + return _transparencyIndex; } /*------------------------------------------------------------------------*/ -- cgit v1.2.3 From f60ecc1f55e8567121add733f0c9b4935cd03aaf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 1 Jun 2014 16:18:17 -0400 Subject: MADS: Revert no longer needed sprite transparency index calculations --- engines/mads/sprites.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index acbb22077f..c67c905251 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -36,6 +36,8 @@ enum { kMarker = 2 }; +#define TRANSPARENT_COLOR_INDEX 0xFF + class DepthEntry { public: int depth; @@ -121,34 +123,17 @@ void MSprite::loadSprite(Common::SeekableReadStream *source, } } - // Do a first post-sprite generation loop to find a pixel that the sprite - // will not use to designate as the transparency - bool colorUsed[PALETTE_COUNT]; - Common::fill(&colorUsed[0], &colorUsed[PALETTE_COUNT], false); - for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) { - if (*outp != transIndex) - colorUsed[palette[*outp]._palIndex] = true; - } - - _transparencyIndex = PALETTE_COUNT - 1; - while (_transparencyIndex >= 0 && colorUsed[_transparencyIndex]) - --_transparencyIndex; - assert(_transparencyIndex >= 0); - // Do a final iteration over the sprite to convert it's pixels to // the final positions in the main palette spriteSize = this->w * this->h; for (outp = getData(); spriteSize > 0; --spriteSize, ++outp) { - if (*outp != transIndex) { + if (*outp != transIndex) *outp = palette[*outp]._palIndex; - } else { - *outp = _transparencyIndex; - } } } byte MSprite::getTransparencyIndex() const { - return _transparencyIndex; + return TRANSPARENT_COLOR_INDEX; } /*------------------------------------------------------------------------*/ -- cgit v1.2.3 From f086b64b7204203380cb7c006b5f9764949eeebd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 3 Jun 2014 20:56:03 -0400 Subject: MADS: Fix drawing of background objects --- engines/mads/sprites.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index c67c905251..f5c2792a70 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -253,15 +253,14 @@ void SpriteSlots::drawBackground() { if (spriteSlot._scale != -1) { // Adjust the drawing position pt.x -= frame->w / 2; - pt.y -= frame->h / 2; + pt.y -= frame->h - 1; } - if (spriteSlot._depth <= 1) { frame->copyTo(&scene._backgroundSurface, pt, frame->getTransparencyIndex()); } else if (scene._depthStyle == 0) { scene._backgroundSurface.copyFrom(frame, pt, spriteSlot._depth, &scene._depthSurface, - 100, frame->getTransparencyIndex()); + -1, false, frame->getTransparencyIndex()); } else { error("Unsupported depth style"); } -- cgit v1.2.3 From b404455eaf3fc5b88aaad4dac7190a9e5217c3ec Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 5 Jun 2014 07:48:03 +0200 Subject: MADS: remove a magic value, use _transparencyIndex --- engines/mads/sprites.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/mads/sprites.cpp') diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp index f5c2792a70..cd358077b5 100644 --- a/engines/mads/sprites.cpp +++ b/engines/mads/sprites.cpp @@ -54,14 +54,14 @@ typedef Common::List DepthList; /*------------------------------------------------------------------------*/ -MSprite::MSprite() - : MSurface() { +MSprite::MSprite() : MSurface() { + _transparencyIndex = TRANSPARENT_COLOR_INDEX; } MSprite::MSprite(Common::SeekableReadStream *source, const Common::Array &palette, const Common::Rect &bounds) : MSurface(bounds.width(), bounds.height()), - _offset(Common::Point(bounds.left, bounds.top)), _transparencyIndex(0xFF) { + _offset(Common::Point(bounds.left, bounds.top)), _transparencyIndex(TRANSPARENT_COLOR_INDEX) { // Load the sprite data loadSprite(source, palette); } @@ -133,7 +133,7 @@ void MSprite::loadSprite(Common::SeekableReadStream *source, } byte MSprite::getTransparencyIndex() const { - return TRANSPARENT_COLOR_INDEX; + return _transparencyIndex; } /*------------------------------------------------------------------------*/ -- cgit v1.2.3