refactor(core/rendering): desacoplar RenderInfo d'Options i UiColor (COUP-01b)

core/rendering/render_info ja no inclou game/options.hpp ni
game/ui/ui_palette.hpp. S'introdueix RenderInfo::Frame amb tot l'estat
extern (posició, show_time, shader_enabled, shader_name, shader_preset,
colors) que el caller injecta a cada init()/update(). La lògica de
persistència (cyclePosition/toggleShowTime) surt de RenderInfo i passa
a global_inputs.cpp, que muta Options i crida saveToFile() directament.

Options::buildRenderInfoFrame(text_color, shadow_color) centralitza la
construcció del Frame seguint el mateix patró que buildScreenConfig /
buildPostFXParams. Director i GameScene criden aquest builder quan
necessiten un Frame (amb UiColor::RENDER_INFO_{TEXT,SHADOW} com a
colors actius).

Amb aquest canvi queda tancada COUP-01: core/rendering/ no té cap
include de game/*.

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:13:58 +02:00
1 parent 9434e4e87d
commit 9395520a23
8 files changed
+77 -59

No files matched your search

+5 -2
View File
@@ -139,11 +139,14 @@ namespace GlobalInputs {
}
void onCycleRenderInfo() {
RenderInfo::cyclePosition();
const int NEXT = (static_cast<int>(Options::video.render_info_position) + 1) % 3;
Options::video.render_info_position = static_cast<Defaults::RenderInfoPosition>(NEXT);
Options::saveToFile();
}
void onToggleRenderTime() {
RenderInfo::toggleShowTime();
Options::video.render_info_show_time = !Options::video.render_info_show_time;
Options::saveToFile();
}
void onExit() {
+25 -40
View File
@@ -9,8 +9,6 @@
#include "core/rendering/screen.hpp"
#include "core/rendering/text.hpp"
#include "core/resources/resource_cache.hpp"
#include "game/options.hpp"
#include "game/ui/ui_palette.hpp"
#include "utils/defines.hpp"
#include "utils/easing.hpp"
@@ -23,6 +21,10 @@ namespace {
// Evita una fileta d'un sol píxel quan acaba de començar a aparèixer.
constexpr float VISIBLE_EPSILON = 0.01F;
// Índex del segment de temps dins de segments_. Si canvia SEGMENT_COUNT
// o l'ordre, actualitzar ací.
constexpr int TIME_SEGMENT = 3;
auto prettify(std::string s) -> std::string {
std::ranges::replace(s, '-', ' ');
std::ranges::transform(s, s.begin(), [](unsigned char c) { return std::tolower(c); });
@@ -48,27 +50,25 @@ auto RenderInfo::get() -> RenderInfo& {
RenderInfo::~RenderInfo() = default;
void RenderInfo::init() {
void RenderInfo::init(const Frame& initial) {
auto font_surface = Resource::Cache::get().getSurface("8bithud.gif");
text_ = std::make_unique<Text>(font_surface, "data/font/8bithud.fnt");
current_ = initial;
segments_[TIME_SEGMENT].mono_digits = true;
// Restaura l'estat guardat: si l'overlay estava engegat, l'activem ja
// plenament visible (sense animació d'entrada inicial).
if (Options::video.render_info_position != Defaults::RenderInfoPosition::OFF) {
visible_pos_ = Options::video.render_info_position;
if (initial.target_position != Defaults::RenderInfoPosition::OFF) {
visible_pos_ = initial.target_position;
info_anim_ = 1.0F;
}
// El segment de temps pot estar activat per persistència: si la barra
// apareix ja plena, el seu segment també ha d'estar-ho.
segments_[3].mono_digits = true;
if (info_anim_ >= 1.0F) {
refreshSegments();
for (auto& seg : segments_) { seg.anim = seg.visible ? 1.0F : 0.0F; }
}
}
void RenderInfo::update(int delta_ms) {
void RenderInfo::update(int delta_ms, const Frame& frame) {
current_ = frame;
elapsed_ms_ += delta_ms;
const float DT = static_cast<float>(delta_ms) / 1000.0F;
@@ -76,7 +76,7 @@ void RenderInfo::update(int delta_ms) {
// visible, entrem (anim→1). Si no, primer eixim (anim→0) del lloc actual;
// quan arriba a 0 commutem visible_pos_ i deixem que el proper frame
// dispari l'entrada. Excepció: de OFF a TOP/BOTTOM commutem en sec.
const auto DESIRED = Options::video.render_info_position;
const auto DESIRED = current_.target_position;
if (DESIRED == visible_pos_) {
// Si el destí és OFF, no cal animar cap a un lloc — la barra ja ha
// d'estar fora. Sense aquest guard, en arribar de BOTTOM→OFF la
@@ -122,21 +122,18 @@ void RenderInfo::refreshSegments() {
segments_[1].visible = true;
segments_[1].mono_digits = false;
// [2] Shader + preset (només amb shader activat)
if (Options::video.shader.enabled) {
const std::string& shader = Options::video.shader.current_shader;
const std::string& preset = (shader == "crtpi")
? Options::video.shader.current_crtpi_preset
: Options::video.shader.current_postfx_preset;
segments_[2].text = " | " + shader + " " + prettify(preset);
// [2] Shader + preset (només amb shader activat). El caller ha triat el
// preset actiu segons el shader; ací només el formatem.
if (current_.shader_enabled) {
segments_[2].text = " | " + current_.shader_name + " " + prettify(current_.shader_preset);
}
segments_[2].visible = Options::video.shader.enabled;
segments_[2].visible = current_.shader_enabled;
segments_[2].mono_digits = false;
// [3] Temps de joc (togglejable i persistent)
segments_[3].text = " | " + formatTime(elapsed_ms_);
segments_[3].visible = Options::video.render_info_show_time;
segments_[3].mono_digits = true;
segments_[TIME_SEGMENT].text = " | " + formatTime(elapsed_ms_);
segments_[TIME_SEGMENT].visible = current_.show_time;
segments_[TIME_SEGMENT].mono_digits = true;
// Els tres primers segments baixem a minúscules per coherència estètica
// amb la resta de la línia; el [3] (temps) manté dígits i puntuació.
@@ -191,25 +188,13 @@ void RenderInfo::render() {
const int SEG_W = segmentWidth(seg, DIGIT_CELL);
if (seg.mono_digits) {
text_->writeMonoDigits(XI + 1, Y + 1, seg.text, UiColor::RENDER_INFO_SHADOW, DIGIT_CELL);
text_->writeMonoDigits(XI, Y, seg.text, UiColor::RENDER_INFO_TEXT, DIGIT_CELL);
text_->writeMonoDigits(XI + 1, Y + 1, seg.text, current_.shadow_color, DIGIT_CELL);
text_->writeMonoDigits(XI, Y, seg.text, current_.text_color, DIGIT_CELL);
} else {
text_->writeColored(XI + 1, Y + 1, seg.text, UiColor::RENDER_INFO_SHADOW);
text_->writeColored(XI, Y, seg.text, UiColor::RENDER_INFO_TEXT);
text_->writeColored(XI + 1, Y + 1, seg.text, current_.shadow_color);
text_->writeColored(XI, Y, seg.text, current_.text_color);
}
cur_x += static_cast<float>(SEG_W) * Easing::outQuad(seg.anim);
}
}
void RenderInfo::cyclePosition() {
const auto CURRENT = Options::video.render_info_position;
const int NEXT = (static_cast<int>(CURRENT) + 1) % 3;
Options::video.render_info_position = static_cast<Defaults::RenderInfoPosition>(NEXT);
Options::saveToFile();
}
void RenderInfo::toggleShowTime() {
Options::video.render_info_show_time = !Options::video.render_info_show_time;
Options::saveToFile();
}
+20 -12
View File
@@ -1,5 +1,7 @@
#pragma once
#include <SDL3/SDL.h>
#include <array>
#include <cstdint>
#include <memory>
@@ -11,9 +13,9 @@ class Text;
// Overlay de debug amb tres estats (OFF / TOP / BOTTOM). Mostra una barra
// d'info dividida en segments independents (fps, driver, shader, temps) que
// apareixen i desapareixen suaument. La posició es commuta amb una tecla
// (cicle OFF → TOP → BOTTOM) i el segment de temps es pot mostrar o amagar
// per separat; les dos opcions persisteixen a config.yaml.
// apareixen i desapareixen suaument. No llig cap configuració; el caller
// (Director a init, GameScene a update) injecta cada frame l'estat desitjat
// via Frame.
class RenderInfo {
public:
static auto get() -> RenderInfo&;
@@ -23,18 +25,23 @@ class RenderInfo {
auto operator=(const RenderInfo&) -> RenderInfo& = delete;
auto operator=(RenderInfo&&) -> RenderInfo& = delete;
void init();
// Estat extern que dirigeix què ha de mostrar RenderInfo. La posició
// determina si la barra entra per dalt o per baix (o s'amaga). El
// shader_preset ja ha d'estar pre-seleccionat (crtpi/postfx) pel caller.
struct Frame {
Defaults::RenderInfoPosition target_position{Defaults::RenderInfoPosition::OFF};
bool show_time{false};
bool shader_enabled{false};
std::string shader_name;
std::string shader_preset;
Uint8 text_color{0};
Uint8 shadow_color{0};
};
void update(int delta_ms);
void init(const Frame& initial);
void update(int delta_ms, const Frame& frame);
void render();
// Avança la posició OFF → TOP → BOTTOM → OFF i persisteix.
static void cyclePosition();
// Mostra/oculta el segment de temps i persisteix. Només té efecte visual
// quan la barra és visible (TOP/BOTTOM).
static void toggleShowTime();
static constexpr int HEIGHT = 10;
static constexpr float SLIDE_SPEED = 5.0F; // posició global (1/s)
static constexpr float SEG_SPEED = 6.0F; // segments individuals (1/s)
@@ -60,4 +67,5 @@ class RenderInfo {
float info_anim_{0.0F}; // 0..1, suavitzat amb outQuad al render
std::array<Segment, SEGMENT_COUNT> segments_{};
int elapsed_ms_{0};
Frame current_{};
};
+2 -1
View File
@@ -22,6 +22,7 @@
#include "core/system/event_buffer.hpp"
#include "game/options.hpp"
#include "game/scenes/game_scene.hpp"
#include "game/ui/ui_palette.hpp"
#include "utils/defaults.hpp"
Director::Director() {
@@ -79,7 +80,7 @@ Director::Director() {
// JA_Music_t que continga, així que no queden streams orfes.
Audio::init(Options::buildAudioConfig());
RenderInfo::get().init();
RenderInfo::get().init(Options::buildRenderInfoFrame(UiColor::RENDER_INFO_TEXT, UiColor::RENDER_INFO_SHADOW));
Notifier::get().init();
current_scene_ = std::make_unique<GameScene>();