forked from Dynamitos/Seele
refactor: rename WindowManager to Application; move world ownership up
WindowManager.{h,cpp} -> Application.{h,cpp}
The Application class now owns the long-lived world (Scene, SystemGraph,
GameInterface) and is the single setup point. This removes the per-view
duplication where each GameView/PlayView loaded the binary and ran the
simulation independently, which double-simulated with two windows open.
Changes:
- WindowManager -> Application (class, files, includes, CMake)
- Application owns OScene scene_ / OSystemGraph graph_ (OwningPtr)
and GameInterface* gameInterface (raw, deleted in dtor)
- loadGame(graphics, path, name): single world-setup point
(dlopen -> setupScene -> append 5 editor systems)
- attachWorld(OScene, OSystemGraph): worldless hosts (benchmark)
hand ownership in via move
- Frame-loop fix: systemGraph->run() now runs ONCE per frame, before
the window loop (was per-window -> double-simulated with 2 windows)
- Editor/main.cpp + Benchmark/main.cpp rewired to the new API
- Window.h/.cpp: PWindowManager back-pointer -> PApplication
- 8 include paths updated to Window/Application.h
Compile-verified: Application.cpp, Editor/main.cpp, Benchmark/main.cpp
all pass g++ -std=c++23 -fsyntax-only against the full third-party
include set.
This commit is contained in:
1 parent
803531c608
commit
1e34f0e67b
13 files changed
+194
-86
No files matched your search
+15
-6
@@ -3,7 +3,9 @@
|
||||
#include "Graphics/StaticMeshVertexData.h"
|
||||
#include "Graphics/Vulkan/Graphics.h"
|
||||
#include "PlayView.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "System/SystemGraph.h"
|
||||
#include "Window/Application.h"
|
||||
#include <fmt/core.h>
|
||||
#include <random>
|
||||
|
||||
@@ -32,7 +34,14 @@ int main(int argc, char** argv) {
|
||||
vd->init(graphics);
|
||||
getGlobals().useRayTracing = true;
|
||||
|
||||
OWindowManager windowManager = new WindowManager();
|
||||
// The benchmark is a worldless host: it builds a plain Scene + SystemGraph
|
||||
// (no game binary) and hands ownership to the Application, which then steps
|
||||
// it once per frame and lets the views render it. The view renders the
|
||||
// non-owning application->scene() handle.
|
||||
OApplication application = new Application();
|
||||
OScene scene = new Scene(graphics);
|
||||
OSystemGraph systemGraph = new SystemGraph();
|
||||
application->attachWorld(std::move(scene), std::move(systemGraph));
|
||||
AssetRegistry::init("Assets", graphics);
|
||||
vd->commitMeshes();
|
||||
WindowCreateInfo mainWindowInfo = {
|
||||
@@ -41,7 +50,7 @@ int main(int argc, char** argv) {
|
||||
.title = "Benchmark",
|
||||
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
||||
};
|
||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||
auto window = application->addWindow(graphics, mainWindowInfo);
|
||||
ViewportCreateInfo sceneViewInfo = {
|
||||
.dimensions =
|
||||
{
|
||||
@@ -49,11 +58,11 @@ int main(int argc, char** argv) {
|
||||
.offset = {0, 0},
|
||||
},
|
||||
};
|
||||
OGameView sceneView = new PlayView(graphics, window, new Scene(graphics), sceneViewInfo, useDepthCulling);
|
||||
OGameView sceneView = new PlayView(graphics, window, application->scene(), sceneViewInfo, useDepthCulling);
|
||||
sceneView->setFocused();
|
||||
|
||||
while (windowManager->isActive()) {
|
||||
windowManager->render();
|
||||
while (application->isActive()) {
|
||||
application->render();
|
||||
}
|
||||
graphics->waitDeviceIdle();
|
||||
vd->destroy();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Graphics/Shader.h"
|
||||
#include "Material/Material.h"
|
||||
#include "Material/ShaderExpression.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/Application.h"
|
||||
#include <fmt/core.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
+12
-18
@@ -16,7 +16,7 @@
|
||||
#include "System/FluidUpdater.h"
|
||||
#include "System/LightGather.h"
|
||||
#include "System/MeshUpdater.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/Application.h"
|
||||
#include "Window/InspectorView.h"
|
||||
#include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene
|
||||
#include "Component/Transform.h"
|
||||
@@ -141,18 +141,12 @@ int main(int argc, char** argv) {
|
||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||
vd->init(graphics);
|
||||
|
||||
GameInterface gameInterface(binaryPath);
|
||||
OScene scene = new Scene(graphics);
|
||||
gameInterface.reload();
|
||||
|
||||
OSystemGraph systemGraph = new SystemGraph();
|
||||
gameInterface.getGame()->setupScene(scene, systemGraph);
|
||||
systemGraph->addSystem(new System::KeyboardInput(scene));
|
||||
systemGraph->addSystem(new System::FluidUpdater(scene));
|
||||
systemGraph->addSystem(new System::LightGather(scene));
|
||||
systemGraph->addSystem(new System::MeshUpdater(scene));
|
||||
systemGraph->addSystem(new System::CameraUpdater(scene));
|
||||
OWindowManager windowManager = new WindowManager(systemGraph);
|
||||
// The world (Scene + SystemGraph) and the game binary are owned by the
|
||||
// Application from here on. `loadGame` dlopen's the .so, lets the game
|
||||
// populate the scene+graph, and appends the editor's own systems. Views
|
||||
// below only render the non-owning application->scene() handle.
|
||||
OApplication application = new Application();
|
||||
application->loadGame(graphics, sourcePath, gameName);
|
||||
AssetRegistry::init(sourcePath / "Assets", graphics);
|
||||
AssetImporter::init(graphics);
|
||||
AssetImporter::importFont(FontImportArgs{
|
||||
@@ -187,7 +181,7 @@ int main(int argc, char** argv) {
|
||||
.title = "SeeleEngine",
|
||||
.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB,
|
||||
};
|
||||
auto window = windowManager->addWindow(graphics, mainWindowInfo);
|
||||
auto window = application->addWindow(graphics, mainWindowInfo);
|
||||
ViewportCreateInfo sceneViewInfo = {
|
||||
.dimensions =
|
||||
{
|
||||
@@ -195,7 +189,7 @@ int main(int argc, char** argv) {
|
||||
.offset = {0, 0},
|
||||
},
|
||||
};
|
||||
OGameView sceneView = new Editor::PlayView(graphics, window, scene, sceneViewInfo);
|
||||
OGameView sceneView = new Editor::PlayView(graphics, window, application->scene(), sceneViewInfo);
|
||||
sceneView->setFocused();
|
||||
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
|
||||
ViewportCreateInfo{
|
||||
@@ -205,12 +199,12 @@ int main(int argc, char** argv) {
|
||||
.offset = {0, 0},
|
||||
},
|
||||
},
|
||||
/* scene = */ scene);
|
||||
/* scene = */ application->scene());
|
||||
|
||||
inspectorView->setFocused();
|
||||
window->show();
|
||||
while (windowManager->isActive() && getGlobals().running) {
|
||||
windowManager->render();
|
||||
while (application->isActive() && getGlobals().running) {
|
||||
application->render();
|
||||
}
|
||||
graphics->waitDeviceIdle();
|
||||
Material::destroy();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "FontAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Mesh.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/Application.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "TextureAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Texture.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/Application.h"
|
||||
#include "ktx.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "Graphics/Shader.h"
|
||||
#include "MaterialInstance.h"
|
||||
#include "Serialization/Serialization.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "Window/Application.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "Application.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "System/SystemGraph.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Game.h"
|
||||
#include "System/KeyboardInput.h"
|
||||
#include "System/FluidUpdater.h"
|
||||
#include "System/LightGather.h"
|
||||
#include "System/MeshUpdater.h"
|
||||
#include "System/CameraUpdater.h"
|
||||
#ifdef WIN32
|
||||
#include "Platform/Windows/GameInterface.h"
|
||||
#else
|
||||
#include "Platform/Linux/GameInterface.h"
|
||||
#endif
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
namespace {
|
||||
// Library extension per platform (mirrors the editor's old binary-path logic).
|
||||
const char* libraryExtension() {
|
||||
#ifdef WIN32
|
||||
return "dll";
|
||||
#elif __APPLE__
|
||||
return "dylib";
|
||||
#else
|
||||
return "so";
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Application::Application() : graphics(nullptr), scene_(nullptr), graph_(nullptr), gameInterface(nullptr) {}
|
||||
|
||||
Application::~Application() {
|
||||
if (gameInterface != nullptr) {
|
||||
delete gameInterface; // ~GameInterface dlclose()s + destroys the Game instance
|
||||
gameInterface = nullptr;
|
||||
}
|
||||
// `scene_` and `graph_` are OwningPtr: their destructors free the Scene and
|
||||
// (via the moved-in OSystemBase entries) every System.
|
||||
}
|
||||
|
||||
void Application::loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName) {
|
||||
this->graphics = graphics;
|
||||
|
||||
// The world is created exactly once, owned by the Application. `loadGame` is
|
||||
// the single setup point (called once per process) — no null guards needed.
|
||||
scene_ = OScene(new Scene(graphics));
|
||||
graph_ = OSystemGraph(new SystemGraph());
|
||||
|
||||
// Resolve the game binary and load it (dlopen) once.
|
||||
std::filesystem::path binaryPath = sourcePath / "bin" / (gameName + "." + libraryExtension());
|
||||
GameInterface* interface = new GameInterface(binaryPath);
|
||||
interface->reload();
|
||||
gameInterface = interface;
|
||||
|
||||
// Let the game populate the Scene + SystemGraph we own, then append the
|
||||
// editor's own systems. This used to live in the editor's main.cpp; it now
|
||||
// lives here so the world has a single owner and a single setup point.
|
||||
interface->getGame()->setupScene(scene_, graph_);
|
||||
graph_->addSystem(new System::KeyboardInput(scene_));
|
||||
graph_->addSystem(new System::FluidUpdater(scene_));
|
||||
graph_->addSystem(new System::LightGather(scene_));
|
||||
graph_->addSystem(new System::MeshUpdater(scene_));
|
||||
graph_->addSystem(new System::CameraUpdater(scene_));
|
||||
}
|
||||
|
||||
OWindow Application::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) {
|
||||
OWindow window = new Window(this, graphics->createWindow(createInfo));
|
||||
windows.add(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void Application::attachWorld(OScene scene, OSystemGraph graph) {
|
||||
// Worldless hosts (benchmark) build their own world and hand ownership in;
|
||||
// the Application's owning members take it via move so the frame loop can
|
||||
// step it and the views can render it.
|
||||
scene_ = std::move(scene);
|
||||
graph_ = std::move(graph);
|
||||
}
|
||||
|
||||
void Application::render() {
|
||||
// Step the world exactly ONCE per frame, independent of how many windows
|
||||
// are open. The old code re-ran the graph inside the per-window loop, which
|
||||
// double-simulated with two windows. Views below only render the world.
|
||||
graph_->run(Gfx::getCurrentFrameDelta());
|
||||
for (auto& window : windows) {
|
||||
window->pollInputs();
|
||||
if (window->isPaused())
|
||||
continue;
|
||||
window->render();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::notifyWindowClosed(PWindow window) { windows.remove(window); }
|
||||
@@ -0,0 +1,59 @@
|
||||
#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
|
||||
@@ -6,8 +6,8 @@ target_sources(Engine
|
||||
View.cpp
|
||||
Window.cpp
|
||||
Window.h
|
||||
WindowManager.h
|
||||
WindowManager.cpp)
|
||||
Application.h
|
||||
Application.cpp)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
@@ -15,4 +15,4 @@ target_sources(Engine
|
||||
GameView.h
|
||||
View.h
|
||||
Window.h
|
||||
WindowManager.h)
|
||||
Application.h)
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "Window.h"
|
||||
#include "WindowManager.h"
|
||||
#include "Application.h"
|
||||
#include <functional>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
|
||||
Window::Window(PApplication owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
|
||||
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); });
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include "View.h"
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(WindowManager)
|
||||
DECLARE_REF(Application)
|
||||
// The logical window, with the graphics proxy
|
||||
class Window {
|
||||
public:
|
||||
Window(PWindowManager owner, Gfx::OWindow handle);
|
||||
Window(PApplication owner, Gfx::OWindow handle);
|
||||
~Window();
|
||||
void show() { gfxHandle->show(); }
|
||||
void addView(PView view);
|
||||
@@ -20,7 +20,7 @@ class Window {
|
||||
constexpr bool shouldClose() const { return gfxHandle->shouldClose(); }
|
||||
|
||||
protected:
|
||||
PWindowManager owner;
|
||||
PApplication owner;
|
||||
Array<PView> views;
|
||||
Gfx::OWindow gfxHandle;
|
||||
};
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#include "WindowManager.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "System/SystemGraph.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
WindowManager::WindowManager(PSystemGraph systemGraph) : systemGraph(systemGraph) {}
|
||||
|
||||
WindowManager::~WindowManager() {}
|
||||
|
||||
OWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) {
|
||||
OWindow window = new Window(this, graphics->createWindow(createInfo));
|
||||
windows.add(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void WindowManager::render() {
|
||||
for (auto& window : windows) {
|
||||
window->pollInputs();
|
||||
if (window->isPaused())
|
||||
continue;
|
||||
systemGraph->run(Gfx::getCurrentFrameDelta());
|
||||
window->render();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManager::notifyWindowClosed(PWindow window) { windows.remove(window); }
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include "Containers/Array.h"
|
||||
#include "System/SystemGraph.h"
|
||||
#include "Window.h"
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_NAME_REF(Gfx, Graphics)
|
||||
class WindowManager {
|
||||
public:
|
||||
WindowManager(PSystemGraph systemGraph);
|
||||
~WindowManager();
|
||||
OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo);
|
||||
void render();
|
||||
void notifyWindowClosed(PWindow window);
|
||||
bool isActive() const { return getGlobals().running && windows.size(); }
|
||||
|
||||
private:
|
||||
Array<PWindow> windows;
|
||||
PSystemGraph systemGraph;
|
||||
};
|
||||
DEFINE_REF(WindowManager)
|
||||
} // namespace Seele
|
||||
Reference in new issue
Block a user