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
@@ -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 <vector>
|
||||
|
||||
#include "core/rendering/canvas.hpp"
|
||||
#include "core/rendering/gif.hpp"
|
||||
#include "core/rendering/screen.hpp"
|
||||
#include "core/resources/resource_helper.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 {
|
||||
Uint32* dst = Screen::get().getCanvasArgb();
|
||||
const int DST_W = Screen::get().getCanvasWidth();
|
||||
const int DST_H = Screen::get().getCanvasHeight();
|
||||
const auto CANVAS = Rendering::activeCanvas();
|
||||
Uint32* dst = CANVAS.pixels;
|
||||
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 SY = (src_rect != nullptr) ? static_cast<int>(src_rect->y) : 0;
|
||||
|
||||
Reference in new issue
Block a user