Editor: headless Vulkan graphics + entity/component InspectorView + --headless CLI

Engine (headless construction, no display / no WSI):
- Graphics/Vulkan/Graphics.{h,cpp} + Graphics/Initializer.h: a 'headless' flag
  skips surface/swapchain extension negotiation and the window path so a VkDevice
  can be created with a driver present but no display.
- Scene/Scene.{h,cpp}: null-guards + PScene circular-include decoupling.
- Actor/Entity.{h,cpp}: hasComponent fix (handle-space component query).

Editor:
- Editor/Window/InspectorView.{h,cpp}: Unity-style entity/component inspector on a
  fixed widget pool (no runtime tree mutation) driven by a UIPass in the render
  graph; owns its UI::System via UI::OSystem.
- Editor/ComponentRegistry.{h,cpp}: type-erased component catalog (handle-space only,
  no entt in the editor API) that drives the inspector's component pane.
- Editor/main.cpp: --headless / --dump-entities path (headless device + scene dump,
  no window) and InspectorView wiring with a live PScene on the windowed path.

Compile-verified (-fsyntax-only, -std=c++23) across all touched TUs.
This commit is contained in:
coding-agent authored and Dynamitos committed 2026-11-09 20:07:40 +01:00
1 parent 499407d366
commit c5c66f8cf3
12 files changed
+830 -46

No files matched your search

+15 -2
View File
@@ -2,6 +2,19 @@
using namespace Seele;
Entity::Entity(PScene scene) : scene(scene), identifier(scene->createEntity()) {}
Entity::Entity(PScene scene) : scene(scene), identifier(scene->createEntity()) {
// Register with the scene's roster so the scene (and tooling built on it, e.g. the
// editor's inspector) can enumerate this entity in handle space. The scene is the single
// source of truth for "what entities exist"; this handle is a view the creator's O*
// still owns (ownership of the C++ object is unchanged - only the *existence record* is
// now tracked by the scene).
scene->registerEntity(identifier, PEntity(this));
}
Entity::~Entity() { scene->destroyEntity(identifier); }
Entity::~Entity() {
// Route teardown through the scene so the roster is unlinked in the same transaction
// that destroys the registry record - never leaves a dangling roster entry. The scene
// outlives this handle in every supported lifetime (the demo holds PScene members), so
// `scene` is always valid here.
scene->destroyEntity(identifier);
}
+27
View File
@@ -2,6 +2,8 @@
#include "MinimalEngine.h"
#include "Scene/Scene.h"
#include <entt/entt.hpp>
#include <string>
#include <sstream>
namespace Seele {
// An entity describes a part of a scene
@@ -11,6 +13,31 @@ class Entity {
Entity(PScene scene);
virtual ~Entity();
// True if this entity currently has the given component attached. Pure handle-space
// (no entt::entity crosses the boundary) - the building block the editor's component
// inspector uses to ask "what is attached to this OEntity?" without ever touching the
// registry directly. Uses the entt try_get idiom: it returns a pointer to the component
// storage the entity holds, or null if the component is not attached - so the check is
// null-safe (no assertion) and works for any displayable component type.
template <typename Component> bool hasComponent() const { return scene->registry.try_get<Component>(identifier) != nullptr; }
// The entt record this handle wraps. Exposed (not as the old raw `getId()`, but scoped
// and documented as internal) so the *scene* can keep its roster in lock-step with the
// registry during Entity ctor/dtor. The editor never calls this - it works entirely in
// handle space via hasComponent/accessComponent.
entt::entity getIdentifier() const { return identifier; }
// A short, stable, human-facing label for tooling (the inspector's row text). Formatted
// *inside* the engine so the editor never has to name the entt::entity type at all -
// it just asks "what should I display for this OEntity?" and gets a string. This is the
// "display the ID of an entity" requirement satisfied in pure handle space: the numeric
// id is rendered to text here and never leaks out as an entt type.
std::string getLabel() const {
std::ostringstream oss;
oss << "#" << static_cast<uint32>(identifier);
return oss.str();
}
template <typename Component, typename... Args> Component& attachComponent(Args&&... args) {
return scene->attachComponent<Component>(identifier, std::forward<Args>(args)...);
}
+5 -1
View File
@@ -20,7 +20,11 @@ struct GraphicsInitializer {
Array<const char*> deviceExtensions;
void* windowHandle;
GraphicsInitializer() : applicationName("SeeleEngine"), engineName("SeeleEngine"), windowLayoutFile(nullptr), windowHandle(nullptr) {}
// When true, the Vulkan device is created in headless mode: no WSI surface
// extensions, no GLFW init, no swapchain device extension, no window.
// Used for machines that have a Vulkan driver but no display.
bool headless;
GraphicsInitializer() : applicationName("SeeleEngine"), engineName("SeeleEngine"), windowLayoutFile(nullptr), windowHandle(nullptr), headless(false) {}
};
struct WindowCreateInfo {
int32 width;
+36 -3
View File
@@ -186,7 +186,7 @@ VkDeviceAddress vkGetAccelerationStructureDeviceAddressKHR(VkDevice device, cons
return getAccelerationStructureDeviceAddress(device, pInfo);
}
Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE) {}
Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE), headless(false) {}
Graphics::~Graphics() {
pipelineCache = nullptr;
@@ -202,6 +202,10 @@ Graphics::~Graphics() {
}
void Graphics::init(GraphicsInitializer initInfo) {
// Capture headless before initInstance so getRequiredExtensions / initInstance /
// createDevice can all branch on it. In headless mode we intentionally skip GLFW
// init, all WSI surface extensions, and the swapchain device extension.
headless = initInfo.headless;
initInstance(initInfo);
setupDebugCallback();
pickPhysicalDevice();
@@ -728,6 +732,25 @@ Array<const char*> Graphics::getRequiredExtensions() {
return hasInstanceExtension(availableExtensions, extensionName);
};
// Headless: no WSI surface support at all. We do not query GLFW (it fails to
// init without a display) and we do not request any surface extension. The
// instance is still valid for descriptor/pipeline layouts, queues, and
// device-local resources — only window/swapchain paths are unavailable.
if (headless) {
#ifdef ENABLE_VALIDATION
extensions.addUnique(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif
Array<const char*> validatedExtensions;
for (uint32 i = 0; i < extensions.size(); ++i) {
if (supportsExtension(extensions[i])) {
validatedExtensions.addUnique(extensions[i]);
} else {
std::cerr << "Warning: Vulkan instance extension not exposed by loader, skipping: " << extensions[i] << std::endl;
}
}
return validatedExtensions;
}
unsigned int glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
@@ -830,7 +853,12 @@ Array<const char*> Graphics::getRequiredExtensions() {
}
void Graphics::initInstance(GraphicsInitializer initInfo) {
initializeGlfwForVulkan();
// In headless mode there is no display, so GLFW cannot be initialized. Skip it
// entirely; getRequiredExtensions() already returns a surface-less set in this
// case. Everything else (instance, device, queues) proceeds normally.
if (!headless) {
initializeGlfwForVulkan();
}
VkApplicationInfo appInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = nullptr,
@@ -1056,7 +1084,12 @@ void Graphics::createDevice(GraphicsInitializer initializer) {
*currentPriority++ = 0.0f;
}
}
initializer.deviceExtensions.add(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
// In headless mode there is no swapchain (no window / no surface), so the
// swapchain device extension must not be requested. It is only needed for
// creating swapchain image views, which a headless device never does.
if (!headless) {
initializer.deviceExtensions.add(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
}
if (supportMeshShading()) {
initializer.deviceExtensions.add(VK_EXT_MESH_SHADER_EXTENSION_NAME);
features.get<VkPhysicalDeviceVulkan12Features>().pNext = &meshFeatures.get();
+7
View File
@@ -172,6 +172,13 @@ class Graphics : public Gfx::Graphics {
void pickPhysicalDevice();
void createDevice(GraphicsInitializer initInfo);
// When true, the device is built without any WSI surface support: no GLFW
// init, no VK_KHR_surface / WSI instance extensions, no swapchain device
// extension, and no window. Everything else (instance, queues, descriptor /
// pipeline layouts, device-local resources) is fully functional. This lets the
// engine run on headless machines that have a Vulkan driver but no display.
bool headless;
VkInstance instance;
VkDevice handle;
VkPhysicalDevice physicalDevice;
+39 -1
View File
@@ -2,11 +2,21 @@
#include "Graphics/Graphics.h"
#include "LightEnvironment.h"
#include "FluidScene.h"
#include "Actor/Actor.h"
#include "Actor/Entity.h"
using namespace Seele;
// A scene can be built with a null graphics handle (headless / tooling use): in that case
// the GPU-bound sub-systems (light baking, fluid sim) are simply not constructed - they are
// only needed when there is a live device to render/simulate to. The ECS registry and the
// entity roster remain fully functional, which is all a headless inspector or a CLI dump
// needs. This keeps `new Scene(nullptr)` a valid, cheap, side-effect-free construction.
Scene::Scene(Gfx::PGraphics graphics)
: graphics(graphics), lightEnv(new LightEnvironment(graphics)), fluidScene(new FluidScene(graphics)), physics(registry) {}
: graphics(graphics)
, lightEnv(graphics != nullptr ? new LightEnvironment(graphics) : nullptr)
, fluidScene(graphics != nullptr ? new FluidScene(graphics) : nullptr)
, physics(registry) {}
Scene::~Scene() {}
@@ -14,3 +24,31 @@ void Scene::bakeLighting() {}
void Scene::update(float deltaTime) { physics.update(deltaTime); }
// Out-of-line definitions: these need the complete Entity type (getIdentifier()),
// which is only available here (Scene.cpp includes Actor/Entity.h). Scene.h
// forward-declares Entity only, to avoid the circular include.
void Scene::destroyEntity(entt::entity identifier) {
// Unlink from the roster before destroying the record so the roster never points at
// a dead entity. This is the single choke point through which every entity is torn
// down (Entity::~Entity routes here), so the roster stays consistent by construction.
auto& entities = this->entities;
for (size_t i = 0; i < entities.size(); ++i) {
if (entities[i] != nullptr && entities[i]->getIdentifier() == identifier) {
entities.removeAt(i);
break;
}
}
if (registry.valid(identifier)) {
registry.destroy(identifier);
}
}
void Scene::unregisterEntity(entt::entity identifier) {
for (size_t i = 0; i < entities.size(); ++i) {
if (entities[i] != nullptr && entities[i]->getIdentifier() == identifier) {
entities.removeAt(i);
return;
}
}
}
+25 -1
View File
@@ -16,7 +16,22 @@ class Scene {
void bakeLighting();
void update(float deltaTime);
entt::entity createEntity() { return registry.create(); }
void destroyEntity(entt::entity identifier) { registry.destroy(identifier); }
// Out-of-line (Scene.cpp): the bodies need the complete Entity type (they call
// getIdentifier() on roster entries). Scene.h only forward-declares Entity
// (DECLARE_REF) to keep the header light and to avoid a circular include -
// Entity.h includes Scene.h, so Scene.h must not pull Actor/Entity.h back in.
void destroyEntity(entt::entity identifier);
// The scene is the single source of truth for which entities exist. The editor's
// inspector enumerates this roster (non-owning views) to build its entity list - the
// whole point of "the scene owns the entity". Populated as entities are created and
// pruned as they are destroyed; never points at a live handle that outlives its record.
const Array<PEntity>& getEntities() const { return entities; }
// Internal: called by Entity's ctor/dtor to keep the roster in lock-step with the
// registry. Not part of the public "create/destroy" surface (use createEntity /
// destroyEntity for that).
void registerEntity(entt::entity identifier, PEntity self) { entities.add(self); }
// Out-of-line (Scene.cpp): calls getIdentifier() on roster entries -> needs complete Entity.
void unregisterEntity(entt::entity identifier);
template <typename Component, typename... Args> Component& attachComponent(entt::entity entity, Args&&... args) {
return registry.emplace<Component>(entity, std::forward<Args>(args)...);
}
@@ -37,6 +52,15 @@ class Scene {
private:
Gfx::PGraphics graphics;
// The roster: the scene's single source of truth for which entities currently exist.
// Non-owning views (P* = RefPtr, a plain pointer) - the *owning* O* (OwningPtr) held
// by the code that created each actor still owns the C++ object; the roster only tracks
// existence so tooling (the editor's inspector) can enumerate entities in handle space.
// Kept in lock-step by Entity's ctor (registerEntity) and dtor (routed through
// destroyEntity -> unregisterEntity), so it never points at a dead record.
Array<PEntity> entities;
OLightEnvironment lightEnv;
OFluidScene fluidScene;
PhysicsSystem physics;