- renderInfo
- fix: no guardava el preset actual
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/rendering/text.hpp"
|
||||
#include "game/options.hpp"
|
||||
|
||||
namespace Overlay {
|
||||
|
||||
@@ -46,6 +47,9 @@ namespace Overlay {
|
||||
static std::vector<Notification> notifications_;
|
||||
static Uint32 last_ticks_ = 0;
|
||||
|
||||
// --- Render info ---
|
||||
static std::string render_info_text_;
|
||||
|
||||
void init() {
|
||||
font_ = std::make_unique<Text>("fonts/8bithud.fnt", "fonts/8bithud.gif");
|
||||
last_ticks_ = SDL_GetTicks();
|
||||
@@ -120,6 +124,19 @@ namespace Overlay {
|
||||
font_->draw(pixel_data, box_x + NOTIF_PADDING_H, box_y + NOTIF_PADDING_V, notif.message.c_str(), NOTIF_TEXT_COLOR);
|
||||
}
|
||||
|
||||
// Render info (FPS, driver, shader) — centrat, posició configurable
|
||||
if (Options::render_info.position != Options::RenderInfoPosition::OFF && !render_info_text_.empty()) {
|
||||
int info_w = font_->width(render_info_text_.c_str());
|
||||
int info_x = (SCREEN_W - info_w) / 2;
|
||||
int info_y = (Options::render_info.position == Options::RenderInfoPosition::TOP)
|
||||
? 1
|
||||
: SCREEN_H - font_->charHeight() - 1;
|
||||
// Ombra (1px desplaçat)
|
||||
font_->draw(pixel_data, info_x + 1, info_y + 1, render_info_text_.c_str(), Options::render_info.shadow_color);
|
||||
// Text
|
||||
font_->draw(pixel_data, info_x, info_y, render_info_text_.c_str(), Options::render_info.text_color);
|
||||
}
|
||||
|
||||
// Elimina les acabades
|
||||
notifications_.erase(
|
||||
std::remove_if(notifications_.begin(), notifications_.end(), [](const Notification& n) { return n.status == Status::FINISHED; }),
|
||||
@@ -139,4 +156,23 @@ namespace Overlay {
|
||||
notifications_.push_back(notif);
|
||||
}
|
||||
|
||||
void toggleRenderInfo() {
|
||||
// Cicla: OFF → TOP → BOTTOM → OFF
|
||||
switch (Options::render_info.position) {
|
||||
case Options::RenderInfoPosition::OFF:
|
||||
Options::render_info.position = Options::RenderInfoPosition::TOP;
|
||||
break;
|
||||
case Options::RenderInfoPosition::TOP:
|
||||
Options::render_info.position = Options::RenderInfoPosition::BOTTOM;
|
||||
break;
|
||||
case Options::RenderInfoPosition::BOTTOM:
|
||||
Options::render_info.position = Options::RenderInfoPosition::OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setRenderInfoText(const char* text) {
|
||||
render_info_text_ = text;
|
||||
}
|
||||
|
||||
} // namespace Overlay
|
||||
|
||||
@@ -11,4 +11,8 @@ namespace Overlay {
|
||||
|
||||
// Mostra una notificació amb animació slide-in/stay/slide-out
|
||||
void showNotification(const char* text, float duration_seconds = 2.0F);
|
||||
|
||||
// Activa/desactiva la info de renderitzat (FPS, driver, shader, preset)
|
||||
void toggleRenderInfo();
|
||||
void setRenderInfoText(const char* text);
|
||||
} // namespace Overlay
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "core/rendering/screen.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/rendering/overlay.hpp"
|
||||
#include "core/rendering/sdl3gpu/sdl3gpu_shader.hpp"
|
||||
#include "game/defines.hpp"
|
||||
#include "game/options.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
Screen* Screen::instance_ = nullptr;
|
||||
|
||||
@@ -81,10 +83,8 @@ void Screen::initShaders() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* gpu = dynamic_cast<Rendering::SDL3GPUShader*>(shader_backend_.get());
|
||||
if (gpu) {
|
||||
std::cout << "GPU driver: " << gpu->getDriverName() << '\n';
|
||||
}
|
||||
gpu_driver_ = shader_backend_->getDriverName();
|
||||
std::cout << "GPU driver: " << gpu_driver_ << '\n';
|
||||
|
||||
// Aplica opcions de vídeo
|
||||
shader_backend_->setScaleMode(Options::video.integer_scale);
|
||||
@@ -97,12 +97,35 @@ void Screen::initShaders() {
|
||||
shader_backend_->setOversample(3);
|
||||
}
|
||||
|
||||
// Aplica presets per defecte (de moment hardcoded, futur: YAML)
|
||||
// Resol el shader actiu des del config
|
||||
if (Options::video.current_shader == "crtpi") {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::CRTPI);
|
||||
} else {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
|
||||
}
|
||||
|
||||
// Resol presets per nom
|
||||
for (int i = 0; i < static_cast<int>(Options::postfx_presets.size()); i++) {
|
||||
if (Options::postfx_presets[i].name == Options::video.current_postfx_preset) {
|
||||
Options::current_postfx_preset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < static_cast<int>(Options::crtpi_presets.size()); i++) {
|
||||
if (Options::crtpi_presets[i].name == Options::video.current_crtpi_preset) {
|
||||
Options::current_crtpi_preset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
applyCurrentPostFXPreset();
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
|
||||
void Screen::present(Uint32* pixel_data) {
|
||||
fps_.increment();
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
updateRenderInfo();
|
||||
Overlay::render(pixel_data);
|
||||
|
||||
if (shader_backend_ && shader_backend_->isHardwareAccelerated() && Options::video.shader_enabled) {
|
||||
@@ -192,9 +215,11 @@ void Screen::nextShaderType() {
|
||||
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::CRTPI);
|
||||
Options::video.current_shader = "crtpi";
|
||||
applyCurrentCrtPiPreset();
|
||||
} else {
|
||||
shader_backend_->setActiveShader(Rendering::ShaderType::POSTFX);
|
||||
Options::video.current_shader = "postfx";
|
||||
applyCurrentPostFXPreset();
|
||||
}
|
||||
}
|
||||
@@ -205,10 +230,12 @@ void Screen::nextPreset() {
|
||||
if (shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX) {
|
||||
if (Options::postfx_presets.empty()) return;
|
||||
Options::current_postfx_preset = (Options::current_postfx_preset + 1) % static_cast<int>(Options::postfx_presets.size());
|
||||
Options::video.current_postfx_preset = Options::postfx_presets[Options::current_postfx_preset].name;
|
||||
applyCurrentPostFXPreset();
|
||||
} else {
|
||||
if (Options::crtpi_presets.empty()) return;
|
||||
Options::current_crtpi_preset = (Options::current_crtpi_preset + 1) % static_cast<int>(Options::crtpi_presets.size());
|
||||
Options::video.current_crtpi_preset = Options::crtpi_presets[Options::current_crtpi_preset].name;
|
||||
applyCurrentCrtPiPreset();
|
||||
}
|
||||
}
|
||||
@@ -276,6 +303,20 @@ auto Screen::getActiveShaderName() const -> const char* {
|
||||
return shader_backend_->getActiveShader() == Rendering::ShaderType::POSTFX ? "POSTFX" : "CRT-PI";
|
||||
}
|
||||
|
||||
void Screen::updateRenderInfo() {
|
||||
std::string driver = gpu_driver_.empty() ? "sdl" : toLower(gpu_driver_);
|
||||
std::string info = std::to_string(fps_.last_value) + " fps - " + driver;
|
||||
|
||||
if (Options::video.shader_enabled) {
|
||||
std::string shader_name = toLower(getActiveShaderName());
|
||||
std::string preset_name = toLower(getCurrentPresetName());
|
||||
info += " - " + shader_name + " " + preset_name;
|
||||
if (Options::video.supersampling) info += " (ss)";
|
||||
}
|
||||
|
||||
Overlay::setRenderInfoText(info.c_str());
|
||||
}
|
||||
|
||||
void Screen::adjustWindowSize() {
|
||||
int w = GAME_WIDTH * zoom_;
|
||||
// Si 4:3 actiu, l'alçada visual és 240 per zoom (200 * 1.2)
|
||||
|
||||
@@ -60,9 +60,29 @@ class Screen {
|
||||
// Backend GPU (nullptr si no disponible o desactivat)
|
||||
std::unique_ptr<Rendering::ShaderBackend> shader_backend_;
|
||||
|
||||
void updateRenderInfo();
|
||||
|
||||
struct FPS {
|
||||
Uint32 ticks{0};
|
||||
int frame_count{0};
|
||||
int last_value{0};
|
||||
|
||||
void increment() { frame_count++; }
|
||||
auto calculate(Uint32 current_ticks) -> int {
|
||||
if (current_ticks - ticks >= 1000) {
|
||||
last_value = frame_count;
|
||||
frame_count = 0;
|
||||
ticks = current_ticks;
|
||||
}
|
||||
return last_value;
|
||||
}
|
||||
};
|
||||
|
||||
int zoom_{3};
|
||||
int max_zoom_{6};
|
||||
bool fullscreen_{false};
|
||||
FPS fps_;
|
||||
std::string gpu_driver_;
|
||||
|
||||
static constexpr int GAME_WIDTH = 320;
|
||||
static constexpr int GAME_HEIGHT = 200;
|
||||
|
||||
Reference in New Issue
Block a user