clang-tidy

This commit is contained in:
2026-03-21 23:08:07 +01:00
parent d946ab7943
commit 55b58ded70
19 changed files with 112 additions and 155 deletions

View File

@@ -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
}