Notifier::init i RenderInfo::init cridaven Resource::Cache::get() i construïen cadascun la seua pròpia instància de Text a partir de "8bithud.gif" + "data/font/8bithud.fnt" (strings hardcoded). Notifier també llegia la paleta "ui" a cada render(). Ara: - Director construeix una sola std::shared_ptr<Text> compartida. - RenderInfo::init(Frame, shared_ptr<Text>) i Notifier::init (shared_ptr<Text>, const Palette&) reben els recursos injectats. - Notifier desa la Palette una volta i la consulta localment a render(), sense tocar el cache global. Resultat: els overlays perden la dependència dels noms dels assets i del cache; el cicle de vida queda controlat pel Director. El camp intern text_ passa a shared_ptr<Text>. El document d'auditoria es tanca: - PATCH-02, COUP-05 → DEFERRED (feature beyond cleanup scope). - INC-04 → WONTFIX (coexistència justificada de writeDX/write*). - Estat global: neteja completada. Build + smoke 5s xvfb OK (exit 124). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
#include "core/rendering/notifier.hpp"
|
|
|
|
#include <utility>
|
|
|
|
#include "core/rendering/screen.hpp"
|
|
#include "core/rendering/text.hpp"
|
|
#include "utils/defines.hpp"
|
|
|
|
auto Notifier::get() -> Notifier& {
|
|
static Notifier instance_;
|
|
return instance_;
|
|
}
|
|
|
|
Notifier::~Notifier() = default;
|
|
|
|
void Notifier::init(std::shared_ptr<Text> text, const Palette& ui_palette) {
|
|
text_ = std::move(text);
|
|
ui_palette_ = ui_palette;
|
|
}
|
|
|
|
void Notifier::update(int delta_ms) {
|
|
const float DT = static_cast<float>(delta_ms) / 1000.0F;
|
|
switch (status_) {
|
|
case Status::RISING:
|
|
y_ += SLIDE_SPEED * DT;
|
|
if (y_ >= static_cast<float>(MARGIN_TOP)) {
|
|
y_ = static_cast<float>(MARGIN_TOP);
|
|
status_ = Status::ACTIVE;
|
|
}
|
|
break;
|
|
case Status::ACTIVE:
|
|
remaining_ms_ -= delta_ms;
|
|
if (remaining_ms_ <= 0) { status_ = Status::VANISHING; }
|
|
break;
|
|
case Status::VANISHING:
|
|
y_ -= SLIDE_SPEED * DT;
|
|
if (y_ <= static_cast<float>(-HEIGHT)) {
|
|
y_ = static_cast<float>(-HEIGHT - MARGIN_TOP);
|
|
status_ = Status::HIDDEN;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Notifier::render() {
|
|
if (status_ == Status::HIDDEN || text_ == nullptr || current_text_.empty()) { return; }
|
|
|
|
const int TEXT_W = text_->length(current_text_, 1);
|
|
const int BOX_W = TEXT_W + (2 * PADDING_H);
|
|
const int BOX_X = (GameCanvas::WIDTH - BOX_W) / 2;
|
|
const int BOX_Y = static_cast<int>(y_);
|
|
|
|
// Fons sòlid amb la paleta UI que ens ha injectat el caller a init()
|
|
// (ARGB directe al canvas, sense tocar cap surface paletada).
|
|
Screen::get().fillRect(BOX_X, BOX_Y, BOX_W, HEIGHT, ui_palette_[current_bg_color_]);
|
|
|
|
text_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
|
GameCanvas::CENTER_X,
|
|
BOX_Y + PADDING_V,
|
|
current_text_,
|
|
1,
|
|
current_text_color_);
|
|
}
|
|
|
|
void Notifier::notify(const std::string& text, Uint8 text_color, Uint8 bg_color, int time_ms) {
|
|
// Política simple: la nova notificació reemplaça la que hi havia. Per
|
|
// gestionar-ne una cua, canviar ací per una FIFO quan calga.
|
|
current_text_ = text;
|
|
current_text_color_ = text_color;
|
|
current_bg_color_ = bg_color;
|
|
remaining_ms_ = time_ms;
|
|
status_ = Status::RISING;
|
|
}
|