mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-02 15:53:51 +00:00
Implement MPQ-path sound loading in AudioEngine
Add AssetManager hookup to AudioEngine so the path-based playSound2D/3D overloads can load files on demand rather than requiring preloading. - Add setAssetManager() to AudioEngine (called during world load alongside other audio manager initializations) - playSound2D(mpqPath) now calls assetManager->readFile() then delegates to the vector<uint8_t> overload (removes the "not yet implemented" warning) - playSound3D(mpqPath, position) same — delegates to the fully spatialized vector overload (was previously silently falling back to 2D)
This commit is contained in:
parent
e73bedd78b
commit
c998c945bf
3 changed files with 28 additions and 6 deletions
|
|
@ -11,6 +11,7 @@ struct ma_engine;
|
||||||
struct ma_sound;
|
struct ma_sound;
|
||||||
|
|
||||||
namespace wowee {
|
namespace wowee {
|
||||||
|
namespace pipeline { class AssetManager; }
|
||||||
namespace audio {
|
namespace audio {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,6 +33,9 @@ public:
|
||||||
void setMasterVolume(float volume);
|
void setMasterVolume(float volume);
|
||||||
float getMasterVolume() const { return masterVolume_; }
|
float getMasterVolume() const { return masterVolume_; }
|
||||||
|
|
||||||
|
// Asset manager (enables sound loading by MPQ path)
|
||||||
|
void setAssetManager(pipeline::AssetManager* am) { assetManager_ = am; }
|
||||||
|
|
||||||
// 3D listener position (for positional audio)
|
// 3D listener position (for positional audio)
|
||||||
void setListenerPosition(const glm::vec3& position);
|
void setListenerPosition(const glm::vec3& position);
|
||||||
void setListenerOrientation(const glm::vec3& forward, const glm::vec3& up);
|
void setListenerOrientation(const glm::vec3& forward, const glm::vec3& up);
|
||||||
|
|
@ -81,6 +85,8 @@ private:
|
||||||
glm::vec3 listenerForward_{0.0f, 0.0f, -1.0f};
|
glm::vec3 listenerForward_{0.0f, 0.0f, -1.0f};
|
||||||
glm::vec3 listenerUp_{0.0f, 1.0f, 0.0f};
|
glm::vec3 listenerUp_{0.0f, 1.0f, 0.0f};
|
||||||
|
|
||||||
|
pipeline::AssetManager* assetManager_ = nullptr;
|
||||||
|
|
||||||
// miniaudio engine (opaque pointer)
|
// miniaudio engine (opaque pointer)
|
||||||
ma_engine* engine_ = nullptr;
|
ma_engine* engine_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "core/logger.hpp"
|
#include "core/logger.hpp"
|
||||||
#include "pipeline/asset_manager.hpp"
|
#include "pipeline/asset_manager.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "../../extern/miniaudio.h"
|
#include "../../extern/miniaudio.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -285,10 +286,16 @@ bool AudioEngine::playSound2D(const std::vector<uint8_t>& wavData, float volume,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioEngine::playSound2D(const std::string& mpqPath, float volume, float pitch) {
|
bool AudioEngine::playSound2D(const std::string& mpqPath, float volume, float pitch) {
|
||||||
// TODO: Load from AssetManager
|
if (!assetManager_) {
|
||||||
// For now, return false (not implemented)
|
LOG_WARNING("AudioEngine::playSound2D(path): no AssetManager set");
|
||||||
LOG_WARNING("AudioEngine::playSound2D from MPQ path not yet implemented");
|
return false;
|
||||||
return false;
|
}
|
||||||
|
auto data = assetManager_->readFile(mpqPath);
|
||||||
|
if (data.empty()) {
|
||||||
|
LOG_WARNING("AudioEngine::playSound2D: failed to load '", mpqPath, "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return playSound2D(data, volume, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioEngine::playSound3D(const std::vector<uint8_t>& wavData, const glm::vec3& position,
|
bool AudioEngine::playSound3D(const std::vector<uint8_t>& wavData, const glm::vec3& position,
|
||||||
|
|
@ -367,8 +374,16 @@ bool AudioEngine::playSound3D(const std::vector<uint8_t>& wavData, const glm::ve
|
||||||
|
|
||||||
bool AudioEngine::playSound3D(const std::string& mpqPath, const glm::vec3& position,
|
bool AudioEngine::playSound3D(const std::string& mpqPath, const glm::vec3& position,
|
||||||
float volume, float pitch, float maxDistance) {
|
float volume, float pitch, float maxDistance) {
|
||||||
// TODO: Implement 3D positional audio
|
if (!assetManager_) {
|
||||||
return playSound2D(mpqPath, volume, pitch);
|
LOG_WARNING("AudioEngine::playSound3D(path): no AssetManager set");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto data = assetManager_->readFile(mpqPath);
|
||||||
|
if (data.empty()) {
|
||||||
|
LOG_WARNING("AudioEngine::playSound3D: failed to load '", mpqPath, "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return playSound3D(data, position, volume, pitch, maxDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioEngine::playMusic(const std::vector<uint8_t>& musicData, float volume, bool loop) {
|
bool AudioEngine::playMusic(const std::vector<uint8_t>& musicData, float volume, bool loop) {
|
||||||
|
|
|
||||||
|
|
@ -3016,6 +3016,7 @@ bool Renderer::loadTestTerrain(pipeline::AssetManager* assetManager, const std::
|
||||||
|
|
||||||
// Initialize music manager with asset manager
|
// Initialize music manager with asset manager
|
||||||
if (musicManager && assetManager && !cachedAssetManager) {
|
if (musicManager && assetManager && !cachedAssetManager) {
|
||||||
|
audio::AudioEngine::instance().setAssetManager(assetManager);
|
||||||
musicManager->initialize(assetManager);
|
musicManager->initialize(assetManager);
|
||||||
if (footstepManager) {
|
if (footstepManager) {
|
||||||
footstepManager->initialize(assetManager);
|
footstepManager->initialize(assetManager);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue