Files
Seele/src/Engine/Window/Application.h
T

59 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include "Containers/Array.h"
#include "System/SystemGraph.h"
#include "Window.h"
#include <filesystem>
namespace Seele {
DECLARE_NAME_REF(Gfx, Graphics)
DECLARE_REF(Scene)
class Game;
class GameInterface;
// The long-lived top-level application object.
//
// Owns the *world*: the single Scene, the single SystemGraph (the running
// simulation) and the loaded game binary (GameInterface). There is exactly one
// of these per process, and it steps the simulation exactly once per frame --
// regardless of how many windows/views observe the scene. Views hold a
// non-owning PScene and only render; they never own the world.
//
// This is the old "WindowManager", renamed so its true responsibilities
// (windowing + world ownership + the frame loop) are named honestly.
class Application {
public:
Application();
~Application();
// Loads the game binary (dlopen) and lets it populate the Scene +
// SystemGraph it owns, then appends the editor's own systems. Called once,
// by the embedding host (the editor / benchmark main). `graphics` is needed
// to construct the Scene; `sourcePath`/`gameName` resolve the .so.
void loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName);
// Window management
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo);
void notifyWindowClosed(PWindow window);
bool isActive() const { return getGlobals().running && windows.size(); }
// Per-frame driver: steps the world ONCE, then renders every window.
void render();
// Non-owning handles so views can render the shared world.
PScene scene() const { return scene_; }
PSystemGraph systemGraph() const { return graph_; }
// Worldless hosts (e.g. the GPU-timing benchmark, which has no game binary)
// build their own world and hand ownership in; the owning members take it via
// move so the frame loop can step `graph_` and views can render `scene_`.
void attachWorld(OScene scene, OSystemGraph graph);
private:
Array<PWindow> windows;
Gfx::PGraphics graphics;
OScene scene_;
OSystemGraph graph_;
GameInterface* gameInterface = nullptr; // owned by Application (dlclose'd in dtor)
};
DEFINE_REF(Application)
} // namespace Seele