refactor(core/rendering): Surface desacoblat de Screen via Canvas (COUP-02b / COUP-03)
Surface::renderWithColorReplace usava Screen::get().getCanvasArgb() i companys per a obtenir el buffer destí. S'introdueix una abstracció mínima: - source/core/rendering/canvas.hpp: struct Canvas amb pixels/width/ height i la fàbrica activeCanvas() que retorna el canvas actiu. - source/core/rendering/canvas.cpp: implementació que delega a Screen. Surface ara inclou canvas.hpp en lloc de screen.hpp i crida Rendering::activeCanvas(). L'indirecció permet, més endavant, empènyer canvases alternatius (off-screen, efectes) sense tocar Surface; ara mateix es comporta idèntic al codi anterior. Build + smoke 5s xvfb OK (exit 124). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
029907d5a0
commit
81fe826d17
5 files changed
+50
-7
No files matched your search
@@ -39,6 +39,7 @@ set(APP_SOURCES
|
|||||||
source/core/input/key_config.cpp
|
source/core/input/key_config.cpp
|
||||||
source/core/input/global_inputs.cpp
|
source/core/input/global_inputs.cpp
|
||||||
source/core/rendering/screen.cpp
|
source/core/rendering/screen.cpp
|
||||||
|
source/core/rendering/canvas.cpp
|
||||||
source/core/rendering/notifier.cpp
|
source/core/rendering/notifier.cpp
|
||||||
source/core/rendering/render_info.cpp
|
source/core/rendering/render_info.cpp
|
||||||
source/core/rendering/gif.cpp
|
source/core/rendering/gif.cpp
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|
|||||||
| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | DONE |
|
| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | DONE |
|
||||||
| CONV-03 | Shaders MSL como raw strings en `.cpp` + helpers duplicados | DONE |
|
| CONV-03 | Shaders MSL como raw strings en `.cpp` + helpers duplicados | DONE |
|
||||||
| DUP-03 | Familia `Text::write*` con bucle UTF-8 repetido 5 veces | DONE |
|
| DUP-03 | Familia `Text::write*` con bucle UTF-8 repetido 5 veces | DONE |
|
||||||
| COUP-02 | `Screen` instancia `SDL3GPUShader` directamente + `Surface` → `Screen::get()` | WIP (a: DONE, b: PENDING) |
|
| COUP-02 | `Screen` instancia `SDL3GPUShader` directamente + `Surface` → `Screen::get()` | DONE |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|
|||||||
| COUP-01a | `notifier.hpp:9` | `core/rendering/notifier.hpp` incluye `game/ui/notification_presets.hpp` | Crítico | DONE | helper `Notification::notify()` en `game/ui` |
|
| COUP-01a | `notifier.hpp:9` | `core/rendering/notifier.hpp` incluye `game/ui/notification_presets.hpp` | Crítico | DONE | helper `Notification::notify()` en `game/ui` |
|
||||||
| COUP-01b | `render_info.cpp:12-13` | `core/rendering/render_info.cpp` incluye `game/options.hpp` + `game/ui/ui_palette.hpp` | Crítico | DONE | `RenderInfo::Frame` injectada; Options.buildRenderInfoFrame() |
|
| COUP-01b | `render_info.cpp:12-13` | `core/rendering/render_info.cpp` incluye `game/options.hpp` + `game/ui/ui_palette.hpp` | Crítico | DONE | `RenderInfo::Frame` injectada; Options.buildRenderInfoFrame() |
|
||||||
| COUP-02a | `screen.cpp:13-14,109` | `Screen` instancia `SDL3GPUShader` concreto | Importante | DONE | `Rendering::makeDefaultShaderBackend()` factory |
|
| COUP-02a | `screen.cpp:13-14,109` | `Screen` instancia `SDL3GPUShader` concreto | Importante | DONE | `Rendering::makeDefaultShaderBackend()` factory |
|
||||||
| COUP-03 | `surface.cpp:81-83,110-112` | `Surface::render` usa `Screen::get()` global | Importante | PENDING | pasar destino por parámetro |
|
| COUP-03 | `surface.cpp:81-83,110-112` | `Surface::render` usa `Screen::get()` global | Importante | DONE | `Rendering::activeCanvas()` intermediari |
|
||||||
| COUP-04 | `notifier.cpp:19`, `render_info.cpp:52` | `Resource::Cache::get().getSurface("8bithud.gif")` con string literal | Importante | PENDING | inyectar la surface |
|
| COUP-04 | `notifier.cpp:19`, `render_info.cpp:52` | `Resource::Cache::get().getSurface("8bithud.gif")` con string literal | Importante | PENDING | inyectar la surface |
|
||||||
| COUP-05 | `animated_sprite.cpp:9,95-116` | parser YAML incrustado en sprite | Importante | PENDING | `AnimationLoader` en `core/resources` |
|
| COUP-05 | `animated_sprite.cpp:9,95-116` | parser YAML incrustado en sprite | Importante | PENDING | `AnimationLoader` en `core/resources` |
|
||||||
| COUP-06 | `notifier.hpp:22`, `render_info.hpp:17`, `screen.hpp:13` | 3 Meyers singletons en mismo subsistema | Importante | DEFERRED | requiere tocar Director |
|
| COUP-06 | `notifier.hpp:22`, `render_info.hpp:17`, `screen.hpp:13` | 3 Meyers singletons en mismo subsistema | Importante | DEFERRED | requiere tocar Director |
|
||||||
@@ -125,4 +125,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
|
|||||||
- `d479475` — DUP-02: `Surface::render` delega a `renderWithColorReplace`
|
- `d479475` — DUP-02: `Surface::render` delega a `renderWithColorReplace`
|
||||||
- `5f46fb2` — CONV-03 + DUP-04 + DUP-05 + PATCH-07: shaders MSL i helpers extrets a `sdl3gpu/msl/` i `sdl3gpu/shader_factory.hpp`
|
- `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`
|
- `a63deac` — DUP-03 + HC-01: `Text` amb `resolveGlyph` i constants `INK_COLOR_INDEX` / `DEFAULT_TEXT_COLOR`
|
||||||
- `<pendent>` — COUP-02a: `Screen` desacoblat de `SDL3GPUShader` via `makeDefaultShaderBackend()`
|
- `029907d` — COUP-02a: `Screen` desacoblat de `SDL3GPUShader` via `makeDefaultShaderBackend()`
|
||||||
|
- `<pendent>` — COUP-02b (= COUP-03): `Surface` usa `Rendering::activeCanvas()` en lloc de `Screen::get()`
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#include "core/rendering/canvas.hpp"
|
||||||
|
|
||||||
|
#include "core/rendering/screen.hpp"
|
||||||
|
|
||||||
|
namespace Rendering {
|
||||||
|
|
||||||
|
auto activeCanvas() -> Canvas {
|
||||||
|
auto& screen = Screen::get();
|
||||||
|
return {
|
||||||
|
.pixels = screen.getCanvasArgb(),
|
||||||
|
.width = screen.getCanvasWidth(),
|
||||||
|
.height = screen.getCanvasHeight(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Rendering
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
// Abstracció mínima del destí de renderitzat CPU. Tots els blitters del
|
||||||
|
// projecte (Surface, els HUDs via Screen::fillRect, ...) emeten píxels en
|
||||||
|
// format ARGB8888 sobre una única superfície lògica que el backend GPU
|
||||||
|
// després transfereix a la textura "scene". L'accés va per la funció
|
||||||
|
// activeCanvas() en lloc de Screen::get() directament, per a que els
|
||||||
|
// consumidors no depenguen del cicle de vida de Screen ni del seu header.
|
||||||
|
namespace Rendering {
|
||||||
|
|
||||||
|
struct Canvas {
|
||||||
|
std::uint32_t* pixels{nullptr};
|
||||||
|
int width{0};
|
||||||
|
int height{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retorna el canvas actiu del joc. En aquesta fase del projecte n'hi ha
|
||||||
|
// sempre un i només un (el de Screen); en el futur, si cal renderitzar
|
||||||
|
// off-screen (miniatures, efectes), es podrà pushejar/popar per ací.
|
||||||
|
[[nodiscard]] auto activeCanvas() -> Canvas;
|
||||||
|
|
||||||
|
} // namespace Rendering
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "core/rendering/canvas.hpp"
|
||||||
#include "core/rendering/gif.hpp"
|
#include "core/rendering/gif.hpp"
|
||||||
#include "core/rendering/screen.hpp"
|
|
||||||
#include "core/resources/resource_helper.hpp"
|
#include "core/resources/resource_helper.hpp"
|
||||||
#include "utils/utils.hpp"
|
#include "utils/utils.hpp"
|
||||||
|
|
||||||
@@ -86,9 +86,10 @@ void Surface::render(int x, int y, const SDL_FRect* src_rect, SDL_FlipMode flip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 target_color, const SDL_FRect* src_rect, SDL_FlipMode flip) const {
|
void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 target_color, const SDL_FRect* src_rect, SDL_FlipMode flip) const {
|
||||||
Uint32* dst = Screen::get().getCanvasArgb();
|
const auto CANVAS = Rendering::activeCanvas();
|
||||||
const int DST_W = Screen::get().getCanvasWidth();
|
Uint32* dst = CANVAS.pixels;
|
||||||
const int DST_H = Screen::get().getCanvasHeight();
|
const int DST_W = CANVAS.width;
|
||||||
|
const int DST_H = CANVAS.height;
|
||||||
|
|
||||||
const int SX = (src_rect != nullptr) ? static_cast<int>(src_rect->x) : 0;
|
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 SY = (src_rect != nullptr) ? static_cast<int>(src_rect->y) : 0;
|
||||||
|
|||||||
Reference in new issue
Block a user