diff options
author | Marisa-Chan | 2013-11-01 17:00:20 +0700 |
---|---|---|
committer | Marisa-Chan | 2013-11-01 17:00:20 +0700 |
commit | 9dc0533f4f077a2a5edce902e8d93860c68c3fda (patch) | |
tree | 0a746267a81b0caf1c77866a86c295e2994957fe | |
parent | be93d7d67dcea18532917a6c1bd6004665973f4f (diff) | |
download | scummvm-rg350-9dc0533f4f077a2a5edce902e8d93860c68c3fda.tar.gz scummvm-rg350-9dc0533f4f077a2a5edce902e8d93860c68c3fda.tar.bz2 scummvm-rg350-9dc0533f4f077a2a5edce902e8d93860c68c3fda.zip |
ZVISION: Implement MusicNode and move ActionMusic to work with it.
-rw-r--r-- | engines/zvision/actions.cpp | 47 | ||||
-rw-r--r-- | engines/zvision/actions.h | 4 | ||||
-rw-r--r-- | engines/zvision/module.mk | 3 | ||||
-rw-r--r-- | engines/zvision/music_node.cpp | 86 | ||||
-rw-r--r-- | engines/zvision/music_node.h | 62 | ||||
-rw-r--r-- | engines/zvision/scr_file_handling.cpp | 4 |
6 files changed, 185 insertions, 21 deletions
diff --git a/engines/zvision/actions.cpp b/engines/zvision/actions.cpp index 06ceea2573..3dd6382060 100644 --- a/engines/zvision/actions.cpp +++ b/engines/zvision/actions.cpp @@ -30,6 +30,7 @@ #include "zvision/zork_raw.h" #include "zvision/zork_avi_decoder.h" #include "zvision/timer_node.h" +#include "zvision/music_node.h" #include "zvision/animation_control.h" #include "common/file.h" @@ -196,9 +197,10 @@ bool ActionKill::execute() { // ActionMusic ////////////////////////////////////////////////////////////////////////////// -ActionMusic::ActionMusic(ZVision *engine, const Common::String &line) : +ActionMusic::ActionMusic(ZVision *engine, const Common::String &line, bool global) : ResultAction(engine), - _volume(255) { + _volume(255), + _universe(global) { uint type; char fileNameBuffer[25]; uint loop; @@ -225,24 +227,35 @@ ActionMusic::ActionMusic(ZVision *engine, const Common::String &line) : } } -bool ActionMusic::execute() { - Audio::RewindableAudioStream *audioStream; +ActionMusic::~ActionMusic() { + if (!_universe) + _engine->getScriptManager()->killSideFx(_key); +} - if (_fileName.contains(".wav")) { - Common::File *file = new Common::File(); - if (file->open(_fileName)) { - audioStream = Audio::makeWAVStream(file, DisposeAfterUse::YES); +bool ActionMusic::execute() { + if (_engine->getScriptManager()->getSideFX(_key)) + return true; + Common::File *file = new Common::File(); + if (!file->exists(_fileName) && _fileName.size() >= 12) { + _fileName.setChar('r', 9); + _fileName.setChar('a', 10); + _fileName.setChar('w', 11); + if (!file->exists(_fileName)) { + _fileName.setChar('i', 9); + _fileName.setChar('f', 10); + _fileName.setChar('p', 11); + if (!file->exists(_fileName)) { + _fileName.setChar('s', 9); + _fileName.setChar('r', 10); + _fileName.setChar('c', 11); + if (!file->exists(_fileName)) + return true; + } } - } else { - audioStream = makeRawZorkStream(_fileName, _engine); - } - - if (_loop) { - Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES); - _engine->_mixer->playStream(_soundType, 0, loopingAudioStream, -1, _volume); - } else { - _engine->_mixer->playStream(_soundType, 0, audioStream, -1, _volume); } + if (file->exists(_fileName)) + _engine->getScriptManager()->addSideFX(new MusicNode(_engine, _key, _fileName, _loop, _volume)); + delete file; return true; } diff --git a/engines/zvision/actions.h b/engines/zvision/actions.h index 8a8412fed5..7464d83b09 100644 --- a/engines/zvision/actions.h +++ b/engines/zvision/actions.h @@ -223,7 +223,8 @@ private: class ActionMusic : public ResultAction { public: - ActionMusic(ZVision *engine, const Common::String &line); + ActionMusic(ZVision *engine, const Common::String &line, bool global); + ~ActionMusic(); bool execute(); private: @@ -232,6 +233,7 @@ private: Common::String _fileName; bool _loop; byte _volume; + bool _universe; }; class ActionPlayAnimation : public ResultAction { diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index edd08c8e9f..8d37311462 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -30,7 +30,8 @@ MODULE_OBJS := \ zfs_archive.o \ zork_avi_decoder.o \ zork_raw.o \ - sidefx.o + sidefx.o \ + music_node.o MODULE_DIRS += \ engines/zvision diff --git a/engines/zvision/music_node.cpp b/engines/zvision/music_node.cpp new file mode 100644 index 0000000000..6be4683178 --- /dev/null +++ b/engines/zvision/music_node.cpp @@ -0,0 +1,86 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/scummsys.h" + +#include "zvision/music_node.h" + +#include "zvision/zvision.h" +#include "zvision/script_manager.h" +#include "zvision/zork_raw.h" + +#include "common/stream.h" +#include "common/file.h" +#include "audio/decoders/wave.h" + + +namespace ZVision { + +MusicNode::MusicNode(ZVision *engine, uint32 key, Common::String &filename, bool loop, int8 volume) + : SideFX(engine, key, SIDEFX_AUDIO) { + _loop = loop; + _volume = volume; + _crossfade = false; + _crossfade_delta = 0; + _crossfade_time = 0; + _attenuate = 0; + _pantrack = false; + _pantrack_X = 0; + + Audio::RewindableAudioStream *audioStream; + + if (filename.contains(".wav")) { + Common::File *file = new Common::File(); + if (file->open(filename)) { + audioStream = Audio::makeWAVStream(file, DisposeAfterUse::YES); + } + } else { + audioStream = makeRawZorkStream(filename, _engine); + } + + _id = _engine->getAudioId(); + + if (_loop) { + Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES); + _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, 0, loopingAudioStream, _id, _volume); + } else { + _engine->_mixer->playStream(Audio::Mixer::kPlainSoundType, 0, audioStream, _id, _volume); + } + + if (_key != StateKey_NotSet) + _engine->getScriptManager()->setStateValue(_key, 1); +} + +MusicNode::~MusicNode() { + _engine->_mixer->stopID(_id); + if (_key != StateKey_NotSet) + _engine->getScriptManager()->setStateValue(_key, 2); + debug(1, "MusicNode: %d destroyed\n", _key); +} + +bool MusicNode::process(uint32 deltaTimeInMillis) { + if (! _engine->_mixer->isSoundIDActive(_id)) + return stop(); + return false; +} + +} // End of namespace ZVision diff --git a/engines/zvision/music_node.h b/engines/zvision/music_node.h new file mode 100644 index 0000000000..6aed4556fa --- /dev/null +++ b/engines/zvision/music_node.h @@ -0,0 +1,62 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ZVISION_MUSIC_NODE_H +#define ZVISION_MUSIC_NODE_H + +#include "zvision/sidefx.h" + +namespace Common { +class String; +} + +namespace ZVision { +class MusicNode : public SideFX { +public: + MusicNode(ZVision *engine, uint32 key, Common::String &file, bool loop, int8 volume); + ~MusicNode(); + + /** + * Decrement the timer by the delta time. If the timer is finished, set the status + * in _globalState and let this node be deleted + * + * @param deltaTimeInMillis The number of milliseconds that have passed since last frame + * @return If true, the node can be deleted after process() finishes + */ + bool process(uint32 deltaTimeInMillis); + +private: + int32 _timeLeft; + bool _pantrack; + int32 _pantrack_X; + int32 _attenuate; + int8 _volume; + int32 _id; + bool _loop; + bool _crossfade; + int32 _crossfade_delta; + int32 _crossfade_time; +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/scr_file_handling.cpp b/engines/zvision/scr_file_handling.cpp index bfa1481007..0df3143a51 100644 --- a/engines/zvision/scr_file_handling.cpp +++ b/engines/zvision/scr_file_handling.cpp @@ -203,7 +203,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:menu_bar_enable*", true)) { // TODO: Implement ActionMenuBarEnable } else if (line.matchString("*:music*", true)) { - actionList.push_back(new ActionMusic(_engine, line)); + actionList.push_back(new ActionMusic(_engine, line, false)); } else if (line.matchString("*:pan_track*", true)) { // TODO: Implement ActionPanTrack } else if (line.matchString("*:playpreload*", true)) { @@ -239,7 +239,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis } else if (line.matchString("*:ttytext*", true)) { // TODO: Implement ActionTTYText } else if (line.matchString("*:universe_music*", true)) { - // TODO: Implement ActionUniverseMusic + actionList.push_back(new ActionMusic(_engine, line, true)); } else if (line.matchString("*:copy_file*", true)) { // Not used. Purposely left empty } else { |