diff --git a/linux-utils/check-includes.sh b/linux-utils/check-includes.sh index c393cc9..efc06f3 100755 --- a/linux-utils/check-includes.sh +++ b/linux-utils/check-includes.sh @@ -4,7 +4,7 @@ SOURCEPATH=../source/ for i in "$SOURCEPATH"/*.cpp 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..." clear done diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index 1a0f50b..773ffc0 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -37,7 +37,7 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string buffer.counter = 0; buffer.current_frame = 0; buffer.completed = false; - buffer.name = ""; + buffer.name.clear(); buffer.speed = 5; buffer.loop = 0; buffer.frames.clear(); @@ -159,18 +159,15 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string // Constructor AnimatedSprite::AnimatedSprite(std::shared_ptr texture, const std::string &file, std::vector *buffer) - : MovingSprite(texture) + : MovingSprite(texture), + current_animation_(0) { // Carga las animaciones - if (file != "") + if (!file.empty()) { AnimatedFile as = loadAnimationFromFile(texture, file); // 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_)); } @@ -178,18 +175,13 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr texture, const std::stri { loadFromVector(buffer); } - - // Inicializa variables - current_animation_ = 0; } // Constructor 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 std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_)); } @@ -366,7 +358,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) buffer.counter = 0; buffer.current_frame = 0; buffer.completed = false; - buffer.name = ""; + buffer.name.clear(); buffer.speed = 5; buffer.loop = 0; buffer.frames.clear(); diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 8c98d7d..603a822 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -37,7 +37,7 @@ protected: public: // Constructor - explicit AnimatedSprite(std::shared_ptr texture = nullptr, const std::string &file = "", std::vector *buffer = nullptr); + explicit AnimatedSprite(std::shared_ptr texture = nullptr, const std::string &file = std::string(), std::vector* buffer = nullptr); explicit AnimatedSprite(const AnimatedFile *animation); // Destructor diff --git a/source/director.cpp b/source/director.cpp index 163d1cf..32dd598 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -340,7 +340,7 @@ bool Director::setFileList() #ifdef MACOS_BUNDLE const std::string prefix = "/../Resources"; #else - const std::string prefix = ""; + const std::string prefix; #endif // Ficheros de configuración @@ -490,7 +490,7 @@ void Director::checkProgramArguments(int argc, char *argv[]) executable_path_ = argv[0]; // Valores por defecto - param_file_argument_ = ""; + param_file_argument_.clear(); // Comprueba el resto de parametros for (int i = 1; i < argc; ++i) diff --git a/source/game.cpp b/source/game.cpp index 23250b1..5afb464 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -2169,7 +2169,7 @@ void Game::renderMessages() if (stage_bitmap_counter_ < STAGE_COUNTER) { const auto stage_number = balloon_formations_->getStage(current_stage_).number; - std::string text = ""; + std::string text; if (stage_number == 10) { // Ultima fase diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index ec1fe02..1fdb6f7 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -129,7 +129,7 @@ void HiScoreTable::fillTexture() const auto score = format(options.game.hi_score_table[i].score); const auto score_lenght = score.size(); const auto num_dots = 25 - name_lenght - score_lenght; - std::string dots = ""; + std::string dots; for (int j = 0; j < (int)num_dots; ++j) { dots = dots + "."; @@ -255,7 +255,7 @@ std::string HiScoreTable::format(int number) const std::string score = std::to_string(number); auto index = (int)score.size() - 1; - std::string result = ""; + std::string result; auto i = 0; while (index >= 0) { diff --git a/source/notify.cpp b/source/notify.cpp index f5c7ab9..3de069b 100644 --- a/source/notify.cpp +++ b/source/notify.cpp @@ -147,18 +147,19 @@ void Notify::clearFinishedNotifications() void Notify::showText(std::string text1, std::string text2, int icon) { // 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 if (numTexts == 0) { return; } + // Si solo hay un texto, lo coloca en la primera variable - else if (numTexts == 1) + if (numTexts == 1) { - text1 = text1 + text2; - text2 = ""; + text1 += text2; + text2.clear(); } // Si las notificaciones no se apilan, elimina las anteriores diff --git a/source/notify.h b/source/notify.h index c6c6187..75d4eb2 100644 --- a/source/notify.h +++ b/source/notify.h @@ -89,7 +89,7 @@ public: void update(); // 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 bool active(); diff --git a/source/options.cpp b/source/options.cpp index dc258be..53194e7 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -393,7 +393,7 @@ bool setOptions(std::string var, const std::string &value) } // Lineas vacias o que empiezan por comentario - else if (var == "" || var.substr(0, 1) == "#") + else if (var.empty() || var.starts_with("#")) { } diff --git a/source/player.cpp b/source/player.cpp index 12adf2d..7f10f9b 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -35,7 +35,7 @@ Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vect demo_ = demo; status_playing_ = PlayerStatus::WAITING; scoreboard_panel_ = 0; - name_ = ""; + name_.clear(); setRecordName(enter_name_->getName()); init(); } diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 34b069e..668d509 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -44,8 +44,8 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer) // Inicializa variables for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i) { - name_[i] = ""; - record_name_[i] = ""; + name_[i].clear(); + record_name_[i].clear(); selector_pos_[i] = 0; score_[i] = 0; mult_[i] = 0; @@ -54,7 +54,7 @@ Scoreboard::Scoreboard(SDL_Renderer *renderer) stage_ = 1; hi_score_ = 0; power_ = 0; - hi_score_name_ = ""; + hi_score_name_.clear(); color_ = {0, 0, 0}; rect_ = {0, 0, 320, 40}; panel_[SCOREBOARD_LEFT_PANEL].mode = ScoreboardMode::SCORE; diff --git a/source/screen.h b/source/screen.h index cbfdc0b..0749648 100644 --- a/source/screen.h +++ b/source/screen.h @@ -152,7 +152,7 @@ public: void attenuate(bool value); // 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 bool notificationsAreActive() const; diff --git a/source/texture.cpp b/source/texture.cpp index 5f5e96f..1e49bea 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -23,7 +23,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path) palettes_.clear(); // Carga el fichero en la textura - if (path_ != "") + if (!path_.empty()) { // Obtiene la extensión const std::string extension = path_.substr(path_.find_last_of(".") + 1); diff --git a/source/texture.h b/source/texture.h index 23446db..c533ab0 100644 --- a/source/texture.h +++ b/source/texture.h @@ -49,7 +49,7 @@ private: public: // Constructor - explicit Texture(SDL_Renderer *renderer, std::string path = ""); + explicit Texture(SDL_Renderer *renderer, std::string path = std::string()); // Destructor ~Texture(); diff --git a/source/title.cpp b/source/title.cpp index 7e7344f..5a170b9 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -330,7 +330,7 @@ void Title::swapControllers() int playerControllerIndex[MAX_CONTROLLERS]; for (int i = 0; i < MAX_CONTROLLERS; ++i) { - text[i] = ""; + text[i].clear(); playerControllerIndex[i] = -1; } diff --git a/source/writer.cpp b/source/writer.cpp index 28f234e..682762e 100644 --- a/source/writer.cpp +++ b/source/writer.cpp @@ -2,22 +2,19 @@ // Constructor Writer::Writer(std::shared_ptr text) - : text_(text) -{ - // Inicializa variables - pos_x_ = 0; - pos_y_ = 0; - kerning_ = 0; - caption_ = ""; - speed_ = 0; - writing_counter_ = 0; - index_ = 0; - lenght_ = 0; - completed_ = false; - enabled_ = false; - enabled_counter_ = 0; - finished_ = false; -} + : text_(text), + pos_x_(0), + pos_y_(0), + kerning_(0), + caption_(std::string()), + speed_(0), + writing_counter_(0), + index_(0), + lenght_(0), + completed_(false), + enabled_(false), + enabled_counter_(0), + finished_(false) {} // Actualiza el objeto void Writer::update() @@ -45,7 +42,11 @@ void Writer::update() else { // Completado - enabled_counter_ > 0 ? enabled_counter_-- : finished_ = true; + finished_ = enabled_counter_ <= 0; + if (!finished_) + { + enabled_counter_--; + } } } }