From 8b413affa80344c9acdf69f496d87a319be089ed Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 20 Apr 2026 09:55:40 +0200 Subject: [PATCH] refactor(core/rendering): Rendering::OPAQUE_ALPHA constant (HC-02) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Surface i Screen repetien el bit d'alpha opac com a 0xFF000000U o com (0xFFU << 24). S'afegeix inline constexpr Rendering::OPAQUE_ALPHA a canvas.hpp i s'usa a les tres ocurrències. Build + smoke 5s xvfb OK (exit 124). Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/audit-core-rendering.md | 5 +++-- source/core/rendering/canvas.hpp | 4 ++++ source/core/rendering/screen.cpp | 5 +++-- source/core/rendering/surface.cpp | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/audit-core-rendering.md b/docs/audit-core-rendering.md index 123d102..b694e83 100644 --- a/docs/audit-core-rendering.md +++ b/docs/audit-core-rendering.md @@ -43,7 +43,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic | ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas | |----|---------------|----------|-----------|--------|-------| | HC-01 | `text.cpp:159` | `render(1, 15)` — `1` (tinta) y `15` (color por defecto) literales | Importante | DONE | `Text::INK_COLOR_INDEX` i `DEFAULT_TEXT_COLOR` | -| HC-02 | `surface.cpp:29`, `screen.cpp:56,218,244` | `0xFF000000U`/`0xFF` alfa repetido | Menor | PENDING | `OPAQUE_ALPHA` | +| HC-02 | `surface.cpp:29`, `screen.cpp:56,218,244` | `0xFF000000U`/`0xFF` alfa repetido | Menor | DONE | `Rendering::OPAQUE_ALPHA` a `canvas.hpp` | | HC-03 | `gif.cpp:71,95,…` | LZW `<11`/`<12`/`<2` y máscaras `0x80/0x70/0x07…` sin nombre | Menor | DONE | `LZW_MIN/MAX_CODE_LENGTH`, `SCREEN_GCT_FLAG`, `SCREEN_GCT_SIZE_MASK`, etc. | | HC-04 | `notifier.hpp:41-46`, `render_info.hpp:38-40` | HUD constants hardcoded en clase, no en `defaults`/YAML | Importante | PENDING | `Defaults::Hud::…` o config.yaml | | HC-05 | `render_info.cpp:19` + `notifier.hpp:43` | `TEXT_SIZE=8` duplicado | Menor | PENDING | constante global font | @@ -131,4 +131,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic - `597402a` — DEAD-04/05/07/08/10 + PATCH-04: neteja mort a `Sprite`/`AnimatedSprite`/`Surface` + `Sprite::update` inline - `ce3b6da` — DEAD-09: esborrats structs d'extensions GIF no usats - `bbb397a` — HC-06 + HC-07 + HC-09 + PATCH-08: constants nominals a `render_info` (segments, shadow offset, position count) i dedup init -- `` — DUP-01 + DUP-06 + HC-03 + HC-10 + PATCH-05: neteja parser GIF (extension single-skip, constants nominals LZW/GCT, signatura sense args morts, un sol parse per construcció de `Surface`) +- `be94a43` — DUP-01 + DUP-06 + HC-03 + HC-10 + PATCH-05: neteja parser GIF (extension single-skip, constants nominals LZW/GCT, signatura sense args morts, un sol parse per construcció de `Surface`) +- `` — HC-02: `Rendering::OPAQUE_ALPHA` a `canvas.hpp` reemplaça `0xFF000000U` repetit diff --git a/source/core/rendering/canvas.hpp b/source/core/rendering/canvas.hpp index 6e79a83..43ea158 100644 --- a/source/core/rendering/canvas.hpp +++ b/source/core/rendering/canvas.hpp @@ -10,6 +10,10 @@ // consumidors no depenguen del cicle de vida de Screen ni del seu header. namespace Rendering { + // Bit alpha completament opac, ja preposicionat al canal alt del + // píxel ARGB8888. Qualsevol RGB | OPAQUE_ALPHA produeix el píxel final. + inline constexpr std::uint32_t OPAQUE_ALPHA = 0xFF000000U; + struct Canvas { std::uint32_t* pixels{nullptr}; int width{0}; diff --git a/source/core/rendering/screen.cpp b/source/core/rendering/screen.cpp index 6969554..a870b12 100644 --- a/source/core/rendering/screen.cpp +++ b/source/core/rendering/screen.cpp @@ -10,6 +10,7 @@ #include #include +#include "core/rendering/canvas.hpp" #include "utils/defines.hpp" namespace { @@ -52,7 +53,7 @@ void Screen::configure(const Config& config) { subsystem_initialized_ = true; canvas_width_ = GameCanvas::WIDTH; canvas_height_ = GameCanvas::HEIGHT; - canvas_.assign(static_cast(GameCanvas::WIDTH) * static_cast(GameCanvas::HEIGHT), 0xFF000000U); + canvas_.assign(static_cast(GameCanvas::WIDTH) * static_cast(GameCanvas::HEIGHT), Rendering::OPAQUE_ALPHA); } destroySdl(); config_ = config; @@ -214,7 +215,7 @@ void Screen::adjustWindowSize() { } void Screen::clear(std::uint8_t r, std::uint8_t g, std::uint8_t b) { - const std::uint32_t COLOR = (0xFFU << 24) | (static_cast(r) << 16) | (static_cast(g) << 8) | static_cast(b); + const std::uint32_t COLOR = Rendering::OPAQUE_ALPHA | (static_cast(r) << 16) | (static_cast(g) << 8) | static_cast(b); std::ranges::fill(canvas_, COLOR); } diff --git a/source/core/rendering/surface.cpp b/source/core/rendering/surface.cpp index 10768c9..e1a7da1 100644 --- a/source/core/rendering/surface.cpp +++ b/source/core/rendering/surface.cpp @@ -23,10 +23,10 @@ auto loadPaletteFromGif(const std::string& file_path) -> Palette { } Palette palette = {}; - // Convertim RGB → ARGB amb canal alpha 0xFF. + // Convertim RGB → ARGB aplicant-hi el canal alpha opac constant. const std::size_t COUNT = std::min(rgb.size(), palette.size()); for (std::size_t i = 0; i < COUNT; ++i) { - palette[i] = 0xFF000000U | rgb[i]; + palette[i] = Rendering::OPAQUE_ALPHA | rgb[i]; } return palette; } @@ -60,7 +60,7 @@ Surface::Surface(const std::string& file_path) { std::vector rgb = GIF::Gif::loadPalette(buffer.data()); const std::size_t COUNT = std::min(rgb.size(), palette_.size()); for (std::size_t i = 0; i < COUNT; ++i) { - palette_[i] = 0xFF000000U | rgb[i]; + palette_[i] = Rendering::OPAQUE_ALPHA | rgb[i]; } printWithDots("Surface : ", getFileName(file_path), "[ LOADED ]");