aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2016-02-11 07:56:58 +0100
committerBastien Bouclet2016-02-11 07:56:58 +0100
commit1f6bfda0ef5556118892e45bc922ba3fdb64047a (patch)
tree695fc0c955db5881dd0c466774f80d6fca37e7fc
parent19ee63703b2c5f1636344ea58121d4e1e7bb7167 (diff)
downloadscummvm-rg350-1f6bfda0ef5556118892e45bc922ba3fdb64047a.tar.gz
scummvm-rg350-1f6bfda0ef5556118892e45bc922ba3fdb64047a.tar.bz2
scummvm-rg350-1f6bfda0ef5556118892e45bc922ba3fdb64047a.zip
MOHAWK: Share the code for reading sound blocks
-rw-r--r--engines/mohawk/myst.cpp87
-rw-r--r--engines/mohawk/myst.h2
-rw-r--r--engines/mohawk/myst_scripts.cpp36
3 files changed, 51 insertions, 74 deletions
diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp
index d4ac513a24..787030c37c 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 59ec45c488..6e661b6580 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 74ff895839..027a7fbf6c 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);
}