diff --git a/source/core/audio/audio_adapter.cpp b/source/core/audio/audio_adapter.cpp index 9221e5a..5ce2d6c 100644 --- a/source/core/audio/audio_adapter.cpp +++ b/source/core/audio/audio_adapter.cpp @@ -3,11 +3,11 @@ #include "core/resources/resource_cache.hpp" namespace AudioResource { - JA_Music_t* getMusic(const std::string& name) { + auto getMusic(const std::string& name) -> JA_Music_t* { return Resource::Cache::get()->getMusic(name); } - JA_Sound_t* getSound(const std::string& name) { + auto getSound(const std::string& name) -> JA_Sound_t* { return Resource::Cache::get()->getSound(name); } } // namespace AudioResource diff --git a/source/core/audio/audio_adapter.hpp b/source/core/audio/audio_adapter.hpp index a5eb16e..9c95864 100644 --- a/source/core/audio/audio_adapter.hpp +++ b/source/core/audio/audio_adapter.hpp @@ -12,6 +12,6 @@ struct JA_Music_t; struct JA_Sound_t; namespace AudioResource { - JA_Music_t* getMusic(const std::string& name); - JA_Sound_t* getSound(const std::string& name); + auto getMusic(const std::string& name) -> JA_Music_t*; + auto getSound(const std::string& name) -> JA_Sound_t*; } // namespace AudioResource diff --git a/source/core/audio/jail_audio.hpp b/source/core/audio/jail_audio.hpp index c0e1bf7..4eba538 100644 --- a/source/core/audio/jail_audio.hpp +++ b/source/core/audio/jail_audio.hpp @@ -2,10 +2,10 @@ // --- Includes --- #include -#include // Para uint32_t, uint8_t -#include // Para NULL, fseek, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET -#include // Para free, malloc +#include // Para uint32_t, uint8_t +#include // Para NULL, fseek, fclose, fopen, fread, ftell, FILE, SEEK_END, SEEK_SET +#include // Para free, malloc #include // Para std::cout #include // Para std::unique_ptr #include // Para std::string @@ -84,7 +84,7 @@ inline JA_Music_t* current_music{nullptr}; inline JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS]; inline SDL_AudioSpec JA_audioSpec{SDL_AUDIO_S16, 2, 48000}; -inline float JA_musicVolume{1.0f}; +inline float JA_musicVolume{1.0F}; inline float JA_soundVolume[JA_MAX_GROUPS]; inline bool JA_musicEnabled{true}; inline bool JA_soundEnabled{true}; @@ -95,7 +95,7 @@ struct JA_FadeState { bool active{false}; Uint64 start_time{0}; int duration_ms{0}; - float initial_volume{0.0f}; + float initial_volume{0.0F}; }; struct JA_OutgoingMusic { @@ -109,7 +109,7 @@ inline JA_FadeState incoming_fade; // --- Forward Declarations --- inline void JA_StopMusic(); inline void JA_StopChannel(const int channel); -inline int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop = 0, const int group = 0); +inline auto JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop = 0, const int group = 0) -> int; inline void JA_CrossfadeMusic(JA_Music_t* music, int crossfade_ms, int loop = -1); // --- Music streaming internals --- @@ -120,11 +120,11 @@ static constexpr int JA_MUSIC_BYTES_PER_SAMPLE = 2; static constexpr int JA_MUSIC_CHUNK_SHORTS = 8192; // Umbral d'audio per davant del cursor de reproducció. Mantenim ≥ 0.5 s a // l'SDL_AudioStream per absorbir jitter de frame i evitar underruns. -static constexpr float JA_MUSIC_LOW_WATER_SECONDS = 0.5f; +static constexpr float JA_MUSIC_LOW_WATER_SECONDS = 0.5F; // Decodifica un chunk del vorbis i el volca a l'stream. Retorna samples // decodificats per canal (0 = EOF de l'stream vorbis). -inline int JA_FeedMusicChunk(JA_Music_t* music) { +inline auto JA_FeedMusicChunk(JA_Music_t* music) -> int { if (!music || !music->vorbis || !music->stream) return 0; short chunk[JA_MUSIC_CHUNK_SHORTS]; @@ -192,7 +192,7 @@ inline void JA_Update() { outgoing_music.fade.active = false; } else { float percent = (float)elapsed / (float)outgoing_music.fade.duration_ms; - SDL_SetAudioStreamGain(outgoing_music.stream, outgoing_music.fade.initial_volume * (1.0f - percent)); + SDL_SetAudioStreamGain(outgoing_music.stream, outgoing_music.fade.initial_volume * (1.0F - percent)); } } @@ -241,7 +241,7 @@ inline void JA_Init(const int freq, const SDL_AudioFormat format, const int num_ sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec); if (sdlAudioDevice == 0) std::cout << "Failed to initialize SDL audio!" << '\n'; for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE; - for (int i = 0; i < JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f; + for (int i = 0; i < JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5F; } inline void JA_Quit() { @@ -255,7 +255,7 @@ inline void JA_Quit() { // --- Music Functions --- -inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) { +inline auto JA_LoadMusic(const Uint8* buffer, Uint32 length) -> JA_Music_t* { if (!buffer || length == 0) return nullptr; // Allocem el JA_Music_t primer per aprofitar el seu `std::vector` @@ -287,13 +287,13 @@ inline JA_Music_t* JA_LoadMusic(const Uint8* buffer, Uint32 length) { // Overload amb filename — els callers l'usen per poder comparar la música // en curs amb JA_GetMusicFilename() i no rearrancar-la si ja és la mateixa. -inline JA_Music_t* JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename) { +inline auto JA_LoadMusic(Uint8* buffer, Uint32 length, const char* filename) -> JA_Music_t* { JA_Music_t* music = JA_LoadMusic(static_cast(buffer), length); if (music && filename) music->filename = filename; return music; } -inline JA_Music_t* JA_LoadMusic(const char* filename) { +inline auto JA_LoadMusic(const char* filename) -> JA_Music_t* { // Carreguem primer el arxiu en memòria i després el descomprimim. FILE* f = fopen(filename, "rb"); if (!f) return nullptr; @@ -351,7 +351,7 @@ inline void JA_PlayMusic(JA_Music_t* music, const int loop = -1) { } } -inline const char* JA_GetMusicFilename(const JA_Music_t* music = nullptr) { +inline auto JA_GetMusicFilename(const JA_Music_t* music = nullptr) -> const char* { if (!music) music = current_music; if (!music || music->filename.empty()) return nullptr; return music->filename.c_str(); @@ -455,15 +455,15 @@ inline void JA_CrossfadeMusic(JA_Music_t* music, const int crossfade_ms, const i current_music->state = JA_MUSIC_STOPPED; return; } - SDL_SetAudioStreamGain(current_music->stream, 0.0f); + SDL_SetAudioStreamGain(current_music->stream, 0.0F); JA_PumpMusic(current_music); // pre-carrega abans de bindejar SDL_BindAudioStream(sdlAudioDevice, current_music->stream); // Configurar fade-in - incoming_fade = {true, SDL_GetTicks(), crossfade_ms, 0.0f}; + incoming_fade = {true, SDL_GetTicks(), crossfade_ms, 0.0F}; } -inline JA_Music_state JA_GetMusicState() { +inline auto JA_GetMusicState() -> JA_Music_state { if (!JA_musicEnabled) return JA_MUSIC_DISABLED; if (!current_music) return JA_MUSIC_INVALID; @@ -483,8 +483,8 @@ inline void JA_DeleteMusic(JA_Music_t* music) { delete music; } -inline float JA_SetMusicVolume(float volume) { - JA_musicVolume = SDL_clamp(volume, 0.0f, 1.0f); +inline auto JA_SetMusicVolume(float volume) -> float { + JA_musicVolume = SDL_clamp(volume, 0.0F, 1.0F); if (current_music && current_music->stream) { SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume); } @@ -495,8 +495,8 @@ inline void JA_SetMusicPosition(float /*value*/) { // No implementat amb el backend de streaming. } -inline float JA_GetMusicPosition() { - return 0.0f; +inline auto JA_GetMusicPosition() -> float { + return 0.0F; } inline void JA_EnableMusic(const bool value) { @@ -506,7 +506,7 @@ inline void JA_EnableMusic(const bool value) { // --- Sound Functions --- -inline JA_Sound_t* JA_LoadSound(uint8_t* buffer, uint32_t size) { +inline auto JA_LoadSound(uint8_t* buffer, uint32_t size) -> JA_Sound_t* { auto sound = std::make_unique(); Uint8* raw = nullptr; if (!SDL_LoadWAV_IO(SDL_IOFromMem(buffer, size), 1, &sound->spec, &raw, &sound->length)) { @@ -517,7 +517,7 @@ inline JA_Sound_t* JA_LoadSound(uint8_t* buffer, uint32_t size) { return sound.release(); } -inline JA_Sound_t* JA_LoadSound(const char* filename) { +inline auto JA_LoadSound(const char* filename) -> JA_Sound_t* { auto sound = std::make_unique(); Uint8* raw = nullptr; if (!SDL_LoadWAV(filename, &sound->spec, &raw, &sound->length)) { @@ -528,7 +528,7 @@ inline JA_Sound_t* JA_LoadSound(const char* filename) { return sound.release(); } -inline int JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group = 0) { +inline auto JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group = 0) -> int { if (!JA_soundEnabled || !sound) return -1; int channel = 0; @@ -541,7 +541,7 @@ inline int JA_PlaySound(JA_Sound_t* sound, const int loop = 0, const int group = return JA_PlaySoundOnChannel(sound, channel, loop, group); } -inline int JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop, const int group) { +inline auto JA_PlaySoundOnChannel(JA_Sound_t* sound, const int channel, const int loop, const int group) -> int { if (!JA_soundEnabled || !sound) return -1; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return -1; @@ -632,15 +632,15 @@ inline void JA_StopChannel(const int channel) { } } -inline JA_Channel_state JA_GetChannelState(const int channel) { +inline auto JA_GetChannelState(const int channel) -> JA_Channel_state { if (!JA_soundEnabled) return JA_SOUND_DISABLED; if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; return channels[channel].state; } -inline float JA_SetSoundVolume(float volume, const int group = -1) { - const float v = SDL_clamp(volume, 0.0f, 1.0f); +inline auto JA_SetSoundVolume(float volume, const int group = -1) -> float { + const float v = SDL_clamp(volume, 0.0F, 1.0F); if (group == -1) { for (int i = 0; i < JA_MAX_GROUPS; ++i) { @@ -672,7 +672,7 @@ inline void JA_EnableSound(const bool value) { JA_soundEnabled = value; } -inline float JA_SetVolume(float volume) { +inline auto JA_SetVolume(float volume) -> float { float v = JA_SetMusicVolume(volume); JA_SetSoundVolume(v, -1); return v; diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 7ccfd4f..84c0d5b 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -379,7 +379,7 @@ namespace Resource { std::string text_file; // Nombre del archivo de texto }; - const std::vector& getTextObjectInfos() { + auto getTextObjectInfos() -> const std::vector& { static const std::vector info = { {.key = "aseprite", .texture_file = "aseprite.gif", .text_file = "aseprite.fnt"}, {.key = "gauntlet", .texture_file = "gauntlet.gif", .text_file = "gauntlet.fnt"}, diff --git a/source/game/ui/notifier.cpp b/source/game/ui/notifier.cpp index 138449a..6086dbf 100644 --- a/source/game/ui/notifier.cpp +++ b/source/game/ui/notifier.cpp @@ -75,7 +75,7 @@ void Notifier::render() { // Actualiza el estado de las notificaiones void Notifier::update(float delta_time) { // Base Y leída cada frame: cada notificación se dibuja en rect.y (relativo a BASE) + BASE - const float BASE = static_cast(getStackBaseY()); + const auto BASE = static_cast(getStackBaseY()); for (auto& notification : notifications_) { // Si la notificación anterior está "entrando", no hagas nada (stall del resto) @@ -88,7 +88,7 @@ void Notifier::update(float delta_time) { switch (notification.state) { case Status::RISING: { - const float TARGET = static_cast(notification.y); + const auto TARGET = static_cast(notification.y); notification.rect.y += SLIDE_SPEED * delta_time; if (notification.rect.y >= TARGET) { notification.rect.y = TARGET; @@ -107,7 +107,7 @@ void Notifier::update(float delta_time) { } case Status::VANISHING: { - const float TARGET_Y = static_cast(notification.y - notification.travel_dist); + const auto TARGET_Y = static_cast(notification.y - notification.travel_dist); notification.rect.y -= SLIDE_SPEED * delta_time; if (notification.rect.y <= TARGET_Y) { notification.rect.y = TARGET_Y; diff --git a/source/main.cpp b/source/main.cpp index c2b1c92..e46b416 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -10,16 +10,16 @@ Empezado en Castalla el 01/07/2022. #include "core/system/director.hpp" -SDL_AppResult SDL_AppInit(void** appstate, int /*argc*/, char* /*argv*/[]) { +auto SDL_AppInit(void** appstate, int /*argc*/, char* /*argv*/[]) -> SDL_AppResult { *appstate = new Director(); return SDL_APP_CONTINUE; } -SDL_AppResult SDL_AppIterate(void* appstate) { +auto SDL_AppIterate(void* appstate) -> SDL_AppResult { return static_cast(appstate)->iterate(); } -SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) { +auto SDL_AppEvent(void* appstate, SDL_Event* event) -> SDL_AppResult { return static_cast(appstate)->handleEvent(*event); }