mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-02 17:03:13 +00:00
MOHAWK: Share the code applying sound blocks
This commit is contained in:
parent
e9525f53c6
commit
19ee63703b
@ -560,36 +560,7 @@ void MohawkEngine_Myst::changeToCard(uint16 card, TransitionType transition) {
|
||||
drawCardBackground();
|
||||
|
||||
// Handle sound
|
||||
int16 soundAction = 0;
|
||||
uint16 soundActionVolume = 0;
|
||||
|
||||
if (_view.sound == kMystSoundActionConditional) {
|
||||
uint16 soundVarValue = _scriptParser->getVar(_view.soundVar);
|
||||
if (soundVarValue >= _view.soundList.size())
|
||||
warning("Conditional sound variable outside range");
|
||||
else {
|
||||
soundAction = _view.soundList[soundVarValue].action;
|
||||
soundActionVolume = _view.soundList[soundVarValue].volume;
|
||||
}
|
||||
} else {
|
||||
soundAction = _view.sound;
|
||||
soundActionVolume = _view.soundVolume;
|
||||
}
|
||||
|
||||
if (soundAction == kMystSoundActionContinue)
|
||||
debug(2, "Continuing with current sound");
|
||||
else if (soundAction == kMystSoundActionChangeVolume) {
|
||||
debug(2, "Continuing with current sound, changing volume");
|
||||
_sound->changeBackgroundVolumeMyst(soundActionVolume);
|
||||
} else if (soundAction == kMystSoundActionStop) {
|
||||
debug(2, "Stopping sound");
|
||||
_sound->stopBackgroundMyst();
|
||||
} else if (soundAction > 0) {
|
||||
debug(2, "Playing new sound %d", soundAction);
|
||||
_sound->replaceBackgroundMyst(soundAction, soundActionVolume);
|
||||
} else {
|
||||
error("Unknown sound action %d", soundAction);
|
||||
}
|
||||
applySoundBlock(_view.soundBlock);
|
||||
|
||||
if (_view.flags & kMystZipDestination)
|
||||
_gameState->addZipDest(_curStack, card);
|
||||
@ -711,30 +682,31 @@ void MohawkEngine_Myst::loadCard() {
|
||||
}
|
||||
|
||||
// The Sound Block (Reminiscent of Riven SLST resources)
|
||||
_view.sound = viewStream->readSint16LE();
|
||||
debugCN(kDebugView, "Sound Control: %d = ", _view.sound);
|
||||
if (_view.sound > 0) {
|
||||
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", _view.sound);
|
||||
_view.soundVolume = viewStream->readUint16LE();
|
||||
debugC(kDebugView, "\tVolume: %d", _view.soundVolume);
|
||||
} else if (_view.sound == kMystSoundActionContinue)
|
||||
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 (_view.sound == kMystSoundActionChangeVolume) {
|
||||
else if (soundBlock.sound == kMystSoundActionChangeVolume) {
|
||||
debugC(kDebugView, "Continue current sound, change volume");
|
||||
_view.soundVolume = viewStream->readUint16LE();
|
||||
debugC(kDebugView, "\tVolume: %d", _view.soundVolume);
|
||||
} else if (_view.sound == kMystSoundActionStop) {
|
||||
soundBlock.soundVolume = viewStream->readUint16LE();
|
||||
debugC(kDebugView, "\tVolume: %d", soundBlock.soundVolume);
|
||||
} else if (soundBlock.sound == kMystSoundActionStop) {
|
||||
debugC(kDebugView, "Stop sound");
|
||||
} else if (_view.sound == kMystSoundActionConditional) {
|
||||
} else if (soundBlock.sound == kMystSoundActionConditional) {
|
||||
debugC(kDebugView, "Conditional sound list");
|
||||
_view.soundVar = viewStream->readUint16LE();
|
||||
debugC(kDebugView, "\tVar: %d", _view.soundVar);
|
||||
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++) {
|
||||
MystSoundItem sound;
|
||||
MystSoundBlock::SoundItem sound;
|
||||
|
||||
sound.action = viewStream->readSint16LE();
|
||||
debugC(kDebugView, "\t\tCondition %d: Action %d", i, sound.action);
|
||||
@ -743,13 +715,15 @@ void MohawkEngine_Myst::loadCard() {
|
||||
debugC(kDebugView, "\t\tCondition %d: Volume %d", i, sound.volume);
|
||||
}
|
||||
|
||||
_view.soundList.push_back(sound);
|
||||
soundBlock.soundList.push_back(sound);
|
||||
}
|
||||
} else {
|
||||
debugC(kDebugView, "Unknown");
|
||||
warning("Unknown sound control value '%d' in card '%d'", _view.sound, _curCard);
|
||||
warning("Unknown sound control value '%d' in card '%d'", soundBlock.sound, _curCard);
|
||||
}
|
||||
|
||||
_view.soundBlock = soundBlock;
|
||||
|
||||
// Resources that scripts can call upon
|
||||
uint16 scriptResCount = viewStream->readUint16LE();
|
||||
debugC(kDebugView, "Script Resource Count: %d", scriptResCount);
|
||||
@ -831,12 +805,12 @@ void MohawkEngine_Myst::loadCard() {
|
||||
}
|
||||
|
||||
// Precache Sound Block data
|
||||
if (_view.sound > 0)
|
||||
cachePreload(ID_MSND, _view.sound);
|
||||
else if (_view.sound == kMystSoundActionConditional) {
|
||||
uint16 value = _scriptParser->getVar(_view.soundVar);
|
||||
if (_view.soundList[value].action > 0) {
|
||||
cachePreload(ID_MSND, _view.soundList[value].action);
|
||||
if (_view.soundBlock.sound > 0)
|
||||
cachePreload(ID_MSND, _view.soundBlock.sound);
|
||||
else if (_view.soundBlock.sound == kMystSoundActionConditional) {
|
||||
uint16 value = _scriptParser->getVar(_view.soundBlock.soundVar);
|
||||
if (_view.soundBlock.soundList[value].action > 0) {
|
||||
cachePreload(ID_MSND, _view.soundBlock.soundList[value].action);
|
||||
}
|
||||
}
|
||||
|
||||
@ -871,7 +845,7 @@ void MohawkEngine_Myst::loadCard() {
|
||||
|
||||
void MohawkEngine_Myst::unloadCard() {
|
||||
_view.conditionalImages.clear();
|
||||
_view.soundList.clear();
|
||||
_view.soundBlock.soundList.clear();
|
||||
_view.scriptResources.clear();
|
||||
}
|
||||
|
||||
@ -1200,4 +1174,37 @@ void MohawkEngine_Myst::dropPage() {
|
||||
checkCursorHints();
|
||||
}
|
||||
|
||||
void MohawkEngine_Myst::applySoundBlock(const MystSoundBlock &block) {
|
||||
int16 soundAction = 0;
|
||||
uint16 soundActionVolume = 0;
|
||||
|
||||
if (block.sound == kMystSoundActionConditional) {
|
||||
uint16 soundVarValue = _scriptParser->getVar(block.soundVar);
|
||||
if (soundVarValue >= block.soundList.size())
|
||||
warning("Conditional sound variable outside range");
|
||||
else {
|
||||
soundAction = block.soundList[soundVarValue].action;
|
||||
soundActionVolume = block.soundList[soundVarValue].volume;
|
||||
}
|
||||
} else {
|
||||
soundAction = block.sound;
|
||||
soundActionVolume = block.soundVolume;
|
||||
}
|
||||
|
||||
if (soundAction == kMystSoundActionContinue)
|
||||
debug(2, "Continuing with current sound");
|
||||
else if (soundAction == kMystSoundActionChangeVolume) {
|
||||
debug(2, "Continuing with current sound, changing volume");
|
||||
_sound->changeBackgroundVolumeMyst(soundActionVolume);
|
||||
} else if (soundAction == kMystSoundActionStop) {
|
||||
debug(2, "Stopping sound");
|
||||
_sound->stopBackgroundMyst();
|
||||
} else if (soundAction > 0) {
|
||||
debug(2, "Playing new sound %d", soundAction);
|
||||
_sound->replaceBackgroundMyst(soundAction, soundActionVolume);
|
||||
} else {
|
||||
error("Unknown sound action %d", soundAction);
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Mohawk
|
||||
|
@ -97,9 +97,16 @@ struct MystCondition {
|
||||
Common::Array<uint16> values;
|
||||
};
|
||||
|
||||
struct MystSoundItem {
|
||||
int16 action;
|
||||
uint16 volume;
|
||||
struct MystSoundBlock {
|
||||
struct SoundItem {
|
||||
int16 action;
|
||||
uint16 volume;
|
||||
};
|
||||
|
||||
int16 sound;
|
||||
uint16 soundVolume;
|
||||
uint16 soundVar;
|
||||
Common::Array<SoundItem> soundList;
|
||||
};
|
||||
|
||||
// View Sound Action Type
|
||||
@ -124,10 +131,7 @@ struct MystView {
|
||||
uint16 mainImage;
|
||||
|
||||
// Sound Data
|
||||
int16 sound;
|
||||
uint16 soundVolume;
|
||||
uint16 soundVar;
|
||||
Common::Array<MystSoundItem> soundList;
|
||||
MystSoundBlock soundBlock;
|
||||
|
||||
// Script Resources
|
||||
enum ScriptResourceType {
|
||||
@ -182,6 +186,7 @@ public:
|
||||
void checkCursorHints();
|
||||
MystArea *updateCurrentResource();
|
||||
bool skippableWait(uint32 duration);
|
||||
void applySoundBlock(const MystSoundBlock &block);
|
||||
|
||||
bool _tweaksEnabled;
|
||||
bool _needsUpdate;
|
||||
|
@ -673,82 +673,51 @@ void MystScriptParser::o_copyImageToBackBuffer(uint16 op, uint16 var, uint16 arg
|
||||
_vm->_gfx->copyImageSectionToBackBuffer(imageId, srcRect, dstRect);
|
||||
}
|
||||
|
||||
// TODO: Implement common engine function for read and processing of sound blocks
|
||||
// for use by this opcode and VIEW sound block.
|
||||
// TODO: Though the playSound and PlaySoundBlocking opcodes play sounds immediately,
|
||||
// this opcode changes the main background sound playing..
|
||||
// Current behavior here and with VIEW sound block is not right as demonstrated
|
||||
// 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) {
|
||||
int16 *soundList = nullptr;
|
||||
uint16 *soundListVolume = nullptr;
|
||||
|
||||
// Used on Stoneship Card 2080
|
||||
// Used on Channelwood Card 3225 with argc = 8 i.e. Conditional Sound List
|
||||
if (argc == 1 || argc == 2 || argc == 8) {
|
||||
debugC(kDebugScript, "Opcode %d: Process Sound Block", op);
|
||||
uint16 decodeIdx = 0;
|
||||
debugC(kDebugScript, "Opcode %d: Process Sound Block", op);
|
||||
|
||||
int16 soundAction = argv[decodeIdx++];
|
||||
uint16 soundVolume = 65535;
|
||||
if (soundAction == kMystSoundActionChangeVolume || soundAction > 0) {
|
||||
soundVolume = argv[decodeIdx++];
|
||||
} else if (soundAction == kMystSoundActionConditional) {
|
||||
debugC(kDebugScript, "Conditional sound list");
|
||||
uint16 condVar = argv[decodeIdx++];
|
||||
uint16 condVarValue = getVar(condVar);
|
||||
uint16 condCount = argv[decodeIdx++];
|
||||
uint16 decodeIdx = 0;
|
||||
|
||||
debugC(kDebugScript, "\tcondVar: %d = %d", condVar, condVarValue);
|
||||
debugC(kDebugScript, "\tcondCount: %d", condCount);
|
||||
MystSoundBlock soundBlock;
|
||||
soundBlock.sound = argv[decodeIdx++];
|
||||
soundBlock.soundVolume = 65535;
|
||||
|
||||
soundList = new int16[condCount];
|
||||
soundListVolume = new uint16[condCount];
|
||||
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++];
|
||||
|
||||
if (condVarValue >= condCount)
|
||||
warning("Opcode %d: Conditional sound variable outside range", op);
|
||||
else {
|
||||
for (uint16 i = 0; i < condCount; i++) {
|
||||
soundList[i] = argv[decodeIdx++];
|
||||
debugC(kDebugScript, "\t\tCondition %d: Action %d", i, soundList[i]);
|
||||
if (soundList[i] == kMystSoundActionChangeVolume || soundList[i] > 0) {
|
||||
soundListVolume[i] = argv[decodeIdx++];
|
||||
} else
|
||||
soundListVolume[i] = 65535;
|
||||
debugC(kDebugScript, "\t\tCondition %d: Volume %d", i, soundListVolume[i]);
|
||||
}
|
||||
uint16 condCount = argv[decodeIdx++];
|
||||
debugC(kDebugScript, "\tcondCount: %d", condCount);
|
||||
for (uint16 i = 0; i < condCount; i++) {
|
||||
MystSoundBlock::SoundItem item;
|
||||
|
||||
soundAction = soundList[condVarValue];
|
||||
soundVolume = soundListVolume[condVarValue];
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
if (soundAction == kMystSoundActionContinue)
|
||||
debugC(kDebugScript, "Continue current sound");
|
||||
else if (soundAction == kMystSoundActionChangeVolume) {
|
||||
debugC(kDebugScript, "Continue current sound, change volume");
|
||||
debugC(kDebugScript, "\tVolume: %d", soundVolume);
|
||||
_vm->_sound->changeBackgroundVolumeMyst(soundVolume);
|
||||
} else if (soundAction == kMystSoundActionStop) {
|
||||
debugC(kDebugScript, "Stop sound");
|
||||
_vm->_sound->stopBackgroundMyst();
|
||||
} else if (soundAction > 0) {
|
||||
debugC(kDebugScript, "Play new Sound, change volume");
|
||||
debugC(kDebugScript, "\tSound: %d", soundAction);
|
||||
debugC(kDebugScript, "\tVolume: %d", soundVolume);
|
||||
_vm->_sound->replaceBackgroundMyst(soundAction, soundVolume);
|
||||
} else {
|
||||
debugC(kDebugScript, "Unknown");
|
||||
warning("Unknown sound control value in opcode %d", op);
|
||||
}
|
||||
} else
|
||||
warning("Unknown arg count in opcode %d", op);
|
||||
|
||||
delete[] soundList;
|
||||
soundList = nullptr;
|
||||
delete[] soundListVolume;
|
||||
soundListVolume = nullptr;
|
||||
_vm->applySoundBlock(soundBlock);
|
||||
}
|
||||
|
||||
void MystScriptParser::o_soundPlaySwitch(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user