refactor: eliminar Options::physics/audio/gameplay (codi mort)
Aquestes tres seccions s'estaven carregant del YAML, parsejant, validant i escrivint, però cap d'elles tenia consumidor en runtime: - Options::physics: l'únic call-site era un std::cout informatiu a director.cpp:109. Ship/Enemy/Bullet llegeixen Defaults::Physics directament. - Options::audio: explícitament desacoblat (audio.hpp:22-25) — la font de configuració era Defaults::Audio via Audio::Config. - Options::gameplay: zero readers. Els arrays són compile-time. Esborrats: - Structs Physics/Gameplay/Music/Sound/Audio i les globals. - Defaults a init(), helpers loadXxxConfigFromYaml, secció escrita a saveToFile, crides al loadFromFile. - La línia "Física: rotation=..." del console output del Director. Es manté Options::window i Options::rendering (sí utilitzats). Hallazgo #21 de CODE_REVIEW.md (opció a: borrar). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e4b6d2df6a
commit
11e9d6569b
3 files changed
+493
-661
No files matched your search
@@ -9,10 +9,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "debug_overlay.hpp"
|
|
||||||
#include "scene.hpp"
|
|
||||||
#include "scene_context.hpp"
|
|
||||||
#include "global_events.hpp"
|
|
||||||
#include "core/audio/audio.hpp"
|
#include "core/audio/audio.hpp"
|
||||||
#include "core/audio/audio_adapter.hpp"
|
#include "core/audio/audio_adapter.hpp"
|
||||||
#include "core/defaults.hpp"
|
#include "core/defaults.hpp"
|
||||||
@@ -22,11 +18,15 @@
|
|||||||
#include "core/resources/resource_helper.hpp"
|
#include "core/resources/resource_helper.hpp"
|
||||||
#include "core/resources/resource_loader.hpp"
|
#include "core/resources/resource_loader.hpp"
|
||||||
#include "core/utils/path_utils.hpp"
|
#include "core/utils/path_utils.hpp"
|
||||||
|
#include "debug_overlay.hpp"
|
||||||
|
#include "game/options.hpp"
|
||||||
#include "game/scenes/game_scene.hpp"
|
#include "game/scenes/game_scene.hpp"
|
||||||
#include "game/scenes/logo_scene.hpp"
|
#include "game/scenes/logo_scene.hpp"
|
||||||
#include "game/scenes/title_scene.hpp"
|
#include "game/scenes/title_scene.hpp"
|
||||||
#include "game/options.hpp"
|
#include "global_events.hpp"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include "scene.hpp"
|
||||||
|
#include "scene_context.hpp"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@@ -106,8 +106,6 @@ Director::Director(std::vector<std::string> const& args) {
|
|||||||
std::cout << "Configuración carregada\n";
|
std::cout << "Configuración carregada\n";
|
||||||
std::cout << " Finestra: " << Options::window.width << "×"
|
std::cout << " Finestra: " << Options::window.width << "×"
|
||||||
<< Options::window.height << '\n';
|
<< Options::window.height << '\n';
|
||||||
std::cout << " Física: rotation=" << Options::physics.rotation_speed
|
|
||||||
<< " rad/s\n";
|
|
||||||
std::cout << " Input: " << Input::get()->getNumGamepads()
|
std::cout << " Input: " << Input::get()->getNumGamepads()
|
||||||
<< " gamepad(s) detectat(s)\n";
|
<< " gamepad(s) detectat(s)\n";
|
||||||
}
|
}
|
||||||
@@ -291,8 +289,7 @@ auto Director::buildScene(SceneType type, SDLManager& sdl, SceneContext& context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context,
|
void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context, System::DebugOverlay& debug_overlay) {
|
||||||
System::DebugOverlay& debug_overlay) {
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
Uint64 last_time = SDL_GetTicks();
|
Uint64 last_time = SDL_GetTicks();
|
||||||
|
|
||||||
@@ -315,8 +312,7 @@ void Director::runFrameLoop(Scene& scene, SDLManager& sdl, SceneContext& context
|
|||||||
if (GlobalEvents::handle(event, sdl, context)) {
|
if (GlobalEvents::handle(event, sdl, context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (event.type == SDL_EVENT_KEY_DOWN
|
if (event.type == SDL_EVENT_KEY_DOWN && event.key.scancode == SDL_SCANCODE_F11) {
|
||||||
&& event.key.scancode == SDL_SCANCODE_F11) {
|
|
||||||
debug_overlay.toggle();
|
debug_overlay.toggle();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+440
-570
File diff suppressed because it is too large.
Load diff
+46
-80
@@ -6,116 +6,82 @@
|
|||||||
|
|
||||||
namespace Options {
|
namespace Options {
|
||||||
|
|
||||||
// Estructures de configuración
|
// Estructures de configuración
|
||||||
|
|
||||||
struct Window {
|
struct Window {
|
||||||
int width{1280};
|
int width{1280};
|
||||||
int height{720};
|
int height{720};
|
||||||
bool fullscreen{false};
|
bool fullscreen{false};
|
||||||
float zoom_factor{1.0F}; // Zoom level (0.5x to max_zoom)
|
float zoom_factor{1.0F}; // Zoom level (0.5x to max_zoom)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Physics {
|
struct Rendering {
|
||||||
float rotation_speed{3.14F}; // rad/s
|
|
||||||
float acceleration{400.0F}; // px/s²
|
|
||||||
float max_velocity{120.0F}; // px/s
|
|
||||||
float friction{20.0F}; // px/s²
|
|
||||||
float enemy_speed{2.0F}; // unitats/frame
|
|
||||||
float bullet_speed{6.0F}; // unitats/frame
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Gameplay {
|
|
||||||
int max_enemies{15};
|
|
||||||
int max_bullets{3};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Rendering {
|
|
||||||
int vsync{1}; // 0=disabled, 1=enabled
|
int vsync{1}; // 0=disabled, 1=enabled
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Music {
|
// Controles de jugadors
|
||||||
bool enabled{true};
|
|
||||||
float volume{0.8F};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Sound {
|
struct KeyboardControls {
|
||||||
bool enabled{true};
|
|
||||||
float volume{1.0F};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Audio {
|
|
||||||
Music music{};
|
|
||||||
Sound sound{};
|
|
||||||
bool enabled{true};
|
|
||||||
float volume{1.0F};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Controles de jugadors
|
|
||||||
|
|
||||||
struct KeyboardControls {
|
|
||||||
SDL_Scancode key_left{SDL_SCANCODE_LEFT};
|
SDL_Scancode key_left{SDL_SCANCODE_LEFT};
|
||||||
SDL_Scancode key_right{SDL_SCANCODE_RIGHT};
|
SDL_Scancode key_right{SDL_SCANCODE_RIGHT};
|
||||||
SDL_Scancode key_thrust{SDL_SCANCODE_UP};
|
SDL_Scancode key_thrust{SDL_SCANCODE_UP};
|
||||||
SDL_Scancode key_shoot{SDL_SCANCODE_SPACE};
|
SDL_Scancode key_shoot{SDL_SCANCODE_SPACE};
|
||||||
SDL_Scancode key_start{SDL_SCANCODE_1};
|
SDL_Scancode key_start{SDL_SCANCODE_1};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GamepadControls {
|
struct GamepadControls {
|
||||||
int button_left{SDL_GAMEPAD_BUTTON_DPAD_LEFT};
|
int button_left{SDL_GAMEPAD_BUTTON_DPAD_LEFT};
|
||||||
int button_right{SDL_GAMEPAD_BUTTON_DPAD_RIGHT};
|
int button_right{SDL_GAMEPAD_BUTTON_DPAD_RIGHT};
|
||||||
int button_thrust{SDL_GAMEPAD_BUTTON_WEST}; // X button
|
int button_thrust{SDL_GAMEPAD_BUTTON_WEST}; // X button
|
||||||
int button_shoot{SDL_GAMEPAD_BUTTON_SOUTH}; // A button
|
int button_shoot{SDL_GAMEPAD_BUTTON_SOUTH}; // A button
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerControls {
|
struct PlayerControls {
|
||||||
KeyboardControls keyboard{};
|
KeyboardControls keyboard{};
|
||||||
GamepadControls gamepad{};
|
GamepadControls gamepad{};
|
||||||
std::string gamepad_name; // Buit = auto-assignar per índex
|
std::string gamepad_name; // Buit = auto-assignar per índex
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables globals (inline per evitar ODR violations)
|
// Variables globals (inline per evitar ODR violations)
|
||||||
|
|
||||||
inline std::string version{}; // Versión del config per validació
|
inline std::string version{}; // Versión del config per validació
|
||||||
inline bool console{false}; // Eixida de debug
|
inline bool console{false}; // Eixida de debug
|
||||||
inline Window window{};
|
inline Window window{};
|
||||||
inline Physics physics{};
|
inline Rendering rendering{};
|
||||||
inline Gameplay gameplay{};
|
|
||||||
inline Rendering rendering{};
|
|
||||||
inline Audio audio{};
|
|
||||||
|
|
||||||
// Controles per player
|
// Controles per player
|
||||||
inline PlayerControls player1{
|
inline PlayerControls player1{
|
||||||
.keyboard =
|
.keyboard =
|
||||||
{.key_left = SDL_SCANCODE_LEFT,
|
{.key_left = SDL_SCANCODE_LEFT,
|
||||||
.key_right = SDL_SCANCODE_RIGHT,
|
.key_right = SDL_SCANCODE_RIGHT,
|
||||||
.key_thrust = SDL_SCANCODE_UP,
|
.key_thrust = SDL_SCANCODE_UP,
|
||||||
.key_shoot = SDL_SCANCODE_SPACE,
|
.key_shoot = SDL_SCANCODE_SPACE,
|
||||||
.key_start = SDL_SCANCODE_1},
|
.key_start = SDL_SCANCODE_1},
|
||||||
.gamepad_name = "" // Primer gamepad disponible
|
.gamepad_name = "" // Primer gamepad disponible
|
||||||
};
|
};
|
||||||
|
|
||||||
inline PlayerControls player2{
|
inline PlayerControls player2{
|
||||||
.keyboard =
|
.keyboard =
|
||||||
{.key_left = SDL_SCANCODE_A,
|
{.key_left = SDL_SCANCODE_A,
|
||||||
.key_right = SDL_SCANCODE_D,
|
.key_right = SDL_SCANCODE_D,
|
||||||
.key_thrust = SDL_SCANCODE_W,
|
.key_thrust = SDL_SCANCODE_W,
|
||||||
.key_shoot = SDL_SCANCODE_LSHIFT,
|
.key_shoot = SDL_SCANCODE_LSHIFT,
|
||||||
.key_start = SDL_SCANCODE_2},
|
.key_start = SDL_SCANCODE_2},
|
||||||
.gamepad_name = "" // Segon gamepad disponible
|
.gamepad_name = "" // Segon gamepad disponible
|
||||||
};
|
};
|
||||||
|
|
||||||
// Per compatibilitat con pollo (no utilitzat en orni, pero necessari per Input)
|
// Per compatibilitat con pollo (no utilitzat en orni, pero necessari per Input)
|
||||||
inline KeyboardControls keyboard_controls{};
|
inline KeyboardControls keyboard_controls{};
|
||||||
inline GamepadControls gamepad_controls{};
|
inline GamepadControls gamepad_controls{};
|
||||||
|
|
||||||
inline std::string config_file_path{}; // Establert per setConfigFile()
|
inline std::string config_file_path{}; // Establert per setConfigFile()
|
||||||
|
|
||||||
// Funciones públiques
|
// Funciones públiques
|
||||||
|
|
||||||
void init(); // Inicialitzar con valors per defecte
|
void init(); // Inicialitzar con valors per defecte
|
||||||
void setConfigFile(
|
void setConfigFile(
|
||||||
const std::string& path); // Establir ruta del file de config
|
const std::string& path); // Establir ruta del file de config
|
||||||
auto loadFromFile() -> bool; // Carregar config YAML
|
auto loadFromFile() -> bool; // Carregar config YAML
|
||||||
auto saveToFile() -> bool; // Guardar config YAML
|
auto saveToFile() -> bool; // Guardar config YAML
|
||||||
|
|
||||||
} // namespace Options
|
} // namespace Options
|
||||||
Reference in new issue
Block a user