Acabat amb cppcheck

Arreglades les herencies de les classes Sprite
This commit is contained in:
2024-10-13 21:00:33 +02:00
parent 809c10048e
commit 7c876e1d4d
21 changed files with 99 additions and 110 deletions

View File

@@ -1,6 +1,8 @@
#include "animated_sprite.h" #include "animated_sprite.h"
#include <algorithm> // for copy
#include <fstream> // for basic_ostream, operator<<, basic_istream, basic... #include <fstream> // for basic_ostream, operator<<, basic_istream, basic...
#include <iostream> // for cout #include <iostream> // for cout
#include <iterator> // for back_insert_iterator, back_inserter
#include <sstream> // for basic_stringstream #include <sstream> // for basic_stringstream
#include "texture.h" // for Texture #include "texture.h" // for Texture

View File

@@ -2,11 +2,11 @@
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_stdinc.h> // for Uint8 #include <SDL2/SDL_stdinc.h> // for Uint8
#include <string> // for string, basic_string #include <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector #include <vector> // for vector
#include "moving_sprite.h" // for MovingSprite #include "moving_sprite.h" // for MovingSprite
#include "texture.h" class Texture;
#include <memory>
struct Animation struct Animation
{ {
@@ -37,7 +37,7 @@ protected:
public: public:
// Constructor // Constructor
explicit AnimatedSprite(std::shared_ptr<Texture> texture = nullptr, const std::string &file = std::string(), 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

View File

@@ -1,10 +1,12 @@
#include "background.h" #include "background.h"
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND #include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888 #include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <algorithm> // for max, min #include <algorithm> // for clamp, max
#include <string> // for basic_string #include "asset.h" // for Asset
#include "asset.h" // for Asset #include "moving_sprite.h" // for MovingSprite
#include "param.h" // for param #include "param.h" // for param
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
// Constructor // Constructor
Background::Background(SDL_Renderer *renderer) Background::Background(SDL_Renderer *renderer)

View File

@@ -1,12 +1,12 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture #include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include "utils.h" // for Color #include <memory> // for unique_ptr, shared_ptr
#include "moving_sprite.h" #include "utils.h" // for Color
#include "sprite.h" class MovingSprite;
#include "texture.h" class Sprite;
#include <memory> class Texture;
/* /*
Esta clase es la encargada de dibujar el fondo que aparece durante la sección Esta clase es la encargada de dibujar el fondo que aparece durante la sección

View File

@@ -428,7 +428,6 @@ void BalloonFormations::initBalloonFormations()
// #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos // #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos
j = 24; j = 24;
balloon_formation_[j].number_of_balloons = 30; balloon_formation_[j].number_of_balloons = 30;
inc_x = 0;
inc_time = 5; inc_time = 5;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++)
{ {

View File

@@ -3,7 +3,6 @@
#include "sprite.h" // for Sprite #include "sprite.h" // for Sprite
#include <memory> // for std::unique_ptr #include <memory> // for std::unique_ptr
// Constantes evaluables en tiempo de compilación
constexpr int BULLET_WIDTH = 12; constexpr int BULLET_WIDTH = 12;
constexpr int BULLET_HEIGHT = 12; constexpr int BULLET_HEIGHT = 12;
constexpr int BULLET_VELY = -3; constexpr int BULLET_VELY = -3;
@@ -23,10 +22,9 @@ Bullet::Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Re
owner_(owner), owner_(owner),
play_area_(play_area) play_area_(play_area)
{ {
vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT
: (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT : 0;
: 0;
auto sprite_offset = powered_up ? 3 : 0; auto sprite_offset = powered_up ? 3 : 0;
auto kind_index = static_cast<int>(kind); auto kind_index = static_cast<int>(kind);
sprite_->setSpriteClip((kind_index + sprite_offset) * width_, 0, sprite_->getWidth(), sprite_->getHeight()); sprite_->setSpriteClip((kind_index + sprite_offset) * width_, 0, sprite_->getWidth(), sprite_->getHeight());
@@ -67,12 +65,12 @@ BulletMoveStatus Bullet::move()
bool Bullet::isEnabled() const bool Bullet::isEnabled() const
{ {
return kind_ != BulletType::NULL_TYPE; return kind_ != BulletType::NONE;
} }
void Bullet::disable() void Bullet::disable()
{ {
kind_ = BulletType::NULL_TYPE; kind_ = BulletType::NONE;
} }
int Bullet::getPosX() const int Bullet::getPosX() const

View File

@@ -13,7 +13,7 @@ enum class BulletType
UP, UP,
LEFT, LEFT,
RIGHT, RIGHT,
NULL_TYPE NONE
}; };
// Enumeración para los resultados del movimiento de la bala // Enumeración para los resultados del movimiento de la bala

View File

@@ -41,7 +41,7 @@
#endif #endif
// Constructor // Constructor
Director::Director(int argc, char *argv[]) Director::Director(int argc, const char *argv[])
{ {
#ifdef RECORDING #ifdef RECORDING
section::name = section::Name::GAME; section::name = section::Name::GAME;
@@ -160,8 +160,8 @@ void Director::initInput()
Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10); Input::get()->bindKey(InputType::RESET, SDL_SCANCODE_F10);
// Asigna botones a inputs // Asigna botones a inputs
const int numGamePads = Input::get()->getNumControllers(); const int num_gamepads = Input::get()->getNumControllers();
for (int i = 0; i < numGamePads; ++i) for (int i = 0; i < num_gamepads; ++i)
{ {
// Mando - Movimiento del jugador // Mando - Movimiento del jugador
Input::get()->bindGameControllerButton(i, InputType::UP, SDL_CONTROLLER_BUTTON_DPAD_UP); Input::get()->bindGameControllerButton(i, InputType::UP, SDL_CONTROLLER_BUTTON_DPAD_UP);
@@ -188,7 +188,7 @@ void Director::initInput()
} }
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso // Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
for (int i = 0; i < numGamePads; ++i) for (int i = 0; i < num_gamepads; ++i)
for (int index = 0; index < (int)options.controller.size(); ++index) for (int index = 0; index < (int)options.controller.size(); ++index)
if (Input::get()->getControllerName(i) == options.controller[index].name) if (Input::get()->getControllerName(i) == options.controller[index].name)
{ {
@@ -200,7 +200,7 @@ void Director::initInput()
} }
// Asigna botones a inputs desde otros inputs // Asigna botones a inputs desde otros inputs
for (int i = 0; i < numGamePads; ++i) for (int i = 0; i < num_gamepads; ++i)
{ {
Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START); Input::get()->bindGameControllerButton(i, InputType::EXIT, InputType::START);
Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER); Input::get()->bindGameControllerButton(i, InputType::RESET, InputType::FIRE_CENTER);
@@ -213,7 +213,7 @@ void Director::initInput()
} }
// Guarda las asignaciones de botones en las opciones // Guarda las asignaciones de botones en las opciones
for (int i = 0; i < numGamePads; ++i) for (int i = 0; i < num_gamepads; ++i)
{ {
options.controller[i].name = Input::get()->getControllerName(i); options.controller[i].name = Input::get()->getControllerName(i);
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j) for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
@@ -484,7 +484,7 @@ void Director::loadParams(const std::string &file_path)
} }
// Comprueba los parametros del programa // Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, char *argv[]) void Director::checkProgramArguments(int argc, const char *argv[])
{ {
// Establece la ruta del programa // Establece la ruta del programa
executable_path_ = argv[0]; executable_path_ = argv[0];
@@ -492,7 +492,7 @@ void Director::checkProgramArguments(int argc, char *argv[])
// Valores por defecto // Valores por defecto
param_file_argument_.clear(); param_file_argument_.clear();
// Comprueba el resto de parametros // Comprueba el resto de parámetros
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
{ {
if (strcmp(argv[i], "--320x240") == 0) if (strcmp(argv[i], "--320x240") == 0)
@@ -566,17 +566,15 @@ void Director::createSystemFolder(const std::string &folder)
void Director::loadSounds() void Director::loadSounds()
{ {
// Obtiene la lista con las rutas a los ficheros de sonidos // Obtiene la lista con las rutas a los ficheros de sonidos
std::vector<std::string> list = Asset::get()->getListByType(AssetType::SOUND); auto list = Asset::get()->getListByType(AssetType::SOUND);
sounds_.clear(); sounds_.clear();
for (const auto &l : list) for (const auto &l : list)
{ {
const size_t lastIndex = l.find_last_of("/") + 1; auto last_index = l.find_last_of('/') + 1;
const std::string name = l.substr(lastIndex, std::string::npos); auto name = l.substr(last_index);
SoundFile temp;
temp.name = name; // Añade el nombre del fichero sounds_.emplace_back(SoundFile{name, JA_LoadSound(l.c_str())});
temp.file = JA_LoadSound(l.c_str()); // Carga el fichero de audio
sounds_.push_back(temp);
} }
} }
@@ -584,78 +582,69 @@ void Director::loadSounds()
void Director::loadMusics() void Director::loadMusics()
{ {
// Obtiene la lista con las rutas a los ficheros musicales // Obtiene la lista con las rutas a los ficheros musicales
std::vector<std::string> list = Asset::get()->getListByType(AssetType::MUSIC); auto list = Asset::get()->getListByType(AssetType::MUSIC);
musics_.clear(); musics_.clear();
for (const auto &l : list) for (const auto &l : list)
{ {
const size_t lastIndex = l.find_last_of("/") + 1; auto last_index = l.find_last_of('/') + 1;
const std::string name = l.substr(lastIndex, std::string::npos); auto name = l.substr(last_index);
MusicFile temp;
temp.name = name; // Añade el nombre del fichero musics_.emplace_back(MusicFile{name, JA_LoadMusic(l.c_str())});
temp.file = JA_LoadMusic(l.c_str()); // Carga el fichero de audio
musics_.push_back(temp);
} }
} }
// Ejecuta la sección con el logo // Ejecuta la sección con el logo
void Director::runLogo() void Director::runLogo()
{ {
auto logo = new Logo(); auto logo = std::make_unique<Logo>();
logo->run(); logo->run();
delete logo;
} }
// Ejecuta la sección con la secuencia de introducción // Ejecuta la sección con la secuencia de introducción
void Director::runIntro() void Director::runIntro()
{ {
auto intro = new Intro(getMusic(musics_, "intro.ogg")); auto intro = std::make_unique<Intro>(getMusic(musics_, "intro.ogg"));
intro->run(); intro->run();
delete intro;
} }
// Ejecuta la sección con el titulo del juego // Ejecuta la sección con el título del juego
void Director::runTitle() void Director::runTitle()
{ {
auto title = new Title(getMusic(musics_, "title.ogg")); auto title = std::make_unique<Title>(getMusic(musics_, "title.ogg"));
title->run(); title->run();
delete title;
} }
// Ejecuta la sección donde se juega al juego // Ejecuta la sección donde se juega al juego
void Director::runGame() void Director::runGame()
{ {
const auto playerID = section::options == section::Options::GAME_PLAY_1P ? 1 : 2; const auto player_id = section::options == section::Options::GAME_PLAY_1P ? 1 : 2;
constexpr auto currentStage = 0; constexpr auto current_stage = 0;
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg")); auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_OFF, getMusic(musics_, "playing.ogg"));
game->run(); game->run();
delete game;
} }
// Ejecuta la sección donde se muestran las instrucciones // Ejecuta la sección donde se muestran las instrucciones
void Director::runInstructions() void Director::runInstructions()
{ {
auto instructions = new Instructions(getMusic(musics_, "title.ogg")); auto instructions = std::make_unique<Instructions>(getMusic(musics_, "title.ogg"));
instructions->run(); instructions->run();
delete instructions;
} }
// Ejecuta la sección donde se muestra la tabla de puntuaciones // Ejecuta la sección donde se muestra la tabla de puntuaciones
void Director::runHiScoreTable() void Director::runHiScoreTable()
{ {
auto hiScoreTable = new HiScoreTable(getMusic(musics_, "title.ogg")); auto hi_score_table = std::make_unique<HiScoreTable>(getMusic(musics_, "title.ogg"));
hiScoreTable->run(); hi_score_table->run();
delete hiScoreTable;
} }
// Ejecuta el juego en modo demo // Ejecuta el juego en modo demo
void Director::runDemoGame() void Director::runDemoGame()
{ {
const auto playerID = (rand() % 2) + 1; const auto player_id = (rand() % 2) + 1;
constexpr auto currentStage = 0; constexpr auto current_stage = 0;
auto game = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, nullptr); auto game = std::make_unique<Game>(player_id, current_stage, GAME_MODE_DEMO_ON, nullptr);
game->run(); game->run();
delete game;
} }
int Director::run() int Director::run()
@@ -702,8 +691,8 @@ int Director::run()
} }
} }
const int returnCode = section::options == section::Options::QUIT_NORMAL ? 0 : 1; const int return_code = section::options == section::Options::QUIT_NORMAL ? 0 : 1;
return returnCode; return return_code;
} }
// Obtiene una fichero a partir de un lang::Code // Obtiene una fichero a partir de un lang::Code

View File

@@ -46,7 +46,7 @@ private:
void loadMusics(); void loadMusics();
// Comprueba los parametros del programa // Comprueba los parametros del programa
void checkProgramArguments(int argc, char *argv[]); void checkProgramArguments(int argc, const char *argv[]);
// Crea la carpeta del sistema donde guardar datos // Crea la carpeta del sistema donde guardar datos
void createSystemFolder(const std::string &folder); void createSystemFolder(const std::string &folder);
@@ -77,7 +77,7 @@ private:
public: public:
// Constructor // Constructor
Director(int argc, char *argv[]); Director(int argc, const char *argv[]);
// Destructor // Destructor
~Director(); ~Director();

View File

@@ -114,12 +114,12 @@ void Logo::updateJAILGAMES()
{ {
for (int i = 0; i < (int)jail_sprite_.size(); ++i) for (int i = 0; i < (int)jail_sprite_.size(); ++i)
{ {
if (jail_sprite_[i]->getPosX() != dest_.x) if (jail_sprite_[i]->getIntPosX() != dest_.x)
{ {
if (i % 2 == 0) if (i % 2 == 0)
{ {
jail_sprite_[i]->incPosX(-SPEED); jail_sprite_[i]->incPosX(-SPEED);
if (jail_sprite_[i]->getPosX() < dest_.x) if (jail_sprite_[i]->getIntPosX() < dest_.x)
{ {
jail_sprite_[i]->setPosX(dest_.x); jail_sprite_[i]->setPosX(dest_.x);
} }
@@ -127,7 +127,7 @@ void Logo::updateJAILGAMES()
else else
{ {
jail_sprite_[i]->incPosX(SPEED); jail_sprite_[i]->incPosX(SPEED);
if (jail_sprite_[i]->getPosX() > dest_.x) if (jail_sprite_[i]->getIntPosX() > dest_.x)
{ {
jail_sprite_[i]->setPosX(dest_.x); jail_sprite_[i]->setPosX(dest_.x);
} }

View File

@@ -7,25 +7,23 @@ Actualizando a la versión "Arcade Edition" en 08/05/2024
*/ */
#include <iostream> // for basic_ostream, char_traits, operator<<, cout #include <iostream> // for basic_ostream, char_traits, operator<<, cout
#include <string> // for basic_string, operator<<, string #include <string> // for basic_string, operator<<, string
#include "director.h" // for Director #include <memory>
#include "director.h" // for Director
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::cout << "Game start" << std::endl; std::cout << "Game start" << std::endl;
// Crea el objeto Director // Crea el objeto Director
Director *director = new Director(argc, argv); auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
// Bucle principal // Bucle principal
const auto exit = director->run(); const auto exit = director->run();
// Destruye el objeto Director const auto endType = exit == 0 ? "keyboard" : "controller";
delete director; std::cout << "\nGame end with " << endType << std::endl;
const auto endType = exit == 0 ? "keyboard" : "controller"; return exit;
std::cout << "\nGame end with " << endType << std::endl;
return exit;
} }

View File

@@ -195,7 +195,7 @@ void loadParamsFromFile(const std::string &file_path)
auto comment_pos = line.find('#'); auto comment_pos = line.find('#');
if (comment_pos != std::string::npos) if (comment_pos != std::string::npos)
{ {
line = line.substr(0, comment_pos); line.resize(comment_pos);
} }
// Usa un stream para separar palabras // Usa un stream para separar palabras

View File

@@ -103,7 +103,7 @@ private:
// [SINGLETON] Ahora el constructor y el destructor son privados // [SINGLETON] Ahora el constructor y el destructor son privados
// Constructor // Constructor
Scoreboard(SDL_Renderer *renderer); explicit Scoreboard(SDL_Renderer *renderer);
// Destructor // Destructor
~Scoreboard(); ~Scoreboard();

View File

@@ -21,13 +21,13 @@ void Sprite::render()
} }
// Obten el valor de la variable // Obten el valor de la variable
int Sprite::getPosX() const int Sprite::getIntPosX() const
{ {
return pos_.x; return pos_.x;
} }
// Obten el valor de la variable // Obten el valor de la variable
int Sprite::getPosY() const int Sprite::getIntPosY() const
{ {
return pos_.y; return pos_.y;
} }

View File

@@ -26,8 +26,8 @@ public:
virtual void render(); virtual void render();
// Obten el valor de la variable // Obten el valor de la variable
int getPosX() const; int getIntPosX() const;
int getPosY() const; int getIntPosY() const;
int getWidth() const; int getWidth() const;
int getHeight() const; int getHeight() const;

View File

@@ -81,7 +81,7 @@ TextFile LoadTextFile(std::string file_path)
} }
// Constructor // Constructor
Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer) Text::Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer)
{ {
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
auto tf = LoadTextFile(text_file); auto tf = LoadTextFile(text_file);
@@ -105,7 +105,7 @@ Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *rendere
} }
// Constructor // Constructor
Text::Text(std::string text_file, std::shared_ptr<Texture> texture) Text::Text(const std::string &text_file, std::shared_ptr<Texture> texture)
{ {
// Carga los offsets desde el fichero // Carga los offsets desde el fichero
auto tf = LoadTextFile(text_file); auto tf = LoadTextFile(text_file);

View File

@@ -44,8 +44,8 @@ private:
public: public:
// Constructor // Constructor
Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer); Text(const std::string &bitmap_file, const std::string &text_file, SDL_Renderer *renderer);
Text(std::string text_file, std::shared_ptr<Texture> texture); Text(const std::string &text_file, std::shared_ptr<Texture> texture);
Text(TextFile *text_file, std::shared_ptr<Texture> texture); Text(TextFile *text_file, std::shared_ptr<Texture> texture);
// Destructor // Destructor

View File

@@ -56,13 +56,13 @@ Texture::~Texture()
// Carga una imagen desde un fichero // Carga una imagen desde un fichero
bool Texture::loadFromFile(const std::string &path) bool Texture::loadFromFile(const std::string &path)
{ {
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha; int req_format = STBI_rgb_alpha;
int width, height, orig_format; int width, height, orig_format;
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format); unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
if (!data) if (!data)
{ {
#ifdef VERBOSE #ifdef VERBOSE
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl; std::cout << "Loading image failed: " << stbi_failure_reason() << std::endl;
#endif #endif
exit(1); exit(1);
@@ -70,6 +70,7 @@ bool Texture::loadFromFile(const std::string &path)
else else
{ {
#ifdef VERBOSE #ifdef VERBOSE
const std::string file_name = path.substr(path.find_last_of("\\/") + 1);
std::cout << "Image loaded: " << file_name << std::endl; std::cout << "Image loaded: " << file_name << std::endl;
#endif #endif
} }
@@ -96,7 +97,7 @@ bool Texture::loadFromFile(const std::string &path)
SDL_Texture *newTexture = nullptr; SDL_Texture *newTexture = nullptr;
// Carga la imagen desde una ruta específica // Carga la imagen desde una ruta específica
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void*>(data), width, height, depth, pitch, pixel_format); auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
if (loadedSurface == nullptr) if (loadedSurface == nullptr)
{ {
#ifdef VERBOSE #ifdef VERBOSE
@@ -137,9 +138,9 @@ bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL
texture_ = SDL_CreateTexture(renderer_, format, access, width, height); texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
if (!texture_) if (!texture_)
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl; std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
#endif #endif
} }
else else
{ {
@@ -312,7 +313,7 @@ void Texture::flipSurface()
// Vuelca los datos // Vuelca los datos
Uint32 *pixels; Uint32 *pixels;
int pitch; int pitch;
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void**>(&pixels), &pitch); SDL_LockTexture(texture_, nullptr, reinterpret_cast<void **>(&pixels), &pitch);
for (int i = 0; i < width_ * height_; ++i) for (int i = 0; i < width_ * height_; ++i)
{ {
pixels[i] = palettes_[paletteIndex_][surface_->data[i]]; pixels[i] = palettes_[paletteIndex_][surface_->data[i]];
@@ -344,7 +345,7 @@ std::vector<Uint32> Texture::loadPal(const std::string &file_name)
fread(buffer, size, 1, f); fread(buffer, size, 1, f);
fclose(f); fclose(f);
auto pal = LoadPalette(buffer); const auto pal = LoadPalette(buffer);
if (!pal) if (!pal)
{ {
return palette; return palette;
@@ -361,9 +362,9 @@ std::vector<Uint32> Texture::loadPal(const std::string &file_name)
} }
// Añade una paleta a la lista // Añade una paleta a la lista
void Texture::addPalette(std::string path) void Texture::addPalette(const std::string &path)
{ {
palettes_.push_back(loadPal(path.c_str())); palettes_.push_back(loadPal(path));
setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000); setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000);
} }

View File

@@ -91,7 +91,7 @@ public:
SDL_Texture *getSDLTexture(); SDL_Texture *getSDLTexture();
// Añade una paleta a la lista // Añade una paleta a la lista
void addPalette(std::string path); void addPalette(const std::string &path);
// Establece un color de la paleta // Establece un color de la paleta
void setPaletteColor(int palette, int index, Uint32 color); void setPaletteColor(int palette, int index, Uint32 color);

View File

@@ -79,7 +79,7 @@ void Writer::setKerning(int value)
} }
// Establece el valor de la variable // Establece el valor de la variable
void Writer::setCaption(std::string text) void Writer::setCaption(const std::string &text)
{ {
caption_ = text; caption_ = text;
lenght_ = text.length(); lenght_ = text.length();

View File

@@ -48,7 +48,7 @@ public:
void setKerning(int value); void setKerning(int value);
// Establece el valor de la variable // Establece el valor de la variable
void setCaption(std::string text); void setCaption(const std::string &text);
// Establece el valor de la variable // Establece el valor de la variable
void setSpeed(int value); void setSpeed(int value);