neteja clang-tidy

This commit is contained in:
2026-05-16 22:47:41 +02:00
parent 17341f923d
commit a903343385
40 changed files with 1246 additions and 1384 deletions
+14 -14
View File
@@ -29,10 +29,10 @@ Background::Background(float total_progress_to_complete)
moon_texture_(Resource::get()->getTexture("game_moon.png")),
grass_sprite_(std::make_unique<AnimatedSprite>(Resource::get()->getTexture("game_grass.png"), Resource::get()->getAnimation("game_grass.ani"))),
total_progress_to_complete_(total_progress_to_complete),
progress_per_stage_(total_progress_to_complete_ / STAGES),
sun_completion_progress_(total_progress_to_complete_ * SUN_COMPLETION_FACTOR),
minimum_completed_progress_(total_progress_to_complete_ * MINIMUM_COMPLETED_PROGRESS_PERCENTAGE),
TOTAL_PROGRESS_TO_COMPLETE(total_progress_to_complete),
PROGRESS_PER_STAGE(TOTAL_PROGRESS_TO_COMPLETE / STAGES),
SUM_COMPLETION_PROGRESS(TOTAL_PROGRESS_TO_COMPLETE * SUN_COMPLETION_FACTOR),
MINIMUM_COMPLETED_PROGRESS(TOTAL_PROGRESS_TO_COMPLETE * MINIMUM_COMPLETED_PROGRESS_PERCENTAGE),
rect_(SDL_FRect{.x = 0, .y = 0, .w = static_cast<float>(gradients_texture_->getWidth() / 2), .h = static_cast<float>(gradients_texture_->getHeight() / 2)}),
src_rect_({.x = 0, .y = 0, .w = 320, .h = 240}),
@@ -167,7 +167,7 @@ void Background::incrementProgress(float amount) {
if (state_ == State::NORMAL) {
float old_progress = progress_;
progress_ += amount;
progress_ = std::min(progress_, total_progress_to_complete_);
progress_ = std::min(progress_, TOTAL_PROGRESS_TO_COMPLETE);
// Notifica el cambio si hay callback y el progreso cambió
if (progress_callback_ && progress_ != old_progress) {
@@ -179,7 +179,7 @@ void Background::incrementProgress(float amount) {
// Establece la progresión absoluta
void Background::setProgress(float absolute_progress) {
float old_progress = progress_;
progress_ = std::clamp(absolute_progress, 0.0F, total_progress_to_complete_);
progress_ = std::clamp(absolute_progress, 0.0F, TOTAL_PROGRESS_TO_COMPLETE);
// Notifica el cambio si hay callback y el progreso cambió
if (progress_callback_ && progress_ != old_progress) {
@@ -282,27 +282,27 @@ void Background::updateProgression(float delta_time) {
float eased_t = easeOutCubic(static_cast<double>(t));
// Interpolación desde progreso inicial hasta mínimo
float progress_range = completion_initial_progress_ - minimum_completed_progress_;
float progress_range = completion_initial_progress_ - MINIMUM_COMPLETED_PROGRESS;
progress_ = completion_initial_progress_ - (progress_range * eased_t);
} else {
// Transición completada, fijar al valor mínimo
progress_ = minimum_completed_progress_;
progress_ = MINIMUM_COMPLETED_PROGRESS;
}
}
// Calcula la transición de los diferentes fondos
const float GRADIENT_NUMBER_FLOAT = std::min(progress_ / progress_per_stage_, 3.0F);
const float GRADIENT_NUMBER_FLOAT = std::min(progress_ / PROGRESS_PER_STAGE, 3.0F);
const float PERCENT = GRADIENT_NUMBER_FLOAT - static_cast<int>(GRADIENT_NUMBER_FLOAT);
gradient_number_ = static_cast<size_t>(GRADIENT_NUMBER_FLOAT);
transition_ = PERCENT;
// Calcula la posición del sol
const float SUN_PROGRESSION = std::min(progress_ / sun_completion_progress_, 1.0F);
const float SUN_PROGRESSION = std::min(progress_ / SUM_COMPLETION_PROGRESS, 1.0F);
sun_index_ = static_cast<size_t>(SUN_PROGRESSION * (sun_path_.size() - 1));
// Calcula la posición de la luna
const float MOON_PROGRESSION = std::min(progress_ / total_progress_to_complete_, 1.0F);
const float MOON_PROGRESSION = std::min(progress_ / TOTAL_PROGRESS_TO_COMPLETE, 1.0F);
moon_index_ = static_cast<size_t>(MOON_PROGRESSION * (moon_path_.size() - 1));
// Actualiza la velocidad de las nubes
@@ -318,12 +318,12 @@ void Background::updateCloudsSpeed() {
// Velocidad base según progreso (de -3.0 a -120.0 píxeles/segundo, igual que la versión original)
float base_clouds_speed = (-CLOUDS_INITIAL_SPEED_PX_PER_S) +
(-CLOUDS_FINAL_SPEED_RANGE_PX_PER_S * (progress_ / total_progress_to_complete_));
(-CLOUDS_FINAL_SPEED_RANGE_PX_PER_S * (progress_ / TOTAL_PROGRESS_TO_COMPLETE));
// En estado completado, las nubes se ralentizan gradualmente
if (state_ == State::COMPLETED) {
float completion_factor = (progress_ - minimum_completed_progress_) /
(total_progress_to_complete_ - minimum_completed_progress_);
float completion_factor = (progress_ - MINIMUM_COMPLETED_PROGRESS) /
(TOTAL_PROGRESS_TO_COMPLETE - MINIMUM_COMPLETED_PROGRESS);
completion_factor = std::max(0.1F, completion_factor);
base_clouds_speed *= completion_factor;
}
+6 -5
View File
@@ -4,6 +4,7 @@
#include <array> // Para array
#include <cstddef> // Para size_t
#include <cstdint> // Para std::uint8_t
#include <functional> // Para function
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
@@ -19,7 +20,7 @@ class AnimatedSprite;
class Background {
public:
// --- Enums ---
enum class State {
enum class State : std::uint8_t {
NORMAL, // Progresión normal del día
COMPLETED // Reducción gradual de la actividad
};
@@ -87,10 +88,10 @@ class Background {
std::unique_ptr<AnimatedSprite> grass_sprite_; // Sprite con la hierba
// --- Variables de configuración ---
const float total_progress_to_complete_; // Progreso total para completar
const float progress_per_stage_; // Progreso por etapa
const float sun_completion_progress_; // Progreso de completado del sol
const float minimum_completed_progress_; // Progreso mínimo calculado dinámicamente
const float TOTAL_PROGRESS_TO_COMPLETE; // Progreso total para completar
const float PROGRESS_PER_STAGE; // Progreso por etapa
const float SUM_COMPLETION_PROGRESS; // Progreso de completado del sol
const float MINIMUM_COMPLETED_PROGRESS; // Progreso mínimo calculado dinámicamente
ProgressCallback progress_callback_; // Callback para notificar cambios de progreso
// --- Variables de estado ---
+1 -1
View File
@@ -481,7 +481,7 @@ void Fade::activate() {
case Type::DIAGONAL: {
rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)};
square_.clear();
square_age_.assign(num_squares_width_ * num_squares_height_, -1);
square_age_.assign(static_cast<size_t>(num_squares_width_) * num_squares_height_, -1);
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) {
rect1_.x = (i % num_squares_width_) * rect1_.w;
rect1_.y = (i / num_squares_width_) * rect1_.h;
+197 -185
View File
@@ -8,145 +8,233 @@
#include <string> // Para char_traits, operator==, basic_string, string
namespace GIF {
inline void readBytes(const uint8_t *&buffer, void *dst, size_t size) {
std::memcpy(dst, buffer, size);
buffer += size;
}
void Gif::decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out) {
if (code_length < 2 || code_length > 12) {
std::cout << "Invalid LZW code length: " << code_length << '\n';
throw std::runtime_error("Invalid LZW code length");
namespace {
inline void readBytes(const uint8_t *&buffer, void *dst, size_t size) {
std::memcpy(dst, buffer, size);
buffer += size;
}
int i, bit;
int prev = -1;
std::vector<DictionaryEntry> dictionary;
int dictionary_ind;
unsigned int mask = 0x01;
int reset_code_length = code_length;
int clear_code = 1 << code_length;
int stop_code = clear_code + 1;
int match_len = 0;
dictionary.resize(1 << (code_length + 1));
for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++) {
dictionary[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
dictionary[dictionary_ind].prev = -1;
dictionary[dictionary_ind].len = 1;
// Llavor del diccionari LZW: 0..N-1 com a entrades base, i salta 2 (clear_code + stop_code).
void resetDictionary(std::vector<DictionaryEntry> &dict, int code_length, int &dictionary_ind) {
dict.resize(1 << (code_length + 1));
for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++) {
dict[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
dict[dictionary_ind].prev = -1;
dict[dictionary_ind].len = 1;
}
dictionary_ind += 2;
}
dictionary_ind += 2;
while (input_length > 0) {
// Llig `code_length + 1` bits LSB-first del flux d'entrada. Llança si s'acaba el buffer.
auto readNextCode(const uint8_t *&input, int &input_length, int code_length, unsigned int &mask) -> int {
int code = 0;
for (i = 0; i < (code_length + 1); i++) {
for (int i = 0; i < code_length + 1; i++) {
if (input_length <= 0) {
std::cout << "Unexpected end of input in decompress" << '\n';
throw std::runtime_error("Unexpected end of input in decompress");
}
bit = ((*input & mask) != 0) ? 1 : 0;
const int BIT = ((*input & mask) != 0) ? 1 : 0;
mask <<= 1;
if (mask == 0x100) {
mask = 0x01;
input++;
input_length--;
}
code |= (bit << i);
code |= (BIT << i);
}
return code;
}
if (code == clear_code) {
code_length = reset_code_length;
dictionary.resize(1 << (code_length + 1));
for (dictionary_ind = 0; dictionary_ind < (1 << code_length); dictionary_ind++) {
dictionary[dictionary_ind].byte = static_cast<uint8_t>(dictionary_ind);
dictionary[dictionary_ind].prev = -1;
dictionary[dictionary_ind].len = 1;
}
dictionary_ind += 2;
prev = -1;
continue;
} else if (code == stop_code) {
break;
// Afig una nova entrada al diccionari. Resol el cas especial KwKwK (code == dictionary_ind)
// començant la cadena des de `prev` en lloc de des de `code`.
void addDictionaryEntry(std::vector<DictionaryEntry> &dict, int dictionary_ind, int code, int prev) {
int ptr = (code == dictionary_ind) ? prev : code;
while (dict[ptr].prev != -1) {
ptr = dict[ptr].prev;
}
dict[dictionary_ind].byte = dict[ptr].byte;
dict[dictionary_ind].prev = prev;
dict[dictionary_ind].len = dict[prev].len + 1;
}
if (prev > -1 && code_length < 12) {
if (code > dictionary_ind) {
std::cout << "LZW error: code (" << code << ") exceeds dictionary_ind (" << dictionary_ind << ")" << '\n';
throw std::runtime_error("LZW error: code exceeds dictionary_ind.");
}
int ptr;
if (code == dictionary_ind) {
ptr = prev;
while (dictionary[ptr].prev != -1)
ptr = dictionary[ptr].prev;
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
} else {
ptr = code;
while (dictionary[ptr].prev != -1)
ptr = dictionary[ptr].prev;
dictionary[dictionary_ind].byte = dictionary[ptr].byte;
}
dictionary[dictionary_ind].prev = prev;
dictionary[dictionary_ind].len = dictionary[prev].len + 1;
dictionary_ind++;
if ((dictionary_ind == (1 << (code_length + 1))) && (code_length < 11)) {
code_length++;
dictionary.resize(1 << (code_length + 1));
}
}
prev = code;
if (code < 0 || static_cast<size_t>(code) >= dictionary.size()) {
std::cout << "Invalid LZW code " << code << ", dictionary size " << static_cast<unsigned long>(dictionary.size()) << '\n';
throw std::runtime_error("LZW error: invalid code encountered");
}
int curCode = code;
match_len = dictionary[curCode].len;
while (curCode != -1) {
out[dictionary[curCode].len - 1] = dictionary[curCode].byte;
if (dictionary[curCode].prev == curCode) {
// Escriu la cadena de bytes associada a `code` en `out` (en ordre invers seguint .prev).
// Retorna la longitud del match per avançar el cursor de l'eixida.
auto emitMatch(const std::vector<DictionaryEntry> &dict, int code, uint8_t *out) -> int {
const int MATCH_LEN = dict[code].len;
int cur_code = code;
while (cur_code != -1) {
out[dict[cur_code].len - 1] = dict[cur_code].byte;
if (dict[cur_code].prev == cur_code) {
std::cout << "Internal error; self-reference detected." << '\n';
throw std::runtime_error("Internal error in decompress: self-reference");
}
curCode = dictionary[curCode].prev;
cur_code = dict[cur_code].prev;
}
out += match_len;
return MATCH_LEN;
}
}
std::vector<uint8_t> Gif::readSubBlocks(const uint8_t *&buffer) {
std::vector<uint8_t> data;
uint8_t block_size = *buffer;
buffer++;
while (block_size != 0) {
data.insert(data.end(), buffer, buffer + block_size);
buffer += block_size;
block_size = *buffer;
// Descompone (uncompress) el bloque comprimido usando LZW.
void decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out) {
if (code_length < 2 || code_length > 12) {
std::cout << "Invalid LZW code length: " << code_length << '\n';
throw std::runtime_error("Invalid LZW code length");
}
int prev = -1;
std::vector<DictionaryEntry> dictionary;
int dictionary_ind = 0;
unsigned int mask = 0x01;
const int RESET_CODE_LENGTH = code_length;
const int CLEAR_CODE = 1 << code_length;
const int STOP_CODE = CLEAR_CODE + 1;
resetDictionary(dictionary, code_length, dictionary_ind);
while (input_length > 0) {
const int CODE = readNextCode(input, input_length, code_length, mask);
if (CODE == CLEAR_CODE) {
code_length = RESET_CODE_LENGTH;
resetDictionary(dictionary, code_length, dictionary_ind);
prev = -1;
continue;
}
if (CODE == STOP_CODE) { break; }
if (prev > -1 && code_length < 12) {
if (CODE > dictionary_ind) {
std::cout << "LZW error: code (" << CODE << ") exceeds dictionary_ind (" << dictionary_ind << ")" << '\n';
throw std::runtime_error("LZW error: code exceeds dictionary_ind.");
}
addDictionaryEntry(dictionary, dictionary_ind, CODE, prev);
dictionary_ind++;
if ((dictionary_ind == (1 << (code_length + 1))) && (code_length < 11)) {
code_length++;
dictionary.resize(1 << (code_length + 1));
}
}
prev = CODE;
if (CODE < 0 || static_cast<size_t>(CODE) >= dictionary.size()) {
std::cout << "Invalid LZW code " << CODE << ", dictionary size " << static_cast<unsigned long>(dictionary.size()) << '\n';
throw std::runtime_error("LZW error: invalid code encountered");
}
out += emitMatch(dictionary, CODE, out);
}
}
// Lee los sub-bloques de datos y los acumula en un std::vector<uint8_t>.
auto readSubBlocks(const uint8_t *&buffer) -> std::vector<uint8_t> {
std::vector<uint8_t> data;
uint8_t block_size = *buffer;
buffer++;
while (block_size != 0) {
data.insert(data.end(), buffer, buffer + block_size);
buffer += block_size;
block_size = *buffer;
buffer++;
}
return data;
}
return data;
}
std::vector<uint8_t> Gif::processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits) {
ImageDescriptor image_descriptor;
readBytes(buffer, &image_descriptor, sizeof(ImageDescriptor));
// Procesa el Image Descriptor y retorna el vector de datos sin comprimir.
auto processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits) -> std::vector<uint8_t> {
ImageDescriptor image_descriptor;
readBytes(buffer, &image_descriptor, sizeof(ImageDescriptor));
uint8_t lzw_code_size;
readBytes(buffer, &lzw_code_size, sizeof(uint8_t));
uint8_t lzw_code_size;
readBytes(buffer, &lzw_code_size, sizeof(uint8_t));
std::vector<uint8_t> compressed_data = readSubBlocks(buffer);
int uncompressed_data_length = image_descriptor.image_width * image_descriptor.image_height;
std::vector<uint8_t> uncompressed_data(uncompressed_data_length);
std::vector<uint8_t> compressed_data = readSubBlocks(buffer);
int uncompressed_data_length = image_descriptor.image_width * image_descriptor.image_height;
std::vector<uint8_t> uncompressed_data(uncompressed_data_length);
decompress(lzw_code_size, compressed_data.data(), static_cast<int>(compressed_data.size()), uncompressed_data.data());
return uncompressed_data;
}
decompress(lzw_code_size, compressed_data.data(), static_cast<int>(compressed_data.size()), uncompressed_data.data());
return uncompressed_data;
}
std::vector<uint32_t> Gif::loadPalette(const uint8_t *buffer) {
// Procesa el stream completo del GIF y devuelve los datos sin comprimir.
auto processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h) -> std::vector<uint8_t> {
uint8_t header[6];
std::memcpy(header, buffer, 6);
buffer += 6;
std::string header_str(reinterpret_cast<char *>(header), 6);
if (header_str != "GIF87a" && header_str != "GIF89a") {
std::cout << "Formato de archivo GIF inválido: " << header_str << '\n';
throw std::runtime_error("Formato de archivo GIF inválido.");
}
ScreenDescriptor screen_descriptor;
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
w = screen_descriptor.width;
h = screen_descriptor.height;
int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
std::vector<RGB> global_color_table;
if ((screen_descriptor.fields & 0x80) != 0) {
const size_t GLOBAL_COLOR_TABLE_SIZE = 1U << (((screen_descriptor.fields & 0x07) + 1));
global_color_table.resize(GLOBAL_COLOR_TABLE_SIZE);
std::memcpy(global_color_table.data(), buffer, 3 * GLOBAL_COLOR_TABLE_SIZE);
buffer += 3 * GLOBAL_COLOR_TABLE_SIZE;
}
uint8_t block_type = *buffer++;
while (block_type != TRAILER) {
if (block_type == EXTENSION_INTRODUCER) {
uint8_t extension_label = *buffer++;
switch (extension_label) {
case GRAPHIC_CONTROL: {
uint8_t block_size = *buffer++;
buffer += block_size;
uint8_t sub_block_size = *buffer++;
while (sub_block_size != 0) {
buffer += sub_block_size;
sub_block_size = *buffer++;
}
break;
}
case APPLICATION_EXTENSION:
case COMMENT_EXTENSION:
case PLAINTEXT_EXTENSION: {
uint8_t block_size = *buffer++;
buffer += block_size;
uint8_t sub_block_size = *buffer++;
while (sub_block_size != 0) {
buffer += sub_block_size;
sub_block_size = *buffer++;
}
break;
}
default: {
uint8_t block_size = *buffer++;
buffer += block_size;
uint8_t sub_block_size = *buffer++;
while (sub_block_size != 0) {
buffer += sub_block_size;
sub_block_size = *buffer++;
}
break;
}
}
} else if (block_type == IMAGE_DESCRIPTOR) {
return processImageDescriptor(buffer, global_color_table, color_resolution_bits);
} else {
std::cout << "Unrecognized block type: 0x" << std::hex << static_cast<int>(block_type) << std::dec << '\n';
return std::vector<uint8_t>{};
}
block_type = *buffer++;
}
return std::vector<uint8_t>{};
}
} // namespace
auto loadPalette(const uint8_t *buffer) -> std::vector<uint32_t> {
uint8_t header[6];
std::memcpy(header, buffer, 6);
buffer += 6;
@@ -156,7 +244,7 @@ namespace GIF {
buffer += sizeof(ScreenDescriptor);
std::vector<uint32_t> global_color_table;
if (screen_descriptor.fields & 0x80) {
if ((screen_descriptor.fields & 0x80) != 0) {
int global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
global_color_table.resize(global_color_table_size);
for (int i = 0; i < global_color_table_size; ++i) {
@@ -170,83 +258,7 @@ namespace GIF {
return global_color_table;
}
std::vector<uint8_t> Gif::processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h) {
uint8_t header[6];
std::memcpy(header, buffer, 6);
buffer += 6;
std::string headerStr(reinterpret_cast<char *>(header), 6);
if (headerStr != "GIF87a" && headerStr != "GIF89a") {
std::cout << "Formato de archivo GIF inválido: " << headerStr << '\n';
throw std::runtime_error("Formato de archivo GIF inválido.");
}
ScreenDescriptor screen_descriptor;
readBytes(buffer, &screen_descriptor, sizeof(ScreenDescriptor));
w = screen_descriptor.width;
h = screen_descriptor.height;
int color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
std::vector<RGB> global_color_table;
if (screen_descriptor.fields & 0x80) {
int global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
global_color_table.resize(global_color_table_size);
std::memcpy(global_color_table.data(), buffer, 3 * global_color_table_size);
buffer += 3 * global_color_table_size;
}
uint8_t block_type = *buffer++;
while (block_type != TRAILER) {
if (block_type == EXTENSION_INTRODUCER) {
uint8_t extension_label = *buffer++;
switch (extension_label) {
case GRAPHIC_CONTROL: {
uint8_t blockSize = *buffer++;
buffer += blockSize;
uint8_t subBlockSize = *buffer++;
while (subBlockSize != 0) {
buffer += subBlockSize;
subBlockSize = *buffer++;
}
break;
}
case APPLICATION_EXTENSION:
case COMMENT_EXTENSION:
case PLAINTEXT_EXTENSION: {
uint8_t blockSize = *buffer++;
buffer += blockSize;
uint8_t subBlockSize = *buffer++;
while (subBlockSize != 0) {
buffer += subBlockSize;
subBlockSize = *buffer++;
}
break;
}
default: {
uint8_t blockSize = *buffer++;
buffer += blockSize;
uint8_t subBlockSize = *buffer++;
while (subBlockSize != 0) {
buffer += subBlockSize;
subBlockSize = *buffer++;
}
break;
}
}
} else if (block_type == IMAGE_DESCRIPTOR) {
return processImageDescriptor(buffer, global_color_table, color_resolution_bits);
} else {
std::cout << "Unrecognized block type: 0x" << std::hex << static_cast<int>(block_type) << std::dec << '\n';
return std::vector<uint8_t>{};
}
block_type = *buffer++;
}
return std::vector<uint8_t>{};
}
std::vector<uint8_t> Gif::loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h) {
auto loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h) -> std::vector<uint8_t> {
return processGifStream(buffer, w, h);
}
+6 -23
View File
@@ -64,29 +64,12 @@ namespace GIF {
uint8_t foreground_color, background_color;
};
class Gif {
public:
// Descompone (uncompress) el bloque comprimido usando LZW.
// Este método puede lanzar std::runtime_error en caso de error.
void decompress(int code_length, const uint8_t *input, int input_length, uint8_t *out);
// Carga la paleta (global color table) a partir de un buffer,
// retornándola en un vector de uint32_t (cada color se compone de R, G, B).
auto loadPalette(const uint8_t *buffer) -> std::vector<uint32_t>;
// Carga la paleta (global color table) a partir de un buffer,
// retornándola en un vector de uint32_t (cada color se compone de R, G, B).
std::vector<uint32_t> loadPalette(const uint8_t *buffer);
// Carga el stream GIF; devuelve un vector con los datos de imagen sin comprimir y
// asigna el ancho y alto mediante referencias.
std::vector<uint8_t> loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h);
private:
// Lee los sub-bloques de datos y los acumula en un std::vector<uint8_t>.
std::vector<uint8_t> readSubBlocks(const uint8_t *&buffer);
// Procesa el Image Descriptor y retorna el vector de datos sin comprimir.
std::vector<uint8_t> processImageDescriptor(const uint8_t *&buffer, const std::vector<RGB> &gct, int resolution_bits);
// Procesa el stream completo del GIF y devuelve los datos sin comprimir.
std::vector<uint8_t> processGifStream(const uint8_t *buffer, uint16_t &w, uint16_t &h);
};
// Carga el stream GIF; devuelve un vector con los datos de imagen sin comprimir y
// asigna el ancho y alto mediante referencias.
auto loadGif(const uint8_t *buffer, uint16_t &w, uint16_t &h) -> std::vector<uint8_t>;
} // namespace GIF
+39 -38
View File
@@ -320,49 +320,50 @@ void Screen::renderShake() {
}
}
#ifdef _DEBUG
// Compone la línia d'informació de debug: "fps - driver - shader preset"
auto Screen::buildDebugInfoText() const -> std::string {
std::string info_text = std::to_string(fps_.last_value) + " fps";
// Driver GPU
if (shader_backend_ && shader_backend_->isHardwareAccelerated()) {
const std::string DRIVER = shader_backend_->getDriverName();
info_text += DRIVER.empty() ? "" : " - " + toLower(DRIVER);
} else {
info_text += " - sdl";
}
// Shader + preset (només si està activat)
if (!Options::video.shader.enabled) { return info_text; }
if (Options::video.shader.current_shader == Rendering::ShaderType::CRTPI) {
const std::string PRESET_NAME = Options::crtpi_presets.empty() ? "" : Options::crtpi_presets.at(static_cast<size_t>(Options::video.shader.current_crtpi_preset)).name;
info_text += " - crtpi " + toLower(PRESET_NAME);
} else {
const std::string PRESET_NAME = Options::postfx_presets.empty() ? "" : Options::postfx_presets.at(static_cast<size_t>(Options::video.shader.current_postfx_preset)).name;
info_text += " - postfx " + toLower(PRESET_NAME);
if (Options::video.supersampling.enabled) { info_text += " (ss)"; }
}
return info_text;
}
// Muestra información por pantalla
void Screen::renderInfo() const {
if (debug_info_.show) {
const Color GOLD(0xFF, 0xD7, 0x00);
const Color GOLD_SHADOW = GOLD.DARKEN(150);
if (!debug_info_.show) { return; }
// Construir texto: fps - driver - preset
std::string info_text = std::to_string(fps_.last_value) + " fps";
const Color GOLD(0xFF, 0xD7, 0x00);
const Color GOLD_SHADOW = GOLD.DARKEN(150);
// Driver GPU
if (shader_backend_ && shader_backend_->isHardwareAccelerated()) {
const std::string DRIVER = shader_backend_->getDriverName();
if (!DRIVER.empty()) {
info_text += " - " + toLower(DRIVER);
}
} else {
info_text += " - sdl";
}
// Shader + preset
if (Options::video.shader.enabled) {
if (Options::video.shader.current_shader == Rendering::ShaderType::CRTPI) {
const std::string PRESET_NAME = Options::crtpi_presets.empty() ? "" : Options::crtpi_presets.at(static_cast<size_t>(Options::video.shader.current_crtpi_preset)).name;
info_text += " - crtpi " + toLower(PRESET_NAME);
} else {
const std::string PRESET_NAME = Options::postfx_presets.empty() ? "" : Options::postfx_presets.at(static_cast<size_t>(Options::video.shader.current_postfx_preset)).name;
info_text += " - postfx " + toLower(PRESET_NAME);
if (Options::video.supersampling.enabled) { info_text += " (ss)"; }
}
}
// Centrado arriba
const int TEXT_WIDTH = debug_info_.text->length(info_text);
const int X_POS = (static_cast<int>(param.game.width) - TEXT_WIDTH) / 2;
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, X_POS, 1, info_text, 1, GOLD, 1, GOLD_SHADOW);
const std::string INFO_TEXT = buildDebugInfoText();
const int TEXT_WIDTH = debug_info_.text->length(INFO_TEXT);
const int X_POS = (static_cast<int>(param.game.width) - TEXT_WIDTH) / 2;
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, X_POS, 1, INFO_TEXT, 1, GOLD, 1, GOLD_SHADOW);
#ifdef RECORDING
const std::string REC_TEXT = "recording";
const int REC_WIDTH = debug_info_.text->length(REC_TEXT);
const int REC_X = (static_cast<int>(param.game.width) - REC_WIDTH) / 2;
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, REC_X, 1 + debug_info_.text->getCharacterSize(), REC_TEXT, 1, GOLD, 1, GOLD_SHADOW);
const std::string REC_TEXT = "recording";
const int REC_WIDTH = debug_info_.text->length(REC_TEXT);
const int REC_X = (static_cast<int>(param.game.width) - REC_WIDTH) / 2;
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, REC_X, 1 + debug_info_.text->getCharacterSize(), REC_TEXT, 1, GOLD, 1, GOLD_SHADOW);
#endif
}
}
#endif
// Inicializa shaders (SDL3GPU)
@@ -380,8 +381,8 @@ void Screen::initShaders() {
Options::video.gpu.acceleration ? Options::video.gpu.preferred_driver : FALLBACK_DRIVER);
}
if (!self->shader_backend_->isHardwareAccelerated()) {
const bool ok = self->shader_backend_->init(self->window_, self->game_canvas_, "", "");
std::cout << "Screen::initShaders: SDL3GPUShader::init() = " << (ok ? "OK" : "FAILED") << '\n';
const bool OK = self->shader_backend_->init(self->window_, self->game_canvas_, "", "");
std::cout << "Screen::initShaders: SDL3GPUShader::init() = " << (OK ? "OK" : "FAILED") << '\n';
}
if (self->shader_backend_ && self->shader_backend_->isHardwareAccelerated()) {
self->shader_backend_->setLinearUpscale(Options::video.supersampling.linear_upscale);
+1
View File
@@ -241,6 +241,7 @@ class Screen {
void renderFlash(); // Dibuja el efecto de flash en la pantalla
void renderShake(); // Aplica el efecto de agitar la pantalla
void renderInfo() const; // Muestra información por pantalla
[[nodiscard]] auto buildDebugInfoText() const -> std::string; // Compone fps + driver + shader/preset para renderInfo
void renderPresent(); // Selecciona y ejecuta el método de renderizado adecuado
void applyCurrentPostFXPreset(); // Aplica el preset PostFX activo al backend
void applyCurrentCrtPiPreset(); // Aplica el preset CrtPi activo al backend
@@ -702,7 +702,7 @@ namespace Rendering {
return;
}
std::memcpy(mapped, pixels, static_cast<size_t>(width * height * 4));
std::memcpy(mapped, pixels, static_cast<size_t>(width) * height * 4);
SDL_UnmapGPUTransferBuffer(device_, upload_buffer_);
}
+2 -1
View File
@@ -2,13 +2,14 @@
#include <SDL3/SDL.h>
#include <cstdint>
#include <string>
#include <utility>
namespace Rendering {
/** @brief Identificador del shader de post-procesado activo */
enum class ShaderType { POSTFX,
enum class ShaderType : std::uint8_t { POSTFX,
CRTPI };
/**
+10 -13
View File
@@ -31,7 +31,7 @@ auto CardSprite::enable() -> bool {
// Ángulo inicial
rotate_.angle = start_angle_;
rotate_.center = {pos_.w / 2.0F, pos_.h / 2.0F};
rotate_.center = {.x = pos_.w / 2.0F, .y = pos_.h / 2.0F};
shadow_visible_ = true;
return true;
@@ -55,7 +55,7 @@ void CardSprite::startExit() {
// Rotación continua
rotate_.enabled = true;
rotate_.amount = exit_rotate_amount_;
rotate_.center = {pos_.w / 2.0F, pos_.h / 2.0F};
rotate_.center = {.x = pos_.w / 2.0F, .y = pos_.h / 2.0F};
}
// Actualiza según el estado
@@ -80,7 +80,7 @@ void CardSprite::updateEntering(float delta_time) {
double eased = entry_easing_(static_cast<double>(progress));
// Zoom: de start_zoom_ a 1.0 con rebote
auto current_zoom = static_cast<float>(start_zoom_ + (1.0 - start_zoom_) * eased);
auto current_zoom = static_cast<float>(start_zoom_ + ((1.0 - start_zoom_) * eased));
horizontal_zoom_ = current_zoom;
vertical_zoom_ = current_zoom;
@@ -90,8 +90,8 @@ void CardSprite::updateEntering(float delta_time) {
// Posición: de entry_start a landing con easing suave (sin rebote)
// Usamos easeOutCubic para que el desplazamiento sea fluido
double pos_eased = easeOutCubic(static_cast<double>(progress));
auto current_x = static_cast<float>(entry_start_x_ + (landing_x_ - entry_start_x_) * pos_eased);
auto current_y = static_cast<float>(entry_start_y_ + (landing_y_ - entry_start_y_) * pos_eased);
auto current_x = static_cast<float>(entry_start_x_ + ((landing_x_ - entry_start_x_) * pos_eased));
auto current_y = static_cast<float>(entry_start_y_ + ((landing_y_ - entry_start_y_) * pos_eased));
setPos(current_x, current_y);
// Detecta el primer toque (cuando el easing alcanza ~1.0 por primera vez)
@@ -117,12 +117,9 @@ void CardSprite::updateExiting(float delta_time) {
// Ganar altura gradualmente (zoom hacia el objetivo)
if (exit_zoom_speed_ > 0.0F && horizontal_zoom_ < exit_target_zoom_) {
float new_zoom = horizontal_zoom_ + exit_zoom_speed_ * delta_time;
if (new_zoom > exit_target_zoom_) {
new_zoom = exit_target_zoom_;
}
horizontal_zoom_ = new_zoom;
vertical_zoom_ = new_zoom;
const float NEW_ZOOM = std::min(horizontal_zoom_ + (exit_zoom_speed_ * delta_time), exit_target_zoom_);
horizontal_zoom_ = NEW_ZOOM;
vertical_zoom_ = NEW_ZOOM;
}
if (isOffScreen()) {
@@ -164,8 +161,8 @@ void CardSprite::renderShadow() {
// Offset respecto a la tarjeta: base + extra proporcional a la altura
// La sombra se aleja en diagonal abajo-derecha (opuesta a la luz en 0,0)
float offset_x = shadow_offset_x_ + height * SHADOW_HEIGHT_MULTIPLIER;
float offset_y = shadow_offset_y_ + height * SHADOW_HEIGHT_MULTIPLIER;
float offset_x = shadow_offset_x_ + (height * SHADOW_HEIGHT_MULTIPLIER);
float offset_y = shadow_offset_y_ + (height * SHADOW_HEIGHT_MULTIPLIER);
shadow_texture_->render(
pos_.x + offset_x,
+2 -1
View File
@@ -2,6 +2,7 @@
#include <SDL3/SDL.h> // Para SDL_FPoint
#include <cstdint> // Para std::uint8_t
#include <functional> // Para function
#include <memory> // Para shared_ptr
@@ -10,7 +11,7 @@
class Texture;
// --- Estados de la tarjeta ---
enum class CardState {
enum class CardState : std::uint8_t {
IDLE, // No activada todavía
ENTERING, // Animación de entrada (zoom + rotación + desplazamiento con rebote)
LANDED, // En reposo sobre la mesa
+3 -2
View File
@@ -2,6 +2,7 @@
#include <SDL3/SDL.h> // Para SDL_FPoint
#include <cstdint> // Para std::uint8_t
#include <functional> // Para std::function
#include <memory> // Para shared_ptr
#include <utility>
@@ -12,12 +13,12 @@
class Texture;
// --- Enums ---
enum class PathType { // Tipos de recorrido
enum class PathType : std::uint8_t { // Tipos de recorrido
VERTICAL,
HORIZONTAL,
};
enum class PathCentered { // Centrado del recorrido
enum class PathCentered : std::uint8_t { // Centrado del recorrido
ON_X,
ON_Y,
NONE,
@@ -1,7 +1,5 @@
#include "core/rendering/sprite/smart_sprite.hpp"
#include "core/rendering/sprite/moving_sprite.hpp" // Para MovingSprite
// Actualiza la posición y comprueba si ha llegado a su destino (time-based)
void SmartSprite::update(float delta_time) {
if (enabled_) {
@@ -3,16 +3,16 @@
#include <memory> // Para shared_ptr
#include <utility>
#include "core/rendering/sprite/animated_sprite.hpp" // Para AnimatedSprite
#include "core/rendering/sprite/moving_sprite.hpp" // Para MovingSprite
class Texture;
// --- Clase SmartSprite: sprite animado que se mueve hacia un destino y puede deshabilitarse automáticamente ---
class SmartSprite : public AnimatedSprite {
// --- Clase SmartSprite: sprite que se mueve hacia un destino y puede deshabilitarse automáticamente ---
class SmartSprite : public MovingSprite {
public:
// --- Constructor y destructor ---
explicit SmartSprite(std::shared_ptr<Texture> texture)
: AnimatedSprite(std::move(texture)) {}
: MovingSprite(std::move(texture)) {}
~SmartSprite() override = default;
// --- Métodos principales ---
+2 -5
View File
@@ -251,11 +251,9 @@ auto Texture::loadSurface(const std::string& file_path) -> std::shared_ptr<Surfa
}
}
// Crear un objeto Gif y llamar a la función loadGif
GIF::Gif gif;
Uint16 w = 0;
Uint16 h = 0;
std::vector<Uint8> raw_pixels = gif.loadGif(buffer.data(), w, h);
std::vector<Uint8> raw_pixels = GIF::loadGif(buffer.data(), w, h);
if (raw_pixels.empty()) {
std::cout << "Error: No se pudo cargar el GIF " << file_path << '\n';
return nullptr;
@@ -329,8 +327,7 @@ auto Texture::loadPaletteFromFile(const std::string& file_path) -> Palette {
}
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
GIF::Gif gif;
std::vector<uint32_t> pal = gif.loadPalette(buffer.data());
std::vector<uint32_t> pal = GIF::loadPalette(buffer.data());
if (pal.empty()) {
std::cout << "Advertencia: No se encontró paleta en el archivo " << file_path << '\n';
return palette; // Devuelve un vector vacío si no hay paleta
+3 -1
View File
@@ -2,10 +2,12 @@
#include <SDL3/SDL.h> // Para SDL_FRect, SDL_SetTextureColorMod, SDL_Renderer, SDL_Texture
#include <cstdint> // Para std::uint8_t
#include "utils/color.hpp" // Para Color
// --- Enums ---
enum class TiledBGMode : int { // Modos de funcionamiento para el tileado de fondo
enum class TiledBGMode : std::uint8_t { // Modos de funcionamiento para el tileado de fondo
CIRCLE = 0,
DIAGONAL = 1,
RANDOM = 2,
+2 -1
View File
@@ -1,6 +1,7 @@
#include "core/rendering/writer.hpp"
#include "core/rendering/text.hpp" // Para Text
// Text es completat ací per `text_->write/length` via shared_ptr; include-cleaner no detecta l'ús indirecte.
#include "core/rendering/text.hpp" // IWYU pragma: keep
// Actualiza el objeto (delta_time en ms)
void Writer::update(float delta_time) {