[Scummvm-cvs-logs] scummvm master -> 1f6bfda0ef5556118892e45bc922ba3fdb64047a

bgK bastien.bouclet at gmail.com
Thu Feb 11 07:58:50 CET 2016


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:
1f6bfda0ef MOHAWK: Share the code for reading sound blocks


Commit: 1f6bfda0ef5556118892e45bc922ba3fdb64047a
    https://github.com/scummvm/scummvm/commit/1f6bfda0ef5556118892e45bc922ba3fdb64047a
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2016-02-11T07:56:58+01:00

Commit Message:
MOHAWK: Share the code for reading sound blocks

Changed paths:
    engines/mohawk/myst.cpp
    engines/mohawk/myst.h
    engines/mohawk/myst_scripts.cpp



diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index d4ac513..787030c 100644
--- a/engines/mohawk/myst.cpp
+++ b/engines/mohawk/myst.cpp
@@ -682,47 +682,7 @@ void MohawkEngine_Myst::loadCard() {
 	}
 
 	// The Sound Block (Reminiscent of Riven SLST resources)
-	MystSoundBlock soundBlock;
-	soundBlock.sound = viewStream->readSint16LE();
-	debugCN(kDebugView, "Sound Control: %d = ", soundBlock.sound);
-	if (soundBlock.sound > 0) {
-		debugC(kDebugView, "Play new Sound, change volume");
-		debugC(kDebugView, "\tSound: %d", soundBlock.sound);
-		soundBlock.soundVolume = viewStream->readUint16LE();
-		debugC(kDebugView, "\tVolume: %d", soundBlock.soundVolume);
-	} else if (soundBlock.sound == kMystSoundActionContinue)
-		debugC(kDebugView, "Continue current sound");
-	else if (soundBlock.sound == kMystSoundActionChangeVolume) {
-		debugC(kDebugView, "Continue current sound, change volume");
-		soundBlock.soundVolume = viewStream->readUint16LE();
-		debugC(kDebugView, "\tVolume: %d", soundBlock.soundVolume);
-	} else if (soundBlock.sound == kMystSoundActionStop) {
-		debugC(kDebugView, "Stop sound");
-	} else if (soundBlock.sound == kMystSoundActionConditional) {
-		debugC(kDebugView, "Conditional sound list");
-		soundBlock.soundVar = viewStream->readUint16LE();
-		debugC(kDebugView, "\tVar: %d", soundBlock.soundVar);
-		uint16 soundCount = viewStream->readUint16LE();
-		debugC(kDebugView, "\tCount: %d", soundCount);
-
-		for (uint16 i = 0; i < soundCount; i++) {
-			MystSoundBlock::SoundItem sound;
-
-			sound.action = viewStream->readSint16LE();
-			debugC(kDebugView, "\t\tCondition %d: Action %d", i, sound.action);
-			if (sound.action == kMystSoundActionChangeVolume || sound.action >= 0) {
-				sound.volume = viewStream->readUint16LE();
-				debugC(kDebugView, "\t\tCondition %d: Volume %d", i, sound.volume);
-			}
-
-			soundBlock.soundList.push_back(sound);
-		}
-	} else {
-		debugC(kDebugView, "Unknown");
-		warning("Unknown sound control value '%d' in card '%d'", soundBlock.sound, _curCard);
-	}
-
-	_view.soundBlock = soundBlock;
+	_view.soundBlock = readSoundBlock(viewStream);
 
 	// Resources that scripts can call upon
 	uint16 scriptResCount = viewStream->readUint16LE();
@@ -1174,6 +1134,51 @@ void MohawkEngine_Myst::dropPage() {
 	checkCursorHints();
 }
 
+MystSoundBlock MohawkEngine_Myst::readSoundBlock(Common::ReadStream *stream) const {
+	MystSoundBlock soundBlock;
+	soundBlock.sound = stream->readSint16LE();
+	debugCN(kDebugView, "Sound Control: %d = ", soundBlock.sound);
+
+	if (soundBlock.sound > 0) {
+		debugC(kDebugView, "Play new Sound, change volume");
+		debugC(kDebugView, "\tSound: %d", soundBlock.sound);
+		soundBlock.soundVolume = stream->readUint16LE();
+		debugC(kDebugView, "\tVolume: %d", soundBlock.soundVolume);
+	} else if (soundBlock.sound == kMystSoundActionContinue)
+		debugC(kDebugView, "Continue current sound");
+	else if (soundBlock.sound == kMystSoundActionChangeVolume) {
+		debugC(kDebugView, "Continue current sound, change volume");
+		soundBlock.soundVolume = stream->readUint16LE();
+		debugC(kDebugView, "\tVolume: %d", soundBlock.soundVolume);
+	} else if (soundBlock.sound == kMystSoundActionStop) {
+		debugC(kDebugView, "Stop sound");
+	} else if (soundBlock.sound == kMystSoundActionConditional) {
+		debugC(kDebugView, "Conditional sound list");
+		soundBlock.soundVar = stream->readUint16LE();
+		debugC(kDebugView, "\tVar: %d", soundBlock.soundVar);
+		uint16 soundCount = stream->readUint16LE();
+		debugC(kDebugView, "\tCount: %d", soundCount);
+
+		for (uint16 i = 0; i < soundCount; i++) {
+			MystSoundBlock::SoundItem sound;
+
+			sound.action = stream->readSint16LE();
+			debugC(kDebugView, "\t\tCondition %d: Action %d", i, sound.action);
+			if (sound.action == kMystSoundActionChangeVolume || sound.action >= 0) {
+				sound.volume = stream->readUint16LE();
+				debugC(kDebugView, "\t\tCondition %d: Volume %d", i, sound.volume);
+			}
+
+			soundBlock.soundList.push_back(sound);
+		}
+	} else {
+		debugC(kDebugView, "Unknown");
+		warning("Unknown sound control value '%d' in card '%d'", soundBlock.sound, _curCard);
+	}
+
+	return soundBlock;
+}
+
 void MohawkEngine_Myst::applySoundBlock(const MystSoundBlock &block) {
 	int16 soundAction = 0;
 	uint16 soundActionVolume = 0;
diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h
index 59ec45c..6e661b6 100644
--- a/engines/mohawk/myst.h
+++ b/engines/mohawk/myst.h
@@ -186,6 +186,8 @@ public:
 	void checkCursorHints();
 	MystArea *updateCurrentResource();
 	bool skippableWait(uint32 duration);
+
+	MystSoundBlock readSoundBlock(Common::ReadStream *stream) const;
 	void applySoundBlock(const MystSoundBlock &block);
 
 	bool _tweaksEnabled;
diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp
index 74ff895..027a7fb 100644
--- a/engines/mohawk/myst_scripts.cpp
+++ b/engines/mohawk/myst_scripts.cpp
@@ -29,6 +29,7 @@
 #include "mohawk/video.h"
 
 #include "common/system.h"
+#include "common/memstream.h"
 #include "common/textconsole.h"
 #include "gui/message.h"
 
@@ -679,44 +680,13 @@ void MystScriptParser::o_copyImageToBackBuffer(uint16 op, uint16 var, uint16 arg
 //       by Channelwood Card 3280 (Tank Valve) and water flow sound behavior in pipe
 //       on cards leading from shed...
 void MystScriptParser::o_changeBackgroundSound(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
-
 	// Used on Stoneship Card 2080
 	// Used on Channelwood Card 3225 with argc = 8 i.e. Conditional Sound List
 	debugC(kDebugScript, "Opcode %d: Process Sound Block", op);
 
-	uint16 decodeIdx = 0;
-
-	MystSoundBlock soundBlock;
-	soundBlock.sound = argv[decodeIdx++];
-	soundBlock.soundVolume = 65535;
-
-	if (soundBlock.sound == kMystSoundActionChangeVolume || soundBlock.sound > 0) {
-		soundBlock.soundVolume = argv[decodeIdx++];
-	} else if (soundBlock.sound == kMystSoundActionConditional) {
-		debugC(kDebugScript, "Conditional sound list");
-		soundBlock.soundVar = argv[decodeIdx++];
-
-		uint16 condCount = argv[decodeIdx++];
-		debugC(kDebugScript, "\tcondCount: %d", condCount);
-		for (uint16 i = 0; i < condCount; i++) {
-			MystSoundBlock::SoundItem item;
-
-			item.action = argv[decodeIdx++];
-			debugC(kDebugScript, "\t\tCondition %d: Action %d", i, item.action);
-
-			if (item.action == kMystSoundActionChangeVolume || item.action > 0) {
-				item.volume = argv[decodeIdx++];
-			} else
-				item.volume = 65535;
-			debugC(kDebugScript, "\t\tCondition %d: Volume %d", i, item.volume);
-
-			soundBlock.soundList.push_back(item);
-		}
-	} else {
-		debugC(kDebugScript, "Unknown");
-		warning("Unknown sound control value in opcode %d", op);
-	}
+	Common::MemoryReadStream stream = Common::MemoryReadStream((const byte *) argv, argc * sizeof(uint16));
 
+	MystSoundBlock soundBlock = _vm->readSoundBlock(&stream);
 	_vm->applySoundBlock(soundBlock);
 }
 






More information about the Scummvm-git-logs mailing list