5f6d51b6cb
Pas 1/N del hallazgo #28. Sense canvi de comportament: Nou: source/core/config/engine_config.hpp - Defineix Config::EngineConfig (POD) amb les sub-structs WindowConfig, RenderingConfig, KeyboardBindings, GamepadBindings, PlayerBindings i el flag console. - Sense singletons ni virtuals; la inversió real es fa en commits posteriors injectant Config::EngineConfig& per constructor. Modificat: source/game/options.hpp - Elimina les struct definitions locals (Window, Rendering, ...). - Afegeix Options::engine_config (única font de veritat). - Conserva Options::window, Options::rendering, player1, player2, keyboard_controls, gamepad_controls i console com a referències inline a camps d'engine_config. Cost runtime zero, callsites existents no requereixen cap canvi. Hallazgo #28 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
2.2 KiB
C++
57 lines
2.2 KiB
C++
// options.hpp - Persistència YAML i globals d'opcions (capa game)
|
|
// © 2026 JailDesigner
|
|
//
|
|
// La configuració runtime viu en una struct única (Config::EngineConfig,
|
|
// definida a `core/config/engine_config.hpp`). Aquest fitxer hi posa al
|
|
// damunt la capa de persistència YAML i les compatibilitats històriques
|
|
// (Options::window, Options::rendering, ...) com a referències inline a
|
|
// camps d'aquesta struct. Cost runtime zero, callsites existents no
|
|
// requereixen cap canvi.
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "core/config/engine_config.hpp"
|
|
|
|
namespace Options {
|
|
|
|
// Única font de veritat de la configuració runtime. Tota la resta de
|
|
// globals d'aquest namespace són referències inline a camps d'aquesta
|
|
// struct.
|
|
inline Config::EngineConfig engine_config{
|
|
.player2 = {
|
|
.keyboard = {
|
|
.key_left = SDL_SCANCODE_A,
|
|
.key_right = SDL_SCANCODE_D,
|
|
.key_thrust = SDL_SCANCODE_W,
|
|
.key_shoot = SDL_SCANCODE_LSHIFT,
|
|
.key_start = SDL_SCANCODE_2,
|
|
},
|
|
.gamepad_name = "",
|
|
},
|
|
};
|
|
|
|
// Aliases (referències) per al codi existent.
|
|
inline Config::WindowConfig& window = engine_config.window;
|
|
inline Config::RenderingConfig& rendering = engine_config.rendering;
|
|
inline Config::PlayerBindings& player1 = engine_config.player1;
|
|
inline Config::PlayerBindings& player2 = engine_config.player2;
|
|
inline Config::KeyboardBindings& keyboard_controls = engine_config.keyboard_controls;
|
|
inline Config::GamepadBindings& gamepad_controls = engine_config.gamepad_controls;
|
|
inline bool& console = engine_config.console;
|
|
|
|
// Persistència YAML (es queda en game/, no en core/)
|
|
inline std::string version{}; // Versión del config per validació
|
|
inline std::string config_file_path{}; // Establert per setConfigFile()
|
|
|
|
// Funciones públiques
|
|
|
|
void init(); // Inicialitzar con valors per defecte
|
|
void setConfigFile(
|
|
const std::string& path); // Establir ruta del file de config
|
|
auto loadFromFile() -> bool; // Carregar config YAML
|
|
auto saveToFile() -> bool; // Guardar config YAML
|
|
|
|
} // namespace Options
|