cppcheck
This commit is contained in:
@@ -51,7 +51,7 @@ void Input::applyGamepadBindingsFromOptions() {
|
||||
}
|
||||
|
||||
// Obtener el primer gamepad conectado
|
||||
auto& gamepad = gamepads_[0];
|
||||
const auto& gamepad = gamepads_[0];
|
||||
|
||||
// Aplicar bindings desde Options
|
||||
// Los valores pueden ser:
|
||||
|
||||
@@ -201,7 +201,7 @@ void OpenGLShader::createQuadGeometry() {
|
||||
checkGLError("glVertexAttribPointer(position)");
|
||||
|
||||
// Atributo 1: Coordenadas de textura (2 floats)
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), reinterpret_cast<void*>(2 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
checkGLError("glVertexAttribPointer(texcoord)");
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@ auto Screen::get() -> Screen* {
|
||||
|
||||
// Constructor
|
||||
Screen::Screen()
|
||||
: palettes_(Asset::get()->getListByType(Asset::Type::PALETTE)) {
|
||||
: window_width_(0),
|
||||
window_height_(0),
|
||||
palettes_(Asset::get()->getListByType(Asset::Type::PALETTE)) {
|
||||
// Arranca SDL VIDEO, crea la ventana y el renderizador
|
||||
initSDLVideo();
|
||||
if (Options::video.fullscreen) {
|
||||
@@ -456,11 +458,10 @@ void Screen::initShaders() {
|
||||
|
||||
// Obtiene información sobre la pantalla
|
||||
void Screen::getDisplayInfo() {
|
||||
int i;
|
||||
int num_displays = 0;
|
||||
SDL_DisplayID* displays = SDL_GetDisplays(&num_displays);
|
||||
if (displays != nullptr) {
|
||||
for (i = 0; i < num_displays; ++i) {
|
||||
for (int i = 0; i < num_displays; ++i) {
|
||||
SDL_DisplayID instance_id = displays[i];
|
||||
const char* name = SDL_GetDisplayName(instance_id);
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ void Surface::loadPalette(const std::string& file_path) {
|
||||
}
|
||||
|
||||
// Carga una paleta desde otra paleta
|
||||
void Surface::loadPalette(Palette palette) {
|
||||
void Surface::loadPalette(const Palette& palette) {
|
||||
palette_ = palette;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class Surface {
|
||||
|
||||
// Carga una paleta desde un archivo
|
||||
void loadPalette(const std::string& file_path);
|
||||
void loadPalette(Palette palette);
|
||||
void loadPalette(const Palette& palette);
|
||||
|
||||
// Copia una región de la SurfaceData de origen a la SurfaceData de destino
|
||||
void render(float dx, float dy, float sx, float sy, float w, float h);
|
||||
|
||||
@@ -35,8 +35,8 @@ void Resource::destroy() { delete Resource::resource; }
|
||||
auto Resource::get() -> Resource* { return Resource::resource; }
|
||||
|
||||
// Constructor
|
||||
Resource::Resource() {
|
||||
loading_text_ = Screen::get()->getText();
|
||||
Resource::Resource()
|
||||
: loading_text_(Screen::get()->getText()) {
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -353,9 +353,9 @@ void Resource::createText() {
|
||||
{"subatomic", "subatomic.gif", "subatomic.txt"},
|
||||
{"8bithud", "8bithud.gif", "8bithud.txt"}};
|
||||
|
||||
for (const auto& resource : resources) {
|
||||
texts_.emplace_back(resource.key, std::make_shared<Text>(getSurface(resource.texture_file), getTextFile(resource.text_file)));
|
||||
printWithDots("Text : ", resource.key, "[ DONE ]");
|
||||
for (const auto& res_info : resources) {
|
||||
texts_.emplace_back(res_info.key, std::make_shared<Text>(getSurface(res_info.texture_file), getTextFile(res_info.text_file)));
|
||||
printWithDots("Text : ", res_info.key, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +415,7 @@ void Resource::renderProgress() {
|
||||
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
|
||||
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
const auto TEXT_COLOR = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
|
||||
const auto LOADING_TEXT_COLOR = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
|
||||
const auto BAR_COLOR = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
const int TEXT_HEIGHT = loading_text_->getCharacterSize();
|
||||
const int CENTER_X = Options::game.width / 2;
|
||||
@@ -427,7 +427,7 @@ void Resource::renderProgress() {
|
||||
CENTER_X - (loading_text_->lenght(APP_NAME) / 2),
|
||||
CENTER_Y - TEXT_HEIGHT,
|
||||
APP_NAME,
|
||||
TEXT_COLOR);
|
||||
LOADING_TEXT_COLOR);
|
||||
|
||||
// Draw VERSION centered below center
|
||||
const std::string VERSION_TEXT = "(" + std::string(Version::GIT_HASH) + ")";
|
||||
@@ -435,7 +435,7 @@ void Resource::renderProgress() {
|
||||
CENTER_X - (loading_text_->lenght(VERSION_TEXT) / 2),
|
||||
CENTER_Y + TEXT_HEIGHT,
|
||||
VERSION_TEXT,
|
||||
TEXT_COLOR);
|
||||
LOADING_TEXT_COLOR);
|
||||
|
||||
// Draw progress bar border
|
||||
const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class Director {
|
||||
public:
|
||||
Director(std::vector<std::string> const& args); // Constructor
|
||||
explicit Director(std::vector<std::string> const& args); // Constructor
|
||||
~Director(); // Destructor
|
||||
static auto run() -> int; // Bucle principal
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ Title::Title()
|
||||
axis_cooldown_(0.0F),
|
||||
remap_completed_(false) {
|
||||
// Inicializa variables
|
||||
temp_keys_[0] = temp_keys_[1] = temp_keys_[2] = SDL_SCANCODE_UNKNOWN;
|
||||
temp_buttons_[0] = temp_buttons_[1] = temp_buttons_[2] = -1;
|
||||
|
||||
state_ = SceneManager::options == SceneManager::Options::TITLE_WITH_LOADING_SCREEN ? State::SHOW_LOADING_SCREEN : State::MAIN_MENU;
|
||||
SceneManager::current = SceneManager::Scene::TITLE;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
|
||||
@@ -1,5 +1,55 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# CONFIGURACIÓN - Editar estas constantes para personalizar el script
|
||||
# ============================================================================
|
||||
|
||||
# Detectar la ubicación del script y la raíz del proyecto
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
# Rutas del proyecto
|
||||
DEFAULT_ANALYSIS_PATH="$PROJECT_ROOT/source"
|
||||
INCLUDE_PATH="$PROJECT_ROOT/source"
|
||||
SUPPRESSIONS_FILE="$SCRIPT_DIR/cppcheck_suppressions"
|
||||
OUTPUT_DIR="$SCRIPT_DIR"
|
||||
BUILD_DIR="$PROJECT_ROOT/build"
|
||||
COMPILE_COMMANDS="$BUILD_DIR/compile_commands.json"
|
||||
|
||||
# Parámetros de compilación comunes (fallback para análisis de archivos específicos)
|
||||
CPPCHECK_STD="--std=c++20"
|
||||
|
||||
# Calcular número de threads (cores - 1, mínimo 1)
|
||||
THREADS=$(($(nproc) - 1))
|
||||
[[ $THREADS -lt 1 ]] && THREADS=1
|
||||
|
||||
# ============================================================================
|
||||
|
||||
# Función para asegurar que compile_commands.json existe
|
||||
ensure_compile_commands() {
|
||||
if [[ ! -f "$COMPILE_COMMANDS" ]]; then
|
||||
echo "⚠ compile_commands.json no encontrado en $BUILD_DIR"
|
||||
echo "Generando compile_commands.json con CMake..."
|
||||
|
||||
# Crear directorio build si no existe
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
# Ejecutar CMake para generar compile_commands.json
|
||||
(cd "$BUILD_DIR" && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. > /dev/null 2>&1)
|
||||
|
||||
if [[ ! -f "$COMPILE_COMMANDS" ]]; then
|
||||
echo "❌ Error: No se pudo generar compile_commands.json"
|
||||
echo "Por favor, ejecuta manualmente:"
|
||||
echo " cd $BUILD_DIR && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ compile_commands.json generado exitosamente"
|
||||
else
|
||||
echo "✓ Usando compile_commands.json existente: $COMPILE_COMMANDS"
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para mostrar el uso del script
|
||||
mostrar_uso() {
|
||||
echo "Uso: $0 [OPCIÓN] [RUTA]"
|
||||
@@ -10,7 +60,7 @@ mostrar_uso() {
|
||||
echo " -u, --unused Ejecutar cppcheck para unusedFunction"
|
||||
echo ""
|
||||
echo "Opciones de ruta:"
|
||||
echo " -p, --path <ruta> Especificar ruta a analizar (default: ../source/)"
|
||||
echo " -p, --path <ruta> Especificar ruta a analizar (default: PROJECT_ROOT/source)"
|
||||
echo " [RUTA] Ruta como último argumento posicional"
|
||||
echo ""
|
||||
echo "Ejemplos:"
|
||||
@@ -22,7 +72,7 @@ mostrar_uso() {
|
||||
|
||||
# Inicializar las variables
|
||||
opcion=""
|
||||
ruta="../source/"
|
||||
ruta="$DEFAULT_ANALYSIS_PATH"
|
||||
|
||||
# Procesar las opciones
|
||||
while [[ $# -gt 0 ]]; do
|
||||
@@ -76,30 +126,67 @@ fi
|
||||
# Ejecutar según la opción seleccionada
|
||||
case $opcion in
|
||||
warning)
|
||||
echo "Ejecutando cppcheck con warning, style, performance en: $ruta"
|
||||
cppcheck --force --enable=warning,style,performance --std=c++20 \
|
||||
--check-level=exhaustive \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
"$ruta" \
|
||||
2>./cppcheck-result-warning-style-performance.txt
|
||||
echo "Resultados guardados en: ./cppcheck-result-warning-style-performance.txt"
|
||||
ensure_compile_commands
|
||||
if [[ "$ruta" == "$DEFAULT_ANALYSIS_PATH" ]]; then
|
||||
echo "Ejecutando cppcheck con warning, style, performance en proyecto completo (usando $THREADS threads)"
|
||||
cppcheck --force --enable=warning,style,performance \
|
||||
--check-level=exhaustive \
|
||||
-j$THREADS \
|
||||
--project="$COMPILE_COMMANDS" \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-warning-style-performance.txt"
|
||||
else
|
||||
echo "Ejecutando cppcheck con warning, style, performance en: $ruta (usando $THREADS threads)"
|
||||
cppcheck --force --enable=warning,style,performance $CPPCHECK_STD \
|
||||
--check-level=exhaustive \
|
||||
-j$THREADS \
|
||||
-I "$INCLUDE_PATH" \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
"$ruta" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-warning-style-performance.txt"
|
||||
fi
|
||||
echo "Resultados guardados en: $OUTPUT_DIR/cppcheck-result-warning-style-performance.txt"
|
||||
;;
|
||||
all)
|
||||
echo "Ejecutando cppcheck con todas las opciones en: $ruta"
|
||||
cppcheck --force --enable=all -I /usr/include --std=c++20 \
|
||||
--suppress=missingIncludeSystem \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
"$ruta" \
|
||||
2>./cppcheck-result-all.txt
|
||||
echo "Resultados guardados en: ./cppcheck-result-all.txt"
|
||||
ensure_compile_commands
|
||||
if [[ "$ruta" == "$DEFAULT_ANALYSIS_PATH" ]]; then
|
||||
echo "Ejecutando cppcheck con todas las opciones en proyecto completo (usando $THREADS threads)"
|
||||
cppcheck --force --enable=all \
|
||||
-j$THREADS \
|
||||
--project="$COMPILE_COMMANDS" \
|
||||
--suppress=missingIncludeSystem \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-all.txt"
|
||||
else
|
||||
echo "Ejecutando cppcheck con todas las opciones en: $ruta (usando $THREADS threads)"
|
||||
cppcheck --force --enable=all -I /usr/include -I "$INCLUDE_PATH" $CPPCHECK_STD \
|
||||
-j$THREADS \
|
||||
--suppress=missingIncludeSystem \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
"$ruta" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-all.txt"
|
||||
fi
|
||||
echo "Resultados guardados en: $OUTPUT_DIR/cppcheck-result-all.txt"
|
||||
;;
|
||||
unused)
|
||||
echo "Ejecutando cppcheck para unusedFunction en: $ruta"
|
||||
cppcheck --enable=style --std=c++20 \
|
||||
--suppressions-list=./cppcheck_suppressions \
|
||||
"$ruta" \
|
||||
2>./cppcheck-result-unusedFunction.txt
|
||||
echo "Resultados guardados en: ./cppcheck-result-unusedFunction.txt"
|
||||
ensure_compile_commands
|
||||
if [[ "$ruta" == "$DEFAULT_ANALYSIS_PATH" ]]; then
|
||||
echo "Ejecutando cppcheck para unusedFunction en proyecto completo (usando $THREADS threads)"
|
||||
cppcheck --enable=style \
|
||||
-j$THREADS \
|
||||
--project="$COMPILE_COMMANDS" \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-unusedFunction.txt"
|
||||
else
|
||||
echo "Ejecutando cppcheck para unusedFunction en: $ruta (usando $THREADS threads)"
|
||||
cppcheck --enable=style $CPPCHECK_STD \
|
||||
-j$THREADS \
|
||||
-I "$INCLUDE_PATH" \
|
||||
--suppressions-list="$SUPPRESSIONS_FILE" \
|
||||
"$ruta" \
|
||||
2>"$OUTPUT_DIR/cppcheck-result-unusedFunction.txt"
|
||||
fi
|
||||
echo "Resultados guardados en: $OUTPUT_DIR/cppcheck-result-unusedFunction.txt"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Opción inválida"
|
||||
|
||||
Reference in New Issue
Block a user