feat(audio): add footstep sounds and fix audio listener orientation

This commit is contained in:
2026-07-07 11:20:17 +08:00
parent efd7af2c62
commit 68ddd78a6f
19 changed files with 137 additions and 27 deletions

View File

@@ -26,8 +26,10 @@ public:
void init();
void play_bgm();
void play_3d(const std::string& sound, const glm::vec3& pos);
void update_listener(glm::vec3 listener_pos);
void play_3d(const std::string& sound, const glm::vec3& pos,
bool check = false);
void update_listener(const glm::vec3& pos, const glm::vec3& forward,
const glm::vec3& up);
void update(float dt);
private:

View File

@@ -0,0 +1,15 @@
#pragma once
#include "Cubed/tools/log.hpp"
#include <AL/al.h>
namespace Cubed {
inline void check_al_error(
std::source_location loaction = std::source_location::current()) {
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
Logger::error("File {} Line {} Function {} OpenAL Error {} ",
loaction.file_name(), loaction.line(),
loaction.function_name(), alGetString(error));
}
}
} // namespace Cubed

View File

@@ -123,6 +123,8 @@ private:
float m_angle{0.0f};
float m_walk_time{0.0f};
float m_footstep_timer = 0.0f;
mutable std::shared_mutex m_player_pos_mutex;
mutable std::shared_mutex m_chunk_pos_mutex;
ChunkPosSet m_player_chunk_pos_set;
@@ -134,6 +136,7 @@ private:
void update_y_move(glm::vec3& player_pos);
void update_z_move(glm::vec3& player_pos);
void update_player_chunk();
void play_walk_sound(float dt);
Gait compute_gait() const;
};
} // namespace Cubed

View File

@@ -90,7 +90,7 @@ public:
bool is_receive_exit();
int chunk_size() const;
static AABB get_block_aabb(const glm::ivec3& pos);
AudioEngine& get_audio();
template <typename Fn>
void register_timer(std::string_view id, TickType threshold, Fn&& f) {
m_timers.emplace(std::piecewise_construct,