41ce3fece5
Pas 5/N del hallazgo #28. Director deixa d'incloure game/options.hpp i les seves crides a Options::*. El seu ctor accepta ara: - Config::EngineConfig& cfg → la struct runtime (window, console, ...). - Config::ConfigPersistence → 4 lambdes (init/set_path/load/save) que delegen la persistència a la capa concreta (game/Options::*). Cap més referència a Options:: ni a "game/..." dins del Director: - cfg_->* substitueix tot Options::* (window, console, player1/2, rendering, engine_config). - persistence_.{init,save,load,set_path} substitueix les funcions d'I/O de YAML. run() i checkProgramArguments deixen de ser estàtics (necessiten accés a cfg_ i persistence_). Això també desfà el smell del hallazgo #37 (Director::run estàtic que llegia estat d'instància). main.cpp queda com a orquestrador: construeix la struct ConfigPersistence amb lambdes que enllacen amb Options::* i la injecta al Director. Afegit: Config::ConfigPersistence a engine_config.hpp. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
// engine_config.hpp - Configuració runtime del motor (window, render, input)
|
|
// © 2026 JailDesigner
|
|
//
|
|
// Struct POD que conté la configuració runtime que els sistemes de `core/`
|
|
// llegeixen i muten. La capa de persistència (YAML) viu a `game/options.cpp`,
|
|
// que omple aquesta struct a init() i loadFromFile().
|
|
//
|
|
// Es passa per referència (mutable quan cal) al constructor dels sistemes
|
|
// que la necessiten, mantenint `core/` agnòstic a `game/`.
|
|
|
|
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
namespace Config {
|
|
|
|
struct WindowConfig {
|
|
int width{1280};
|
|
int height{720};
|
|
bool fullscreen{false};
|
|
float zoom_factor{1.0F}; // Zoom level (0.5x to max_zoom)
|
|
};
|
|
|
|
struct RenderingConfig {
|
|
int vsync{1}; // 0=disabled, 1=enabled
|
|
};
|
|
|
|
struct KeyboardBindings {
|
|
SDL_Scancode key_left{SDL_SCANCODE_LEFT};
|
|
SDL_Scancode key_right{SDL_SCANCODE_RIGHT};
|
|
SDL_Scancode key_thrust{SDL_SCANCODE_UP};
|
|
SDL_Scancode key_shoot{SDL_SCANCODE_SPACE};
|
|
SDL_Scancode key_start{SDL_SCANCODE_1};
|
|
};
|
|
|
|
struct GamepadBindings {
|
|
int button_left{SDL_GAMEPAD_BUTTON_DPAD_LEFT};
|
|
int button_right{SDL_GAMEPAD_BUTTON_DPAD_RIGHT};
|
|
int button_thrust{SDL_GAMEPAD_BUTTON_WEST}; // X button
|
|
int button_shoot{SDL_GAMEPAD_BUTTON_SOUTH}; // A button
|
|
};
|
|
|
|
struct PlayerBindings {
|
|
KeyboardBindings keyboard{};
|
|
GamepadBindings gamepad{};
|
|
std::string gamepad_name; // Empty = auto-assign by index
|
|
};
|
|
|
|
struct EngineConfig {
|
|
WindowConfig window{};
|
|
RenderingConfig rendering{};
|
|
PlayerBindings player1{};
|
|
PlayerBindings player2{};
|
|
KeyboardBindings keyboard_controls{}; // Defaults globals per Input
|
|
GamepadBindings gamepad_controls{};
|
|
bool console{false};
|
|
};
|
|
|
|
// Capa de persistència delegada cap a l'EngineConfig. Permet al Director
|
|
// orquestrar init/load/save sense conèixer cap esquema concret (YAML,
|
|
// SQLite, ...) ni la capa que el conté (`game/options.cpp`).
|
|
struct ConfigPersistence {
|
|
std::function<void()> init_defaults; // Restaura valors per defecte
|
|
std::function<void(const std::string& path)> set_path; // Indica on guardar
|
|
std::function<bool()> load; // Llegeix path → EngineConfig
|
|
std::function<bool()> save; // Escriu EngineConfig → path
|
|
};
|
|
|
|
} // namespace Config
|