refactor: introduir Config::EngineConfig com a struct POD a core/
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>
This commit is contained in:
+33
-64
@@ -1,79 +1,48 @@
|
||||
#pragma once
|
||||
// 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.
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_Scancode
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/config/engine_config.hpp"
|
||||
|
||||
namespace Options {
|
||||
|
||||
// Estructures de configuración
|
||||
|
||||
struct Window {
|
||||
int width{1280};
|
||||
int height{720};
|
||||
bool fullscreen{false};
|
||||
float zoom_factor{1.0F}; // Zoom level (0.5x to max_zoom)
|
||||
};
|
||||
|
||||
struct Rendering {
|
||||
int vsync{1}; // 0=disabled, 1=enabled
|
||||
};
|
||||
|
||||
// Controles de jugadors
|
||||
|
||||
struct KeyboardControls {
|
||||
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 GamepadControls {
|
||||
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 PlayerControls {
|
||||
KeyboardControls keyboard{};
|
||||
GamepadControls gamepad{};
|
||||
std::string gamepad_name; // Buit = auto-assignar per índex
|
||||
};
|
||||
|
||||
// Variables globals (inline per evitar ODR violations)
|
||||
|
||||
inline std::string version{}; // Versión del config per validació
|
||||
inline bool console{false}; // Eixida de debug
|
||||
inline Window window{};
|
||||
inline Rendering rendering{};
|
||||
|
||||
// Controles per player
|
||||
inline PlayerControls player1{
|
||||
.keyboard =
|
||||
{.key_left = SDL_SCANCODE_LEFT,
|
||||
.key_right = SDL_SCANCODE_RIGHT,
|
||||
.key_thrust = SDL_SCANCODE_UP,
|
||||
.key_shoot = SDL_SCANCODE_SPACE,
|
||||
.key_start = SDL_SCANCODE_1},
|
||||
.gamepad_name = "" // Primer gamepad disponible
|
||||
};
|
||||
|
||||
inline PlayerControls player2{
|
||||
.keyboard =
|
||||
{.key_left = SDL_SCANCODE_A,
|
||||
// Ú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 = "" // Segon gamepad disponible
|
||||
.key_start = SDL_SCANCODE_2,
|
||||
},
|
||||
.gamepad_name = "",
|
||||
},
|
||||
};
|
||||
|
||||
// Per compatibilitat con pollo (no utilitzat en orni, pero necessari per Input)
|
||||
inline KeyboardControls keyboard_controls{};
|
||||
inline GamepadControls gamepad_controls{};
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user