diff --git a/docs/audit-core-rendering.md b/docs/audit-core-rendering.md index cea883b..da23023 100644 --- a/docs/audit-core-rendering.md +++ b/docs/audit-core-rendering.md @@ -19,7 +19,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic | ID | Título | Estado | |----|--------|--------| | COUP-01 | Inversión de dependencia `core/rendering → game/*` | DONE | -| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | PENDING | +| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | DONE | | CONV-03 | Shaders MSL como raw strings en `.cpp` + helpers duplicados | PENDING | | DUP-03 | Familia `Text::write*` con bucle UTF-8 repetido 5 veces | PENDING | | COUP-02 | `Screen` instancia `SDL3GPUShader` directamente + `Surface` → `Screen::get()` | PENDING | @@ -31,7 +31,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic | ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas | |----|---------------|----------|-----------|--------|-------| | DUP-01 | `gif.cpp:238-276` | 3 ramas del switch extension saltan bloque+subloops idénticos | Importante | PENDING | helper `skipExtensionBlocks` | -| DUP-02 | `surface.cpp:80-137` | `render` vs `renderWithColorReplace` ~90% idénticos | Crítico | PENDING | inner loop compartido | +| DUP-02 | `surface.cpp:80-137` | `render` vs `renderWithColorReplace` ~90% idénticos | Crítico | DONE | `render()` delega amb source==target==transparent | | DUP-03 | `text.cpp:145-289` | bucle UTF-8 repetido en write/writeColored/writeMonoDigits/length/lengthMonoDigits | Importante | PENDING | iterador de glifos | | DUP-04 | `sdl3gpu_shader.cpp:165-201` + `crtpi_pipeline.cpp:165-202` | `createShaderMSL/SPIRV` duplicados | Importante | PENDING | extraer a `shader_factory` | | DUP-05 | `sdl3gpu_shader.cpp:18-35` + `crtpi_pipeline.cpp:17-34` | vertex shader MSL duplicado | Menor | PENDING | compartir string | @@ -121,4 +121,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic - `9243db1` — docs: full de treball inicial (aquest fitxer) - `9434e4e` — COUP-01a: `Notifier` desacoblat de `game/ui/notification_presets` -- `` — COUP-01b: `RenderInfo` desacoblat de `game/options` + `game/ui/ui_palette` +- `9395520` — COUP-01b: `RenderInfo` desacoblat de `game/options` + `game/ui/ui_palette` +- `` — DUP-02: `Surface::render` delega a `renderWithColorReplace` diff --git a/source/core/rendering/surface.cpp b/source/core/rendering/surface.cpp index d3ecd48..f41203b 100644 --- a/source/core/rendering/surface.cpp +++ b/source/core/rendering/surface.cpp @@ -78,32 +78,11 @@ auto Surface::getPixel(int x, int y) const -> Uint8 { } void Surface::render(int x, int y, const SDL_FRect* src_rect, SDL_FlipMode flip) const { - Uint32* dst = Screen::get().getCanvasArgb(); - const int DST_W = Screen::get().getCanvasWidth(); - const int DST_H = Screen::get().getCanvasHeight(); - - const int SX = (src_rect != nullptr) ? static_cast(src_rect->x) : 0; - const int SY = (src_rect != nullptr) ? static_cast(src_rect->y) : 0; - int sw = (src_rect != nullptr) ? static_cast(src_rect->w) : surface_data_->width; - int sh = (src_rect != nullptr) ? static_cast(src_rect->h) : surface_data_->height; - - sw = std::min(sw, surface_data_->width - SX); - sh = std::min(sh, surface_data_->height - SY); - - const Uint8* src = surface_data_->data.get(); - for (int iy = 0; iy < sh; ++iy) { - for (int ix = 0; ix < sw; ++ix) { - const int SRC_X = (flip == SDL_FLIP_HORIZONTAL) ? (SX + sw - 1 - ix) : (SX + ix); - const int SRC_Y = (flip == SDL_FLIP_VERTICAL) ? (SY + sh - 1 - iy) : (SY + iy); - const int DST_X = x + ix; - const int DST_Y = y + iy; - if (DST_X < 0 || DST_X >= DST_W || DST_Y < 0 || DST_Y >= DST_H) { continue; } - - const Uint8 COLOR = src[SRC_X + (SRC_Y * surface_data_->width)]; - if (COLOR == transparent_color_) { continue; } - dst[DST_X + (DST_Y * DST_W)] = palette_[sub_palette_[COLOR]]; - } - } + // Delegem a la versió amb remap: fent source==target==transparent_color_, + // qualsevol píxel opaC tindrà COLOR != source_color (els transparents ja + // s'han filtrat), així que REMAPPED = sub_palette_[COLOR] — idèntic al + // camí sense remap. Això evita duplicar el bucle de blit. + renderWithColorReplace(x, y, transparent_color_, transparent_color_, src_rect, flip); } void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 target_color, const SDL_FRect* src_rect, SDL_FlipMode flip) const {