feat(gameplay): add ocean wave ambient sounds with random selection

Add four ocean wave FLAC sound files and play one randomly when player is within 10 blocks of sea level and in an ocean biome. Include a Random member initialized from ChunkGenerator seed for consistent randomization.
This commit is contained in:
2026-07-07 16:50:59 +08:00
parent 6b3872dc97
commit f36b05e2fd
6 changed files with 26 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -6,6 +6,7 @@
#include "Cubed/gameplay/client_player.hpp"
#include "Cubed/gameplay/game_time.hpp"
#include "Cubed/gameplay/network_client.hpp"
#include "Cubed/tools/cubed_random.hpp"
#include "Cubed/tools/priority_thread_pool.hpp"
#include <absl/container/flat_hash_set.h>
@@ -153,6 +154,8 @@ private:
std::atomic<std::shared_ptr<PriorityThreadPool>> m_thread_pool;
Random m_random;
void client_run(std::stop_token token);
void report_player_info();

View File

@@ -1,6 +1,7 @@
#include "Cubed/gameplay/client_world.hpp"
#include "Cubed/config.hpp"
#include "Cubed/gameplay/chunk_generator.hpp"
#include "Cubed/gameplay/game_time.hpp"
#include "Cubed/gameplay/packet.hpp"
#include "Cubed/tools/math_tools.hpp"
@@ -357,6 +358,8 @@ void ClientWorld::init(std::string_view player_name,
std::shared_ptr<NetworkClient> client) {
m_player.init(player_name);
m_client = client;
m_random.init(ChunkGenerator::seed());
// timer
register_ticktimer("player_pos", 1, [this]() { report_player_info(); });
m_timers.try_emplace("Birds Sound", 60.0f, [this]() {
@@ -375,6 +378,26 @@ void ClientWorld::init(std::string_view player_name,
}
});
m_timers.try_emplace("Ocean Wave", 3.0f, [this]() {
auto player_pos = m_player.get_player_pos();
if (player_pos.y < SEA_LEVEL - 10 || player_pos.y > SEA_LEVEL + 10) {
return;
}
auto ans = m_random.random_int(1, 4);
std::string sound =
"ambient/ocean/wave00" + std::to_string(ans) + ".flac";
ChunkPos pos = get_chunk_pos(player_pos.x, player_pos.z);
{
chunk_cacc cacc;
if (m_chunks.find(cacc, pos)) {
if (cacc->second->get_biome() == BiomeType::OCEAN) {
m_audio.play_2d(sound, true);
}
}
}
});
LoginReq req;
req.set_name(m_player.get_name());
while (!client->is_connected()) {