clang-tidy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "core/rendering/pixel_reveal.hpp"
|
||||
|
||||
#include <algorithm> // Para min
|
||||
#include <algorithm> // Para min, ranges::all_of
|
||||
#include <numeric> // Para iota
|
||||
#include <queue> // Para queue (BFS en modo ORDERED)
|
||||
#include <random> // Para mt19937, shuffle
|
||||
@@ -30,7 +30,7 @@ PixelReveal::PixelReveal(int width, int height, float pixels_per_second, float s
|
||||
std::vector<int> offsets;
|
||||
offsets.push_back(0);
|
||||
std::queue<std::pair<int, int>> bq;
|
||||
bq.push({0, num_steps_});
|
||||
bq.emplace(0, num_steps_);
|
||||
while (static_cast<int>(offsets.size()) < num_steps_) {
|
||||
auto [lo, hi] = bq.front();
|
||||
bq.pop();
|
||||
@@ -39,14 +39,14 @@ PixelReveal::PixelReveal(int width, int height, float pixels_per_second, float s
|
||||
}
|
||||
const int MID = (lo + hi) / 2;
|
||||
offsets.push_back(MID);
|
||||
bq.push({lo, MID});
|
||||
bq.push({MID, hi});
|
||||
bq.emplace(lo, MID);
|
||||
bq.emplace(MID, hi);
|
||||
}
|
||||
// Genera el orden: para cada offset, todas las columnas col = offset, offset+N, offset+2N, ...
|
||||
std::vector<int> ordered_cols;
|
||||
ordered_cols.reserve(width_);
|
||||
for (const int off : offsets) {
|
||||
for (int col = off; col < width_; col += num_steps_) {
|
||||
for (const int OFF : offsets) {
|
||||
for (int col = OFF; col < width_; col += num_steps_) {
|
||||
ordered_cols.push_back(col);
|
||||
}
|
||||
}
|
||||
@@ -105,11 +105,6 @@ void PixelReveal::render(int dst_x, int dst_y) const {
|
||||
}
|
||||
|
||||
// Indica si el revelado ha completado todas las filas
|
||||
bool PixelReveal::isComplete() const {
|
||||
for (const int step : row_step_) {
|
||||
if (step < num_steps_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
auto PixelReveal::isComplete() const -> bool {
|
||||
return std::ranges::all_of(row_step_, [this](int s) { return s >= num_steps_; });
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class PixelReveal {
|
||||
void render(int dst_x, int dst_y) const;
|
||||
|
||||
// Indica si el revelado ha completado todas las filas
|
||||
[[nodiscard]] bool isComplete() const;
|
||||
[[nodiscard]] auto isComplete() const -> bool;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Surface> cover_surface_; // Máscara negra que se va haciendo transparente
|
||||
|
||||
@@ -392,7 +392,7 @@ auto Screen::findPalette(const std::string& name) -> size_t {
|
||||
}
|
||||
|
||||
// Muestra información por pantalla
|
||||
void Screen::renderInfo() {
|
||||
void Screen::renderInfo() const {
|
||||
if (show_debug_info_ && (Resource::Cache::get() != nullptr)) {
|
||||
auto text = Resource::Cache::get()->getText("smb2");
|
||||
auto color = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
@@ -459,7 +459,7 @@ auto loadData(const std::string& filepath) -> std::vector<uint8_t> {
|
||||
void Screen::applyCurrentPostFXPreset() {
|
||||
if (shader_backend_ && !Options::postfx_presets.empty()) {
|
||||
const auto& p = Options::postfx_presets[static_cast<size_t>(Options::current_postfx_preset)];
|
||||
Rendering::PostFXParams params{p.vignette, p.scanlines, p.chroma, p.mask, p.gamma, p.curvature, p.bleeding};
|
||||
Rendering::PostFXParams params{.vignette = p.vignette, .scanlines = p.scanlines, .chroma = p.chroma, .mask = p.mask, .gamma = p.gamma, .curvature = p.curvature, .bleeding = p.bleeding};
|
||||
shader_backend_->setPostFXParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class Screen {
|
||||
auto findPalette(const std::string& name) -> size_t; // Localiza la paleta dentro del vector de paletas
|
||||
void initShaders(); // Inicializa los shaders
|
||||
void applyCurrentPostFXPreset(); // Aplica los parámetros del preset actual al backend
|
||||
void renderInfo(); // Muestra información por pantalla
|
||||
void renderInfo() const; // Muestra información por pantalla
|
||||
void getDisplayInfo(); // Obtiene información sobre la pantalla
|
||||
auto initSDLVideo() -> bool; // Arranca SDL VIDEO y crea la ventana
|
||||
void createText(); // Crea el objeto de texto
|
||||
|
||||
@@ -412,15 +412,15 @@ void SDL3GPUShader::render() {
|
||||
float vw = 0.0F;
|
||||
float vh = 0.0F;
|
||||
if (integer_scale_) {
|
||||
const int scale = std::max(1, std::min(static_cast<int>(sw) / tex_width_, static_cast<int>(sh) / tex_height_));
|
||||
vw = static_cast<float>(tex_width_ * scale);
|
||||
vh = static_cast<float>(tex_height_ * scale);
|
||||
const int SCALE = std::max(1, std::min(static_cast<int>(sw) / tex_width_, static_cast<int>(sh) / tex_height_));
|
||||
vw = static_cast<float>(tex_width_ * SCALE);
|
||||
vh = static_cast<float>(tex_height_ * SCALE);
|
||||
} else {
|
||||
const float scale = std::min(
|
||||
const float SCALE = std::min(
|
||||
static_cast<float>(sw) / static_cast<float>(tex_width_),
|
||||
static_cast<float>(sh) / static_cast<float>(tex_height_));
|
||||
vw = static_cast<float>(tex_width_) * scale;
|
||||
vh = static_cast<float>(tex_height_) * scale;
|
||||
vw = static_cast<float>(tex_width_) * SCALE;
|
||||
vh = static_cast<float>(tex_height_) * SCALE;
|
||||
}
|
||||
vx = std::floor((static_cast<float>(sw) - vw) * 0.5F);
|
||||
vy = std::floor((static_cast<float>(sh) - vh) * 0.5F);
|
||||
|
||||
@@ -40,7 +40,7 @@ class SDL3GPUShader : public ShaderBackend {
|
||||
|
||||
void render() override;
|
||||
void setTextureSize(float width, float height) override {}
|
||||
void cleanup() override; // Libera pipeline/texturas pero mantiene el device vivo
|
||||
void cleanup() final; // Libera pipeline/texturas pero mantiene el device vivo
|
||||
void destroy(); // Limpieza completa (device + swapchain); llamar solo al cerrar
|
||||
[[nodiscard]] auto isHardwareAccelerated() const -> bool override { return is_initialized_; }
|
||||
|
||||
|
||||
@@ -430,19 +430,30 @@ void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 tar
|
||||
|
||||
// Hash 2D estable per a dithering sense flickering
|
||||
static auto pixelThreshold(int col, int row) -> float {
|
||||
auto h = static_cast<uint32_t>(col) * 2246822519U ^ static_cast<uint32_t>(row) * 2654435761U;
|
||||
auto h = (static_cast<uint32_t>(col) * 2246822519U) ^ (static_cast<uint32_t>(row) * 2654435761U);
|
||||
h ^= (h >> 13);
|
||||
h *= 1274126177U;
|
||||
h ^= (h >> 16);
|
||||
return static_cast<float>(h & 0xFFFFU) / 65536.0F;
|
||||
}
|
||||
|
||||
// Calcula la densidad de fade para un pixel en posición screen_y
|
||||
static auto computeFadeDensity(int screen_y, int fade_h, int canvas_height) -> float {
|
||||
if (screen_y < fade_h) {
|
||||
return static_cast<float>(fade_h - screen_y) / static_cast<float>(fade_h);
|
||||
}
|
||||
if (screen_y >= canvas_height - fade_h) {
|
||||
return static_cast<float>(screen_y - (canvas_height - fade_h)) / static_cast<float>(fade_h);
|
||||
}
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
// Render amb dissolució als cantons superior/inferior (hash 2D, sense parpelleig)
|
||||
void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height, SDL_FRect* src_rect) {
|
||||
const int SX = src_rect ? static_cast<int>(src_rect->x) : 0;
|
||||
const int SY = src_rect ? static_cast<int>(src_rect->y) : 0;
|
||||
const int SW = src_rect ? static_cast<int>(src_rect->w) : static_cast<int>(surface_data_->width);
|
||||
const int SH = src_rect ? static_cast<int>(src_rect->h) : static_cast<int>(surface_data_->height);
|
||||
const int SX = (src_rect != nullptr) ? static_cast<int>(src_rect->x) : 0;
|
||||
const int SY = (src_rect != nullptr) ? static_cast<int>(src_rect->y) : 0;
|
||||
const int SW = (src_rect != nullptr) ? static_cast<int>(src_rect->w) : static_cast<int>(surface_data_->width);
|
||||
const int SH = (src_rect != nullptr) ? static_cast<int>(src_rect->h) : static_cast<int>(surface_data_->height);
|
||||
|
||||
auto surface_data_dest = Screen::get()->getRendererSurface()->getSurfaceData();
|
||||
|
||||
@@ -452,12 +463,7 @@ void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height
|
||||
continue;
|
||||
}
|
||||
|
||||
float density = 0.0F;
|
||||
if (SCREEN_Y < fade_h) {
|
||||
density = static_cast<float>(fade_h - SCREEN_Y) / static_cast<float>(fade_h);
|
||||
} else if (SCREEN_Y >= canvas_height - fade_h) {
|
||||
density = static_cast<float>(SCREEN_Y - (canvas_height - fade_h)) / static_cast<float>(fade_h);
|
||||
}
|
||||
const float DENSITY = computeFadeDensity(SCREEN_Y, fade_h, canvas_height);
|
||||
|
||||
for (int col = 0; col < SW; col++) {
|
||||
const int SCREEN_X = x + col;
|
||||
@@ -465,12 +471,12 @@ void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height
|
||||
continue;
|
||||
}
|
||||
|
||||
const Uint8 COLOR = surface_data_->data[(SY + row) * static_cast<int>(surface_data_->width) + (SX + col)];
|
||||
const Uint8 COLOR = surface_data_->data[((SY + row) * static_cast<int>(surface_data_->width)) + (SX + col)];
|
||||
if (static_cast<int>(COLOR) == transparent_color_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pixelThreshold(col, row) < density) {
|
||||
if (pixelThreshold(col, row) < DENSITY) {
|
||||
continue; // Pixel tapat per la zona de fade
|
||||
}
|
||||
|
||||
@@ -481,10 +487,10 @@ void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height
|
||||
|
||||
// Idem però reemplaçant un color índex
|
||||
void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height, Uint8 source_color, Uint8 target_color, SDL_FRect* src_rect) {
|
||||
const int SX = src_rect ? static_cast<int>(src_rect->x) : 0;
|
||||
const int SY = src_rect ? static_cast<int>(src_rect->y) : 0;
|
||||
const int SW = src_rect ? static_cast<int>(src_rect->w) : static_cast<int>(surface_data_->width);
|
||||
const int SH = src_rect ? static_cast<int>(src_rect->h) : static_cast<int>(surface_data_->height);
|
||||
const int SX = (src_rect != nullptr) ? static_cast<int>(src_rect->x) : 0;
|
||||
const int SY = (src_rect != nullptr) ? static_cast<int>(src_rect->y) : 0;
|
||||
const int SW = (src_rect != nullptr) ? static_cast<int>(src_rect->w) : static_cast<int>(surface_data_->width);
|
||||
const int SH = (src_rect != nullptr) ? static_cast<int>(src_rect->h) : static_cast<int>(surface_data_->height);
|
||||
|
||||
auto surface_data_dest = Screen::get()->getRendererSurface()->getSurfaceData();
|
||||
|
||||
@@ -494,12 +500,7 @@ void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height
|
||||
continue;
|
||||
}
|
||||
|
||||
float density = 0.0F;
|
||||
if (SCREEN_Y < fade_h) {
|
||||
density = static_cast<float>(fade_h - SCREEN_Y) / static_cast<float>(fade_h);
|
||||
} else if (SCREEN_Y >= canvas_height - fade_h) {
|
||||
density = static_cast<float>(SCREEN_Y - (canvas_height - fade_h)) / static_cast<float>(fade_h);
|
||||
}
|
||||
const float DENSITY = computeFadeDensity(SCREEN_Y, fade_h, canvas_height);
|
||||
|
||||
for (int col = 0; col < SW; col++) {
|
||||
const int SCREEN_X = x + col;
|
||||
@@ -507,12 +508,12 @@ void Surface::renderWithVerticalFade(int x, int y, int fade_h, int canvas_height
|
||||
continue;
|
||||
}
|
||||
|
||||
const Uint8 COLOR = surface_data_->data[(SY + row) * static_cast<int>(surface_data_->width) + (SX + col)];
|
||||
const Uint8 COLOR = surface_data_->data[((SY + row) * static_cast<int>(surface_data_->width)) + (SX + col)];
|
||||
if (static_cast<int>(COLOR) == transparent_color_) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pixelThreshold(col, row) < density) {
|
||||
if (pixelThreshold(col, row) < DENSITY) {
|
||||
continue; // Pixel tapat per la zona de fade
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ SurfaceAnimatedSprite::SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, S
|
||||
: SurfaceMovingSprite(std::move(surface), pos) {
|
||||
// animations_ queda buit (protegit per el guard de animate())
|
||||
if (surface_) {
|
||||
clip_ = {0, 0, static_cast<float>(surface_->getWidth()), static_cast<float>(surface_->getHeight())};
|
||||
clip_ = {.x = 0, .y = 0, .w = surface_->getWidth(), .h = surface_->getHeight()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ auto SurfaceAnimatedSprite::getIndex(const std::string& name) -> int {
|
||||
|
||||
// Calcula el frame correspondiente a la animación (time-based)
|
||||
void SurfaceAnimatedSprite::animate(float delta_time) {
|
||||
if (animations_.empty()) return;
|
||||
if (animations_.empty()) { return; }
|
||||
if (animations_[current_animation_].speed <= 0.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
// Hash 2D estable per a dithering (rank aleatori per posició de píxel)
|
||||
static auto pixelRank(int col, int row) -> float {
|
||||
auto h = static_cast<uint32_t>(col) * 2246822519U ^ static_cast<uint32_t>(row) * 2654435761U;
|
||||
auto h = (static_cast<uint32_t>(col) * 2246822519U) ^ (static_cast<uint32_t>(row) * 2654435761U);
|
||||
h ^= (h >> 13);
|
||||
h *= 1274126177U;
|
||||
h ^= (h >> 16);
|
||||
@@ -28,7 +28,7 @@ auto SurfaceDissolveSprite::computePixelRank(int col, int row, int frame_h, Diss
|
||||
y_factor = static_cast<float>(frame_h - 1 - row) / static_cast<float>(frame_h);
|
||||
}
|
||||
|
||||
return y_factor * 0.7F + RANDOM * 0.3F;
|
||||
return (y_factor * 0.7F) + (RANDOM * 0.3F);
|
||||
}
|
||||
|
||||
// Constructor per a surface directa (sense AnimationResource)
|
||||
@@ -92,14 +92,14 @@ void SurfaceDissolveSprite::rebuildDisplaySurface() {
|
||||
// Copia píxels filtrats per progress_
|
||||
for (int row = 0; row < SH; ++row) {
|
||||
for (int col = 0; col < SW; ++col) {
|
||||
const Uint8 COLOR = src_data->data[(SY + row) * SRC_W + (SX + col)];
|
||||
const Uint8 COLOR = src_data->data[((SY + row) * SRC_W) + (SX + col)];
|
||||
if (COLOR == TRANSPARENT) {
|
||||
continue;
|
||||
}
|
||||
const float RANK = computePixelRank(col, row, SH, direction_);
|
||||
if (RANK >= progress_) {
|
||||
const Uint8 OUT = (COLOR == source_color_) ? target_color_ : COLOR;
|
||||
dst_data->data[(SY + row) * DST_W + (SX + col)] = OUT;
|
||||
dst_data->data[((SY + row) * DST_W) + (SX + col)] = OUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user