refactor(core/rendering): Rendering::OPAQUE_ALPHA constant (HC-02)
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) <noreply@anthropic.com>
This commit is contained in:
1 parent
be94a4390e
commit
8b413affa8
4 files changed
+13
-7
No files matched your search
@@ -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};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
|
||||
#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<std::size_t>(GameCanvas::WIDTH) * static_cast<std::size_t>(GameCanvas::HEIGHT), 0xFF000000U);
|
||||
canvas_.assign(static_cast<std::size_t>(GameCanvas::WIDTH) * static_cast<std::size_t>(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<std::uint32_t>(r) << 16) | (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b);
|
||||
const std::uint32_t COLOR = Rendering::OPAQUE_ALPHA | (static_cast<std::uint32_t>(r) << 16) | (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b);
|
||||
std::ranges::fill(canvas_, COLOR);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::uint32_t> 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 ]");
|
||||
|
||||
Reference in new issue
Block a user