diff options
| author | untodesu <kirill@untode.su> | 2025-07-01 03:08:39 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-07-01 03:08:39 +0500 |
| commit | 458e0005690ea9d579588a0a12368fc2c2c9a93a (patch) | |
| tree | 588a9ca6cb3c76d9193b5bd4601d64f0e50e8c8c /game/client/world/voxel_sounds.cc | |
| parent | c7b0c8e0286a1b2bb7ec55e579137dfc3b22eeb9 (diff) | |
| download | voxelius-458e0005690ea9d579588a0a12368fc2c2c9a93a.tar.bz2 voxelius-458e0005690ea9d579588a0a12368fc2c2c9a93a.zip | |
I hyper-focued on refactoring again
- I put a cool-sounding "we are number one" remix on repeat and straight
up grinded the entire repository to a better state until 03:09 AM. I
guess I have something wrong in my brain that makes me do this shit
Diffstat (limited to 'game/client/world/voxel_sounds.cc')
| -rw-r--r-- | game/client/world/voxel_sounds.cc | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/game/client/world/voxel_sounds.cc b/game/client/world/voxel_sounds.cc new file mode 100644 index 0000000..235a851 --- /dev/null +++ b/game/client/world/voxel_sounds.cc @@ -0,0 +1,86 @@ +#include "client/pch.hh" + +#include "client/world/voxel_sounds.hh" + +#include "client/resource/sound_effect.hh" + +constexpr static std::size_t NUM_SURFACES = static_cast<std::size_t>(world::voxel_surface::COUNT); + +static std::vector<resource_ptr<SoundEffect>> footsteps_sounds[NUM_SURFACES]; +static std::mt19937_64 randomizer; + +static void add_footsteps_effect(world::voxel_surface surface, const char* name) +{ + if(auto effect = resource::load<SoundEffect>(name)) { + auto surface_index = static_cast<std::size_t>(surface); + footsteps_sounds[surface_index].push_back(effect); + } +} + +static resource_ptr<SoundEffect> get_footsteps_effect(world::voxel_surface surface) +{ + auto surface_index = static_cast<std::size_t>(surface); + + if(surface_index >= NUM_SURFACES) { + // Surface index out of range + return nullptr; + } + + const auto& sounds = footsteps_sounds[surface_index]; + + if(sounds.empty()) { + // No sounds for this surface + return nullptr; + } + + auto dist = std::uniform_int_distribution<std::size_t>(0, sounds.size() - 1); + return sounds.at(dist(randomizer)); +} + +void world::voxel_sounds::init(void) +{ + add_footsteps_effect(voxel_surface::DEFAULT, "sounds/surface/default1.wav"); + add_footsteps_effect(voxel_surface::DEFAULT, "sounds/surface/default2.wav"); + add_footsteps_effect(voxel_surface::DEFAULT, "sounds/surface/default3.wav"); + add_footsteps_effect(voxel_surface::DEFAULT, "sounds/surface/default4.wav"); + + add_footsteps_effect(voxel_surface::DIRT, "sounds/surface/dirt1.wav"); + + add_footsteps_effect(voxel_surface::GRASS, "sounds/surface/grass1.wav"); + add_footsteps_effect(voxel_surface::GRASS, "sounds/surface/grass2.wav"); + add_footsteps_effect(voxel_surface::GRASS, "sounds/surface/grass3.wav"); + + add_footsteps_effect(voxel_surface::GRAVEL, "sounds/surface/gravel1.wav"); + + add_footsteps_effect(voxel_surface::SAND, "sounds/surface/sand1.wav"); + add_footsteps_effect(voxel_surface::SAND, "sounds/surface/sand2.wav"); + + add_footsteps_effect(voxel_surface::WOOD, "sounds/surface/wood1.wav"); + add_footsteps_effect(voxel_surface::WOOD, "sounds/surface/wood2.wav"); + add_footsteps_effect(voxel_surface::WOOD, "sounds/surface/wood3.wav"); +} + +void world::voxel_sounds::shutdown(void) +{ + for(std::size_t i = 0; i < NUM_SURFACES; ++i) { + footsteps_sounds[i].clear(); + } +} + +resource_ptr<SoundEffect> world::voxel_sounds::get_footsteps(voxel_surface surface) +{ + if(auto effect = get_footsteps_effect(surface)) { + return effect; + } + + if(auto effect = get_footsteps_effect(voxel_surface::DEFAULT)) { + return effect; + } + + return nullptr; +} + +resource_ptr<SoundEffect> world::voxel_sounds::get_placebreak(voxel_surface surface) +{ + return nullptr; +} |
