From 458e0005690ea9d579588a0a12368fc2c2c9a93a Mon Sep 17 00:00:00 2001 From: untodesu Date: Tue, 1 Jul 2025 03:08:39 +0500 Subject: 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 --- src/game/client/sound_effect.cc | 115 ---------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 src/game/client/sound_effect.cc (limited to 'src/game/client/sound_effect.cc') diff --git a/src/game/client/sound_effect.cc b/src/game/client/sound_effect.cc deleted file mode 100644 index 182f49d..0000000 --- a/src/game/client/sound_effect.cc +++ /dev/null @@ -1,115 +0,0 @@ -#include "client/pch.hh" - -#include "client/sound_effect.hh" - -#include "core/resource.hh" - -#include "client/globals.hh" - -static emhash8::HashMap> resource_map; - -static std::size_t drwav_read_physfs(void* file, void* output, std::size_t count) -{ - return static_cast(PHYSFS_readBytes(reinterpret_cast(file), output, count)); -} - -static drwav_bool32 drwav_seek_physfs(void* file, int offset, drwav_seek_origin origin) -{ - if(origin == drwav_seek_origin_current) { - return PHYSFS_seek(reinterpret_cast(file), PHYSFS_tell(reinterpret_cast(file)) + offset); - } else { - return PHYSFS_seek(reinterpret_cast(file), offset); - } -} - -template<> -resource_ptr resource::load(const char* name, unsigned int flags) -{ - auto it = resource_map.find(name); - - if(it != resource_map.cend()) { - // Return an existing resource - return it->second; - } - - if(globals::sound_ctx == nullptr) { - // Sound is disabled - return nullptr; - } - - auto file = PHYSFS_openRead(name); - - if(file == nullptr) { - spdlog::warn("resource: {} [SoundEffect]: {}", name, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return nullptr; - } - - drwav wav_info; - - if(!drwav_init(&wav_info, &drwav_read_physfs, &drwav_seek_physfs, file, nullptr)) { - spdlog::warn("resource: {} [SoundEffect]: drwav_init failed", name); - PHYSFS_close(file); - return nullptr; - } - - if(wav_info.channels != 1) { - spdlog::warn("resource: {} [SoundEffect]: only mono sound files are allowed", name); - drwav_uninit(&wav_info); - PHYSFS_close(file); - return nullptr; - } - - auto samples = new ALshort[wav_info.totalPCMFrameCount]; - auto count = drwav_read_pcm_frames_s16(&wav_info, wav_info.totalPCMFrameCount, reinterpret_cast(samples)); - auto sample_rate = static_cast(wav_info.sampleRate); - auto length = static_cast(count * sizeof(ALshort)); - - drwav_uninit(&wav_info); - PHYSFS_close(file); - - auto new_resource = std::make_shared(); - new_resource->name = std::string(name); - - alGenBuffers(1, &new_resource->buffer); - alBufferData(new_resource->buffer, AL_FORMAT_MONO16, samples, length, sample_rate); - - delete[] samples; - - return resource_map.insert_or_assign(name, new_resource).first->second; -} - -template<> -void resource::hard_cleanup(void) -{ - for(const auto& it : resource_map) { - if(it.second.use_count() > 1L) { - spdlog::warn("resource: zombie resource [SoundEffect] {} [use_count={}]", it.first, it.second.use_count()); - } else { - spdlog::debug("resource: releasing [SoundEffect] {}", it.first); - } - - alDeleteBuffers(1, &it.second->buffer); - } - - resource_map.clear(); -} - -template<> -void resource::soft_cleanup(void) -{ - auto iter = resource_map.cbegin(); - - while(iter != resource_map.cend()) { - if(iter->second.use_count() == 1L) { - spdlog::debug("resource: releasing [SoundEffect] {}", iter->first); - - alDeleteBuffers(1, &iter->second->buffer); - - iter = resource_map.erase(iter); - - continue; - } - - iter = std::next(iter); - } -} -- cgit