This commit is contained in:
2026-04-17 22:20:37 +02:00
parent 513eacf356
commit 20b9a95619
38 changed files with 310 additions and 622 deletions

View File

@@ -22,6 +22,8 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
while (std::getline(file, line)) {
if (line == "[animation]") {
animation_t buffer;
buffer.speed = 0;
buffer.loop = -1;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.completed = false;
@@ -82,7 +84,7 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
}
// Carga la animación desde un fichero
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose) {
animatedSprite_t loadAnimationFromFile(Texture *texture, const std::string &filePath, bool verbose) {
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
std::ifstream file(filePath);
if (!file.good()) {
@@ -109,42 +111,34 @@ animatedSprite_t loadAnimationFromMemory(Texture *texture, const std::vector<uin
}
// Constructor
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer) {
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, const std::string &file, std::vector<std::string> *buffer)
: currentAnimation(0) {
// Copia los punteros
setTexture(texture);
setRenderer(renderer);
// Carga las animaciones
if (file != "") {
if (!file.empty()) {
animatedSprite_t as = loadAnimationFromFile(texture, file);
// Copia los datos de las animaciones
for (auto animation : as.animations) {
this->animation.push_back(animation);
}
animation.insert(animation.end(), as.animations.begin(), as.animations.end());
}
else if (buffer) {
loadFromVector(buffer);
}
// Inicializa variables
currentAnimation = 0;
}
// Constructor
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation) {
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
: currentAnimation(0) {
// Copia los punteros
setTexture(animation->texture);
setRenderer(renderer);
// Inicializa variables
currentAnimation = 0;
// Copia los datos de las animaciones
for (auto a : animation->animations) {
this->animation.push_back(a);
}
this->animation.insert(this->animation.end(), animation->animations.begin(), animation->animations.end());
}
// Destructor
@@ -156,10 +150,10 @@ AnimatedSprite::~AnimatedSprite() {
}
// Obtiene el indice de la animación a partir del nombre
int AnimatedSprite::getIndex(std::string name) {
int AnimatedSprite::getIndex(const std::string &name) {
int index = -1;
for (auto a : animation) {
for (const auto &a : animation) {
index++;
if (a.name == name) {
return index;
@@ -222,12 +216,12 @@ void AnimatedSprite::setCurrentFrame(int num) {
}
// Establece el valor del contador
void AnimatedSprite::setAnimationCounter(std::string name, int num) {
void AnimatedSprite::setAnimationCounter(const std::string &name, int num) {
animation[getIndex(name)].counter = num;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(std::string name, int speed) {
void AnimatedSprite::setAnimationSpeed(const std::string &name, int speed) {
animation[getIndex(name)].counter = speed;
}
@@ -237,7 +231,7 @@ void AnimatedSprite::setAnimationSpeed(int index, int speed) {
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(std::string name, int loop) {
void AnimatedSprite::setAnimationLoop(const std::string &name, int loop) {
animation[getIndex(name)].loop = loop;
}
@@ -247,7 +241,7 @@ void AnimatedSprite::setAnimationLoop(int index, int loop) {
}
// Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(std::string name, bool value) {
void AnimatedSprite::setAnimationCompleted(const std::string &name, bool value) {
animation[getIndex(name)].completed = value;
}
@@ -262,7 +256,7 @@ bool AnimatedSprite::animationIsCompleted() {
}
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index) {
SDL_Rect AnimatedSprite::getAnimationClip(const std::string &name, Uint8 index) {
return animation[getIndex(name)].frames[index];
}
@@ -292,6 +286,8 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source) {
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]") {
animation_t buffer;
buffer.speed = 0;
buffer.loop = -1;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.completed = false;
@@ -391,7 +387,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source) {
}
// Establece la animacion actual
void AnimatedSprite::setCurrentAnimation(std::string name) {
void AnimatedSprite::setCurrentAnimation(const std::string &name) {
const int newAnimation = getIndex(name);
if (currentAnimation != newAnimation) {
currentAnimation = newAnimation;

View File

@@ -25,7 +25,7 @@ struct animatedSprite_t {
};
// Carga la animación desde un fichero
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false);
animatedSprite_t loadAnimationFromFile(Texture *texture, const std::string &filePath, bool verbose = false);
// Carga la animación desde bytes en memoria
animatedSprite_t loadAnimationFromMemory(Texture *texture, const std::vector<uint8_t> &bytes, const std::string &nameForLogs = "", bool verbose = false);
@@ -38,7 +38,7 @@ class AnimatedSprite : public MovingSprite {
public:
// Constructor
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
explicit AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, const std::string &file = "", std::vector<std::string> *buffer = nullptr);
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
// Destructor
@@ -54,35 +54,35 @@ class AnimatedSprite : public MovingSprite {
void setCurrentFrame(int num);
// Establece el valor del contador
void setAnimationCounter(std::string name, int num);
void setAnimationCounter(const std::string &name, int num);
// Establece la velocidad de una animación
void setAnimationSpeed(std::string name, int speed);
void setAnimationSpeed(const std::string &name, int speed);
void setAnimationSpeed(int index, int speed);
// Establece el frame al que vuelve la animación al finalizar
void setAnimationLoop(std::string name, int loop);
void setAnimationLoop(const std::string &name, int loop);
void setAnimationLoop(int index, int loop);
// Establece el valor de la variable
void setAnimationCompleted(std::string name, bool value);
void setAnimationCompleted(const std::string &name, bool value);
void setAnimationCompleted(int index, bool value);
// Comprueba si ha terminado la animación
bool animationIsCompleted();
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
SDL_Rect getAnimationClip(const std::string &name = "default", Uint8 index = 0);
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
// Obtiene el indice de la animación a partir del nombre
int getIndex(std::string name);
int getIndex(const std::string &name);
// Carga la animación desde un vector
bool loadFromVector(std::vector<std::string> *source);
// Establece la animacion actual
void setCurrentAnimation(std::string name = "default");
void setCurrentAnimation(const std::string &name = "default");
void setCurrentAnimation(int index = 0);
// Actualiza las variables del objeto

View File

@@ -8,9 +8,8 @@
#include "game/defaults.hpp" // for GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
// Constructor
Fade::Fade(SDL_Renderer *renderer) {
mRenderer = renderer;
Fade::Fade(SDL_Renderer *renderer)
: mRenderer(renderer) {
mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mBackbuffer != nullptr) {
SDL_SetTextureScaleMode(mBackbuffer, SDL_SCALEMODE_NEAREST);
@@ -53,7 +52,6 @@ void Fade::render() {
int alpha = mCounter * 4;
if (alpha >= 255) {
alpha = 255;
mFullscreenDone = true;
// Deja todos los buffers del mismo color

View File

@@ -10,23 +10,23 @@ constexpr int FADE_RANDOM_SQUARE = 2;
// Clase Fade
class Fade {
private:
SDL_Renderer *mRenderer; // El renderizador de la ventana
SDL_Texture *mBackbuffer; // Textura para usar como backbuffer
Uint8 mFadeType; // Tipo de fade a realizar
Uint16 mCounter; // Contador interno
bool mEnabled; // Indica si el fade está activo
bool mFinished; // Indica si ha terminado la transición
Uint8 mR, mG, mB; // Colores para el fade
Uint8 mROriginal, mGOriginal, mBOriginal; // Colores originales para FADE_RANDOM_SQUARE
Uint32 mLastSquareTicks; // Ticks del último cuadrado dibujado (FADE_RANDOM_SQUARE)
Uint16 mSquaresDrawn; // Número de cuadrados dibujados (FADE_RANDOM_SQUARE)
bool mFullscreenDone; // Indica si el fade fullscreen ha terminado la fase de fundido
SDL_Rect mRect1; // Rectangulo usado para crear los efectos de transición
SDL_Rect mRect2; // Rectangulo usado para crear los efectos de transición
SDL_Renderer *mRenderer = nullptr; // El renderizador de la ventana
SDL_Texture *mBackbuffer = nullptr; // Textura para usar como backbuffer
Uint8 mFadeType = FADE_FULLSCREEN; // Tipo de fade a realizar
Uint16 mCounter = 0; // Contador interno
bool mEnabled = false; // Indica si el fade está activo
bool mFinished = false; // Indica si ha terminado la transición
Uint8 mR = 0, mG = 0, mB = 0; // Colores para el fade
Uint8 mROriginal = 0, mGOriginal = 0, mBOriginal = 0; // Colores originales para FADE_RANDOM_SQUARE
Uint32 mLastSquareTicks = 0; // Ticks del último cuadrado dibujado (FADE_RANDOM_SQUARE)
Uint16 mSquaresDrawn = 0; // Número de cuadrados dibujados (FADE_RANDOM_SQUARE)
bool mFullscreenDone = false; // Indica si el fade fullscreen ha terminado la fase de fundido
SDL_Rect mRect1{}; // Rectangulo usado para crear los efectos de transición
SDL_Rect mRect2{}; // Rectangulo usado para crear los efectos de transición
public:
// Constructor
Fade(SDL_Renderer *renderer);
explicit Fade(SDL_Renderer *renderer);
// Destructor
~Fade();

View File

@@ -3,53 +3,26 @@
#include "core/rendering/texture.h" // for Texture
// Constructor
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer) {
// Copia los punteros
this->texture = texture;
this->renderer = renderer;
// Establece el alto y el ancho del sprite
this->w = w;
this->h = h;
// Establece la posición X,Y del sprite
this->x = x;
this->y = y;
xPrev = x;
yPrev = y;
// Establece la velocidad X,Y del sprite
vx = velx;
vy = vely;
// Establece la aceleración X,Y del sprite
ax = accelx;
ay = accely;
// Establece el zoom W,H del sprite
zoomW = 1;
zoomH = 1;
// Establece el angulo con el que se dibujará
angle = (double)0;
// Establece los valores de rotacion
rotateEnabled = false;
rotateSpeed = 0;
rotateAmount = (double)0;
// Contador interno
counter = 0;
// Establece el rectangulo de donde coger la imagen
spriteClip = {0, 0, w, h};
// Establece el centro de rotación
center = nullptr;
// Establece el tipo de volteado
currentFlip = SDL_FLIP_NONE;
};
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
: Sprite(0, 0, w, h, texture, renderer),
x(x),
y(y),
xPrev(x),
yPrev(y),
vx(velx),
vy(vely),
ax(accelx),
ay(accely),
zoomW(1),
zoomH(1),
angle(0.0),
rotateEnabled(false),
rotateSpeed(0),
rotateAmount(0.0),
counter(0),
center(nullptr),
currentFlip(SDL_FLIP_NONE) {
}
// Reinicia todas las variables
void MovingSprite::clear() {

View File

@@ -33,7 +33,7 @@ class MovingSprite : public Sprite {
public:
// Constructor
MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
explicit MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
// Mueve el sprite
void move();

View File

@@ -77,7 +77,8 @@ auto Screen::get() -> Screen * {
}
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) {
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
: borderColor{0x00, 0x00, 0x00} {
// Inicializa variables
this->window = window;
this->renderer = renderer;
@@ -85,9 +86,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) {
gameCanvasWidth = GAMECANVAS_WIDTH;
gameCanvasHeight = GAMECANVAS_HEIGHT;
// Define el color del borde para el modo de pantalla completa
borderColor = {0x00, 0x00, 0x00};
// Establece el modo de video (fullscreen/ventana + logical presentation)
// ANTES de crear la textura — SDL3 GPU necesita la logical presentation
// del renderer ya aplicada al swapchain quan es reclama la ventana per a GPU.

View File

@@ -3,48 +3,26 @@
#include "core/rendering/texture.h" // for Texture
// Constructor
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer) {
// Establece la posición X,Y del sprite
this->x = x;
this->y = y;
// Establece el alto y el ancho del sprite
this->w = w;
this->h = h;
// Establece el puntero al renderizador de la ventana
this->renderer = renderer;
// Establece la textura donde están los gráficos para el sprite
this->texture = texture;
// Establece el rectangulo de donde coger la imagen
spriteClip = {0, 0, w, h};
// Inicializa variables
enabled = true;
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
: x(x),
y(y),
w(w),
h(h),
renderer(renderer),
texture(texture),
spriteClip{0, 0, w, h},
enabled(true) {
}
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) {
// Establece la posición X,Y del sprite
x = rect.x;
y = rect.y;
// Establece el alto y el ancho del sprite
w = rect.w;
h = rect.h;
// Establece el puntero al renderizador de la ventana
this->renderer = renderer;
// Establece la textura donde están los gráficos para el sprite
this->texture = texture;
// Establece el rectangulo de donde coger la imagen
spriteClip = {0, 0, w, h};
// Inicializa variables
enabled = true;
Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer)
: x(rect.x),
y(rect.y),
w(rect.w),
h(rect.h),
renderer(renderer),
texture(texture),
spriteClip{0, 0, rect.w, rect.h},
enabled(true) {
}
// Destructor

View File

@@ -19,7 +19,7 @@ class Sprite {
public:
// Constructor
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
// Destructor

View File

@@ -39,8 +39,10 @@ static void computeTextFileOffsets(textFile_t &tf) {
}
// Llena una estructuta textFile_t desde un fichero
textFile_t LoadTextFile(std::string file, bool verbose) {
textFile_t LoadTextFile(const std::string &file, bool verbose) {
textFile_t tf;
tf.boxWidth = 0;
tf.boxHeight = 0;
for (int i = 0; i < 128; ++i) {
tf.offset[i].x = 0;
tf.offset[i].y = 0;
@@ -65,6 +67,8 @@ textFile_t LoadTextFile(std::string file, bool verbose) {
// Llena una estructura textFile_t desde bytes en memoria
textFile_t LoadTextFileFromMemory(const std::vector<uint8_t> &bytes, bool verbose) {
textFile_t tf;
tf.boxWidth = 0;
tf.boxHeight = 0;
for (int i = 0; i < 128; ++i) {
tf.offset[i].x = 0;
tf.offset[i].y = 0;
@@ -83,7 +87,7 @@ textFile_t LoadTextFileFromMemory(const std::vector<uint8_t> &bytes, bool verbos
}
// Constructor
Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer) {
Text::Text(const std::string &bitmapFile, const std::string &textFile, SDL_Renderer *renderer) {
// Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile);
@@ -105,7 +109,7 @@ Text::Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer)
}
// Constructor
Text::Text(std::string textFile, Texture *texture, SDL_Renderer *renderer) {
Text::Text(const std::string &textFile, Texture *texture, SDL_Renderer *renderer) {
// Carga los offsets desde el fichero
textFile_t tf = LoadTextFile(textFile);
@@ -172,7 +176,7 @@ Text::~Text() {
}
// Escribe texto en pantalla
void Text::write(int x, int y, std::string text, int kerning, int lenght) {
void Text::write(int x, int y, const std::string &text, int kerning, int lenght) {
int shift = 0;
if (lenght == -1) {
@@ -192,14 +196,14 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght) {
}
// Escribe el texto con colores
void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght) {
void Text::writeColored(int x, int y, const std::string &text, color_t color, int kerning, int lenght) {
sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x, y, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255);
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght) {
void Text::writeShadowed(int x, int y, const std::string &text, color_t color, Uint8 shadowDistance, int kerning, int lenght) {
sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
sprite->getTexture()->setColor(255, 255, 255);
@@ -207,13 +211,13 @@ void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 sh
}
// Escribe el texto centrado en un punto x
void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght) {
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int lenght) {
x -= (Text::lenght(text, kerning) / 2);
write(x, y, text, kerning, lenght);
}
// Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) {
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) {
const bool centered = ((flags & TXT_CENTER) == TXT_CENTER);
const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW);
const bool colored = ((flags & TXT_COLOR) == TXT_COLOR);
@@ -245,7 +249,7 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
}
// Obtiene la longitud en pixels de una cadena
int Text::lenght(std::string text, int kerning) {
int Text::lenght(const std::string &text, int kerning) {
int shift = 0;
for (int i = 0; i < (int)text.length(); ++i)

View File

@@ -28,7 +28,7 @@ struct textFile_t {
};
// Llena una estructuta textFile_t desde un fichero
textFile_t LoadTextFile(std::string file, bool verbose = false);
textFile_t LoadTextFile(const std::string &file, bool verbose = false);
// Llena una estructura textFile_t desde bytes en memoria
textFile_t LoadTextFileFromMemory(const std::vector<uint8_t> &bytes, bool verbose = false);
@@ -48,8 +48,8 @@ class Text {
public:
// Constructor
Text(std::string bitmapFile, std::string textFile, SDL_Renderer *renderer);
Text(std::string textFile, Texture *texture, SDL_Renderer *renderer);
Text(const std::string &bitmapFile, const std::string &textFile, SDL_Renderer *renderer);
Text(const std::string &textFile, Texture *texture, SDL_Renderer *renderer);
Text(textFile_t *textFile, Texture *texture, SDL_Renderer *renderer);
// Constructor desde bytes en memoria: comparte ownership del texture (no lo libera)
@@ -58,23 +58,27 @@ class Text {
// Destructor
~Text();
// No copiable (gestiona memoria dinámica)
Text(const Text &) = delete;
Text &operator=(const Text &) = delete;
// Escribe el texto en pantalla
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
void write(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
// Escribe el texto con colores
void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1);
void writeColored(int x, int y, const std::string &text, color_t color, int kerning = 1, int lenght = -1);
// Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
void writeShadowed(int x, int y, const std::string &text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
// Escribe el texto centrado en un punto x
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
void writeCentered(int x, int y, const std::string &text, int kerning = 1, int lenght = -1);
// Escribe texto con extras
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = color_t(255, 255, 255), Uint8 shadowDistance = 1, color_t shadowColor = color_t(0, 0, 0), int lenght = -1);
void writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning = 1, color_t textColor = color_t(255, 255, 255), Uint8 shadowDistance = 1, color_t shadowColor = color_t(0, 0, 0), int lenght = -1);
// Obtiene la longitud en pixels de una cadena
int lenght(std::string text, int kerning = 1);
int lenght(const std::string &text, int kerning = 1);
// Devuelve el valor de la variable
int getCharacterSize();

View File

@@ -15,30 +15,25 @@ void Texture::setGlobalScaleMode(SDL_ScaleMode mode) {
}
// Constructor
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) {
// Copia punteros
this->renderer = renderer;
this->path = path;
// Inicializa
texture = nullptr;
width = 0;
height = 0;
Texture::Texture(SDL_Renderer *renderer, const std::string &path, bool verbose)
: texture(nullptr),
renderer(renderer),
width(0),
height(0),
path(path) {
// Carga el fichero en la textura
if (path != "") {
if (!path.empty()) {
loadFromFile(path, renderer, verbose);
}
}
// Constructor desde bytes
Texture::Texture(SDL_Renderer *renderer, const std::vector<uint8_t> &bytes, bool verbose) {
this->renderer = renderer;
this->path = "";
texture = nullptr;
width = 0;
height = 0;
Texture::Texture(SDL_Renderer *renderer, const std::vector<uint8_t> &bytes, bool verbose)
: texture(nullptr),
renderer(renderer),
width(0),
height(0),
path("") {
if (!bytes.empty()) {
loadFromMemory(bytes.data(), bytes.size(), renderer, verbose);
}
@@ -53,7 +48,7 @@ Texture::~Texture() {
// Helper: convierte píxeles RGBA decodificados por stbi en SDL_Texture
static SDL_Texture *createTextureFromPixels(SDL_Renderer *renderer, unsigned char *data, int w, int h, int *out_w, int *out_h) {
const int pitch = 4 * w;
SDL_Surface *loadedSurface = SDL_CreateSurfaceFrom(w, h, SDL_PIXELFORMAT_RGBA32, (void *)data, pitch);
SDL_Surface *loadedSurface = SDL_CreateSurfaceFrom(w, h, SDL_PIXELFORMAT_RGBA32, static_cast<void *>(data), pitch);
if (loadedSurface == nullptr) {
return nullptr;
}
@@ -68,7 +63,7 @@ static SDL_Texture *createTextureFromPixels(SDL_Renderer *renderer, unsigned cha
}
// Carga una imagen desde un fichero
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose) {
bool Texture::loadFromFile(const std::string &path, SDL_Renderer *renderer, bool verbose) {
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha;
int w, h, orig_format;

View File

@@ -24,7 +24,7 @@ class Texture {
static void setGlobalScaleMode(SDL_ScaleMode mode);
// Constructor
Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false);
explicit Texture(SDL_Renderer *renderer, const std::string &path = "", bool verbose = false);
// Constructor desde bytes (PNG en memoria)
Texture(SDL_Renderer *renderer, const std::vector<uint8_t> &bytes, bool verbose = false);
@@ -33,7 +33,7 @@ class Texture {
~Texture();
// Carga una imagen desde un fichero
bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false);
bool loadFromFile(const std::string &path, SDL_Renderer *renderer, bool verbose = false);
// Carga una imagen desde bytes en memoria
bool loadFromMemory(const uint8_t *data, size_t size, SDL_Renderer *renderer, bool verbose = false);

View File

@@ -3,23 +3,20 @@
#include "core/rendering/text.h" // for Text
// Constructor
Writer::Writer(Text *text) {
// Copia los punteros
this->text = text;
// Inicializa variables
posX = 0;
posY = 0;
kerning = 0;
caption = "";
speed = 0;
writingCounter = 0;
index = 0;
lenght = 0;
completed = false;
enabled = false;
enabledCounter = 0;
finished = false;
Writer::Writer(Text *text)
: text(text),
posX(0),
posY(0),
kerning(0),
caption(""),
speed(0),
writingCounter(0),
index(0),
lenght(0),
completed(false),
enabled(false),
enabledCounter(0),
finished(false) {
}
// Actualiza el objeto
@@ -73,7 +70,7 @@ void Writer::setKerning(int value) {
}
// Establece el valor de la variable
void Writer::setCaption(std::string text) {
void Writer::setCaption(const std::string &text) {
caption = text;
lenght = text.length();
}

View File

@@ -25,7 +25,7 @@ class Writer {
public:
// Constructor
Writer(Text *text);
explicit Writer(Text *text);
// Actualiza el objeto
void update();
@@ -43,7 +43,7 @@ class Writer {
void setKerning(int value);
// Establece el valor de la variable
void setCaption(std::string text);
void setCaption(const std::string &text);
// Establece el valor de la variable
void setSpeed(int value);