mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(audio): add footstep sounds and fix audio listener orientation
This commit is contained in:
@@ -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:
|
||||
|
||||
15
include/Cubed/audio/audio_error.hpp
Normal file
15
include/Cubed/audio/audio_error.hpp
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user