diff options
-rw-r--r-- | engines/zvision/actions.cpp | 24 | ||||
-rw-r--r-- | engines/zvision/actions.h | 10 | ||||
-rw-r--r-- | engines/zvision/music_node.cpp | 19 | ||||
-rw-r--r-- | engines/zvision/music_node.h | 3 | ||||
-rw-r--r-- | engines/zvision/scr_file_handling.cpp | 2 |
5 files changed, 50 insertions, 8 deletions
diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 92d6f6c389..5d1dc9a608 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -121,12 +121,32 @@ bool ActionChangeLocation::execute() { ActionCrossfade::ActionCrossfade(ZVision *engine, int32 slotkey, const Common::String &line) : ResultAction(engine, slotkey) { sscanf(line.c_str(), - "%u %u %u %u %u %u %u", + "%u %u %d %d %d %d %d", &_keyOne, &_keyTwo, &_oneStartVolume, &_twoStartVolume, &_oneEndVolume, &_twoEndVolume, &_timeInMillis); } bool ActionCrossfade::execute() { - // TODO: Implement + if (_keyOne) { + SideFX *fx = _engine->getScriptManager()->getSideFX(_keyOne); + if (fx && fx->getType() == SideFX::SIDEFX_AUDIO) { + MusicNode *mus = (MusicNode *)fx; + if (_oneStartVolume >= 0) + mus->setVolume((_oneStartVolume * 255) / 100); + + mus->setFade(_timeInMillis, (_oneEndVolume * 255) / 100); + } + } + + if (_keyTwo) { + SideFX *fx = _engine->getScriptManager()->getSideFX(_keyTwo); + if (fx && fx->getType() == SideFX::SIDEFX_AUDIO) { + MusicNode *mus = (MusicNode *)fx; + if (_twoStartVolume >= 0) + mus->setVolume((_twoStartVolume * 255) / 100); + + mus->setFade(_timeInMillis, (_twoEndVolume * 255) / 100); + } + } return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index b204fbeb28..5c6cf6c35f 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -140,11 +140,11 @@ public: private: uint32 _keyOne; uint32 _keyTwo; - uint _oneStartVolume; - uint _twoStartVolume; - uint _oneEndVolume; - uint _twoEndVolume; - uint _timeInMillis; + int32 _oneStartVolume; + int32 _twoStartVolume; + int32 _oneEndVolume; + int32 _twoEndVolume; + int32 _timeInMillis; }; class ActionDebug : public ResultAction { diff --git a/engines/zvision/music_node.cpp b/engines/zvision/music_node.cpp index 081c9dbcca..30271480c1 100644 --- a/engines/zvision/music_node.cpp +++ b/engines/zvision/music_node.cpp @@ -91,12 +91,31 @@ void MusicNode::unsetPanTrack() { setVolume(_volume); } +void MusicNode::setFade(int32 time, uint8 target) { + _crossfade_target = target; + _crossfade_time = time; + _crossfade = true; +} + bool MusicNode::process(uint32 deltaTimeInMillis) { if (! _engine->_mixer->isSoundHandleActive(_handle)) return stop(); else { uint8 _newvol = _volume; + if (_crossfade) { + if (_crossfade_time > 0) { + if ((int32)deltaTimeInMillis > _crossfade_time) + deltaTimeInMillis = _crossfade_time; + _newvol += floor(((float)(_crossfade_target - _newvol) / (float)_crossfade_time)) * (float)deltaTimeInMillis; + _crossfade_time -= deltaTimeInMillis; + } + else { + _crossfade = false; + _newvol = _crossfade_target; + } + } + if (_pantrack || _volume != _newvol) setVolume(_newvol); } diff --git a/engines/zvision/music_node.h b/engines/zvision/music_node.h index 9ccf9ab657..6e3033f6b0 100644 --- a/engines/zvision/music_node.h +++ b/engines/zvision/music_node.h @@ -49,6 +49,9 @@ public: void setPanTrack(int16 pos); void unsetPanTrack(); + + void setFade(int32 time, uint8 target); + private: int32 _timeLeft; bool _pantrack; diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index 002871af0b..833db11ad1 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -220,7 +220,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (act.matchString("change_location", true)) { actionList.push_back(new ActionChangeLocation(_engine, slot, args)); } else if (act.matchString("crossfade", true)) { - // TODO: Implement ActionCrossfade + actionList.push_back(new ActionCrossfade(_engine, slot, args)); } else if (act.matchString("debug", true)) { // TODO: Implement ActionDebug } else if (act.matchString("delay_render", true)) { |