diff --git a/.clang-tidy b/.clang-tidy index d57bbb5..2d21feb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,8 +19,9 @@ Checks: - -modernize-avoid-c-arrays,-warnings-as-errors WarningsAsErrors: '*' -# Solo incluir archivos de tu código fuente -HeaderFilterRegex: '^source/(sections|ui)/.*' +# Solo incluir archivos de tu código fuente (external tiene su propio .clang-tidy) +# Excluye jail_audio.hpp del análisis +HeaderFilterRegex: '^source/(?!core/audio/jail_audio\.hpp).*' FormatStyle: file CheckOptions: diff --git a/CMakeLists.txt b/CMakeLists.txt index f1383b7..7f34eeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,3 +171,67 @@ endif() # Especificar la ubicación del ejecutable set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) + +# --- 5. STATIC ANALYSIS TARGETS --- + +# Buscar herramientas de análisis estático +find_program(CLANG_TIDY_EXE NAMES clang-tidy) +find_program(CLANG_FORMAT_EXE NAMES clang-format) + +# Recopilar todos los archivos fuente para formateo +file(GLOB_RECURSE ALL_SOURCE_FILES + "${CMAKE_SOURCE_DIR}/source/*.cpp" + "${CMAKE_SOURCE_DIR}/source/*.hpp" + "${CMAKE_SOURCE_DIR}/source/*.h" +) + +# Excluir directorio external del análisis +list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX ".*/external/.*") + +# Para clang-tidy, también excluir jail_audio.hpp +set(CLANG_TIDY_SOURCES ${ALL_SOURCE_FILES}) +list(FILTER CLANG_TIDY_SOURCES EXCLUDE REGEX ".*jail_audio\\.hpp$") + +# Targets de clang-tidy +if(CLANG_TIDY_EXE) + add_custom_target(tidy + COMMAND ${CLANG_TIDY_EXE} + -p ${CMAKE_BINARY_DIR} + ${CLANG_TIDY_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-tidy..." + ) + + add_custom_target(tidy-fix + COMMAND ${CLANG_TIDY_EXE} + -p ${CMAKE_BINARY_DIR} + --fix + ${CLANG_TIDY_SOURCES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-tidy with fixes..." + ) +else() + message(STATUS "clang-tidy no encontrado - targets 'tidy' y 'tidy-fix' no disponibles") +endif() + +# Targets de clang-format +if(CLANG_FORMAT_EXE) + add_custom_target(format + COMMAND ${CLANG_FORMAT_EXE} + -i + ${ALL_SOURCE_FILES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running clang-format..." + ) + + add_custom_target(format-check + COMMAND ${CLANG_FORMAT_EXE} + --dry-run + --Werror + ${ALL_SOURCE_FILES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Checking clang-format..." + ) +else() + message(STATUS "clang-format no encontrado - targets 'format' y 'format-check' no disponibles") +endif() diff --git a/source/core/audio/audio.hpp b/source/core/audio/audio.hpp index 78597f3..b2eea8b 100644 --- a/source/core/audio/audio.hpp +++ b/source/core/audio/audio.hpp @@ -78,7 +78,7 @@ class Audio { // --- Tipos anidados --- struct Music { MusicState state{MusicState::STOPPED}; // Estado actual de la música - std::string name{}; // Última pista de música reproducida + std::string name; // Última pista de música reproducida bool loop{false}; // Indica si se reproduce en bucle }; diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 5c2cda4..2febb44 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -197,7 +197,7 @@ void Cache::loadSounds() { sound = JA_LoadSound(l.c_str()); } - sounds_.emplace_back(SoundResource{name, sound}); + sounds_.emplace_back(SoundResource{.name = name, .sound = sound}); printWithDots("Sound : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -224,7 +224,7 @@ void Cache::loadMusics() { music = JA_LoadMusic(l.c_str()); } - musics_.emplace_back(MusicResource{name, music}); + musics_.emplace_back(MusicResource{.name = name, .music = music}); printWithDots("Music : ", name, "[ LOADED ]"); updateLoadingProgress(1); } @@ -238,7 +238,7 @@ void Cache::loadSurfaces() { for (const auto& l : list) { auto name = getFileName(l); - surfaces_.emplace_back(SurfaceResource{name, std::make_shared(l)}); + surfaces_.emplace_back(SurfaceResource{.name = name, .surface = std::make_shared(l)}); surfaces_.back().surface->setTransparentColor(0); updateLoadingProgress(); } @@ -261,7 +261,7 @@ void Cache::loadPalettes() { for (const auto& l : list) { auto name = getFileName(l); - palettes_.emplace_back(ResourcePalette{name, readPalFile(l)}); + palettes_.emplace_back(ResourcePalette{.name = name, .palette = readPalFile(l)}); updateLoadingProgress(); } } @@ -274,7 +274,7 @@ void Cache::loadTextFiles() { for (const auto& l : list) { auto name = getFileName(l); - text_files_.emplace_back(TextFileResource{name, Text::loadTextFile(l)}); + text_files_.emplace_back(TextFileResource{.name = name, .text_file = Text::loadTextFile(l)}); updateLoadingProgress(); } } @@ -291,7 +291,7 @@ void Cache::loadAnimations() { // Cargar bytes del archivo YAML sin parsear (carga lazy) auto yaml_bytes = Helper::loadFile(l); - animations_.emplace_back(AnimationResource{name, yaml_bytes}); + animations_.emplace_back(AnimationResource{.name = name, .yaml_data = yaml_bytes}); printWithDots("Animation : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -305,7 +305,7 @@ void Cache::loadRooms() { for (const auto& l : list) { auto name = getFileName(l); - rooms_.emplace_back(RoomResource{name, std::make_shared(Room::loadYAML(l))}); + rooms_.emplace_back(RoomResource{.name = name, .room = std::make_shared(Room::loadYAML(l))}); printWithDots("Room : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -313,22 +313,22 @@ void Cache::loadRooms() { void Cache::createText() { struct ResourceInfo { - std::string key{}; // Identificador del recurso - std::string texture_file{}; // Nombre del archivo de textura - std::string text_file{}; // Nombre del archivo de texto + std::string key; // Identificador del recurso + std::string texture_file; // Nombre del archivo de textura + std::string text_file; // Nombre del archivo de texto }; std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n'; std::vector resources = { - {"aseprite", "aseprite.gif", "aseprite.txt"}, - {"gauntlet", "gauntlet.gif", "gauntlet.txt"}, - {"smb2", "smb2.gif", "smb2.txt"}, - {"subatomic", "subatomic.gif", "subatomic.txt"}, - {"8bithud", "8bithud.gif", "8bithud.txt"}}; + {.key = "aseprite", .texture_file = "aseprite.gif", .text_file = "aseprite.txt"}, + {.key = "gauntlet", .texture_file = "gauntlet.gif", .text_file = "gauntlet.txt"}, + {.key = "smb2", .texture_file = "smb2.gif", .text_file = "smb2.txt"}, + {.key = "subatomic", .texture_file = "subatomic.gif", .text_file = "subatomic.txt"}, + {.key = "8bithud", .texture_file = "8bithud.gif", .text_file = "8bithud.txt"}}; for (const auto& res_info : resources) { - texts_.emplace_back(TextResource{res_info.key, std::make_shared(getSurface(res_info.texture_file), getTextFile(res_info.text_file))}); + texts_.emplace_back(TextResource{.name = res_info.key, .text = std::make_shared(getSurface(res_info.texture_file), getTextFile(res_info.text_file))}); printWithDots("Text : ", res_info.key, "[ DONE ]"); } } @@ -374,7 +374,7 @@ void Cache::calculateTotal() { total += list.size(); } - count_ = ResourceCount{total, 0}; + count_ = ResourceCount{.total = total, .loaded = 0}; } // Muestra el progreso de carga diff --git a/source/core/resources/resource_cache.hpp b/source/core/resources/resource_cache.hpp index 6968391..4872bf5 100644 --- a/source/core/resources/resource_cache.hpp +++ b/source/core/resources/resource_cache.hpp @@ -74,17 +74,17 @@ class Cache { static Cache* cache; // Variables miembro - std::vector sounds_{}; // Vector con los sonidos - std::vector musics_{}; // Vector con las musicas - std::vector surfaces_{}; // Vector con las surfaces - std::vector palettes_{}; // Vector con las paletas - std::vector text_files_{}; // Vector con los ficheros de texto - std::vector texts_{}; // Vector con los objetos de texto - std::vector animations_{}; // Vector con las animaciones - std::vector rooms_{}; // Vector con las habitaciones + std::vector sounds_; // Vector con los sonidos + std::vector musics_; // Vector con las musicas + std::vector surfaces_; // Vector con las surfaces + std::vector palettes_; // Vector con las paletas + std::vector text_files_; // Vector con los ficheros de texto + std::vector texts_; // Vector con los objetos de texto + std::vector animations_; // Vector con las animaciones + std::vector rooms_; // Vector con las habitaciones ResourceCount count_{}; // Contador de recursos - std::shared_ptr loading_text_{}; // Texto para la pantalla de carga + std::shared_ptr loading_text_; // Texto para la pantalla de carga }; } // namespace Resource diff --git a/source/core/resources/resource_list.cpp b/source/core/resources/resource_list.cpp index f846c22..cfa455b 100644 --- a/source/core/resources/resource_list.cpp +++ b/source/core/resources/resource_list.cpp @@ -109,8 +109,8 @@ void List::loadFromString(const std::string& config_content, const std::string& } // Extraer campos - std::string type_str = asset["type"].get_value(); - std::string path = asset["path"].get_value(); + auto type_str = asset["type"].get_value(); + auto path = asset["path"].get_value(); // Valores por defecto bool required = true; diff --git a/source/core/resources/resource_pack.hpp b/source/core/resources/resource_pack.hpp index cbfcf21..2e87aa0 100644 --- a/source/core/resources/resource_pack.hpp +++ b/source/core/resources/resource_pack.hpp @@ -13,7 +13,7 @@ namespace Resource { // Entry metadata for each resource in the pack struct ResourceEntry { - std::string filename{}; // Relative path within pack + std::string filename; // Relative path within pack uint64_t offset{0}; // Byte offset in data block uint64_t size{0}; // Size in bytes uint32_t checksum{0}; // CRC32 checksum for verification @@ -60,8 +60,8 @@ class Pack { static auto readFile(const std::string& filepath) -> std::vector; // File I/O - std::unordered_map resources_{}; // Member variables - std::vector data_{}; // Encrypted data block + std::unordered_map resources_; // Member variables + std::vector data_; // Encrypted data block bool loaded_{false}; }; diff --git a/source/core/resources/resource_types.hpp b/source/core/resources/resource_types.hpp index dc9d6ee..227fe18 100644 --- a/source/core/resources/resource_types.hpp +++ b/source/core/resources/resource_types.hpp @@ -15,48 +15,48 @@ struct JA_Sound_t; // Estructura para almacenar ficheros de sonido y su nombre struct SoundResource { - std::string name{}; // Nombre del sonido + std::string name; // Nombre del sonido JA_Sound_t* sound{nullptr}; // Objeto con el sonido }; // Estructura para almacenar ficheros musicales y su nombre struct MusicResource { - std::string name{}; // Nombre de la musica + std::string name; // Nombre de la musica JA_Music_t* music{nullptr}; // Objeto con la música }; // Estructura para almacenar objetos Surface y su nombre struct SurfaceResource { - std::string name{}; // Nombre de la surface - std::shared_ptr surface{}; // Objeto con la surface + std::string name; // Nombre de la surface + std::shared_ptr surface; // Objeto con la surface }; // Estructura para almacenar objetos Palette y su nombre struct ResourcePalette { - std::string name{}; // Nombre de la surface + std::string name; // Nombre de la surface Palette palette{}; // Paleta }; // Estructura para almacenar ficheros TextFile y su nombre struct TextFileResource { - std::string name{}; // Nombre del fichero - std::shared_ptr text_file{}; // Objeto con los descriptores de la fuente de texto + std::string name; // Nombre del fichero + std::shared_ptr text_file; // Objeto con los descriptores de la fuente de texto }; // Estructura para almacenar objetos Text y su nombre struct TextResource { - std::string name{}; // Nombre del objeto - std::shared_ptr text{}; // Objeto + std::string name; // Nombre del objeto + std::shared_ptr text; // Objeto }; // Estructura para almacenar ficheros animaciones y su nombre struct AnimationResource { - std::string name{}; // Nombre del fichero - std::vector yaml_data{}; // Bytes del archivo YAML sin parsear + std::string name; // Nombre del fichero + std::vector yaml_data; // Bytes del archivo YAML sin parsear }; // Estructura para almacenar habitaciones y su nombre struct RoomResource { - std::string name{}; // Nombre de la habitación - std::shared_ptr room{}; // Habitación + std::string name; // Nombre de la habitación + std::shared_ptr room; // Habitación };