[Scummvm-cvs-logs] scummvm master -> 7ab00631dd09fc9822b41b81fb53e06aeac0d5e4

dreammaster dreammaster at scummvm.org
Sun Jun 1 15:11:28 CEST 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7ab00631dd MADS: Add enum for sprite asset loading flags


Commit: 7ab00631dd09fc9822b41b81fb53e06aeac0d5e4
    https://github.com/scummvm/scummvm/commit/7ab00631dd09fc9822b41b81fb53e06aeac0d5e4
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2014-06-01T09:10:49-04:00

Commit Message:
MADS: Add enum for sprite asset loading flags

Changed paths:
    engines/mads/assets.cpp
    engines/mads/assets.h
    engines/mads/sprites.cpp
    engines/mads/sprites.h
    engines/mads/user_interface.cpp



diff --git a/engines/mads/assets.cpp b/engines/mads/assets.cpp
index 0bbf617..82585d5 100644
--- a/engines/mads/assets.cpp
+++ b/engines/mads/assets.cpp
@@ -76,7 +76,7 @@ void SpriteAsset::load(Common::SeekableReadStream *stream, int flags) {
 	spriteStream->skip(32);
 	_frameCount = spriteStream->readUint16LE();
 
-	if ((flags & SPRITE_SET_CHAR_INFO) == 0)
+	if ((flags & ASSET_CHAR_INFO) == 0)
 		_charInfo = nullptr;
 	else
 		_charInfo = new SpriteSetCharInfo(spriteStream);
@@ -98,7 +98,7 @@ void SpriteAsset::load(Common::SeekableReadStream *stream, int flags) {
 	delete palStream;
 
 	// Process the palette data
-	if (flags & 9) {
+	if (flags & (ASSET_TRANSLATE | ASSET_SPINNING_OBJECT)) {
 		_usageIndex = 0;
 
 		if (flags & 8) {
diff --git a/engines/mads/assets.h b/engines/mads/assets.h
index 9242802..155590f 100644
--- a/engines/mads/assets.h
+++ b/engines/mads/assets.h
@@ -29,7 +29,10 @@
 
 namespace MADS {
 
-#define SPRITE_SET_CHAR_INFO 4
+enum AssetFlags {
+	ASSET_TRANSLATE = 1, ASSET_HEADER_ONLY = 2, ASSET_CHAR_INFO = 4,
+	ASSET_SPINNING_OBJECT = 8
+};
 
 class MADSEngine;
 class MSprite;
diff --git a/engines/mads/sprites.cpp b/engines/mads/sprites.cpp
index 4f5d50d..acbb220 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<RGB6> &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;
 }
 
 /*------------------------------------------------------------------------*/
diff --git a/engines/mads/sprites.h b/engines/mads/sprites.h
index 324122e..6ea3c9e 100644
--- a/engines/mads/sprites.h
+++ b/engines/mads/sprites.h
@@ -117,6 +117,7 @@ public:
 	virtual ~MSprite();
 
 	Common::Point _offset;
+	int _transparencyIndex;
 
 	byte getTransparencyIndex() const;
 };
diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp
index e410d17..7392d53 100644
--- a/engines/mads/user_interface.cpp
+++ b/engines/mads/user_interface.cpp
@@ -845,7 +845,7 @@ void UserInterface::loadInventoryAnim(int objectId) {
 
 	if (_vm->_invObjectsAnimated) {
 		Common::String resName = Common::String::format("*OB%.3dI", objectId);
-		SpriteAsset *asset = new SpriteAsset(_vm, resName, 8);
+		SpriteAsset *asset = new SpriteAsset(_vm, resName, ASSET_SPINNING_OBJECT);
 		_invSpritesIndex = scene._sprites.add(asset, 1);
 		if (_invSpritesIndex >= 0) {
 			_invFrameNumber = 1;






More information about the Scummvm-git-logs mailing list