diff --git a/engines/mm/mm.cpp b/engines/mm/mm.cpp index 8dfe75bc068..03c008881ca 100644 --- a/engines/mm/mm.cpp +++ b/engines/mm/mm.cpp @@ -23,8 +23,11 @@ namespace MM { +MMEngine *g_engine; + MMEngine::MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc) : - Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") { + Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") { + g_engine = this; } bool MMEngine::hasFeature(EngineFeature f) const { @@ -50,4 +53,8 @@ Common::Platform MMEngine::getPlatform() const { return _gameDescription->desc.platform; } +bool MMEngine::getIsCD() const { + return getFeatures() & ADGF_CD; +} + } // namespace MM diff --git a/engines/mm/mm.h b/engines/mm/mm.h index 137d4cf2d08..526bcb4f59b 100644 --- a/engines/mm/mm.h +++ b/engines/mm/mm.h @@ -67,6 +67,11 @@ public: */ uint32 getGameID() const; + /** + * Returns true if the game is the CD version + */ + bool getIsCD() const; + /** * Get a random number */ @@ -75,6 +80,8 @@ public: } }; +extern MMEngine *g_engine; + } // namespace MM #endif // MM_MM_H diff --git a/engines/mm/module.mk b/engines/mm/module.mk index a6c44557b70..3133c8fc05a 100644 --- a/engines/mm/module.mk +++ b/engines/mm/module.mk @@ -10,6 +10,9 @@ MODULE_OBJS := \ shared/utils/xeen_font.o \ shared/xeen/cc_archive.o \ shared/xeen/file.o \ + shared/xeen/sound.o \ + shared/xeen/sound_driver.o \ + shared/xeen/sound_driver_adlib.o \ shared/xeen/sprites.o \ shared/xeen/xsurface.o @@ -255,9 +258,6 @@ MODULE_OBJS += \ xeen/saves.o \ xeen/screen.o \ xeen/scripts.o \ - xeen/sound.o \ - xeen/sound_driver.o \ - xeen/sound_driver_adlib.o \ xeen/spells.o \ xeen/sprites.o \ xeen/subtitles.o \ diff --git a/engines/mm/xeen/sound.cpp b/engines/mm/shared/xeen/sound.cpp similarity index 95% rename from engines/mm/xeen/sound.cpp rename to engines/mm/shared/xeen/sound.cpp index d9fbddbbfb2..07debccf992 100644 --- a/engines/mm/xeen/sound.cpp +++ b/engines/mm/shared/xeen/sound.cpp @@ -23,24 +23,25 @@ #include "audio/decoders/voc.h" #include "backends/audiocd/audiocd.h" #include "common/config-manager.h" -#include "mm/xeen/sound.h" -#include "mm/xeen/sound_driver_adlib.h" -#include "mm/xeen/xeen.h" +#include "mm/shared/xeen/sound.h" +#include "mm/shared/xeen/sound_driver_adlib.h" +#include "mm/mm.h" namespace MM { +namespace Shared { namespace Xeen { Sound::Sound(Audio::Mixer *mixer) : _mixer(mixer), _fxOn(true), _musicOn(true), _subtitles(false), _songData(nullptr), _effectsData(nullptr), _musicSide(0), _musicPercent(100), _musicVolume(0), _sfxVolume(0) { _SoundDriver = new SoundDriverAdlib(); - if (g_vm->getIsCD()) + if (g_engine->getIsCD()) g_system->getAudioCDManager()->open(); } Sound::~Sound() { stopAllAudio(); - if (g_vm->getIsCD()) + if (g_engine->getIsCD()) g_system->getAudioCDManager()->close(); delete _SoundDriver; @@ -111,7 +112,7 @@ void Sound::setFxOn(bool isOn) { ConfMan.setBool("mute", false); ConfMan.flushToDisk(); - g_vm->syncSoundSettings(); + g_engine->syncSoundSettings(); } void Sound::loadEffectsData() { @@ -215,7 +216,7 @@ void Sound::setMusicOn(bool isOn) { ConfMan.setBool("mute", false); ConfMan.flushToDisk(); - g_vm->syncSoundSettings(); + g_engine->syncSoundSettings(); } bool Sound::isMusicPlaying() const { @@ -250,5 +251,6 @@ void Sound::updateVolume() { songCommand(SET_VOLUME, _musicPercent * _musicVolume / 100, _sfxVolume); } -} // End of namespace Xeen -} // End of namespace MM +} // namespace Xeen +} // namespace Shared +} // namespace MM diff --git a/engines/mm/shared/xeen/sound.h b/engines/mm/shared/xeen/sound.h new file mode 100644 index 00000000000..8bfd0127e39 --- /dev/null +++ b/engines/mm/shared/xeen/sound.h @@ -0,0 +1,168 @@ +/* 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 3 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, see . + * + */ + +#ifndef MM_SHARED_XEEN_SOUND_H +#define MM_SHARED_XEEN_SOUND_H + +#include "audio/mixer.h" +#include "audio/audiostream.h" +#include "mm/shared/xeen/file.h" +#include "mm/shared/xeen/sound_driver.h" + +namespace MM { +namespace Shared { +namespace Xeen { + +class Sound { +private: + SoundDriver *_SoundDriver; + const byte *_effectsData; + Common::Array _effectsOffsets; + const byte *_songData; + Audio::Mixer *_mixer; + Audio::SoundHandle _soundHandle; + byte _musicPercent; + int _musicVolume, _sfxVolume; +private: + /** + * Loads effects data that was embedded in the music driver + */ + void loadEffectsData(); + + /** + * Updates any playing music + */ + void update(); + + /** + * Updates the music and sound effects playing volume + */ + void updateVolume(); +public: + bool _fxOn; + bool _musicOn; + Common::String _currentMusic; + int _musicSide; + bool _subtitles; +public: + Sound(Audio::Mixer *mixer); + virtual ~Sound(); + + /** + * Starts an effect playing + */ + void playFX(uint effectId); + + /** + * Stops any currently playing FX + */ + void stopFX(); + + /** + * Executes special music command + */ + int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0); + + /** + * Stops any currently playing music + */ + void stopSong() { + songCommand(STOP_SONG); + } + + /** + * Sets the in-game music volume percent. This is separate from the ScummVM volume + */ + void setMusicPercent(byte percent); + + /** + * Plays a song + */ + void playSong(Common::SeekableReadStream &stream); + + /** + * Plays a song + */ + void playSong(const Common::String &name, int param = 0); + + /** + * Returns true if music is playing + */ + bool isMusicPlaying() const; + + /** + * Sets whether music is on + */ + void setMusicOn(bool isOn); + + /** + * Sets whether sound effects is on + */ + void setFxOn(bool isOn); + + /** + * Called to reload sound settings + */ + void updateSoundSettings(); + + /** + * Stops all playing music, FX, and sound samples + */ + void stopAllAudio(); + + /** + * Play a given sound + */ + void playSound(Common::SeekableReadStream &s, int unused = 0); + + /** + * Play a given sound + */ + void playSound(const Common::String &name, int unused = 0); + + /** + * Play a given sound + */ + void playSound(const Common::String &name, int ccNum, int unused); + + /** + * Stop playing a sound loaded from a .m file + * @remarks In the original, passing 1 to playSound stopped the sound + */ + void stopSound(); + + /** + * Returns true if a sound file is currently playing + * @remarks In the original, passing 0 to playSound returned play status + */ + bool isSoundPlaying() const; + + /** + * Play a given voice file + */ + void playVoice(const Common::String &name, int ccMode = -1); +}; + +} // namespace Xeen +} // namespace Shared +} // namespace MM + +#endif diff --git a/engines/mm/xeen/sound_driver.cpp b/engines/mm/shared/xeen/sound_driver.cpp similarity index 97% rename from engines/mm/xeen/sound_driver.cpp rename to engines/mm/shared/xeen/sound_driver.cpp index fbab864cca1..c7ebd7f1b6f 100644 --- a/engines/mm/xeen/sound_driver.cpp +++ b/engines/mm/shared/xeen/sound_driver.cpp @@ -19,13 +19,15 @@ * */ +#include "common/debug.h" #include "common/md5.h" #include "common/config-manager.h" -#include "mm/xeen/sound_driver.h" -#include "mm/xeen/xeen.h" -#include "mm/xeen/files.h" +#include "mm/shared/xeen/sound_driver.h" +#include "mm/shared/xeen/file.h" +#include "mm/mm.h" namespace MM { +namespace Shared { namespace Xeen { SoundDriver::SoundDriver() : _frameCtr(0) { @@ -238,5 +240,6 @@ const CommandFn SoundDriver::FX_COMMANDS[16] = { &SoundDriver::cmdChangeFrequency, &SoundDriver::fxEndSubroutine }; -} // End of namespace Xeen -} // End of namespace MM +} // namespace Xeen +} // namespace Shared +} // namespace MM diff --git a/engines/mm/xeen/sound_driver.h b/engines/mm/shared/xeen/sound_driver.h similarity index 96% rename from engines/mm/xeen/sound_driver.h rename to engines/mm/shared/xeen/sound_driver.h index ed3f25d745f..7cc6eb66806 100644 --- a/engines/mm/xeen/sound_driver.h +++ b/engines/mm/shared/xeen/sound_driver.h @@ -19,8 +19,8 @@ * */ -#ifndef XEEN_SOUND_DRIVER_H -#define XEEN_SOUND_DRIVER_H +#ifndef MM_SHARED_XEEN_SOUND_DRIVER_H +#define MM_SHARED_XEEN_SOUND_DRIVER_H #include "audio/fmopl.h" #include "audio/mixer.h" @@ -28,7 +28,7 @@ #include "common/mutex.h" #include "common/queue.h" #include "common/stack.h" -#include "mm/xeen/files.h" +#include "mm/shared/xeen/file.h" #define CHANNEL_COUNT 9 @@ -37,6 +37,7 @@ namespace OPL { } namespace MM { +namespace Shared { namespace Xeen { enum MusicCommand { @@ -199,7 +200,8 @@ public: } }; -} // End of namespace Xeen -} // End of namespace MM +} // namespace Xeen +} // namespace Shared +} // namespace MM #endif diff --git a/engines/mm/xeen/sound_driver_adlib.cpp b/engines/mm/shared/xeen/sound_driver_adlib.cpp similarity index 98% rename from engines/mm/xeen/sound_driver_adlib.cpp rename to engines/mm/shared/xeen/sound_driver_adlib.cpp index a0b06ca2b89..240a4477c12 100644 --- a/engines/mm/xeen/sound_driver_adlib.cpp +++ b/engines/mm/shared/xeen/sound_driver_adlib.cpp @@ -19,10 +19,12 @@ * */ -#include "mm/xeen/sound_driver_adlib.h" -#include "mm/xeen/xeen.h" +#include "common/debug.h" +#include "mm/shared/xeen/sound_driver_adlib.h" +#include "mm/mm.h" namespace MM { +namespace Shared { namespace Xeen { #define CALLBACKS_PER_SECOND 73 @@ -424,5 +426,6 @@ byte SoundDriverAdlib::calculateLevel(byte level, bool isFx) { return scaling | (0x3f - totalLevel); } -} // End of namespace Xeen -} // End of namespace MM +} // namespace Xeen +} // namespace Shared +} // namespace MM diff --git a/engines/mm/xeen/sound_driver_adlib.h b/engines/mm/shared/xeen/sound_driver_adlib.h similarity index 95% rename from engines/mm/xeen/sound_driver_adlib.h rename to engines/mm/shared/xeen/sound_driver_adlib.h index eb9708230e5..b01c8cf8247 100644 --- a/engines/mm/xeen/sound_driver_adlib.h +++ b/engines/mm/shared/xeen/sound_driver_adlib.h @@ -19,16 +19,17 @@ * */ -#ifndef XEEN_SOUND_DRIVER_ADLIB_H -#define XEEN_SOUND_DRIVER_ADLIB_H +#ifndef MM_SHARED_XEEN_SOUND_DRIVER_ADLIB_H +#define MM_SHARED_XEEN_SOUND_DRIVER_ADLIB_H -#include "mm/xeen/sound_driver.h" +#include "mm/shared/xeen/sound_driver.h" namespace OPL { class OPL; } namespace MM { +namespace Shared { namespace Xeen { class SoundDriverAdlib : public SoundDriver { @@ -162,7 +163,8 @@ public: int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0) override; }; -} // End of namespace Xeen -} // End of namespace MM +} // namespace Xeen +} // namespace Shared +} // namespace MM #endif diff --git a/engines/mm/xeen/sound.h b/engines/mm/xeen/sound.h index 22612bfdd93..133af64a2a7 100644 --- a/engines/mm/xeen/sound.h +++ b/engines/mm/xeen/sound.h @@ -22,143 +22,12 @@ #ifndef XEEN_SOUND_H #define XEEN_SOUND_H -#include "audio/mixer.h" -#include "audio/audiostream.h" -#include "mm/xeen/files.h" -#include "mm/xeen/sound_driver.h" +#include "mm/shared/xeen/sound.h" namespace MM { namespace Xeen { -class Sound { -private: - SoundDriver *_SoundDriver; - const byte *_effectsData; - Common::Array _effectsOffsets; - const byte *_songData; - Audio::Mixer *_mixer; - Audio::SoundHandle _soundHandle; - byte _musicPercent; - int _musicVolume, _sfxVolume; -private: - /** - * Loads effects data that was embedded in the music driver - */ - void loadEffectsData(); - - /** - * Updates any playing music - */ - void update(); - - /** - * Updates the music and sound effects playing volume - */ - void updateVolume(); -public: - bool _fxOn; - bool _musicOn; - Common::String _currentMusic; - int _musicSide; - bool _subtitles; -public: - Sound(Audio::Mixer *mixer); - virtual ~Sound(); - - /** - * Starts an effect playing - */ - void playFX(uint effectId); - - /** - * Stops any currently playing FX - */ - void stopFX(); - - /** - * Executes special music command - */ - int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0); - - /** - * Stops any currently playing music - */ - void stopSong() { - songCommand(STOP_SONG); - } - - /** - * Sets the in-game music volume percent. This is separate from the ScummVM volume - */ - void setMusicPercent(byte percent); - - /** - * Plays a song - */ - void playSong(Common::SeekableReadStream &stream); - - /** - * Plays a song - */ - void playSong(const Common::String &name, int param = 0); - - /** - * Returns true if music is playing - */ - bool isMusicPlaying() const; - - /** - * Sets whether music is on - */ - void setMusicOn(bool isOn); - - /** - * Sets whether sound effects is on - */ - void setFxOn(bool isOn); - - /** - * Called to reload sound settings - */ - void updateSoundSettings(); - - /** - * Stops all playing music, FX, and sound samples - */ - void stopAllAudio(); - - /** - * Play a given sound - */ - void playSound(Common::SeekableReadStream &s, int unused = 0); - - /** - * Play a given sound - */ - void playSound(const Common::String &name, int unused = 0); - - /** - * Play a given sound - */ - void playSound(const Common::String &name, int ccNum, int unused); - - /** - * Stop playing a sound loaded from a .m file - * @remarks In the original, passing 1 to playSound stopped the sound - */ - void stopSound(); - - /** - * Returns true if a sound file is currently playing - * @remarks In the original, passing 0 to playSound returned play status - */ - bool isSoundPlaying() const; - - /** - * Play a given voice file - */ - void playVoice(const Common::String &name, int ccMode = -1); -}; +using Shared::Xeen::Sound; } // End of namespace Xeen } // End of namespace MM diff --git a/engines/mm/xeen/xeen.cpp b/engines/mm/xeen/xeen.cpp index 8b622b4e554..c63c5c66c13 100644 --- a/engines/mm/xeen/xeen.cpp +++ b/engines/mm/xeen/xeen.cpp @@ -339,9 +339,5 @@ uint32 XeenEngine::getGameFeatures() const { return _gameDescription->features; } -bool XeenEngine::getIsCD() const { - return getFeatures() & ADGF_CD; -} - } // End of namespace Xeen } // End of namespace MM diff --git a/engines/mm/xeen/xeen.h b/engines/mm/xeen/xeen.h index 16a59760602..e3ed79f2ef0 100644 --- a/engines/mm/xeen/xeen.h +++ b/engines/mm/xeen/xeen.h @@ -198,11 +198,6 @@ public: */ uint32 getGameFeatures() const; - /** - * Returns true if the game is the CD version - */ - bool getIsCD() const; - /** * Returns a random number */