treball en curs: correccions de tidy

This commit is contained in:
2026-05-16 17:19:40 +02:00
parent 3421f34a84
commit ee2dd0bc2c
30 changed files with 1220 additions and 1479 deletions
+106 -106
View File
@@ -79,13 +79,13 @@ auto Screen::get() -> Screen * {
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
: borderColor{0x00, 0x00, 0x00} {
: border_color_{0x00, 0x00, 0x00} {
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->window_ = window;
this->renderer_ = renderer;
gameCanvasWidth = GAMECANVAS_WIDTH;
gameCanvasHeight = GAMECANVAS_HEIGHT;
game_canvas_width_ = GAMECANVAS_WIDTH;
game_canvas_height_ = GAMECANVAS_HEIGHT;
// Establece el modo de video (fullscreen/ventana + logical presentation)
// ANTES de crear la textura — SDL3 GPU necesita la logical presentation
@@ -103,11 +103,11 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
// Crea la textura donde se dibujan los graficos del juego.
// ARGB8888 per simplificar el readback cap al pipeline SDL3 GPU.
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas != nullptr) {
SDL_SetTextureScaleMode(gameCanvas, Options::video.scale_mode);
game_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_, game_canvas_height_);
if (game_canvas_ != nullptr) {
SDL_SetTextureScaleMode(game_canvas_, Options::video.scale_mode);
}
if (gameCanvas == nullptr) {
if (game_canvas_ == nullptr) {
if (Options::settings.console) {
std::cout << "gameCanvas could not be created!\nSDL Error: " << SDL_GetError() << '\n';
}
@@ -115,14 +115,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
#ifndef NO_SHADERS
// Buffer de readback del gameCanvas (lo dimensionamos una vez)
pixel_buffer_.resize(static_cast<size_t>(gameCanvasWidth) * static_cast<size_t>(gameCanvasHeight));
pixel_buffer_.resize(static_cast<size_t>(game_canvas_width_) * static_cast<size_t>(game_canvas_height_));
#endif
// Renderiza una vez la textura vacía al renderer abans d'inicialitzar els
// shaders: jaildoctors_dilemma ho fa així i evita que el driver Vulkan
// crashegi en la creació del pipeline gràfic. `initShaders()` es crida
// després des de `Director` amb el swapchain ja estable.
SDL_RenderTexture(renderer, gameCanvas, nullptr, nullptr);
SDL_RenderTexture(renderer, game_canvas_, nullptr, nullptr);
// Estado inicial de las notificaciones. El Text real se enlaza después vía
// `initNotifications()` quan `Resource` ja estigui inicialitzat. Dividim
@@ -130,12 +130,12 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
// de carregar recursos: si el SDL_Renderer ha fet abans moltes
// allocacions (carrega de textures), el driver Vulkan crasheja quan
// després es reclama la ventana per al dispositiu GPU.
notificationText = nullptr;
notificationMessage = "";
notificationTextColor = {0xFF, 0xFF, 0xFF};
notificationOutlineColor = {0x00, 0x00, 0x00};
notificationEndTime = 0;
notificationY = 2;
notification_text_ = nullptr;
notification_message_ = "";
notification_text_color_ = {0xFF, 0xFF, 0xFF};
notification_outline_color_ = {0x00, 0x00, 0x00};
notification_end_time_ = 0;
notification_y_ = 2;
// Registra callbacks natius d'Emscripten per a fullscreen/orientation
registerEmscriptenEventCallbacks();
@@ -144,7 +144,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
// Enllaça el Text de les notificacions amb el recurs compartit de `Resource`.
// S'ha de cridar després de `Resource::init(...)`.
void Screen::initNotifications() {
notificationText = Resource::get()->getText("8bithud");
notification_text_ = Resource::get()->getText("8bithud");
}
// Destructor
@@ -153,24 +153,24 @@ Screen::~Screen() {
#ifndef NO_SHADERS
shutdownShaders();
#endif
SDL_DestroyTexture(gameCanvas);
SDL_DestroyTexture(game_canvas_);
}
// Limpia la pantalla
void Screen::clean(Color color) {
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_);
}
// Prepara para empezar a dibujar en la textura de juego
void Screen::start() {
SDL_SetRenderTarget(renderer, gameCanvas);
SDL_SetRenderTarget(renderer_, game_canvas_);
}
// Vuelca el contenido del renderizador en pantalla
void Screen::blit() {
// Dibuja la notificación activa sobre el gameCanvas antes de presentar
SDL_SetRenderTarget(renderer, gameCanvas);
SDL_SetRenderTarget(renderer_, game_canvas_);
renderNotification();
#ifndef NO_SHADERS
@@ -180,7 +180,7 @@ void Screen::blit() {
// i restaurem el shader actiu, així CRTPI no aplica les seues scanlines
// quan l'usuari ho ha desactivat.
if (shader_backend_ && shader_backend_->isHardwareAccelerated()) {
SDL_Surface *surface = SDL_RenderReadPixels(renderer, nullptr);
SDL_Surface *surface = SDL_RenderReadPixels(renderer_, nullptr);
if (surface != nullptr) {
if (surface->format == SDL_PIXELFORMAT_ARGB8888) {
std::memcpy(pixel_buffer_.data(), surface->pixels, pixel_buffer_.size() * sizeof(Uint32));
@@ -193,11 +193,11 @@ void Screen::blit() {
}
SDL_DestroySurface(surface);
}
SDL_SetRenderTarget(renderer, nullptr);
SDL_SetRenderTarget(renderer_, nullptr);
if (Options::video.shader.enabled) {
// Ruta normal: shader amb els seus params.
shader_backend_->uploadPixels(pixel_buffer_.data(), gameCanvasWidth, gameCanvasHeight);
shader_backend_->uploadPixels(pixel_buffer_.data(), game_canvas_width_, game_canvas_height_);
shader_backend_->render();
} else {
// Shader off: POSTFX amb params zero (passa-per-aquí). CRTPI no
@@ -208,7 +208,7 @@ void Screen::blit() {
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
}
shader_backend_->setPostFXParams(Rendering::PostFXParams{});
shader_backend_->uploadPixels(pixel_buffer_.data(), gameCanvasWidth, gameCanvasHeight);
shader_backend_->uploadPixels(pixel_buffer_.data(), game_canvas_width_, game_canvas_height_);
shader_backend_->render();
if (PREV_SHADER != Rendering::ShaderType::POSTFX) {
shader_backend_->setActiveShader(PREV_SHADER);
@@ -219,18 +219,18 @@ void Screen::blit() {
#endif
// Vuelve a dejar el renderizador en modo normal
SDL_SetRenderTarget(renderer, nullptr);
SDL_SetRenderTarget(renderer_, nullptr);
// Borra el contenido previo
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
SDL_RenderClear(renderer_);
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_FRect fdest = {(float)dest.x, (float)dest.y, (float)dest.w, (float)dest.h};
SDL_RenderTexture(renderer, gameCanvas, nullptr, &fdest);
SDL_FRect fdest = {(float)dest_.x, (float)dest_.y, (float)dest_.w, (float)dest_.h};
SDL_RenderTexture(renderer_, game_canvas_, nullptr, &fdest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(renderer);
SDL_RenderPresent(renderer_);
}
// ============================================================================
@@ -254,11 +254,11 @@ void Screen::setVideoMode(bool fullscreen) {
// createTiledBackground() crea/destrueix una textura target nova, i això
// reinicialitza l'estat intern del renderer. Recreem gameCanvas aquí
// mateix per garantir el mateix efecte en qualsevol escena.
if (gameCanvas != nullptr) {
SDL_DestroyTexture(gameCanvas);
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
if (gameCanvas != nullptr) {
SDL_SetTextureScaleMode(gameCanvas, Options::video.scale_mode);
if (game_canvas_ != nullptr) {
SDL_DestroyTexture(game_canvas_);
game_canvas_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_, game_canvas_height_);
if (game_canvas_ != nullptr) {
SDL_SetTextureScaleMode(game_canvas_, Options::video.scale_mode);
}
}
}
@@ -313,7 +313,7 @@ void Screen::toggleIntegerScale() {
// Establece el V-Sync
void Screen::setVSync(bool enabled) {
Options::video.vsync = enabled;
SDL_SetRenderVSync(renderer, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED);
#ifndef NO_SHADERS
if (shader_backend_) {
shader_backend_->setVSync(enabled);
@@ -328,7 +328,7 @@ void Screen::toggleVSync() {
// Cambia el color del borde
void Screen::setBorderColor(Color color) {
borderColor = color;
border_color_ = color;
}
// ============================================================================
@@ -337,7 +337,7 @@ void Screen::setBorderColor(Color color) {
// SDL_SetWindowFullscreen + visibilidad del cursor
void Screen::applyFullscreen(bool fullscreen) {
SDL_SetWindowFullscreen(window, fullscreen);
SDL_SetWindowFullscreen(window_, fullscreen);
if (fullscreen) {
SDL_HideCursor();
Mouse::cursor_visible = false;
@@ -350,9 +350,9 @@ void Screen::applyFullscreen(bool fullscreen) {
// Calcula windowWidth/Height/dest para el modo ventana y aplica SDL_SetWindowSize
void Screen::applyWindowedLayout() {
windowWidth = gameCanvasWidth;
windowHeight = gameCanvasHeight;
dest = {.x = 0, .y = 0, .w = gameCanvasWidth, .h = gameCanvasHeight};
window_width_ = game_canvas_width_;
window_height_ = game_canvas_height_;
dest_ = {.x = 0, .y = 0, .w = game_canvas_width_, .h = game_canvas_height_};
#ifdef __EMSCRIPTEN__
windowWidth *= WASM_RENDER_SCALE;
@@ -362,20 +362,20 @@ void Screen::applyWindowedLayout() {
#endif
// Modifica el tamaño de la ventana
SDL_SetWindowSize(window, windowWidth * Options::window.zoom, windowHeight * Options::window.zoom);
SDL_SetWindowSize(window_, window_width_ * Options::window.zoom, window_height_ * Options::window.zoom);
// Sense aquesta sincronia, en Windows + Vulkan el swapchain del SDL3 GPU
// es queda en estat out-of-date després del resize i SDL_AcquireGPU-
// SwapchainTexture deixa de tornar una textura vàlida → finestra negra.
// En Linux Mesa el driver ho tolera, però el patró segur (igual que
// jaildoctors_dilemma) és esperar que el WM completi el resize abans de
// reposicionar i continuar amb el render.
SDL_SyncWindow(window);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_SyncWindow(window_);
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
// Obtiene el tamaño de la ventana en fullscreen y calcula el rect del juego
void Screen::applyFullscreenLayout() {
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
SDL_GetWindowSize(window_, &window_width_, &window_height_);
computeFullscreenGameRect();
}
@@ -384,34 +384,34 @@ void Screen::computeFullscreenGameRect() {
if (Options::video.integer_scale) {
// Calcula el tamaño de la escala máxima
int scale = 0;
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight)) {
while (((game_canvas_width_ * (scale + 1)) <= window_width_) && ((game_canvas_height_ * (scale + 1)) <= window_height_)) {
scale++;
}
dest.w = gameCanvasWidth * scale;
dest.h = gameCanvasHeight * scale;
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
dest_.w = game_canvas_width_ * scale;
dest_.h = game_canvas_height_ * scale;
dest_.x = (window_width_ - dest_.w) / 2;
dest_.y = (window_height_ - dest_.h) / 2;
} else {
// Manté la relació d'aspecte sense escalat enter (letterbox/pillarbox).
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight)) {
dest.h = windowHeight;
dest.w = static_cast<int>(std::lround(windowHeight * ratio));
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
float ratio = (float)game_canvas_width_ / (float)game_canvas_height_;
if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_)) {
dest_.h = window_height_;
dest_.w = static_cast<int>(std::lround(window_height_ * ratio));
dest_.x = (window_width_ - dest_.w) / 2;
dest_.y = (window_height_ - dest_.h) / 2;
} else {
dest.w = windowWidth;
dest.h = static_cast<int>(std::lround(windowWidth / ratio));
dest.x = (windowWidth - dest.w) / 2;
dest.y = (windowHeight - dest.h) / 2;
dest_.w = window_width_;
dest_.h = static_cast<int>(std::lround(window_width_ / ratio));
dest_.x = (window_width_ - dest_.w) / 2;
dest_.y = (window_height_ - dest_.h) / 2;
}
}
}
// Aplica la logical presentation y persiste el estado en options
void Screen::applyLogicalPresentation(bool fullscreen) {
SDL_SetRenderLogicalPresentation(renderer, windowWidth, windowHeight, SDL_LOGICAL_PRESENTATION_LETTERBOX);
SDL_SetRenderLogicalPresentation(renderer_, window_width_, window_height_, SDL_LOGICAL_PRESENTATION_LETTERBOX);
Options::video.fullscreen = fullscreen;
}
@@ -420,32 +420,32 @@ void Screen::applyLogicalPresentation(bool fullscreen) {
// ============================================================================
// Muestra una notificación en la línea superior durante durationMs
void Screen::notify(const std::string &text, Color textColor, Color outlineColor, Uint32 durationMs) {
notificationMessage = text;
notificationTextColor = textColor;
notificationOutlineColor = outlineColor;
notificationEndTime = SDL_GetTicks() + durationMs;
void Screen::notify(const std::string &text, Color text_color, Color outline_color, Uint32 duration_ms) {
notification_message_ = text;
notification_text_color_ = text_color;
notification_outline_color_ = outline_color;
notification_end_time_ = SDL_GetTicks() + duration_ms;
}
// Limpia la notificación actual
void Screen::clearNotification() {
notificationEndTime = 0;
notificationMessage.clear();
notification_end_time_ = 0;
notification_message_.clear();
}
// Dibuja la notificación activa (si la hay) sobre el gameCanvas
void Screen::renderNotification() {
if (notificationText == nullptr || SDL_GetTicks() >= notificationEndTime) {
if (notification_text_ == nullptr || SDL_GetTicks() >= notification_end_time_) {
return;
}
notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE,
gameCanvasWidth / 2,
notificationY,
notificationMessage,
notification_text_->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE,
game_canvas_width_ / 2,
notification_y_,
notification_message_,
1,
notificationTextColor,
notification_text_color_,
1,
notificationOutlineColor);
notification_outline_color_);
}
// ============================================================================
@@ -462,11 +462,11 @@ void Screen::handleCanvasResized() {
#endif
}
void Screen::syncFullscreenFlagFromBrowser(bool isFullscreen) {
void Screen::syncFullscreenFlagFromBrowser(bool is_fullscreen) {
#ifdef __EMSCRIPTEN__
Options::video.fullscreen = isFullscreen;
#else
(void)isFullscreen;
(void)is_fullscreen;
#endif
}
@@ -511,9 +511,9 @@ void Screen::initShaders() {
Options::video.gpu.acceleration ? Options::video.gpu.preferred_driver : FALLBACK_DRIVER);
}
if (!shader_backend_->isHardwareAccelerated()) {
const bool ok = shader_backend_->init(window, gameCanvas, "", "");
const bool OK = shader_backend_->init(window_, game_canvas_, "", "");
if (Options::settings.console) {
std::cout << "Screen::initShaders: SDL3GPUShader::init() = " << (ok ? "OK" : "FAILED") << '\n';
std::cout << "Screen::initShaders: SDL3GPUShader::init() = " << (OK ? "OK" : "FAILED") << '\n';
}
}
if (shader_backend_->isHardwareAccelerated()) {
@@ -625,16 +625,16 @@ void Screen::applyCurrentPostFXPreset() {
if (Options::current_postfx_preset < 0 || Options::current_postfx_preset >= static_cast<int>(Options::postfx_presets.size())) {
Options::current_postfx_preset = 0;
}
const auto &PRESET = Options::postfx_presets[Options::current_postfx_preset];
const auto &preset = Options::postfx_presets[Options::current_postfx_preset];
Rendering::PostFXParams p;
p.vignette = PRESET.vignette;
p.scanlines = PRESET.scanlines;
p.chroma = PRESET.chroma;
p.mask = PRESET.mask;
p.gamma = PRESET.gamma;
p.curvature = PRESET.curvature;
p.bleeding = PRESET.bleeding;
p.flicker = PRESET.flicker;
p.vignette = preset.vignette;
p.scanlines = preset.scanlines;
p.chroma = preset.chroma;
p.mask = preset.mask;
p.gamma = preset.gamma;
p.curvature = preset.curvature;
p.bleeding = preset.bleeding;
p.flicker = preset.flicker;
shader_backend_->setPostFXParams(p);
#endif
}
@@ -646,22 +646,22 @@ void Screen::applyCurrentCrtPiPreset() {
if (Options::current_crtpi_preset < 0 || Options::current_crtpi_preset >= static_cast<int>(Options::crtpi_presets.size())) {
Options::current_crtpi_preset = 0;
}
const auto &PRESET = Options::crtpi_presets[Options::current_crtpi_preset];
const auto &preset = Options::crtpi_presets[Options::current_crtpi_preset];
Rendering::CrtPiParams p;
p.scanline_weight = PRESET.scanline_weight;
p.scanline_gap_brightness = PRESET.scanline_gap_brightness;
p.bloom_factor = PRESET.bloom_factor;
p.input_gamma = PRESET.input_gamma;
p.output_gamma = PRESET.output_gamma;
p.mask_brightness = PRESET.mask_brightness;
p.curvature_x = PRESET.curvature_x;
p.curvature_y = PRESET.curvature_y;
p.mask_type = PRESET.mask_type;
p.enable_scanlines = PRESET.enable_scanlines;
p.enable_multisample = PRESET.enable_multisample;
p.enable_gamma = PRESET.enable_gamma;
p.enable_curvature = PRESET.enable_curvature;
p.enable_sharper = PRESET.enable_sharper;
p.scanline_weight = preset.scanline_weight;
p.scanline_gap_brightness = preset.scanline_gap_brightness;
p.bloom_factor = preset.bloom_factor;
p.input_gamma = preset.input_gamma;
p.output_gamma = preset.output_gamma;
p.mask_brightness = preset.mask_brightness;
p.curvature_x = preset.curvature_x;
p.curvature_y = preset.curvature_y;
p.mask_type = preset.mask_type;
p.enable_scanlines = preset.enable_scanlines;
p.enable_multisample = preset.enable_multisample;
p.enable_gamma = preset.enable_gamma;
p.enable_curvature = preset.enable_curvature;
p.enable_sharper = preset.enable_sharper;
shader_backend_->setCrtPiParams(p);
#endif
}