329ae7a38e
Pas 7 final del hallazgo #28. La capa de game/options havia esdevingut exclusivament una capa de persistència YAML que llegia i escrivia Config::EngineConfig. El nom "Options" no reflectia bé aquest rol. Canvis: - Renomenats fitxers: game/options.{hpp,cpp} → game/config_yaml.{hpp,cpp} (preservant la història de git via mv). - Renomenat namespace: Options → ConfigYaml. - Esborrades del .hpp les referències-alias inline (window, rendering, player1, player2, keyboard_controls, gamepad_controls, console) que ja no tenien call-sites externs (només existien per a la transició). El .hpp ara només exposa engine_config + version + path + funcions. - A config_yaml.cpp s'introdueixen aliases internes (anonymous namespace) per mantenir llegible el codi de la implementació, sense exposar-les. - Actualitzat main.cpp per a usar ConfigYaml::*. - Actualitzats els comentaris stale a sdl_manager.hpp, director.hpp, engine_config.hpp i audio.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/config_yaml.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/config_yaml.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
|