From b51109e3809a45ed77bd39a2d2b0e54763dc7df6 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 20 Apr 2026 09:40:54 +0200 Subject: [PATCH] refactor(core/rendering): esborrar codi mort de Text (DEAD-01 + DEAD-02) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eliminats cinc mètodes sense callers externs: - writeShadowed / writeCentered: la funcionalitat viu a writeDX(flags, ...) que és l'API reutilitzable; ningú crida aquestes variants discretes. - glyphWidth / getGlyphClip: getters per glif no consumits enlloc. - codepointToUtf8: helper de serialització UTF-8 no consumit (només es consumeix el parser nextCodepoint, que queda). Build + smoke 5s xvfb OK (exit 124). Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/audit-core-rendering.md | 7 +++--- source/core/rendering/text.cpp | 46 ---------------------------------- source/core/rendering/text.hpp | 6 ----- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/docs/audit-core-rendering.md b/docs/audit-core-rendering.md index f0b0d38..7c0b653 100644 --- a/docs/audit-core-rendering.md +++ b/docs/audit-core-rendering.md @@ -94,8 +94,8 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic | ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas | |----|---------------|----------|-----------|--------|-------| -| DEAD-01 | `text.hpp:50-51` | `writeShadowed`, `writeCentered` sin callers externos | Importante | PENDING | borrar | -| DEAD-02 | `text.hpp:62-63,67` | `glyphWidth`, `getGlyphClip`, `codepointToUtf8` sin callers | Importante | PENDING | borrar | +| DEAD-01 | `text.hpp:50-51` | `writeShadowed`, `writeCentered` sin callers externos | Importante | DONE | esborrats | +| DEAD-02 | `text.hpp:62-63,67` | `glyphWidth`, `getGlyphClip`, `codepointToUtf8` sin callers | Importante | DONE | esborrats | | DEAD-03 | `text.hpp:64` | `getSprite()` sin callers | Menor | PENDING | borrar | | DEAD-04 | `sprite.hpp:33` | `getRect()` sin callers | Menor | PENDING | borrar | | DEAD-05 | `sprite.hpp:42-43` | `incX`, `incY` sin callers | Menor | PENDING | borrar | @@ -126,4 +126,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic - `5f46fb2` — CONV-03 + DUP-04 + DUP-05 + PATCH-07: shaders MSL i helpers extrets a `sdl3gpu/msl/` i `sdl3gpu/shader_factory.hpp` - `a63deac` — DUP-03 + HC-01: `Text` amb `resolveGlyph` i constants `INK_COLOR_INDEX` / `DEFAULT_TEXT_COLOR` - `029907d` — COUP-02a: `Screen` desacoblat de `SDL3GPUShader` via `makeDefaultShaderBackend()` -- `` — COUP-02b (= COUP-03): `Surface` usa `Rendering::activeCanvas()` en lloc de `Screen::get()` +- `81fe826` — COUP-02b (= COUP-03): `Surface` usa `Rendering::activeCanvas()` en lloc de `Screen::get()` +- `` — DEAD-01 + DEAD-02: esborrats `writeShadowed`/`writeCentered`/`glyphWidth`/`getGlyphClip`/`codepointToUtf8` diff --git a/source/core/rendering/text.cpp b/source/core/rendering/text.cpp index 1f40c73..fe53872 100644 --- a/source/core/rendering/text.cpp +++ b/source/core/rendering/text.cpp @@ -47,26 +47,6 @@ auto Text::nextCodepoint(const std::string& s, std::size_t& pos) -> std::uint32_ return cp; } -auto Text::codepointToUtf8(std::uint32_t cp) -> std::string { - std::string result; - if (cp < 0x80) { - result += static_cast(cp); - } else if (cp < 0x800) { - result += static_cast(0xC0 | (cp >> 6)); - result += static_cast(0x80 | (cp & 0x3F)); - } else if (cp < 0x10000) { - result += static_cast(0xE0 | (cp >> 12)); - result += static_cast(0x80 | ((cp >> 6) & 0x3F)); - result += static_cast(0x80 | (cp & 0x3F)); - } else { - result += static_cast(0xF0 | (cp >> 18)); - result += static_cast(0x80 | ((cp >> 12) & 0x3F)); - result += static_cast(0x80 | ((cp >> 6) & 0x3F)); - result += static_cast(0x80 | (cp & 0x3F)); - } - return result; -} - // Format .fnt: claus "box_width/box_height/columns/cell_spacing/row_spacing" // i una línia per glif amb "codepoint_decimal amplada_visual". Els glifs // s'ordenen al png per ordre d'aparició al .fnt (glyph_index). @@ -165,16 +145,6 @@ void Text::writeColored(int x, int y, const std::string& text, Uint8 color, int } } -void Text::writeShadowed(int x, int y, const std::string& text, Uint8 color, Uint8 shadow_distance, int kerning, int length) { - writeColored(x + shadow_distance, y + shadow_distance, text, color, kerning, length); - write(x, y, text, kerning, length); -} - -void Text::writeCentered(int x, int y, const std::string& text, int kerning, int length) { - x -= (Text::length(text, kerning) / 2); - write(x, y, text, kerning, length); -} - void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerning, Uint8 text_color, Uint8 shadow_distance, Uint8 shadow_color, int length) { const bool CENTERED = ((flags & CENTER_FLAG) == CENTER_FLAG); const bool SHADOWED = ((flags & SHADOW_FLAG) == SHADOW_FLAG); @@ -265,22 +235,6 @@ auto Text::length(const std::string& text, int kerning) const -> int { return shift > 0 ? shift - kerning : 0; } -auto Text::glyphWidth(std::uint32_t codepoint, int kerning) const -> int { - if (const Offset* off = resolveGlyph(codepoint); off != nullptr) { - return off->w + kerning; - } - return 0; -} - -auto Text::getGlyphClip(std::uint32_t codepoint) const -> SDL_FRect { - const Offset* off = resolveGlyph(codepoint); - if (off == nullptr) { return {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F}; } - return {.x = static_cast(off->x), - .y = static_cast(off->y), - .w = static_cast(box_width_), - .h = static_cast(box_height_)}; -} - auto Text::resolveGlyph(std::uint32_t cp) const -> const Offset* { auto it = offset_.find(cp); if (it == offset_.end()) { it = offset_.find('?'); } diff --git a/source/core/rendering/text.hpp b/source/core/rendering/text.hpp index a65c023..6dac085 100644 --- a/source/core/rendering/text.hpp +++ b/source/core/rendering/text.hpp @@ -54,8 +54,6 @@ class Text { void write(int x, int y, const std::string& text, int kerning = 1, int length = -1); void writeColored(int x, int y, const std::string& text, Uint8 color, int kerning = 1, int length = -1); - void writeShadowed(int x, int y, const std::string& text, Uint8 color, Uint8 shadow_distance = 1, int kerning = 1, int length = -1); - void writeCentered(int x, int y, const std::string& text, int kerning = 1, int length = -1); void writeDX(Uint8 flags, int x, int y, const std::string& text, int kerning = 1, Uint8 text_color = 0, Uint8 shadow_distance = 1, Uint8 shadow_color = 0, int length = -1); // Dibuixa amb amplada fixa només per als dígits '0'-'9' (cadascun centrat @@ -66,12 +64,8 @@ class Text { [[nodiscard]] auto length(const std::string& text, int kerning = 1) const -> int; [[nodiscard]] auto lengthMonoDigits(const std::string& text, int digit_cell_w, int kerning = 1) const -> int; [[nodiscard]] auto getCharacterSize() const -> int { return box_width_; } - [[nodiscard]] auto glyphWidth(std::uint32_t codepoint, int kerning = 0) const -> int; - [[nodiscard]] auto getGlyphClip(std::uint32_t codepoint) const -> SDL_FRect; - [[nodiscard]] auto getSprite() const -> Sprite* { return sprite_.get(); } static auto loadTextFile(const std::string& file_path) -> std::shared_ptr; - static auto codepointToUtf8(std::uint32_t cp) -> std::string; static auto nextCodepoint(const std::string& s, std::size_t& pos) -> std::uint32_t; private: