diff --git a/src/audio/player.cpp b/src/audio/player.cpp index b943b79c..fd22e9d2 100644 --- a/src/audio/player.cpp +++ b/src/audio/player.cpp @@ -63,7 +63,7 @@ void AudioPlayer::threadStart() { auto it = remove_if( _sounds.begin(), _sounds.end(), - [](const shared_ptr &sound) { return sound->stopped(); }); + [](const shared_ptr &sound) { return sound->isStopped(); }); _sounds.erase(it, _sounds.end()); @@ -105,10 +105,9 @@ shared_ptr AudioPlayer::play(const shared_ptr &strea if (!stream) { throw invalid_argument("Audio stream is empty"); } - bool loop = type == AudioType::Music; float gain = getVolume(type) / 100.0f; - shared_ptr sound(new SoundInstance(stream, loop, gain)); + shared_ptr sound(new SoundInstance(stream, false, gain)); lock_guard lock(_soundsMutex); _sounds.push_back(sound); diff --git a/src/audio/soundinstance.cpp b/src/audio/soundinstance.cpp index fb16ad6a..c1e98f2e 100644 --- a/src/audio/soundinstance.cpp +++ b/src/audio/soundinstance.cpp @@ -115,7 +115,7 @@ void SoundInstance::stop() { _state = State::Stopped; } -bool SoundInstance::stopped() const { +bool SoundInstance::isStopped() const { return _state == State::Stopped; } diff --git a/src/audio/soundinstance.h b/src/audio/soundinstance.h index 37216881..03272f55 100644 --- a/src/audio/soundinstance.h +++ b/src/audio/soundinstance.h @@ -37,7 +37,7 @@ public: void update(); void stop(); - bool stopped() const; + bool isStopped() const; int duration() const; private: diff --git a/src/game/game.cpp b/src/game/game.cpp index f633cb5b..5a8c0043 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -121,9 +121,12 @@ void Game::playVideo(const string &name) { _video = bik.video(); + if (_music && !_music->isStopped()) { + _music->stop(); + } shared_ptr audio(_video->audio()); if (audio) { - AudioPlayer::instance().play(audio, AudioType::Movie); + _movieAudio = AudioPlayer::instance().play(audio, AudioType::Movie); } } @@ -148,12 +151,12 @@ string Game::getMainMenuMusic() const { } void Game::playMusic(const string &resRef) { - if (_music) { + if (_musicResRef == resRef) return; + + if (_music && !_music->isStopped()) { _music->stop(); } - if (!resRef.empty()) { - _music = ::playMusic(resRef); - } + _musicResRef = resRef; } void Game::loadMainMenu() { @@ -390,6 +393,8 @@ void Game::update() { if (_video->isFinished()) { _video.reset(); } + } else if (!_musicResRef.empty() && (!_music || _music->isStopped())) { + _music = ::playMusic(_musicResRef); } if (!_nextModule.empty()) { diff --git a/src/game/game.h b/src/game/game.h index 194bacc5..651f72b8 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -155,7 +155,6 @@ private: std::unique_ptr _objectFactory; GameScreen _screen { GameScreen::MainMenu }; Party _party; - std::shared_ptr _music; uint32_t _ticks { 0 }; bool _quit { false }; std::shared_ptr _video; @@ -186,6 +185,14 @@ private: // END GUI + // Audio + + std::string _musicResRef; + std::shared_ptr _music; + std::shared_ptr _movieAudio; + + // END Audio + // Globals/locals std::map _globalBooleans; diff --git a/src/game/gui/dialog.cpp b/src/game/gui/dialog.cpp index 06dd2e81..521b93b1 100644 --- a/src/game/gui/dialog.cpp +++ b/src/game/gui/dialog.cpp @@ -437,7 +437,7 @@ void Dialog::update(float dt) { endCurrentEntry(); } } else if (endOnAudioStop) { - bool stopped = _currentVoice && _currentVoice->stopped(); + bool stopped = _currentVoice && _currentVoice->isStopped(); if (stopped) { endCurrentEntry(); } diff --git a/src/program.cpp b/src/program.cpp index e752ff27..69fa620b 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -67,7 +67,7 @@ void Program::initOptions() { ("soundvol", po::value()->default_value(kDefaultSoundVolume), "sound volume in percents") ("movievol", po::value()->default_value(kDefaultMovieVolume), "movie volume in percents") ("port", po::value()->default_value(kDefaultMultiplayerPort), "multiplayer port number") - ("debug", po::value()->default_value(0), "debug level (0-3)"); + ("debug", po::value()->default_value(0), "debug log level (0-3)"); _cmdLineOpts.add(_commonOpts).add_options() ("help", "print this message")