fixes for mac music

This commit is contained in:
2025-11-30 15:19:14 +01:00
parent da32b5be1a
commit 7f07036f07
24 changed files with 236 additions and 172 deletions

View File

@ -558,16 +558,20 @@ bool ApplicationManager::initializeGame() {
Audio::instance().init();
// Discover available tracks (up to 100) and queue for background loading
m_totalTracks = 0;
std::vector<std::string> trackPaths;
trackPaths.reserve(100);
for (int i = 1; i <= 100; ++i) {
char buf[128];
std::snprintf(buf, sizeof(buf), "assets/music/music%03d.mp3", i);
// Use simple file existence check via std::filesystem
if (std::filesystem::exists(buf)) {
Audio::instance().addTrackAsync(buf);
++m_totalTracks;
} else {
char base[128];
std::snprintf(base, sizeof(base), "assets/music/music%03d", i);
std::string path = AssetPath::resolveWithExtensions(base, { ".mp3" });
if (path.empty()) {
break;
}
trackPaths.push_back(path);
}
m_totalTracks = static_cast<int>(trackPaths.size());
for (const auto& path : trackPaths) {
Audio::instance().addTrackAsync(path);
}
if (m_totalTracks > 0) {
Audio::instance().startBackgroundLoading();

View File

@ -208,27 +208,14 @@ bool AssetManager::loadSoundEffectWithFallback(const std::string& id, const std:
return false;
}
// Try WAV first, then MP3 fallback (matching main.cpp pattern)
std::string wavPath = "assets/music/" + baseName + ".wav";
std::string mp3Path = "assets/music/" + baseName + ".mp3";
// Check WAV first
if (fileExists(wavPath)) {
if (m_soundSystem->loadSound(id, wavPath)) {
logInfo("Loaded sound effect: " + id + " from " + wavPath + " (WAV)");
return true;
}
const std::string basePath = "assets/music/" + baseName;
std::string resolved = AssetPath::resolveWithExtensions(basePath, { ".wav", ".mp3" });
if (!resolved.empty() && m_soundSystem->loadSound(id, resolved)) {
logInfo("Loaded sound effect: " + id + " from " + resolved);
return true;
}
// Fallback to MP3
if (fileExists(mp3Path)) {
if (m_soundSystem->loadSound(id, mp3Path)) {
logInfo("Loaded sound effect: " + id + " from " + mp3Path + " (MP3 fallback)");
return true;
}
}
setError("Failed to load sound effect: " + id + " (tried both WAV and MP3)");
setError("Failed to load sound effect: " + id + " (no supported audio extension found)");
return false;
}