Files
orni-attack/source/core/system/director.hpp
T
JailDesigner 41ce3fece5 refactor(#28): Director rep EngineConfig + ConfigPersistence, main orquestra
Pas 5/N del hallazgo #28.

Director deixa d'incloure game/options.hpp i les seves crides a
Options::*. El seu ctor accepta ara:
- Config::EngineConfig& cfg     → la struct runtime (window, console, ...).
- Config::ConfigPersistence     → 4 lambdes (init/set_path/load/save)
  que delegen la persistència a la capa concreta (game/Options::*).

Cap més referència a Options:: ni a "game/..." dins del Director:
- cfg_->* substitueix tot Options::* (window, console, player1/2,
  rendering, engine_config).
- persistence_.{init,save,load,set_path} substitueix les funcions
  d'I/O de YAML.

run() i checkProgramArguments deixen de ser estàtics (necessiten
accés a cfg_ i persistence_). Això també desfà el smell del
hallazgo #37 (Director::run estàtic que llegia estat d'instància).

main.cpp queda com a orquestrador: construeix la struct
ConfigPersistence amb lambdes que enllacen amb Options::* i la
injecta al Director.

Afegit: Config::ConfigPersistence a engine_config.hpp.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 19:40:52 +02:00

51 lines
1.6 KiB
C++

#pragma once
#include <memory>
#include <string>
#include <vector>
#include "core/config/engine_config.hpp"
#include "scene_context.hpp"
class Scene;
class SDLManager;
namespace System {
class DebugOverlay;
}
class Director {
public:
// `cfg` ha de viure tant com el Director (típicament owned per main).
// `persistence` encapsula init/load/save delegats a la capa concreta
// (game/Options::*).
Director(std::vector<std::string> const& args,
Config::EngineConfig& cfg,
Config::ConfigPersistence persistence);
~Director();
// Bucle principal del juego.
auto run() -> int;
private:
std::string executable_path_;
std::string system_folder_;
Config::EngineConfig* cfg_;
Config::ConfigPersistence persistence_;
auto checkProgramArguments(std::vector<std::string> const& args)
-> std::string;
void createSystemFolder(const std::string& folder);
// Construye la escena correspondiente al tipo solicitado. Retorna
// nullptr para EXIT u otros valores no constructibles.
static auto buildScene(SceneManager::SceneContext::SceneType type,
SDLManager& sdl,
SceneManager::SceneContext& context)
-> std::unique_ptr<Scene>;
// Ejecuta el bucle de frames de UNA escena hasta que scene.isFinished()
// sea true. Maneja delta_time, eventos (globales + escena), update y draw.
// El debug_overlay es global a todas las escenas; el Director lo posee.
static void runFrameLoop(Scene& scene, SDLManager& sdl, SceneManager::SceneContext& context, System::DebugOverlay& debug_overlay);
};