Commitet pa gastar el Cppcheck

This commit is contained in:
2024-10-08 20:32:24 +02:00
parent c00f4326ae
commit 3e3d764b25
12 changed files with 241 additions and 405 deletions

View File

@@ -5,20 +5,21 @@
#include <SDL2/SDL_video.h> // for SDL_WINDOWEVENT_SIZE_CHANGED
#include <algorithm> // for max
#include <vector> // for vector
#include "asset.h" // for Asset
#include "background.h" // for Background
#include "global_inputs.h" // for globalInputs::check
#include "input.h" // for Input
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
#include "lang.h" // for getText
#include "options.h" // for options
#include "param.h" // for param
#include "screen.h" // for Screen
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR
#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t
#include "asset.h" // for Asset
#include "background.h" // for Background
#include "global_inputs.h" // for globalInputs::check
#include "input.h" // for Input
#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state
#include "lang.h" // for getText
#include "options.h" // for options
#include "param.h" // for param
#include "screen.h" // for Screen
#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR
#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t
// Constructor
HiScoreTable::HiScoreTable(JA_Music_t *music) : music(music)
HiScoreTable::HiScoreTable(JA_Music_t *music)
: music(music)
{
// Copia punteros
renderer = Screen::get()->getRenderer();
@@ -74,7 +75,9 @@ void HiScoreTable::update()
// Mantiene la música sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(music);
}
// Actualiza el objeto screen
Screen::get()->update();
@@ -105,14 +108,14 @@ void HiScoreTable::update()
void HiScoreTable::fillTexture()
{
// hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots
const int maxNames = 10;
const int spaceBetweenHeader = 32;
const int spaceBetweenLines = text->getCharacterSize() * 2.0f;
const int size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
const int firstLine = (param.game.height - size) / 2;
constexpr auto maxNames = 10;
constexpr auto spaceBetweenHeader = 32;
const auto spaceBetweenLines = text->getCharacterSize() * 2.0f;
const auto size = spaceBetweenHeader + spaceBetweenLines * (maxNames - 1) + text->getCharacterSize();
const auto firstLine = (param.game.height - size) / 2;
// Pinta en el backbuffer el texto y los sprites
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
auto *temp = SDL_GetRenderTarget(renderer);
SDL_SetRenderTarget(renderer, backbuffer);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
@@ -123,16 +126,16 @@ void HiScoreTable::fillTexture()
// Escribe los nombres de la tabla de puntuaciones
for (int i = 0; i < maxNames; ++i)
{
const int nameLenght = options.game.hiScoreTable[i].name.length();
const std::string score = format(options.game.hiScoreTable[i].score);
const int scoreLenght = score.size();
const int numDots = 25 - nameLenght - scoreLenght;
const auto nameLenght = options.game.hiScoreTable[i].name.length();
const auto score = format(options.game.hiScoreTable[i].score);
const auto scoreLenght = score.size();
const auto numDots = 25 - nameLenght - scoreLenght;
std::string dots = "";
for (int j = 0; j < numDots; ++j)
for (int j = 0; j < (int)numDots; ++j)
{
dots = dots + ".";
}
const std::string line = options.game.hiScoreTable[i].name + dots + score;
const auto line = options.game.hiScoreTable[i].name + dots + score;
text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
}
@@ -158,6 +161,7 @@ void HiScoreTable::render()
// Copia el backbuffer al renderizador
SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea);
// Renderiza el fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
@@ -226,47 +230,6 @@ void HiScoreTable::run()
}
}
// Transforma un valor numérico en una cadena de 6 cifras
std::string HiScoreTable::scoreToString(int num)
{
if ((num >= 0) && (num <= 9))
{
return ("000000" + std::to_string(num));
}
if ((num >= 10) && (num <= 99))
{
return ("00000" + std::to_string(num));
}
if ((num >= 100) && (num <= 999))
{
return ("0000" + std::to_string(num));
}
if ((num >= 1000) && (num <= 9999))
{
return ("000" + std::to_string(num));
}
if ((num >= 010000) && (num <= 99999))
{
return ("00" + std::to_string(num));
}
if ((num >= 100000) && (num <= 999999))
{
return ("0" + std::to_string(num));
}
if ((num >= 1000000) && (num <= 9999999))
{
return (std::to_string(num));
}
return (std::to_string(num));
}
// Gestiona el fade
void HiScoreTable::updateFade()
{
@@ -291,9 +254,9 @@ std::string HiScoreTable::format(int number)
const std::string separator = ".";
const std::string score = std::to_string(number);
int index = (int)score.size() - 1;
auto index = (int)score.size() - 1;
std::string result = "";
int i = 0;
auto i = 0;
while (index >= 0)
{
result = score.at(index) + result;