al streaming fix

This commit is contained in:
MihailRis
2024-03-04 13:32:04 +03:00
parent 75ee269db3
commit d41973583c
4 changed files with 25 additions and 13 deletions
-1
View File
@@ -200,7 +200,6 @@ void ALSpeaker::stop() {
if (source) { if (source) {
AL_CHECK(alSourceStop(source)); AL_CHECK(alSourceStop(source));
al->freeSource(source); al->freeSource(source);
source = 0;
} }
} }
+3 -3
View File
@@ -351,8 +351,8 @@ Channel* audio::get_channel(int index) {
return channels.at(index).get(); return channels.at(index).get();
} }
float audio::get_master_volume() { size_t audio::count_speakers() {
return channels.at(0)->getVolume(); return speakers.size();
} }
void audio::update(double delta) { void audio::update(double delta) {
@@ -362,7 +362,7 @@ void audio::update(double delta) {
entry.second->update(delta); entry.second->update(delta);
} }
float masterVolume = get_master_volume(); float masterVolume = channels.at(0)->getVolume();
for (auto it = speakers.begin(); it != speakers.end();) { for (auto it = speakers.begin(); it != speakers.end();) {
auto speaker = it->second.get(); auto speaker = it->second.get();
int speakerChannel = speaker->getChannel(); int speakerChannel = speaker->getChannel();
+2 -2
View File
@@ -467,8 +467,8 @@ namespace audio {
/// @return channel or nullptr /// @return channel or nullptr
extern Channel* get_channel(int index); extern Channel* get_channel(int index);
/// @brief Get volume of the master channel /// @brief Get alive speakers number (including paused)
extern float get_master_volume(); extern size_t count_speakers();
/// @brief Update audio streams and sound instanced /// @brief Update audio streams and sound instanced
/// @param delta time elapsed since the last update (seconds) /// @param delta time elapsed since the last update (seconds)
+20 -7
View File
@@ -155,8 +155,15 @@ Engine::~Engine() {
std::cout << "-- engine finished" << std::endl; std::cout << "-- engine finished" << std::endl;
} }
inline const std::string checkPacks(const std::unordered_set<std::string>& packs, const std::vector<std::string>& dependencies) { inline const std::string checkPacks(
for (const std::string& str : dependencies) if (packs.find(str) == packs.end()) return str; const std::unordered_set<std::string>& packs,
const std::vector<std::string>& dependencies
) {
for (const std::string& str : dependencies) {
if (packs.find(str) == packs.end()) {
return str;
}
}
return ""; return "";
} }
@@ -172,15 +179,20 @@ void Engine::loadContent() {
std::string missingDependency; std::string missingDependency;
std::unordered_set<std::string> loadedPacks, existingPacks; std::unordered_set<std::string> 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) { 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); missingDependency = checkPacks(existingPacks, pack.dependencies);
if(!missingDependency.empty()) if (!missingDependency.empty()) {
throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'"); 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); loadedPacks.insert(pack.id);
resRoots.push_back(pack.folder); resRoots.push_back(pack.folder);
contentPacks.push_back(pack); contentPacks.push_back(pack);
@@ -226,6 +238,7 @@ double Engine::getDelta() const {
} }
void Engine::setScreen(std::shared_ptr<Screen> screen) { void Engine::setScreen(std::shared_ptr<Screen> screen) {
audio::reset();
this->screen = screen; this->screen = screen;
} }