From d0fbd68055e3f4a796330cc8acc6c0954b5327ff Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 15:48:53 +0500 Subject: Run clang-format across the project --- game/client/resource/sound_effect.cc | 180 +++++++++++++++++------------------ game/client/resource/sound_effect.hh | 16 ++-- game/client/resource/texture_gui.cc | 166 ++++++++++++++++---------------- game/client/resource/texture_gui.hh | 30 +++--- 4 files changed, 196 insertions(+), 196 deletions(-) (limited to 'game/client/resource') diff --git a/game/client/resource/sound_effect.cc b/game/client/resource/sound_effect.cc index 4fb3e82..d6cc7c5 100644 --- a/game/client/resource/sound_effect.cc +++ b/game/client/resource/sound_effect.cc @@ -1,90 +1,90 @@ -#include "client/pch.hh" - -#include "client/resource/sound_effect.hh" - -#include "core/resource/resource.hh" - -#include "core/utils/physfs.hh" - -#include "client/globals.hh" - -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); - } -} - -static const void* sound_effect_load_func(const char* name, std::uint32_t flags) -{ - assert(name); - - if(globals::sound_ctx == nullptr) { - // Sound is disabled - return nullptr; - } - - auto file = PHYSFS_openRead(name); - - if(file == nullptr) { - spdlog::warn("sfx: {}: {}", name, utils::physfs_error()); - return nullptr; - } - - drwav wav_info; - - if(!drwav_init(&wav_info, &drwav_read_physfs, &drwav_seek_physfs, file, nullptr)) { - spdlog::warn("sfx: {}: drwav_init failed", name); - PHYSFS_close(file); - return nullptr; - } - - if(wav_info.channels != 1) { - spdlog::warn("sfx: {}: 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 = new SoundEffect(); - 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 new_resource; -} - -static void sound_effect_free_func(const void* resource) -{ - assert(resource); - - auto sound_effect = reinterpret_cast(resource); - - alDeleteBuffers(1, &sound_effect->buffer); - - delete sound_effect; -} - -void SoundEffect::register_resource(void) -{ - resource::register_loader(&sound_effect_load_func, &sound_effect_free_func); -} +#include "client/pch.hh" + +#include "client/resource/sound_effect.hh" + +#include "core/resource/resource.hh" + +#include "core/utils/physfs.hh" + +#include "client/globals.hh" + +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); + } +} + +static const void* sound_effect_load_func(const char* name, std::uint32_t flags) +{ + assert(name); + + if(globals::sound_ctx == nullptr) { + // Sound is disabled + return nullptr; + } + + auto file = PHYSFS_openRead(name); + + if(file == nullptr) { + spdlog::warn("sfx: {}: {}", name, utils::physfs_error()); + return nullptr; + } + + drwav wav_info; + + if(!drwav_init(&wav_info, &drwav_read_physfs, &drwav_seek_physfs, file, nullptr)) { + spdlog::warn("sfx: {}: drwav_init failed", name); + PHYSFS_close(file); + return nullptr; + } + + if(wav_info.channels != 1) { + spdlog::warn("sfx: {}: 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 = new SoundEffect(); + 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 new_resource; +} + +static void sound_effect_free_func(const void* resource) +{ + assert(resource); + + auto sound_effect = reinterpret_cast(resource); + + alDeleteBuffers(1, &sound_effect->buffer); + + delete sound_effect; +} + +void SoundEffect::register_resource(void) +{ + resource::register_loader(&sound_effect_load_func, &sound_effect_free_func); +} diff --git a/game/client/resource/sound_effect.hh b/game/client/resource/sound_effect.hh index f2db33b..ab68ed2 100644 --- a/game/client/resource/sound_effect.hh +++ b/game/client/resource/sound_effect.hh @@ -1,8 +1,8 @@ -#pragma once - -struct SoundEffect final { - static void register_resource(void); - - std::string name; - ALuint buffer; -}; +#pragma once + +struct SoundEffect final { + static void register_resource(void); + + std::string name; + ALuint buffer; +}; diff --git a/game/client/resource/texture_gui.cc b/game/client/resource/texture_gui.cc index beb2f54..be8a6ed 100644 --- a/game/client/resource/texture_gui.cc +++ b/game/client/resource/texture_gui.cc @@ -1,83 +1,83 @@ -#include "client/pch.hh" - -#include "client/resource/texture_gui.hh" - -#include "core/resource/image.hh" -#include "core/resource/resource.hh" - -static const void* texture_gui_load_func(const char* name, std::uint32_t flags) -{ - assert(name); - - unsigned int image_load_flags = 0U; - - if(flags & TEXTURE_GUI_LOAD_VFLIP) { - image_load_flags |= IMAGE_LOAD_FLIP; - } - - if(flags & TEXTURE_GUI_LOAD_GRAYSCALE) { - image_load_flags |= IMAGE_LOAD_GRAY; - } - - if(auto image = resource::load(name, image_load_flags)) { - GLuint gl_texture; - - glGenTextures(1, &gl_texture); - glBindTexture(GL_TEXTURE_2D, gl_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->size.x, image->size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); - - if(flags & TEXTURE_GUI_LOAD_CLAMP_S) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - } - else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - } - - if(flags & TEXTURE_GUI_LOAD_CLAMP_T) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - } - else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } - - if(flags & TEXTURE_GUI_LOAD_LINEAR_MAG) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } - else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } - - if(flags & TEXTURE_GUI_LOAD_LINEAR_MIN) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } - else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - - auto new_resource = new TextureGUI(); - new_resource->handle = static_cast(gl_texture); - new_resource->size.x = image->size.x; - new_resource->size.y = image->size.y; - - return new_resource; - } - - return nullptr; -} - -static void texture_gui_free_func(const void* resource) -{ - assert(resource); - - auto texture_gui = reinterpret_cast(resource); - auto gl_texture = static_cast(texture_gui->handle); - - glDeleteTextures(1, &gl_texture); - - delete texture_gui; -} - -void TextureGUI::register_resource(void) -{ - resource::register_loader(&texture_gui_load_func, &texture_gui_free_func); -} +#include "client/pch.hh" + +#include "client/resource/texture_gui.hh" + +#include "core/resource/image.hh" +#include "core/resource/resource.hh" + +static const void* texture_gui_load_func(const char* name, std::uint32_t flags) +{ + assert(name); + + unsigned int image_load_flags = 0U; + + if(flags & TEXTURE_GUI_LOAD_VFLIP) { + image_load_flags |= IMAGE_LOAD_FLIP; + } + + if(flags & TEXTURE_GUI_LOAD_GRAYSCALE) { + image_load_flags |= IMAGE_LOAD_GRAY; + } + + if(auto image = resource::load(name, image_load_flags)) { + GLuint gl_texture; + + glGenTextures(1, &gl_texture); + glBindTexture(GL_TEXTURE_2D, gl_texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->size.x, image->size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); + + if(flags & TEXTURE_GUI_LOAD_CLAMP_S) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + } + + if(flags & TEXTURE_GUI_LOAD_CLAMP_T) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + + if(flags & TEXTURE_GUI_LOAD_LINEAR_MAG) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + if(flags & TEXTURE_GUI_LOAD_LINEAR_MIN) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + + auto new_resource = new TextureGUI(); + new_resource->handle = static_cast(gl_texture); + new_resource->size.x = image->size.x; + new_resource->size.y = image->size.y; + + return new_resource; + } + + return nullptr; +} + +static void texture_gui_free_func(const void* resource) +{ + assert(resource); + + auto texture_gui = reinterpret_cast(resource); + auto gl_texture = static_cast(texture_gui->handle); + + glDeleteTextures(1, &gl_texture); + + delete texture_gui; +} + +void TextureGUI::register_resource(void) +{ + resource::register_loader(&texture_gui_load_func, &texture_gui_free_func); +} diff --git a/game/client/resource/texture_gui.hh b/game/client/resource/texture_gui.hh index 2d42c83..9ce0535 100644 --- a/game/client/resource/texture_gui.hh +++ b/game/client/resource/texture_gui.hh @@ -1,15 +1,15 @@ -#pragma once - -constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_S = 0x0001; -constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_T = 0x0002; -constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MAG = 0x0004; -constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MIN = 0x0008; -constexpr static unsigned int TEXTURE_GUI_LOAD_VFLIP = 0x0010; -constexpr static unsigned int TEXTURE_GUI_LOAD_GRAYSCALE = 0x0020; - -struct TextureGUI final { - static void register_resource(void); - - ImTextureID handle; - glm::ivec2 size; -}; +#pragma once + +constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_S = 0x0001; +constexpr static unsigned int TEXTURE_GUI_LOAD_CLAMP_T = 0x0002; +constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MAG = 0x0004; +constexpr static unsigned int TEXTURE_GUI_LOAD_LINEAR_MIN = 0x0008; +constexpr static unsigned int TEXTURE_GUI_LOAD_VFLIP = 0x0010; +constexpr static unsigned int TEXTURE_GUI_LOAD_GRAYSCALE = 0x0020; + +struct TextureGUI final { + static void register_resource(void); + + ImTextureID handle; + glm::ivec2 size; +}; -- cgit