Optimitzat el tema de comparacions i asignacions de strings buits. Mes que optimitzat, ara està mes mono
This commit is contained in:
@@ -4,7 +4,7 @@ SOURCEPATH=../source/
|
|||||||
|
|
||||||
for i in "$SOURCEPATH"/*.cpp
|
for i in "$SOURCEPATH"/*.cpp
|
||||||
do
|
do
|
||||||
include-what-you-use -D DEBUG -D VERBOSE -std=c++14 -Wall "$i"
|
include-what-you-use -D DEBUG -D VERBOSE -std=c++20 -Wall "$i"
|
||||||
read -p "Presiona cualquier tecla para continuar..."
|
read -p "Presiona cualquier tecla para continuar..."
|
||||||
clear
|
clear
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
|
|||||||
buffer.counter = 0;
|
buffer.counter = 0;
|
||||||
buffer.current_frame = 0;
|
buffer.current_frame = 0;
|
||||||
buffer.completed = false;
|
buffer.completed = false;
|
||||||
buffer.name = "";
|
buffer.name.clear();
|
||||||
buffer.speed = 5;
|
buffer.speed = 5;
|
||||||
buffer.loop = 0;
|
buffer.loop = 0;
|
||||||
buffer.frames.clear();
|
buffer.frames.clear();
|
||||||
@@ -159,18 +159,15 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr<Texture> texture, std::string
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
|
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file, std::vector<std::string> *buffer)
|
||||||
: MovingSprite(texture)
|
: MovingSprite(texture),
|
||||||
|
current_animation_(0)
|
||||||
{
|
{
|
||||||
// Carga las animaciones
|
// Carga las animaciones
|
||||||
if (file != "")
|
if (!file.empty())
|
||||||
{
|
{
|
||||||
AnimatedFile as = loadAnimationFromFile(texture, file);
|
AnimatedFile as = loadAnimationFromFile(texture, file);
|
||||||
|
|
||||||
// Copia los datos de las animaciones
|
// Copia los datos de las animaciones
|
||||||
/*for (auto animation : as.animations)
|
|
||||||
{
|
|
||||||
animations_.push_back(animation);
|
|
||||||
}*/
|
|
||||||
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
|
std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,18 +175,13 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
|
|||||||
{
|
{
|
||||||
loadFromVector(buffer);
|
loadFromVector(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
current_animation_ = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
|
AnimatedSprite::AnimatedSprite(const AnimatedFile *animation)
|
||||||
: MovingSprite(animation->texture)
|
: MovingSprite(animation->texture),
|
||||||
|
current_animation_(0)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
|
||||||
current_animation_ = 0;
|
|
||||||
|
|
||||||
// Copia los datos de las animaciones
|
// Copia los datos de las animaciones
|
||||||
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
|
std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_));
|
||||||
}
|
}
|
||||||
@@ -366,7 +358,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
buffer.counter = 0;
|
buffer.counter = 0;
|
||||||
buffer.current_frame = 0;
|
buffer.current_frame = 0;
|
||||||
buffer.completed = false;
|
buffer.completed = false;
|
||||||
buffer.name = "";
|
buffer.name.clear();
|
||||||
buffer.speed = 5;
|
buffer.speed = 5;
|
||||||
buffer.loop = 0;
|
buffer.loop = 0;
|
||||||
buffer.frames.clear();
|
buffer.frames.clear();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = "", std::vector<std::string> *buffer = nullptr);
|
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), std::vector<std::string>* buffer = nullptr);
|
||||||
explicit AnimatedSprite(const AnimatedFile *animation);
|
explicit AnimatedSprite(const AnimatedFile *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ bool Director::setFileList()
|
|||||||
#ifdef MACOS_BUNDLE
|
#ifdef MACOS_BUNDLE
|
||||||
const std::string prefix = "/../Resources";
|
const std::string prefix = "/../Resources";
|
||||||
#else
|
#else
|
||||||
const std::string prefix = "";
|
const std::string prefix;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ficheros de configuración
|
// Ficheros de configuración
|
||||||
@@ -490,7 +490,7 @@ void Director::checkProgramArguments(int argc, char *argv[])
|
|||||||
executable_path_ = argv[0];
|
executable_path_ = argv[0];
|
||||||
|
|
||||||
// Valores por defecto
|
// Valores por defecto
|
||||||
param_file_argument_ = "";
|
param_file_argument_.clear();
|
||||||
|
|
||||||
// Comprueba el resto de parametros
|
// Comprueba el resto de parametros
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
|
|||||||
@@ -2169,7 +2169,7 @@ void Game::renderMessages()
|
|||||||
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
if (stage_bitmap_counter_ < STAGE_COUNTER)
|
||||||
{
|
{
|
||||||
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
const auto stage_number = balloon_formations_->getStage(current_stage_).number;
|
||||||
std::string text = "";
|
std::string text;
|
||||||
|
|
||||||
if (stage_number == 10)
|
if (stage_number == 10)
|
||||||
{ // Ultima fase
|
{ // Ultima fase
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void HiScoreTable::fillTexture()
|
|||||||
const auto score = format(options.game.hi_score_table[i].score);
|
const auto score = format(options.game.hi_score_table[i].score);
|
||||||
const auto score_lenght = score.size();
|
const auto score_lenght = score.size();
|
||||||
const auto num_dots = 25 - name_lenght - score_lenght;
|
const auto num_dots = 25 - name_lenght - score_lenght;
|
||||||
std::string dots = "";
|
std::string dots;
|
||||||
for (int j = 0; j < (int)num_dots; ++j)
|
for (int j = 0; j < (int)num_dots; ++j)
|
||||||
{
|
{
|
||||||
dots = dots + ".";
|
dots = dots + ".";
|
||||||
@@ -255,7 +255,7 @@ std::string HiScoreTable::format(int number)
|
|||||||
const std::string score = std::to_string(number);
|
const std::string score = std::to_string(number);
|
||||||
|
|
||||||
auto index = (int)score.size() - 1;
|
auto index = (int)score.size() - 1;
|
||||||
std::string result = "";
|
std::string result;
|
||||||
auto i = 0;
|
auto i = 0;
|
||||||
while (index >= 0)
|
while (index >= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -147,18 +147,19 @@ void Notify::clearFinishedNotifications()
|
|||||||
void Notify::showText(std::string text1, std::string text2, int icon)
|
void Notify::showText(std::string text1, std::string text2, int icon)
|
||||||
{
|
{
|
||||||
// Cuenta el número de textos a mostrar
|
// Cuenta el número de textos a mostrar
|
||||||
const int numTexts = (text1 != "") + (text2 != "");
|
const int numTexts = !text1.empty() + !text2.empty();
|
||||||
|
|
||||||
// Si no hay texto, acaba
|
// Si no hay texto, acaba
|
||||||
if (numTexts == 0)
|
if (numTexts == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si solo hay un texto, lo coloca en la primera variable
|
// Si solo hay un texto, lo coloca en la primera variable
|
||||||
else if (numTexts == 1)
|
if (numTexts == 1)
|
||||||
{
|
{
|
||||||
text1 = text1 + text2;
|
text1 += text2;
|
||||||
text2 = "";
|
text2.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si las notificaciones no se apilan, elimina las anteriores
|
// Si las notificaciones no se apilan, elimina las anteriores
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void showText(std::string text1 = "", std::string text2 = "", int icon = -1);
|
void showText(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1);
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool active();
|
bool active();
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ bool setOptions(std::string var, const std::string &value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lineas vacias o que empiezan por comentario
|
// Lineas vacias o que empiezan por comentario
|
||||||
else if (var == "" || var.substr(0, 1) == "#")
|
else if (var.empty() || var.starts_with("#"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vect
|
|||||||
demo_ = demo;
|
demo_ = demo;
|
||||||
status_playing_ = PlayerStatus::WAITING;
|
status_playing_ = PlayerStatus::WAITING;
|
||||||
scoreboard_panel_ = 0;
|
scoreboard_panel_ = 0;
|
||||||
name_ = "";
|
name_.clear();
|
||||||
setRecordName(enter_name_->getName());
|
setRecordName(enter_name_->getName());
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
|||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i)
|
||||||
{
|
{
|
||||||
name_[i] = "";
|
name_[i].clear();
|
||||||
record_name_[i] = "";
|
record_name_[i].clear();
|
||||||
selector_pos_[i] = 0;
|
selector_pos_[i] = 0;
|
||||||
score_[i] = 0;
|
score_[i] = 0;
|
||||||
mult_[i] = 0;
|
mult_[i] = 0;
|
||||||
@@ -54,7 +54,7 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer)
|
|||||||
stage_ = 1;
|
stage_ = 1;
|
||||||
hi_score_ = 0;
|
hi_score_ = 0;
|
||||||
power_ = 0;
|
power_ = 0;
|
||||||
hi_score_name_ = "";
|
hi_score_name_.clear();
|
||||||
color_ = {0, 0, 0};
|
color_ = {0, 0, 0};
|
||||||
rect_ = {0, 0, 320, 40};
|
rect_ = {0, 0, 320, 40};
|
||||||
panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE;
|
panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE;
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public:
|
|||||||
void attenuate(bool value);
|
void attenuate(bool value);
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
void showNotification(std::string text1 = std::string(), std::string text2 = std::string(), int icon = -1);
|
||||||
|
|
||||||
// Indica si hay alguna notificación activa en pantalla
|
// Indica si hay alguna notificación activa en pantalla
|
||||||
bool notificationsAreActive() const;
|
bool notificationsAreActive() const;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
|||||||
palettes_.clear();
|
palettes_.clear();
|
||||||
|
|
||||||
// Carga el fichero en la textura
|
// Carga el fichero en la textura
|
||||||
if (path_ != "")
|
if (!path_.empty())
|
||||||
{
|
{
|
||||||
// Obtiene la extensión
|
// Obtiene la extensión
|
||||||
const std::string extension = path_.substr(path_.find_last_of(".") + 1);
|
const std::string extension = path_.substr(path_.find_last_of(".") + 1);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit Texture(SDL_Renderer *renderer, std::string path = "");
|
explicit Texture(SDL_Renderer *renderer, std::string path = std::string());
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ void Title::swapControllers()
|
|||||||
int playerControllerIndex[MAX_CONTROLLERS];
|
int playerControllerIndex[MAX_CONTROLLERS];
|
||||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||||
{
|
{
|
||||||
text[i] = "";
|
text[i].clear();
|
||||||
playerControllerIndex[i] = -1;
|
playerControllerIndex[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,19 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Writer::Writer(std::shared_ptr<Text> text)
|
Writer::Writer(std::shared_ptr<Text> text)
|
||||||
: text_(text)
|
: text_(text),
|
||||||
{
|
pos_x_(0),
|
||||||
// Inicializa variables
|
pos_y_(0),
|
||||||
pos_x_ = 0;
|
kerning_(0),
|
||||||
pos_y_ = 0;
|
caption_(std::string()),
|
||||||
kerning_ = 0;
|
speed_(0),
|
||||||
caption_ = "";
|
writing_counter_(0),
|
||||||
speed_ = 0;
|
index_(0),
|
||||||
writing_counter_ = 0;
|
lenght_(0),
|
||||||
index_ = 0;
|
completed_(false),
|
||||||
lenght_ = 0;
|
enabled_(false),
|
||||||
completed_ = false;
|
enabled_counter_(0),
|
||||||
enabled_ = false;
|
finished_(false) {}
|
||||||
enabled_counter_ = 0;
|
|
||||||
finished_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza el objeto
|
||||||
void Writer::update()
|
void Writer::update()
|
||||||
@@ -45,7 +42,11 @@ void Writer::update()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Completado
|
// Completado
|
||||||
enabled_counter_ > 0 ? enabled_counter_-- : finished_ = true;
|
finished_ = enabled_counter_ <= 0;
|
||||||
|
if (!finished_)
|
||||||
|
{
|
||||||
|
enabled_counter_--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user