diff --git a/src/audio/player.cpp b/src/audio/player.cpp index 221f72d..7478acb 100644 --- a/src/audio/player.cpp +++ b/src/audio/player.cpp @@ -3,10 +3,10 @@ audio::Player::Player(Master& master) : master_(master) {} audio::SoundSource* audio::Player::PlaySound(const std::shared_ptr& sound, - const glm::vec3* attach_position) + const game::TransformNode* attach_node) { SoundSource* source = new SoundSource(this, sound); - source->AttachToPosition(attach_position); + source->AttachToNode(attach_node); return source; } diff --git a/src/audio/player.hpp b/src/audio/player.hpp index f541caa..f20e87d 100644 --- a/src/audio/player.hpp +++ b/src/audio/player.hpp @@ -14,7 +14,7 @@ public: Player(Master& master); DELETE_COPY_MOVE(Player) - SoundSource* PlaySound(const std::shared_ptr& sound, const glm::vec3* attach_position); + SoundSource* PlaySound(const std::shared_ptr& sound, const game::TransformNode* attach_node); void Update(); diff --git a/src/audio/source.cpp b/src/audio/source.cpp index 52ea8c6..096f95e 100644 --- a/src/audio/source.cpp +++ b/src/audio/source.cpp @@ -47,12 +47,11 @@ void audio::Source::SetVelocity(const glm::vec3& velocity) alSource3f(source_, AL_VELOCITY, velocity.x, velocity.y, velocity.z); } -void audio::Source::AttachToPosition(const glm::vec3* position) +void audio::Source::AttachToNode(const game::TransformNode* node) { - attach_position_ = position; - if (attach_position_) - SetPosition(*attach_position_); - // TsrDebugf(DML_2, "Attached source %p to position %p\n", this, position); + attach_node_ = node; + if (attach_node_) + SetPosition(attach_node_->GetGlobalPosition()); } void audio::Source::SetRelativeToListener(bool relative) @@ -71,8 +70,8 @@ void audio::Source::SetRelativeToListener(bool relative) void audio::Source::Update() { - if (attach_position_) - SetPosition(*attach_position_); + if (attach_node_) + SetPosition(attach_node_->GetGlobalPosition()); } void audio::Source::Delete() diff --git a/src/audio/source.hpp b/src/audio/source.hpp index 2bc9422..8c1ddca 100644 --- a/src/audio/source.hpp +++ b/src/audio/source.hpp @@ -3,6 +3,8 @@ #include "master.hpp" #include +#include "game/transform_node.hpp" + namespace audio { @@ -24,7 +26,7 @@ public: void SetPosition(const glm::vec3& position); void SetVelocity(const glm::vec3& velocity); - void AttachToPosition(const glm::vec3* position); + void AttachToNode(const game::TransformNode* node); void SetRelativeToListener(bool relative); virtual void SetLooping(bool looping) = 0; @@ -45,7 +47,7 @@ protected: unsigned int source_ = 0; - const glm::vec3* attach_position_ = nullptr; + const game::TransformNode* attach_node_ = nullptr; bool should_play_ = true; // auto play when created bool finished_ = false; bool delete_on_finish_ = true; // auto delete when finished diff --git a/src/gameview/entityview.cpp b/src/gameview/entityview.cpp index db4e9c5..d674d66 100644 --- a/src/gameview/entityview.cpp +++ b/src/gameview/entityview.cpp @@ -103,7 +103,7 @@ bool game::view::EntityView::ProcessPlaySoundMsg(net::InMessage& msg) return true; // dont play if not loaded yet auto sound = assets::CacheManager::GetSound("data/" + std::string(name) + ".snd"); - auto snd = audioplayer_.PlaySound(sound, &root_.local.position); + auto snd = audioplayer_.PlaySound(sound, &root_); snd->SetVolume(volume); snd->SetPitch(pitch); diff --git a/src/gameview/vehicleview.cpp b/src/gameview/vehicleview.cpp index a5a6063..26092e5 100644 --- a/src/gameview/vehicleview.cpp +++ b/src/gameview/vehicleview.cpp @@ -387,7 +387,7 @@ void game::view::VehicleView::UpdateSounds() if (accel && !snd_accel_src_) { - snd_accel_src_ = audioplayer_.PlaySound(snd_accel_, &root_.local.position); + snd_accel_src_ = audioplayer_.PlaySound(snd_accel_, &root_); snd_accel_src_->SetLooping(true); } else if (!accel && snd_accel_src_)