cppcheck
This commit is contained in:
@@ -265,6 +265,7 @@ if(CPPCHECK_EXE)
|
||||
--inline-suppr
|
||||
--suppress=missingIncludeSystem
|
||||
--suppress=toomanyconfigs
|
||||
--suppress=*:*/source/external/*
|
||||
--quiet
|
||||
-I ${CMAKE_SOURCE_DIR}/source
|
||||
${CPPCHECK_SOURCES}
|
||||
|
||||
@@ -42,7 +42,7 @@ class AnimatedSprite : public MovingSprite {
|
||||
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
~AnimatedSprite() override;
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
@@ -86,7 +86,7 @@ class AnimatedSprite : public MovingSprite {
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update();
|
||||
void update() override;
|
||||
|
||||
// OLD - Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
|
||||
|
||||
@@ -70,11 +70,13 @@ void MovingSprite::render() {
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float MovingSprite::getPosX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float MovingSprite::getPosY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ class Texture;
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite {
|
||||
protected:
|
||||
float x; // Posición en el eje X
|
||||
float y; // Posición en el eje Y
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float x; // Posición en el eje X (sub-pixel; Sprite::x es int)
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float y; // Posición en el eje Y (sub-pixel; Sprite::y es int)
|
||||
|
||||
float xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior en el eje Y
|
||||
@@ -42,18 +44,20 @@ class MovingSprite : public Sprite {
|
||||
void rotate();
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void update();
|
||||
virtual void update();
|
||||
|
||||
// Reinicia todas las variables
|
||||
void clear();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
void render() override;
|
||||
|
||||
// Obten el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float getPosX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
// cppcheck-suppress duplInheritedMember
|
||||
float getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
@@ -84,7 +88,7 @@ class MovingSprite : public Sprite {
|
||||
Uint16 getRotateSpeed();
|
||||
|
||||
// Establece la posición y el tamaño del objeto
|
||||
void setRect(SDL_Rect rect);
|
||||
void setRect(SDL_Rect rect) override;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
@@ -144,7 +148,7 @@ class MovingSprite : public Sprite {
|
||||
SDL_FlipMode getFlip();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
SDL_Rect getRect() override;
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
@@ -46,16 +46,6 @@ void SmartSprite::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool SmartSprite::isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setEnabled(bool enabled) {
|
||||
this->enabled = enabled;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int SmartSprite::getEnabledCounter() {
|
||||
return enabledCounter;
|
||||
|
||||
@@ -9,7 +9,6 @@ class Texture;
|
||||
class SmartSprite : public AnimatedSprite {
|
||||
private:
|
||||
// Variables
|
||||
bool enabled; // Indica si esta habilitado
|
||||
bool onDestination; // Indica si está en el destino
|
||||
int destX; // Posicion de destino en el eje X
|
||||
int destY; // Posicion de destino en el eje Y
|
||||
@@ -30,16 +29,10 @@ class SmartSprite : public AnimatedSprite {
|
||||
void init();
|
||||
|
||||
// Actualiza la posición y comprueba si ha llegado a su destino
|
||||
void update();
|
||||
void update() override;
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool isEnabled();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool enabled);
|
||||
void render() override;
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getEnabledCounter();
|
||||
|
||||
@@ -23,10 +23,10 @@ class Sprite {
|
||||
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
||||
|
||||
// Destructor
|
||||
~Sprite();
|
||||
virtual ~Sprite();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
virtual void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX();
|
||||
@@ -77,14 +77,14 @@ class Sprite {
|
||||
void setRenderer(SDL_Renderer *renderer);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool value);
|
||||
virtual void setEnabled(bool value);
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
virtual bool isEnabled();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
virtual SDL_Rect getRect();
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
virtual void setRect(SDL_Rect rect);
|
||||
};
|
||||
@@ -18,8 +18,7 @@ ResourcePack::~ResourcePack() {
|
||||
}
|
||||
|
||||
uint32_t ResourcePack::calculateChecksum(const std::vector<uint8_t>& data) {
|
||||
return std::accumulate(data.begin(), data.end(), uint32_t(0x12345678),
|
||||
[](uint32_t acc, uint8_t b) { return ((acc << 5) + acc) + b; });
|
||||
return std::accumulate(data.begin(), data.end(), uint32_t(0x12345678), [](uint32_t acc, uint8_t b) { return ((acc << 5) + acc) + b; });
|
||||
}
|
||||
|
||||
void ResourcePack::encryptData(std::vector<uint8_t>& data, const std::string& key) {
|
||||
@@ -157,6 +156,7 @@ bool ResourcePack::addDirectory(const std::string& directory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// cppcheck-suppress useStlAlgorithm
|
||||
for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) {
|
||||
if (entry.is_regular_file()) {
|
||||
std::string filepath = entry.path().string();
|
||||
|
||||
@@ -63,6 +63,9 @@ class Director {
|
||||
// Destructor
|
||||
~Director();
|
||||
|
||||
Director(const Director &) = delete;
|
||||
Director &operator=(const Director &) = delete;
|
||||
|
||||
// Ejecuta un frame del juego
|
||||
SDL_AppResult iterate();
|
||||
|
||||
|
||||
@@ -146,6 +146,9 @@ class Balloon {
|
||||
// Destructor
|
||||
~Balloon();
|
||||
|
||||
Balloon(const Balloon &) = delete;
|
||||
Balloon &operator=(const Balloon &) = delete;
|
||||
|
||||
// Centra el globo en la posición X
|
||||
void allignTo(int x);
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ class Bullet {
|
||||
// Destructor
|
||||
~Bullet();
|
||||
|
||||
Bullet(const Bullet &) = delete;
|
||||
Bullet &operator=(const Bullet &) = delete;
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ class Item {
|
||||
// Destructor
|
||||
~Item();
|
||||
|
||||
Item(const Item &) = delete;
|
||||
Item &operator=(const Item &) = delete;
|
||||
|
||||
// Centra el objeto en la posición X
|
||||
void allignTo(int x);
|
||||
|
||||
|
||||
@@ -86,6 +86,9 @@ class Player {
|
||||
// Destructor
|
||||
~Player();
|
||||
|
||||
Player(const Player &) = delete;
|
||||
Player &operator=(const Player &) = delete;
|
||||
|
||||
// Iniciador
|
||||
void init();
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <stdlib.h> // for rand
|
||||
|
||||
#include <algorithm> // for max, min
|
||||
#include <numeric> // for accumulate
|
||||
#include <fstream> // for basic_ifstream
|
||||
#include <iostream> // for basic_ostream, char_traits, operator<<
|
||||
#include <numeric> // for accumulate
|
||||
|
||||
#include "core/audio/jail_audio.hpp" // for JA_PlaySound, JA_DeleteSound, JA_LoadSound
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::handle
|
||||
@@ -2184,8 +2184,7 @@ void Game::updateDeathSequence() {
|
||||
|
||||
// Calcula y establece el valor de amenaza en funcion de los globos activos
|
||||
void Game::evaluateAndSetMenace() {
|
||||
menaceCurrent = std::accumulate(balloons.begin(), balloons.end(), Uint8(0),
|
||||
[](Uint8 acc, Balloon *b) { return b->isEnabled() ? acc + b->getMenace() : acc; });
|
||||
menaceCurrent = std::accumulate(balloons.begin(), balloons.end(), Uint8(0), [](Uint8 acc, Balloon *b) { return b->isEnabled() ? acc + b->getMenace() : acc; });
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
@@ -3048,8 +3047,7 @@ bool Game::canPowerBallBeCreated() {
|
||||
|
||||
// Calcula el poder actual de los globos en pantalla
|
||||
int Game::calculateScreenPower() {
|
||||
return std::accumulate(balloons.begin(), balloons.end(), 0,
|
||||
[](int acc, Balloon *b) { return b->isEnabled() ? acc + b->getPower() : acc; });
|
||||
return std::accumulate(balloons.begin(), balloons.end(), 0, [](int acc, Balloon *b) { return b->isEnabled() ? acc + b->getPower() : acc; });
|
||||
}
|
||||
|
||||
// Inicializa las variables que contienen puntos de ruta para mover objetos
|
||||
|
||||
@@ -243,7 +243,7 @@ class Game {
|
||||
Uint8 lastStageReached; // Contiene el numero de la última pantalla que se ha alcanzado
|
||||
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
|
||||
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
|
||||
int cloudsSpeed; // Velocidad a la que se desplazan las nubes
|
||||
int cloudsSpeed{0}; // Velocidad a la que se desplazan las nubes
|
||||
int pauseCounter; // Contador para salir del menu de pausa y volver al juego
|
||||
bool leavingPauseMenu; // Indica si esta saliendo del menu de pausa para volver al juego
|
||||
bool pauseInitialized; // Indica si la pausa ha sido inicializada
|
||||
@@ -524,6 +524,9 @@ class Game {
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
Game(const Game &) = delete;
|
||||
Game &operator=(const Game &) = delete;
|
||||
|
||||
// Bucle para el juego
|
||||
void run();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Instructions {
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
bool manualQuit; // Indica si se quiere salir del modo manual
|
||||
mode_e mode; // Modo en el que se van a ejecutar las instrucciones
|
||||
mode_e mode{m_auto}; // Modo en el que se van a ejecutar las instrucciones
|
||||
bool finished; // Indica si las instrucciones han terminado
|
||||
bool quitRequested; // Indica si se ha solicitado salir de la aplicación
|
||||
|
||||
@@ -45,6 +45,9 @@ class Instructions {
|
||||
// Destructor
|
||||
~Instructions();
|
||||
|
||||
Instructions(const Instructions &) = delete;
|
||||
Instructions &operator=(const Instructions &) = delete;
|
||||
|
||||
// Bucle principal
|
||||
void run(mode_e mode);
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ class Intro {
|
||||
// Destructor
|
||||
~Intro();
|
||||
|
||||
Intro(const Intro &) = delete;
|
||||
Intro &operator=(const Intro &) = delete;
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ class Logo {
|
||||
// Destructor
|
||||
~Logo();
|
||||
|
||||
Logo(const Logo &) = delete;
|
||||
Logo &operator=(const Logo &) = delete;
|
||||
|
||||
// Bucle principal
|
||||
void run();
|
||||
|
||||
|
||||
@@ -860,11 +860,13 @@ void Title::iterate() {
|
||||
demoGame->iterate();
|
||||
|
||||
if (demoGame->hasFinished()) {
|
||||
bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
const bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
||||
delete demoGame;
|
||||
demoGame = nullptr;
|
||||
demoGameActive = false;
|
||||
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
if (wasQuit) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
} else if (demoThenInstructions) {
|
||||
|
||||
@@ -39,8 +39,8 @@ class Title {
|
||||
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Instructions *instructions; // Objeto para la sección de las instrucciones
|
||||
Game *demoGame; // Objeto para lanzar la demo del juego
|
||||
Instructions *instructions{nullptr}; // Objeto para la sección de las instrucciones
|
||||
Game *demoGame{nullptr}; // Objeto para lanzar la demo del juego
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
section_t *section; // Indicador para el bucle del titulo
|
||||
|
||||
@@ -88,14 +88,14 @@ class Title {
|
||||
|
||||
// Variables para la vibración del título (SUBSECTION_TITLE_2)
|
||||
int vibrationStep; // Paso actual de la vibración
|
||||
int vibrationCoffeeBaseX; // Posición X base del bitmap Coffee
|
||||
int vibrationCrisisBaseX; // Posición X base del bitmap Crisis
|
||||
int vibrationCoffeeBaseX{0}; // Posición X base del bitmap Coffee
|
||||
int vibrationCrisisBaseX{0}; // Posición X base del bitmap Crisis
|
||||
bool vibrationInitialized; // Indica si se han capturado las posiciones base
|
||||
|
||||
// Variables para sub-estados delegados (instrucciones y demo)
|
||||
bool instructionsActive; // Indica si las instrucciones están activas
|
||||
bool demoGameActive; // Indica si el juego demo está activo
|
||||
mode_e instructionsMode; // Modo de las instrucciones activas
|
||||
mode_e instructionsMode{m_auto}; // Modo de las instrucciones activas
|
||||
bool demoThenInstructions; // Indica si tras la demo hay que mostrar instrucciones
|
||||
|
||||
// Inicializa los valores
|
||||
@@ -147,6 +147,9 @@ class Title {
|
||||
// Destructor
|
||||
~Title();
|
||||
|
||||
Title(const Title &) = delete;
|
||||
Title &operator=(const Title &) = delete;
|
||||
|
||||
// Bucle para el titulo del juego
|
||||
void run();
|
||||
|
||||
|
||||
@@ -430,8 +430,7 @@ void Menu::setSelectorPos(int index) {
|
||||
|
||||
// Obtiene la anchura del elemento más ancho del menu
|
||||
int Menu::getWidestItem() {
|
||||
return std::accumulate(item.begin(), item.end(), 0,
|
||||
[](int acc, const item_t &i) { return std::max(acc, i.rect.w); });
|
||||
return std::accumulate(item.begin(), item.end(), 0, [](int acc, const item_t &i) { return std::max(acc, i.rect.w); });
|
||||
}
|
||||
|
||||
// Deja el menu apuntando al primer elemento
|
||||
@@ -792,8 +791,7 @@ int Menu::findWidth() {
|
||||
|
||||
// Calcula el alto del menu
|
||||
int Menu::findHeight() {
|
||||
const int height = std::accumulate(item.begin(), item.end(), 0,
|
||||
[](int acc, const item_t &i) { return acc + i.rect.h + i.hPaddingDown; });
|
||||
const int height = std::accumulate(item.begin(), item.end(), 0, [](int acc, const item_t &i) { return acc + i.rect.h + i.hPaddingDown; });
|
||||
|
||||
return height - item.back().hPaddingDown;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user