neteja tidy: ranges::fill, default member init, NOLINT _USE_MATH_DEFINES

This commit is contained in:
2026-05-17 08:05:30 +02:00
parent ab858aacb8
commit a39cd45bf1
19 changed files with 69 additions and 89 deletions
+2 -2
View File
@@ -259,7 +259,7 @@ namespace Ja {
sdl_audio_device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_spec); sdl_audio_device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audio_spec);
if (sdl_audio_device == 0) { std::cout << "Failed to initialize SDL audio!" << '\n'; } if (sdl_audio_device == 0) { std::cout << "Failed to initialize SDL audio!" << '\n'; }
for (auto& ch : channels) { ch.state = ChannelState::FREE; } for (auto& ch : channels) { ch.state = ChannelState::FREE; }
std::fill(std::begin(sound_volume), std::end(sound_volume), 0.5F); std::ranges::fill(sound_volume, 0.5F);
} }
inline void quit() { inline void quit() {
@@ -663,7 +663,7 @@ namespace Ja {
const float V = SDL_clamp(volume, 0.0F, 1.0F); const float V = SDL_clamp(volume, 0.0F, 1.0F);
if (group == -1) { if (group == -1) {
std::fill(std::begin(sound_volume), std::end(sound_volume), V); std::ranges::fill(sound_volume, V);
} else if (group >= 0 && group < MAX_GROUPS) { } else if (group >= 0 && group < MAX_GROUPS) {
sound_volume[group] = V; sound_volume[group] = V;
} else { } else {
+1
View File
@@ -1,3 +1,4 @@
// NOLINTNEXTLINE(bugprone-reserved-identifier) -- requerido por <cmath> para exponer M_PI en MSVC
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include "core/rendering/background.hpp" #include "core/rendering/background.hpp"
+1 -9
View File
@@ -20,13 +20,10 @@
#include "core/rendering/text.hpp" // Para Text #include "core/rendering/text.hpp" // Para Text
#include "core/rendering/texture.hpp" // Para Texture #include "core/rendering/texture.hpp" // Para Texture
#include "core/resources/asset.hpp" // Para Asset #include "core/resources/asset.hpp" // Para Asset
#include "core/resources/resource.hpp" // Para Resource
#include "core/system/director.hpp" // Para Director::debug_config
#include "game/options.hpp" // Para Video, video, Window, window #include "game/options.hpp" // Para Video, video, Window, window
#include "game/ui/notifier.hpp" // Para Notifier #include "game/ui/notifier.hpp" // Para Notifier
#include "game/ui/service_menu.hpp" // Para ServiceMenu #include "game/ui/service_menu.hpp" // Para ServiceMenu
#include "utils/param.hpp" // Para Param, param, ParamGame, ParamDebug #include "utils/param.hpp" // Para Param, param, ParamGame, ParamDebug
#include "utils/utils.hpp" // Para toLower
// Singleton // Singleton
Screen* Screen::instance = nullptr; Screen* Screen::instance = nullptr;
@@ -82,12 +79,7 @@ auto Screen::get() -> Screen* { return Screen::instance; }
// Constructor // Constructor
Screen::Screen() Screen::Screen()
: window_(nullptr), : src_rect_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}),
renderer_(nullptr),
game_canvas_(nullptr),
service_menu_(nullptr),
notifier_(nullptr),
src_rect_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}),
dst_rect_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}) { dst_rect_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}) {
// Arranca SDL VIDEO, crea la ventana y el renderizador // Arranca SDL VIDEO, crea la ventana y el renderizador
initSDLVideo(); initSDLVideo();
+5 -5
View File
@@ -214,11 +214,11 @@ class Screen {
#endif #endif
// --- Objetos y punteros --- // --- Objetos y punteros ---
SDL_Window* window_; // Ventana de la aplicación SDL_Window* window_ = nullptr; // Ventana de la aplicación
SDL_Renderer* renderer_; // El renderizador de la ventana SDL_Renderer* renderer_ = nullptr; // El renderizador de la ventana
SDL_Texture* game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador SDL_Texture* game_canvas_ = nullptr; // Textura donde se dibuja todo antes de volcarse al renderizador
ServiceMenu* service_menu_; // Objeto para mostrar el menú de servicio ServiceMenu* service_menu_ = nullptr; // Objeto para mostrar el menú de servicio
Notifier* notifier_; // Objeto para mostrar las notificaciones por pantalla Notifier* notifier_ = nullptr; // Objeto para mostrar las notificaciones por pantalla
std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla std::shared_ptr<Text> text_; // Objeto para escribir texto en pantalla
std::unique_ptr<Rendering::ShaderBackend> shader_backend_; // Backend de shaders (SDL3GPU) std::unique_ptr<Rendering::ShaderBackend> shader_backend_; // Backend de shaders (SDL3GPU)
+1 -3
View File
@@ -9,9 +9,7 @@
std::unique_ptr<ResourceLoader> ResourceLoader::instance = nullptr; std::unique_ptr<ResourceLoader> ResourceLoader::instance = nullptr;
ResourceLoader::ResourceLoader() ResourceLoader::ResourceLoader() = default;
: resource_pack_(nullptr),
fallback_to_files_(true) {}
auto ResourceLoader::getInstance() -> ResourceLoader& { auto ResourceLoader::getInstance() -> ResourceLoader& {
if (!instance) { if (!instance) {
+2 -2
View File
@@ -11,9 +11,9 @@ class ResourcePack;
class ResourceLoader { class ResourceLoader {
private: private:
static std::unique_ptr<ResourceLoader> instance; static std::unique_ptr<ResourceLoader> instance;
ResourcePack* resource_pack_; ResourcePack* resource_pack_ = nullptr;
std::string pack_path_; std::string pack_path_;
bool fallback_to_files_; bool fallback_to_files_ = true;
ResourceLoader(); ResourceLoader();
+1 -2
View File
@@ -10,8 +10,7 @@
const std::string ResourcePack::DEFAULT_ENCRYPT_KEY = "CCAE_RESOURCES__2024"; const std::string ResourcePack::DEFAULT_ENCRYPT_KEY = "CCAE_RESOURCES__2024";
ResourcePack::ResourcePack() ResourcePack::ResourcePack() = default;
: loaded_(false) {}
ResourcePack::~ResourcePack() { ResourcePack::~ResourcePack() {
clear(); clear();
+1 -1
View File
@@ -17,7 +17,7 @@ class ResourcePack {
private: private:
std::unordered_map<std::string, ResourceEntry> resources_; std::unordered_map<std::string, ResourceEntry> resources_;
std::vector<uint8_t> data_; std::vector<uint8_t> data_;
bool loaded_; bool loaded_ = false;
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t; static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
static void encryptData(std::vector<uint8_t>& data, const std::string& key); static void encryptData(std::vector<uint8_t>& data, const std::string& key);
+2 -8
View File
@@ -9,19 +9,13 @@
// Implementación de StageData // Implementación de StageData
StageData::StageData(int power_to_complete, int min_menace, int max_menace, std::string name) StageData::StageData(int power_to_complete, int min_menace, int max_menace, std::string name)
: status_(StageStatus::LOCKED), : name_(std::move(name)),
name_(std::move(name)),
power_to_complete_(power_to_complete), power_to_complete_(power_to_complete),
min_menace_(min_menace), min_menace_(min_menace),
max_menace_(max_menace) {} max_menace_(max_menace) {}
// Implementación de StageManager // Implementación de StageManager
StageManager::StageManager() StageManager::StageManager() { initialize(); }
: power_change_callback_(nullptr),
power_collection_state_(PowerCollectionState::ENABLED),
current_stage_index_(0),
current_power_(0),
total_power_(0) { initialize(); }
void StageManager::initialize() { void StageManager::initialize() {
stages_.clear(); stages_.clear();
+5 -5
View File
@@ -40,7 +40,7 @@ class StageData {
private: private:
// --- Variables de estado --- // --- Variables de estado ---
StageStatus status_; // Estado actual de la fase StageStatus status_ = StageStatus::LOCKED; // Estado actual de la fase
std::string name_; // Nombre de la fase std::string name_; // Nombre de la fase
int power_to_complete_; // Poder necesario para completar la fase int power_to_complete_; // Poder necesario para completar la fase
int min_menace_; // Nivel mínimo de amenaza int min_menace_; // Nivel mínimo de amenaza
@@ -102,10 +102,10 @@ class StageManager : public IStageInfo {
// --- Variables de estado --- // --- Variables de estado ---
std::vector<StageData> stages_; // Lista de todas las fases std::vector<StageData> stages_; // Lista de todas las fases
PowerChangeCallback power_change_callback_; // Callback para notificar cambios de poder PowerChangeCallback power_change_callback_; // Callback para notificar cambios de poder
PowerCollectionState power_collection_state_; // Estado de recolección de poder PowerCollectionState power_collection_state_ = PowerCollectionState::ENABLED; // Estado de recolección de poder
size_t current_stage_index_; // Índice de la fase actual size_t current_stage_index_ = 0; // Índice de la fase actual
int current_power_; // Poder actual en la fase activa int current_power_ = 0; // Poder actual en la fase activa
int total_power_; // Poder total acumulado en todo el juego int total_power_ = 0; // Poder total acumulado en todo el juego
// --- Métodos internos --- // --- Métodos internos ---
void createDefaultStages(); // Crea las fases predeterminadas del juego void createDefaultStages(); // Crea las fases predeterminadas del juego
-1
View File
@@ -36,7 +36,6 @@ HiScoreTable::HiScoreTable()
background_(std::make_unique<Background>()), background_(std::make_unique<Background>()),
view_area_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}), view_area_(SDL_FRect{.x = 0, .y = 0, .w = param.game.width, .h = param.game.height}),
fade_mode_(Fade::Mode::IN),
background_fade_color_(Color(0, 0, 0)) { background_fade_color_(Color(0, 0, 0)) {
// Inicializa el resto // Inicializa el resto
Section::name = Section::Name::HI_SCORE_TABLE; Section::name = Section::Name::HI_SCORE_TABLE;
+1 -1
View File
@@ -58,7 +58,7 @@ class HiScoreTable {
float elapsed_time_ = 0.0F; // Tiempo transcurrido (segundos) float elapsed_time_ = 0.0F; // Tiempo transcurrido (segundos)
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla
Fade::Mode fade_mode_; // Modo de fade a utilizar Fade::Mode fade_mode_ = Fade::Mode::IN; // Modo de fade a utilizar
Color background_fade_color_; // Color de atenuación del fondo Color background_fade_color_; // Color de atenuación del fondo
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla
-1
View File
@@ -35,7 +35,6 @@ Title::Title()
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)), tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)), game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))), mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
state_(State::LOGO_ANIMATING),
num_controllers_(Input::get()->getNumGamepads()) { num_controllers_(Input::get()->getNumGamepads()) {
// Configura objetos // Configura objetos
tiled_bg_->setColor(param.title.bg_color); tiled_bg_->setColor(param.title.bg_color);
+1 -1
View File
@@ -94,7 +94,7 @@ class Title {
Anchor anchor_; // Anclas para definir la posición de los elementos del título Anchor anchor_; // Anclas para definir la posición de los elementos del título
Section::Name next_section_; // Siguiente sección a cargar Section::Name next_section_; // Siguiente sección a cargar
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
State state_; // Estado actual de la sección State state_ = State::LOGO_ANIMATING; // Estado actual de la sección
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
float counter_time_ = 0.0F; // Temporizador para la pantalla de título (en segundos) float counter_time_ = 0.0F; // Temporizador para la pantalla de título (en segundos)
float blink_accumulator_ = 0.0F; // Acumulador para el parpadeo (en segundos) float blink_accumulator_ = 0.0F; // Acumulador para el parpadeo (en segundos)
-1
View File
@@ -33,7 +33,6 @@ Notifier::Notifier(const std::string& icon_file, std::shared_ptr<Text> text)
icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr), icon_texture_(!icon_file.empty() ? std::make_unique<Texture>(renderer_, icon_file) : nullptr),
text_(std::move(text)), text_(std::move(text)),
bg_color_(param.notification.color), bg_color_(param.notification.color),
stack_(false),
has_icons_(!icon_file.empty()) {} has_icons_(!icon_file.empty()) {}
// Dibuja las notificaciones por pantalla // Dibuja las notificaciones por pantalla
+1 -1
View File
@@ -88,7 +88,7 @@ class Notifier {
std::vector<Notification> notifications_; // Lista de notificaciones activas std::vector<Notification> notifications_; // Lista de notificaciones activas
Color bg_color_; // Color de fondo de las notificaciones Color bg_color_; // Color de fondo de las notificaciones
// Nota: wait_time_ eliminado, ahora se usa STAY_DURATION_S // Nota: wait_time_ eliminado, ahora se usa STAY_DURATION_S
bool stack_; // Indica si las notificaciones se apilan bool stack_ = false; // Indica si las notificaciones se apilan
bool has_icons_; // Indica si el notificador tiene textura para iconos bool has_icons_; // Indica si el notificador tiene textura para iconos
// --- Métodos internos --- // --- Métodos internos ---
+1 -3
View File
@@ -28,9 +28,7 @@ void ServiceMenu::destroy() { delete ServiceMenu::instance; }
auto ServiceMenu::get() -> ServiceMenu* { return ServiceMenu::instance; } auto ServiceMenu::get() -> ServiceMenu* { return ServiceMenu::instance; }
// Constructor // Constructor
ServiceMenu::ServiceMenu() ServiceMenu::ServiceMenu() {
: current_settings_group_(SettingsGroup::MAIN),
previous_settings_group_(current_settings_group_) {
auto element_text = Resource::get()->getText("04b_25_flat"); auto element_text = Resource::get()->getText("04b_25_flat");
auto title_text = Resource::get()->getText("04b_25_flat_2x"); auto title_text = Resource::get()->getText("04b_25_flat_2x");
+2 -2
View File
@@ -88,8 +88,8 @@ class ServiceMenu {
std::vector<std::unique_ptr<MenuOption>> options_; std::vector<std::unique_ptr<MenuOption>> options_;
std::vector<MenuOption*> display_options_; std::vector<MenuOption*> display_options_;
std::vector<std::pair<std::string, std::string>> option_pairs_; std::vector<std::pair<std::string, std::string>> option_pairs_;
SettingsGroup current_settings_group_; SettingsGroup current_settings_group_ = SettingsGroup::MAIN;
SettingsGroup previous_settings_group_; SettingsGroup previous_settings_group_ = SettingsGroup::MAIN;
std::string title_; std::string title_;
size_t selected_ = 0; size_t selected_ = 0;
size_t main_menu_selected_ = 0; size_t main_menu_selected_ = 0;
+1
View File
@@ -1,3 +1,4 @@
// NOLINTNEXTLINE(bugprone-reserved-identifier) -- requerido por <cmath> para exponer M_PI en MSVC
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include "utils/color.hpp" #include "utils/color.hpp"