refactor(core/rendering): desacoplar Notifier de game/ui (COUP-01a)

core/rendering/notifier.hpp ja no inclou game/ui/notification_presets.hpp,
i Notifier només exposa l'API crua notify(text, text_color, bg_color,
time_ms). El helper de conveniència basat en Preset es trasllada com a
funció lliure Notification::notify() a game/ui/notification_presets.hpp
(direcció game → core, correcta). Els callers de global_inputs.cpp
passen a usar el helper i afegeixen l'include explícit.

Sota l'auditoria de core/rendering (docs/audit-core-rendering.md).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
JailDesignerandClaude Opus 4.7 committed 2026-04-20 09:06:40 +02:00
1 parent 9243db1b9f
commit 9434e4e87d
5 files changed
+27 -29

No files matched your search

+5 -3
View File
@@ -18,7 +18,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/*` | PENDING |
| COUP-01 | Inversión de dependencia `core/rendering → game/*` | WIP (a: DONE, b: PENDING) |
| DUP-02 | `Surface::render` / `renderWithColorReplace` duplicados | PENDING |
| 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 |
@@ -70,7 +70,8 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
| ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas |
|----|---------------|----------|-----------|--------|-------|
| COUP-01 | `notifier.hpp:9`, `render_info.cpp:12-13` | `core/rendering` incluye `game/ui/*` y `game/options.hpp` | Crítico | PENDING | inyectar via Config/callback |
| 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 | PENDING | `RenderInfo::State` inyectada pel Director |
| COUP-02 | `screen.cpp:13-14,109` | `Screen` instancia `SDL3GPUShader` concreto | Importante | PENDING | factory/registry |
| COUP-03 | `surface.cpp:81-83,110-112` | `Surface::render` usa `Screen::get()` global | Importante | PENDING | pasar destino por parámetro |
| COUP-04 | `notifier.cpp:19`, `render_info.cpp:52` | `Resource::Cache::get().getSurface("8bithud.gif")` con string literal | Importante | PENDING | inyectar la surface |
@@ -118,4 +119,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
## Registro de commits
(Se irá rellenando a medida que se apliquen los cambios.)
- `9243db1` — docs: full de treball inicial (aquest fitxer)
- `<pendent>` — COUP-01a: `Notifier` desacoblat de `game/ui/notification_presets`
+7 -6
View File
@@ -12,6 +12,7 @@
#include "core/rendering/screen.hpp"
#include "core/system/event_buffer.hpp"
#include "game/options.hpp"
#include "game/ui/notification_presets.hpp"
#include "utils/defaults.hpp"
namespace GlobalInputs {
@@ -37,7 +38,7 @@ namespace GlobalInputs {
}
void notifyLocale(const std::string& key) {
Notifier::get().notify(Locale::get().text(key));
Notification::notify(Locale::get().text(key));
}
void onDecZoom() {
@@ -46,7 +47,7 @@ namespace GlobalInputs {
Options::window.zoom--;
Screen::get().setWindowZoom(Options::window.zoom);
Options::saveToFile();
Notifier::get().notify(Locale::get().text("input.zoom") + " x" + std::to_string(Options::window.zoom));
Notification::notify(Locale::get().text("input.zoom") + " x" + std::to_string(Options::window.zoom));
}
void onIncZoom() {
@@ -55,7 +56,7 @@ namespace GlobalInputs {
Options::window.zoom++;
Screen::get().setWindowZoom(Options::window.zoom);
Options::saveToFile();
Notifier::get().notify(Locale::get().text("input.zoom") + " x" + std::to_string(Options::window.zoom));
Notification::notify(Locale::get().text("input.zoom") + " x" + std::to_string(Options::window.zoom));
}
void onFullscreen() {
@@ -83,7 +84,7 @@ namespace GlobalInputs {
Options::video.shader.current_shader = (Options::video.shader.current_shader == "crtpi") ? "postfx" : "crtpi";
reapplyShader();
Options::saveToFile();
Notifier::get().notify(Locale::get().text("input.shader") + ": " + Options::video.shader.current_shader);
Notification::notify(Locale::get().text("input.shader") + ": " + Options::video.shader.current_shader);
}
// Busca l'entrada actual al vector de presets i passa a la següent
@@ -108,7 +109,7 @@ namespace GlobalInputs {
reapplyShader();
Options::saveToFile();
const std::string& name = IS_CRTPI ? Options::video.shader.current_crtpi_preset : Options::video.shader.current_postfx_preset;
Notifier::get().notify(Locale::get().text("input.preset") + ": " + name);
Notification::notify(Locale::get().text("input.preset") + ": " + name);
}
void onNextScalingMode() {
@@ -151,7 +152,7 @@ namespace GlobalInputs {
return;
}
exit_window_s = EXIT_WINDOW_S;
Notifier::get().notify(Locale::get().text("input.press_again_exit"), Notification::EXIT);
Notification::notify(Locale::get().text("input.press_again_exit"), Notification::EXIT);
}
} // namespace
-8
View File
@@ -67,14 +67,6 @@ void Notifier::render() {
current_text_color_);
}
void Notifier::notify(const std::string& text) {
notify(text, Notification::DEFAULT);
}
void Notifier::notify(const std::string& text, const Notification::Preset& preset) {
notify(text, preset.text_color, preset.bg_color, preset.time_ms);
}
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.
+3 -9
View File
@@ -6,8 +6,6 @@
#include <memory>
#include <string>
#include "game/ui/notification_presets.hpp"
class Text;
// Popup transitori a dalt i centrat. Entra lliscant des de dalt, es queda
@@ -15,10 +13,9 @@ class Text;
// 8bithud i la paleta "ui" amb la resta d'overlays (carregades per RenderInfo
// a l'arrencada; si Notifier::init() es crida primer, les carrega ell).
//
// Ús típic:
// Notifier::get().notify("Text ràpid"); // preset DEFAULT
// Notifier::get().notify("Text ràpid", miPreset); // preset custom
// Notifier::get().notify("Urgent", 11, 3, 800); // colors i durada explícits
// API crua: Notifier::get().notify(text, text_color, bg_color, time_ms).
// Per a treballar amb presets del joc, vegeu Notification::notify() a
// game/ui/notification_presets.hpp.
class Notifier {
public:
static auto get() -> Notifier&;
@@ -33,9 +30,6 @@ class Notifier {
void update(int delta_ms);
void render();
// Tres overloads; els dos simples deleguen al tercer.
void notify(const std::string& text);
void notify(const std::string& text, const Notification::Preset& preset);
void notify(const std::string& text, Uint8 text_color, Uint8 bg_color, int time_ms);
static constexpr int PADDING_H = 6;
+12 -3
View File
@@ -2,11 +2,14 @@
#include <SDL3/SDL.h>
#include <string>
#include "core/rendering/notifier.hpp"
// Temes per a les notificacions de pantalla. Un "preset" captura els dos
// colors (text i fons, índexs sobre la paleta "ui") i el temps de visibilitat
// en mil·lisegons. Qualsevol component que cride Notifier::notify(text)
// rebrà l'estil DEFAULT; si necessita un altre look, pot passar el preset per
// nom o especificar els camps un a un.
// en mil·lisegons. Per a llançar una notificació amb un preset concret,
// cridar Notification::notify(text, preset); si s'omet, s'usa DEFAULT.
namespace Notification {
struct Preset {
@@ -34,4 +37,10 @@ namespace Notification {
.time_ms = 4000,
};
// Helper de conveniència: aplica un preset (per defecte DEFAULT) cridant
// la API crua de Notifier. La direcció game → core és la correcta.
inline void notify(const std::string& text, const Preset& preset = DEFAULT) {
Notifier::get().notify(text, preset.text_color, preset.bg_color, preset.time_ms);
}
} // namespace Notification