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:
2026-05-20 19:24:06 +02:00
parent aa0abd9ae1
commit 5f6d51b6cb
2 changed files with 94 additions and 64 deletions
+61
View File
@@ -0,0 +1,61 @@
// 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 <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};
};
} // namespace Config