[Scummvm-cvs-logs] scummvm master -> b58f6f397da29454e359384f6908b403f48d990e

dreammaster dreammaster at scummvm.org
Tue Oct 14 02:29:35 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:
b58f6f397d MADS: New conversation message logic for cutscene animations


Commit: b58f6f397da29454e359384f6908b403f48d990e
    https://github.com/scummvm/scummvm/commit/b58f6f397da29454e359384f6908b403f48d990e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2014-10-13T20:28:34-04:00

Commit Message:
MADS: New conversation message logic for cutscene animations

Changed paths:
    engines/mads/animation.cpp
    engines/mads/animation.h
    engines/mads/nebular/menu_nebular.cpp
    engines/mads/palette.cpp
    engines/mads/palette.h



diff --git a/engines/mads/animation.cpp b/engines/mads/animation.cpp
index 0807d8e..bc3708b 100644
--- a/engines/mads/animation.cpp
+++ b/engines/mads/animation.cpp
@@ -159,6 +159,7 @@ Animation *Animation::init(MADSEngine *vm, Scene *scene) {
 }
 
 Animation::Animation(MADSEngine *vm, Scene *scene) : _vm(vm), _scene(scene) {
+	_flags = 0;
 	_font = nullptr;
 	_resetFlag = false;
 	_messageCtr = 0;
@@ -174,6 +175,8 @@ Animation::Animation(MADSEngine *vm, Scene *scene) : _vm(vm), _scene(scene) {
 	_actionDetails._indirectObjectId = -1;
 	_currentFrame = 0;
 	_oldFrameEntry = 0;
+	_rgbResult = -1;
+	_palIndex1 = _palIndex2 = -1;
 }
 
 Animation::~Animation() {
@@ -204,6 +207,7 @@ void Animation::load(MSurface &backSurface, DepthSurface &depthSurface,
 
 	if (_header._bgType == ANIMBG_INTERFACE)
 		flags |= PALFLAG_RESERVED;
+	_flags = flags;
 
 	if (flags & ANIMFLAG_LOAD_BACKGROUND) {
 		loadBackground(backSurface, depthSurface, _header, flags, palCycles, sceneInfo);
@@ -414,6 +418,7 @@ bool Animation::hasScroll() const {
 
 void Animation::update() {
 	Scene &scene = _vm->_game->_scene;
+	Palette &palette = *_vm->_palette;
 
 	if (_header._manualFlag) {
 		int spriteListIndex = _spriteListIndexes[_header._spritesIndex];
@@ -532,26 +537,42 @@ void Animation::update() {
 		} else if ((_currentFrame >= _messages[idx]._startFrame) && (_currentFrame <= _messages[idx]._endFrame)) {
 			// Start displaying the message
 			AnimMessage &me = _messages[idx];
+			uint8 colIndex1, colIndex2;
+
+			if (_flags & ANIMFLAG_ANIMVIEW) {
+				_rgbResult = palette._paletteUsage.checkRGB(me._rgb1, -1, true, &_palIndex1);
+				_rgbResult = palette._paletteUsage.checkRGB(me._rgb2, _rgbResult, true, &_palIndex2);
+
+				// Update the palette with the two needed colors
+				int palCount = _palIndex2 - _palIndex1;
+				if (palCount < 0)
+					palCount = _palIndex1 - _palIndex2 + 1;
+				palette.setPalette(palette._mainPalette, MIN(_palIndex1, _palIndex2), palCount);
+
+				colIndex1 = _palIndex1;
+				colIndex2 = _palIndex2;
+			} else {
+				// The color index to use is dependant on how many messages are currently on-screen
+				switch (_messageCtr) {
+				case 1:
+					colIndex1 = 252;
+					break;
+				case 2:
+					colIndex1 = 16;
+					break;
+				default:
+					colIndex1 = 250;
+					break;
+				}
+				colIndex2 = colIndex1 + 1;
 
-			// The color index to use is dependant on how many messages are currently on-screen
-			uint8 colIndex;
-			switch (_messageCtr) {
-			case 1:
-				colIndex = 252;
-				break;
-			case 2:
-				colIndex = 16;
-				break;
-			default:
-				colIndex = 250;
-				break;
+				_vm->_palette->setEntry(colIndex1, me._rgb1[0], me._rgb1[1], me._rgb1[2]);
+				_vm->_palette->setEntry(colIndex2, me._rgb2[0], me._rgb2[1], me._rgb2[2]);
 			}
 
-			_vm->_palette->setEntry(colIndex, me._rgb1[0], me._rgb1[1], me._rgb1[2]);
-			_vm->_palette->setEntry(colIndex + 1, me._rgb2[0], me._rgb2[1], me._rgb2[2]);
-
 			// Add a kernel message to display the given text
-			me._kernelMsgIndex = scene._kernelMessages.add(me._pos, colIndex * 0x101 + 0x100,
+			me._kernelMsgIndex = scene._kernelMessages.add(me._pos,
+				colIndex1 | (colIndex2 << 8),
 				0, 0, INDEFINITE_TIMEOUT, me._msg);
 			assert(me._kernelMsgIndex >= 0);
 			++_messageCtr;
diff --git a/engines/mads/animation.h b/engines/mads/animation.h
index 917d899..b7e98e7 100644
--- a/engines/mads/animation.h
+++ b/engines/mads/animation.h
@@ -37,7 +37,8 @@ enum AnimFlag {
 	ANIMFLAG_DITHER				= 0x1000,	// Dither to 16 colors
 	ANIMFLAG_CUSTOM_FONT		= 0x2000,	// Load ccustom font
 	ANIMFLAG_LOAD_BACKGROUND	= 0x0100,	// Load background
-	ANIMFLAG_LOAD_BACKGROUND_ONLY = 0x0200	// Load background only
+	ANIMFLAG_LOAD_BACKGROUND_ONLY = 0x0200,	// Load background only
+	ANIMFLAG_ANIMVIEW			= 0x8000	// Cutscene animation
 };
 
 enum AnimBgType {
@@ -155,6 +156,9 @@ private:
 	uint32 _nextScrollTimer;
 	int _messageCtr;
 	int _trigger;
+	int _flags;
+	int _rgbResult;
+	int _palIndex1, _palIndex2;
 	TriggerMode _triggerMode;
 	ActionDetails _actionDetails;
 
diff --git a/engines/mads/nebular/menu_nebular.cpp b/engines/mads/nebular/menu_nebular.cpp
index 3919e70..0d7b11c 100644
--- a/engines/mads/nebular/menu_nebular.cpp
+++ b/engines/mads/nebular/menu_nebular.cpp
@@ -890,9 +890,9 @@ void AnimationView::loadNextResource() {
 	// Load the new animation
 	delete _currentAnimation;
 	_currentAnimation = Animation::init(_vm, &scene);
+	int flags = ANIMFLAG_ANIMVIEW | (resEntry._bgFlag ? ANIMFLAG_LOAD_BACKGROUND : 0);
 	_currentAnimation->load(scene._backgroundSurface, scene._depthSurface, 
-		resEntry._resourceName, resEntry._bgFlag ? ANIMFLAG_LOAD_BACKGROUND : 0,
-		&paletteCycles, _sceneInfo);
+		resEntry._resourceName, flags, &paletteCycles, _sceneInfo);
 
 	// Signal for a screen refresh
 	scene._spriteSlots.fullRefresh();
diff --git a/engines/mads/palette.cpp b/engines/mads/palette.cpp
index c098e23..1787b3c 100644
--- a/engines/mads/palette.cpp
+++ b/engines/mads/palette.cpp
@@ -317,6 +317,62 @@ int PaletteUsage::rgbFactor(byte *palEntry, RGB6 &pal6) {
 	return total;
 }
 
+int PaletteUsage::checkRGB(const byte *rgb, int palStart, bool flag, int *palIndex) {
+	Palette &palette = *_vm->_palette;
+	bool match = false;
+	int result;
+	if (palStart >= 0) {
+		result = palStart;
+	} else {
+		result = -1;
+		for (int i = 0; i < palette._highRange; ++i) {
+			if (!palette._rgbList[i]) {
+				result = i;
+				break;
+			}
+		}
+	}
+
+	if (result >= 0) {
+		int mask = 1 << result;
+		byte *palP = &palette._mainPalette[0];
+		uint32 *flagsP = &palette._palFlags[0];
+
+		for (; flagsP < &palette._palFlags[PALETTE_COUNT]; ++flagsP, ++result) {
+			if ((!(*flagsP & 1) || flag) && !(*flagsP & 2)) {
+				if (!memcmp(palP, rgb, 3)) {
+					*flagsP |= mask;
+					
+					if (palIndex)
+						*palIndex = result;
+					match = true;
+					break;
+				}
+			}
+		}
+
+		if (!match) {
+			palP = &palette._mainPalette[0];
+			flagsP = &palette._palFlags[0];
+
+			for (int i = 0; i < PALETTE_COUNT; ++i, palP += 3, ++flagsP) {
+				if (!*flagsP) {
+					Common::copy(rgb, rgb + 3, palP);
+					*flagsP |= mask;
+
+					if (palIndex)
+						*palIndex = i;
+					match = true;
+					break;
+				}
+			}
+		}
+	}
+
+	assert(match);
+	return result;
+}
+
 /*------------------------------------------------------------------------*/
 
 void RGBList::clear() {
diff --git a/engines/mads/palette.h b/engines/mads/palette.h
index 9b8b714..27d25f2 100644
--- a/engines/mads/palette.h
+++ b/engines/mads/palette.h
@@ -136,6 +136,8 @@ public:
 	void updateUsage(Common::Array<int> &usageList, int sceneUsageIndex);
 
 	void resetPalFlags(int idx);
+
+	int checkRGB(const byte *rgb, int palStart, bool flag, int *palIndex);
 };
 
 class RGBList {






More information about the Scummvm-git-logs mailing list