From d41973583cf3da24d3257eb614b36ded56cd6fc7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 4 Mar 2024 13:32:04 +0300 Subject: [PATCH] al streaming fix --- src/audio/AL/ALAudio.cpp | 1 - src/audio/audio.cpp | 6 +++--- src/audio/audio.h | 4 ++-- src/engine.cpp | 27 ++++++++++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/audio/AL/ALAudio.cpp b/src/audio/AL/ALAudio.cpp index e4601d67..62e8f5ed 100644 --- a/src/audio/AL/ALAudio.cpp +++ b/src/audio/AL/ALAudio.cpp @@ -200,7 +200,6 @@ void ALSpeaker::stop() { if (source) { AL_CHECK(alSourceStop(source)); al->freeSource(source); - source = 0; } } diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 47c3bcbc..4467490a 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -351,8 +351,8 @@ Channel* audio::get_channel(int index) { return channels.at(index).get(); } -float audio::get_master_volume() { - return channels.at(0)->getVolume(); +size_t audio::count_speakers() { + return speakers.size(); } void audio::update(double delta) { @@ -362,7 +362,7 @@ void audio::update(double delta) { entry.second->update(delta); } - float masterVolume = get_master_volume(); + float masterVolume = channels.at(0)->getVolume(); for (auto it = speakers.begin(); it != speakers.end();) { auto speaker = it->second.get(); int speakerChannel = speaker->getChannel(); diff --git a/src/audio/audio.h b/src/audio/audio.h index 9a29b932..772dde46 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -467,8 +467,8 @@ namespace audio { /// @return channel or nullptr extern Channel* get_channel(int index); - /// @brief Get volume of the master channel - extern float get_master_volume(); + /// @brief Get alive speakers number (including paused) + extern size_t count_speakers(); /// @brief Update audio streams and sound instanced /// @param delta time elapsed since the last update (seconds) diff --git a/src/engine.cpp b/src/engine.cpp index e69c8458..ec3a0632 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -155,8 +155,15 @@ Engine::~Engine() { std::cout << "-- engine finished" << std::endl; } -inline const std::string checkPacks(const std::unordered_set& packs, const std::vector& dependencies) { - for (const std::string& str : dependencies) if (packs.find(str) == packs.end()) return str; +inline const std::string checkPacks( + const std::unordered_set& packs, + const std::vector& dependencies +) { + for (const std::string& str : dependencies) { + if (packs.find(str) == packs.end()) { + return str; + } + } return ""; } @@ -172,15 +179,20 @@ void Engine::loadContent() { std::string missingDependency; std::unordered_set loadedPacks, existingPacks; - for (const auto& item : srcPacks) { existingPacks.insert(item.id); } + for (const auto& item : srcPacks) { + existingPacks.insert(item.id); + } - while(existingPacks.size() > loadedPacks.size()) { + while (existingPacks.size() > loadedPacks.size()) { for (auto& pack : srcPacks) { - if(loadedPacks.find(pack.id) != loadedPacks.end()) continue; + if(loadedPacks.find(pack.id) != loadedPacks.end()) { + continue; + } missingDependency = checkPacks(existingPacks, pack.dependencies); - if(!missingDependency.empty()) + if (!missingDependency.empty()) { throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'"); - if(pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) { + } + if (pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) { loadedPacks.insert(pack.id); resRoots.push_back(pack.folder); contentPacks.push_back(pack); @@ -226,6 +238,7 @@ double Engine::getDelta() const { } void Engine::setScreen(std::shared_ptr screen) { + audio::reset(); this->screen = screen; }