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

+208
View File
@@ -0,0 +1,208 @@
#include "ComponentRegistry.h"
#include "Asset/MeshAsset.h"
#include "Component/Camera.h"
#include "Component/DirectionalLight.h"
#include "Component/Mesh.h"
#include "Component/PointLight.h"
#include "Component/Transform.h"
#include <ostream>
#include <sstream>
using namespace Seele;
using namespace Seele::Editor;
// --- small formatting helpers ------------------------------------------------------
namespace {
// Render a glm::vec / Quaternion (which all have operator<<) into a trimmed string.
template <typename T>
std::string fmtVec(const T& v) {
std::ostringstream oss;
oss.precision(4);
oss << std::fixed << v;
return oss.str();
}
std::string fmtFloat(float f) {
std::ostringstream oss;
oss.precision(4);
oss << std::fixed << f;
return oss.str();
}
} // namespace
// All of the editor's component-inspection entry points live in Seele::Editor (matching the
// declarations in ComponentRegistry.h). The using-directives above (using namespace Seele;
// using namespace Seele::Editor;) make the types (PEntity, PScene, ComponentEntry, Array,
// glm, the Component::* types) resolvable unqualified inside this block, while the function
// *definitions* themselves are correctly placed in the same namespace as their declarations -
// no duplicate/ambiguous global-scope symbols.
namespace Seele {
namespace Editor {
std::vector<ComponentEntry>& componentCatalog() {
static std::vector<ComponentEntry> catalog;
return catalog;
}
void initComponentRegistry() {
auto& catalog = componentCatalog();
// Idempotent: build the catalog only once. The set of displayable component *types* is
// fixed for the editor's lifetime, so we never add to it after the first call.
if (!catalog.empty()) {
return;
}
// Every entry works through the handle's own hasComponent/accessComponent - the exact
// same call shape game code uses to read components, just applied to an OEntity view.
// Transform: position / rotation / scale. The single most important component to
// display - every placed actor has one.
catalog.push_back(ComponentEntry{
.name = "Transform",
.isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent<Component::Transform>(); },
.describe = [](PEntity e) -> std::string {
if (e == nullptr || !e->hasComponent<Component::Transform>()) {
return "";
}
const auto& t = e->accessComponent<Component::Transform>();
std::ostringstream oss;
oss << "Position: " << fmtVec(t.getPosition()) << "\n";
oss << "Rotation: " << fmtVec(t.getRotation()) << "\n";
oss << "Scale: " << fmtVec(t.getScale());
return oss.str();
},
});
// Camera: projection params.
catalog.push_back(ComponentEntry{
.name = "Camera",
.isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent<Component::Camera>(); },
.describe = [](PEntity e) -> std::string {
if (e == nullptr || !e->hasComponent<Component::Camera>()) {
return "";
}
const auto& c = e->accessComponent<Component::Camera>();
std::ostringstream oss;
oss << "Field Of View (deg): " << fmtFloat(glm::degrees(c.fieldOfView)) << "\n";
oss << "Aspect Ratio: " << fmtFloat(c.aspectRatio) << "\n";
oss << "Near Plane: " << fmtFloat(c.nearPlane) << "\n";
oss << "Far Plane: " << fmtFloat(c.farPlane) << "\n";
oss << "Main Camera: " << (c.mainCamera ? "true" : "false");
return oss.str();
},
});
// PointLight: color + intensity + attenuation.
catalog.push_back(ComponentEntry{
.name = "PointLight",
.isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent<Component::PointLight>(); },
.describe = [](PEntity e) -> std::string {
if (e == nullptr || !e->hasComponent<Component::PointLight>()) {
return "";
}
const auto& l = e->accessComponent<Component::PointLight>();
std::ostringstream oss;
oss << "Color: " << fmtVec(l.color) << "\n";
oss << "Intensity: " << fmtFloat(l.intensity) << "\n";
oss << "Attenuation: " << fmtFloat(l.attenuation);
return oss.str();
},
});
// DirectionalLight: color + intensity.
catalog.push_back(ComponentEntry{
.name = "DirectionalLight",
.isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent<Component::DirectionalLight>(); },
.describe = [](PEntity e) -> std::string {
if (e == nullptr || !e->hasComponent<Component::DirectionalLight>()) {
return "";
}
const auto& l = e->accessComponent<Component::DirectionalLight>();
std::ostringstream oss;
oss << "Color: " << fmtVec(l.color) << "\n";
oss << "Intensity: " << fmtFloat(l.intensity);
return oss.str();
},
});
// Mesh (static): the mesh asset's name/folder + staticness + meshlet count.
catalog.push_back(ComponentEntry{
.name = "Mesh",
.isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent<Component::Mesh>(); },
.describe = [](PEntity e) -> std::string {
if (e == nullptr || !e->hasComponent<Component::Mesh>()) {
return "";
}
const auto& m = e->accessComponent<Component::Mesh>();
std::ostringstream oss;
oss << "Asset: ";
if (m.asset != nullptr) {
oss << m.asset->getFolderPath() << "/" << m.asset->getName();
} else {
oss << "(none)";
}
oss << "\n";
oss << "Static: " << (m.isStatic ? "true" : "false") << "\n";
oss << "Meshlets: " << m.meshletOffsets.size();
return oss.str();
},
});
}
std::vector<EntityInfo> enumerateEntities(const PScene& scene) {
std::vector<EntityInfo> out;
if (scene == nullptr) {
return out;
}
// The scene's roster is the source of truth for "what entities exist" - this is the
// "OEntity you can query via the scene" the user asked for. We iterate handles (PEntity
// views), never entt ids. The roster is appended in creation order and pruned on
// destroy, so it is stable across frames (no re-sorting needed, no entt::entity anywhere).
const Array<PEntity>& roster = scene->getEntities();
for (size_t i = 0; i < roster.size(); ++i) {
PEntity e = roster[i];
if (e == nullptr) {
continue;
}
EntityInfo info;
info.entity = e; // non-owning handle the row points at
info.label = e->getLabel(); // "#<id>" formatted in the engine; no entt type leaks
// Component summary: the names of every cataloged component this entity actually
// has, comma-joined. Uses isAttached (handle-space) - no registry access in the editor.
std::vector<std::string> names;
for (auto& entry : componentCatalog()) {
if (entry.isAttached(e)) {
names.push_back(entry.name);
}
}
if (names.empty()) {
info.componentSummary = "no components";
} else {
info.componentSummary = names[0];
for (size_t n = 1; n < names.size(); ++n) {
info.componentSummary += ", " + names[n];
}
}
out.push_back(std::move(info));
}
return out;
}
std::vector<ComponentDisplay> describeEntityComponents(const PScene& scene, PEntity entity) {
std::vector<ComponentDisplay> out;
if (scene == nullptr || entity == nullptr) {
return out;
}
// Walk the catalog in order; for each component the entity has, render its fields via
// the handle's own accessComponent. The editor never touches the registry directly.
for (auto& entry : componentCatalog()) {
if (!entry.isAttached(entity)) {
continue; // entity does not have this component (or it is not displayable)
}
out.push_back(ComponentDisplay{.name = entry.name, .fieldText = entry.describe(entity)});
}
return out;
}
} // namespace Editor
} // namespace Seele
+83
View File
@@ -0,0 +1,83 @@
#pragma once
// The editor's component-inspection layer. Operates ENTIRELY in engine handle space
// (OEntity / PScene) - the entt::entity type never appears in this header or in any
// function the editor calls. Every EnTT operation the inspector needs (does-this-entity-
// have-T, read-T) is performed by the Entity/Scene methods (hasComponent / accessComponent
// / getEntities), which is exactly the separation the engine wants: tooling works through
// handles, the registry stays internal to the engine.
#include "Actor/Actor.h"
#include "Scene/Scene.h"
#include <functional>
#include <string>
#include <vector>
namespace Seele {
namespace Editor {
// A single entry in the component catalog: how to recognize one component type on an
// entity and how to render its fields as human-readable text (Unity-inspector style).
//
// Both callbacks take a PEntity (a non-owning handle view) - never a raw entt id. They use
// the entity's own hasComponent<T>() / accessComponent<T>() so the inspector code reads
// exactly the way game code attaches/reads components: in handle space.
//
// This is the type-erased bridge between "I have an OEntity handle" and "show me every
// component attached to it". EnTT does not expose a generic "iterate all registered
// component types" API, so the inspector keeps an explicit catalog of the types it knows
// how to display. Adding a new engine component to the inspector is one entry in
// ComponentRegistry.cpp - no changes to this header.
struct ComponentEntry {
// Display name shown as the section header in the inspector (e.g. "Transform").
std::string name;
// True if the given entity currently has this component attached.
std::function<bool(PEntity)> isAttached;
// Render the component's fields as a multi-line string (Unity-style: "field: value" per
// line). Returns "" when the entity does not have the component (the caller skips it).
std::function<std::string(PEntity)> describe;
};
// The catalog of every component type the editor knows how to display. Populated exactly
// once by initComponentRegistry() (called from the editor's main before the first frame).
// The vector is process-global by design: component *types* are a fixed set, so the
// catalog is built once and read-only afterwards.
std::vector<ComponentEntry>& componentCatalog();
// Build the catalog. Idempotent - safe to call more than once; it only (re)populates the
// static vector, which every editor tool reads. Must be called before any inspector reads
// the catalog (main.cpp does this before the render loop).
void initComponentRegistry();
// One row in the entity list (the left pane). Built from the scene's roster of live
// handles - the "ID of an entity" is shown via the handle's own getLabel() (formatted in
// the engine, so no entt type leaks), and the component summary is the names of the
// cataloged components the handle actually has.
struct EntityInfo {
// The non-owning handle the row refers to. The editor stores these to drive the
// "selected entity" state across frames. Non-owning by design: the *scene* owns the
// entity's existence (the roster) and the creator's O* owns the C++ object.
PEntity entity;
// A short, stable label for the row (e.g. "#3") - the "ID of an entity" the user asked
// to display, produced by Entity::getLabel() so the entt type never reaches the editor.
std::string label;
// Human-readable summary of the attached components (e.g. "Transform, Mesh") for the
// row's subtitle.
std::string componentSummary;
};
// Enumerate every live entity in the scene (as non-owning handles) with its label + a
// component summary. Source of the left pane. Iterates the scene's roster (getEntities) -
// the scene's single source of truth for "what entities exist" - so this is the
// "OEntity you can query via the scene" the user asked for, with no entt id anywhere.
std::vector<EntityInfo> enumerateEntities(const PScene& scene);
// Describe one entity's components for the inspector pane: a vector of (componentName,
// fieldText) pairs, one entry per attached, displayable component, in catalog order. The
// caller (InspectorView) maps these to UI::Text rows and refreshes them in update().
struct ComponentDisplay {
std::string name;
std::string fieldText;
};
std::vector<ComponentDisplay> describeEntityComponents(const PScene& scene, PEntity entity);
} // namespace Editor
} // namespace Seele
+228 -21
View File
@@ -1,26 +1,141 @@
#include "InspectorView.h"
#include "Actor/Actor.h"
#include "Asset/AssetRegistry.h"
#include "Asset/FontLoader.h"
#include "ComponentRegistry.h"
#include "Graphics/Graphics.h"
#include "UI/Element/Button.h"
#include "UI/Element/Div.h"
#include "UI/Element/Text.h"
#include "UI/Style/Fonts.h" // Font_Arial tag type (Text.h does not pull this in)
#include "UI/System.h"
using namespace Seele;
using namespace Seele::Editor;
using namespace Seele::UI;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo)
: View(graphics, window, createInfo, "InspectorView"),
uiSystem(new UI::System(
new UI::Div<M_8>(UI::Attributes{}, {
new UI::Div<BG_Red, FlexRow, M_4>({},
{
new UI::Text<Font_Arial, Text_8XL>("Other Test T"),
}),
new UI::Text<Font_Arial>("Test fasdf agll;sdfgkj ahsf"),
}))) {
renderGraph.addPass(new UIPass(graphics, uiSystem));
namespace {
// Split a multi-line string into trimmed, non-empty lines (for the field display).
std::vector<std::string> splitLines(const std::string& text) {
std::vector<std::string> out;
std::string cur;
for (char c : text) {
if (c == '\n') {
if (!cur.empty()) {
out.push_back(cur);
cur.clear();
}
} else {
cur.push_back(c);
}
}
if (!cur.empty()) {
out.push_back(cur);
}
return out;
}
} // namespace
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo, PScene scene)
: View(graphics, owner, createInfo, "InspectorView"), scene(scene) {
// ------------------------------------------------------------------
// Build the ENTIRE fixed widget tree exactly once, here, in the constructor.
//
// "Children fixed at construction": the UI tree's structure is immutable at
// runtime. We create every widget as a named local (so we can keep a raw pointer
// for setText()), then reference those same objects in the tree's initializer-list.
// The initializer-list's Element* -> OElement implicit conversion stores an OWNING
// ref in each parent's children array (Array<OElement>) for the element's whole
// lifetime, so the raw pointers below remain valid for the life of the view.
// ------------------------------------------------------------------
// ---- Leaf widgets (named locals; also referenced by the tree below) ----------
// Entity-list row labels + select buttons (one row per pool slot).
Text<Font_Arial>* rowLabels[kMaxEntities];
Button<>* rowButtons[kMaxEntities];
for (int i = 0; i < kMaxEntities; i++) {
// Text has no default ctor (text is a required arg); start with an empty string
// and refresh() fills it each frame. Button's default ctor is deleted (Div()
// = delete) so we must pass explicit Attributes.
rowLabels[i] = new Text<Font_Arial>("");
rowButtons[i] = new Button<>(UI::Attributes{});
// The button's onClick is the ONLY sanctioned way selection state changes;
// refresh() (called from update() next frame) reads it back and re-renders the
// component pane. We do not markDirty() here - the next frame's refresh() is
// the sanctioned per-frame mutation path, and markDirty() is an Element method
// (not callable on this View).
rowButtons[i]->attr.onClick = [this, i](MouseEvent&) {
selectedEntity = i;
return true;
};
// PElement is a NON-OWNING wrapper (no operator=(T*)); the tree's owning
// OElement refs (stored in the parent Div's children below) are what keep these
// alive. We construct an explicit PElement temporary to copy-assign the handle.
entityPool[i].label = PElement(rowLabels[i]);
entityPool[i].button = PElement(rowButtons[i]);
}
// Component-inspector pane: a header line + a fixed pool of field lines.
// Text has no default ctor - pass an initial string (refresh() overwrites it).
Text<Font_Arial, Text_8XL>* header = new Text<Font_Arial, Text_8XL>("(no entity selected)");
Text<Font_Arial>* lines[kMaxComponentLines];
for (int i = 0; i < kMaxComponentLines; i++) {
lines[i] = new Text<Font_Arial>("");
}
componentHeader = PElement(header);
for (int i = 0; i < kMaxComponentLines; i++) {
componentLines[i] = PElement(lines[i]);
}
// ---- Compose the tree (structure fixed at construction) ----------------------
// Element's only children ctor is (Attributes, initializer_list<OElement>) - there is
// no variadic form and initializer_list cannot be built from an Array, so the child
// list must be a braced-init at the call site. A braced list MAY contain function-call
// expressions, so a small lambda builds each identical row (returning the owning
// OElement of the row Div) and we reference makeRow(0..7) explicitly. The label/button
// handles for refresh() were already stashed in entityPool[] above (non-owning PElement);
// the row Div's children array holds the OWNING refs that keep the widgets alive.
auto makeRow = [this, &rowLabels, &rowButtons](int i) -> OElement {
return OElement(new Div<FlexRow, M_4>(
UI::Attributes{},
std::initializer_list<OElement>{OElement(rowLabels[i]), OElement(rowButtons[i])}));
};
// Left pane: a vertical (FlexCol) stack of the 8 fixed entity rows. The child list is
// a braced-init of makeRow(0..7) - each call returns the owning OElement of one row.
Div<FlexCol, M_8, BG_Red>* leftPane = new Div<FlexCol, M_8, BG_Red>(
UI::Attributes{},
std::initializer_list<OElement>{
makeRow(0), makeRow(1), makeRow(2), makeRow(3),
makeRow(4), makeRow(5), makeRow(6), makeRow(7),
});
// Right pane: a vertical (FlexCol) stack of the header line + the fixed field-line pool.
// Same braced-init pattern; makeLine(i) returns the owning OElement of one field Text.
auto makeLine = [this, &lines](int i) -> OElement {
return OElement(lines[i]);
};
Div<FlexCol, M_8>* rightPane = new Div<FlexCol, M_8>(
UI::Attributes{},
std::initializer_list<OElement>{
OElement(header),
makeLine(0), makeLine(1), makeLine(2), makeLine(3),
makeLine(4), makeLine(5), makeLine(6), makeLine(7),
makeLine(8), makeLine(9), makeLine(10), makeLine(11),
makeLine(12), makeLine(13), makeLine(14), makeLine(15),
});
// Root: a horizontal (FlexRow) split - entity list on the left, inspector on the right.
Div<FlexRow, M_8>* root = new Div<FlexRow, M_8>(
UI::Attributes{},
std::initializer_list<OElement>{OElement(leftPane), OElement(rightPane)});
// Hand the fully-built root tree to the UI system. The system is owned by the view
// (uiSystem is an OwningPtr); construct the owning handle in place.
uiSystem = UI::OSystem(new UI::System(OElement(root)));
// Register a UIPass to render the UI. Keep a raw pointer to it so the window input
// callbacks can forward events (RenderGraph exposes only resources, not passes).
uiPass = new UIPass(graphics, uiSystem);
renderGraph.addPass(ORenderPass(uiPass));
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
}
@@ -29,22 +144,114 @@ InspectorView::~InspectorView() {}
void InspectorView::beginUpdate() {}
void InspectorView::update() {}
void InspectorView::update() {
refresh();
}
void InspectorView::commitUpdate() {}
void InspectorView::prepareRender() {}
void InspectorView::render() { renderGraph.render(Component::Camera(), Component::Transform()); }
void InspectorView::render() {
// Drives every pass in the graph, including the UIPass (which runs
// system->processInput() + system->beginFrame() internally before rendering).
// The UI system's per-frame update is performed by the pass, not by us.
renderGraph.render(Component::Camera(), Component::Transform());
}
void InspectorView::applyArea(URect ) {}
void InspectorView::applyArea(URect) {
// The Viewport was already resized by View::resize before this is called. Recreate
// the render graph's passes at the new size so the UI (and everything) re-layouts.
renderGraph.setViewport(viewport);
renderGraph.createRenderPass();
}
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifierFlags) {}
void InspectorView::keyCallback(KeyCode code, InputAction action, uint32_t modifier) {
if (uiPass != nullptr) {
uiPass->key(code, action, KeyModifierFlags(modifier), 0);
}
}
void InspectorView::mouseMoveCallback(double, double) {}
void InspectorView::mouseMoveCallback(double xPos, double yPos) {
if (uiPass != nullptr) {
uiPass->mouseMove(Vector2(xPos, yPos));
}
}
void InspectorView::mouseButtonCallback(MouseButton, InputAction, KeyModifierFlags) {}
void InspectorView::mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) {
if (uiPass != nullptr) {
uiPass->mouseButton(button, action, KeyModifierFlags(modifier), Vector2(0, 0));
}
}
void InspectorView::scrollCallback(double, double) {}
void InspectorView::scrollCallback(double xOffset, double yOffset) {
if (uiPass != nullptr) {
uiPass->scroll(Vector2(xOffset, yOffset));
}
}
void InspectorView::fileCallback(int, const char**) {}
void InspectorView::refresh() {
// Re-read the scene's live entity roster + the selected entity's components, and
// push the results into the fixed widget pool via Text::setText. This is the ONLY
// per-frame mutation of the UI tree - children are never added or removed.
//
// The pool handles are UI::PElement (the Element base ref) because Text/Button are
// class templates (can't be member types). We downcast to the concrete type at the
// use site. Every downcast target is guaranteed valid: we built each widget with the
// exact concrete type below and the tree's owning OElement refs keep it alive.
auto setTextOn = [](UI::PElement handle, const std::string& text) {
if (handle == nullptr) {
return;
}
if (auto* t = dynamic_cast<UI::Text<Font_Arial>*>(handle.getHandle())) {
t->setText(text);
}
};
auto entities = enumerateEntities(scene);
// --- Entity list pane: fill the fixed row pool from the live roster -----------
for (int i = 0; i < kMaxEntities; i++) {
if (i < (int)entities.size()) {
setTextOn(entityPool[i].label,
entities[i].label + " [" + entities[i].componentSummary + "]");
} else {
setTextOn(entityPool[i].label, "");
}
}
// --- Component inspector pane: describe the selected entity -------------------
if (selectedEntity >= 0 && selectedEntity < (int)entities.size()) {
PEntity ent = entities[selectedEntity].entity;
setTextOn(componentHeader, "Components: " + entities[selectedEntity].label);
auto components = describeEntityComponents(scene, ent);
int line = 0;
for (auto& c : components) {
if (line >= kMaxComponentLines) {
break; // fixed pool: truncate beyond it
}
setTextOn(componentLines[line], " " + c.name);
line++;
// Multi-line field text is folded into the subsequent pool lines (clamped).
auto fields = splitLines(c.fieldText);
for (auto& f : fields) {
if (line >= kMaxComponentLines) {
break;
}
setTextOn(componentLines[line], " " + f);
line++;
}
}
// Clear leftover pool lines so stale data never shows (fixed pool must be clean).
for (; line < kMaxComponentLines; line++) {
setTextOn(componentLines[line], "");
}
} else {
setTextOn(componentHeader, "(no entity selected)");
for (int i = 0; i < kMaxComponentLines; i++) {
setTextOn(componentLines[i], "");
}
}
}
+56 -15
View File
@@ -1,37 +1,78 @@
#pragma once
#include "Graphics/RenderPass/RenderGraph.h"
#include "Graphics/RenderPass/UIPass.h"
#include "Window/View.h"
#include "UI/System.h"
#include "UI/Style/Fonts.h"
#include "Graphics/RenderPass/UIPass.h"
#include "UI/Element.h" // UI::PElement / UI::OElement (complete, for the fixed widget pool)
#include "Scene/Scene.h" // PScene
namespace Seele {
DECLARE_REF(Actor)
namespace Editor {
// The editor's component inspector. Left pane lists the scene's live entities
// (from the ComponentRegistry via Scene::getEntities); right pane shows the selected
// entity's components as Unity-style "field: value" text, refreshed every frame.
//
// The UI tree is a FIXED widget pool: it is built once in the constructor and never
// adds/removes children at runtime. Per-frame the only mutation is UI::Text::setText
// on the pre-built widgets (the "children fixed at construction" constraint). Selection
// state is changed exclusively through UI::Button onClick handlers (the sanctioned
// click path) and read back in update().
//
// Pool handles are UI::PElement (the Element base ref). Text/Button/Div are class
// templates (UI::Text<...>, UI::Button<...>) so they can't be named as member types;
// we hold the base and dynamic_cast to the concrete type at the use site in refresh().
class InspectorView : public View {
public:
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo);
virtual ~InspectorView();
// `scene` is the scene to inspect (non-owning; the editor owns its lifetime).
// The roster + component data are read from it each frame via the ComponentRegistry.
InspectorView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo, PScene scene);
virtual ~InspectorView() override;
virtual void beginUpdate() override;
virtual void update() override;
virtual void commitUpdate() override;
virtual void prepareRender() override;
virtual void render() override;
protected:
virtual void applyArea(URect area) override;
UI::PSystem uiSystem;
RenderGraph renderGraph;
Component::Camera cam;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) override;
virtual void scrollCallback(double xOffset, double yOffset) override;
virtual void fileCallback(int count, const char** paths) override;
private:
// Fixed widget pools. Handles are UI::PElement (base) because Text/Button are class
// templates. Each is safe for the life of the view: the constructed element is stored
// in a parent Div's children array (Array<OElement>) which holds an OWNING ref; the
// PElement here is a second (shared) ref to the same object. refresh() dynamic_casts
// to the concrete UI::Text<Font_Arial>/UI::Button<> to call setText()/attr.
static constexpr int kMaxEntities = 8; // entity-list rows
static constexpr int kMaxComponentLines = 16; // component-inspector text lines
PScene scene;
// The UI::System is a long-lived object with no other owner, so the view OWNS it
// (OwningPtr, via the OSystem typedef from DEFINE_REF(System)). UIPass takes a
// non-owning PSystem, which OSystem converts to implicitly.
UI::OSystem uiSystem;
RenderGraph renderGraph;
// Direct handle to the UI render pass so the window input callbacks can be
// forwarded to the UI system (RenderGraph exposes only resources, not passes).
UIPass* uiPass = nullptr;
// Selection state: written by button onClick, read in refresh().
int selectedEntity = -1;
struct EntityRow {
UI::PElement label = nullptr; // UI::Text<Font_Arial> (cast in refresh())
UI::PElement button = nullptr; // UI::Button<> (cast in refresh())
};
EntityRow entityPool[kMaxEntities];
UI::PElement componentHeader = nullptr;
UI::PElement componentLines[kMaxComponentLines];
// Rebuild the pool text from the current scene state (called from update()).
void refresh();
};
DEFINE_REF(InspectorView)
} // namespace Editor
+101 -2
View File
@@ -13,7 +13,12 @@
#include "Window/PlayView.h"
#include "Window/WindowManager.h"
#include "Window/InspectorView.h"
#include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene
#include "Component/Transform.h"
#include "Actor/Entity.h"
#include "ComponentRegistry.h"
#include <fmt/core.h>
#include <iostream>
using namespace Seele;
using namespace Seele::Editor;
@@ -21,7 +26,97 @@ using namespace Seele::Editor;
// make it global so it gets deleted last and automatically
static Gfx::OGraphics graphics;
int main() {
// Headless path: build a real Vulkan device with no WSI (no display available),
// populate a Scene with a few entities + components, dump the registry to stdout
// via the same handle-space query the editor's inspector uses, then tear down.
// Used for CI / smoke verification on display-less machines: the driver is
// present, only the display is not, so surface extensions are intentionally
// omitted while everything else (instance, device, queues, GPU buffers) works.
static int runHeadlessDump() {
std::cout << "[headless] constructing Vulkan::Graphics (no WSI / no swapchain)...\n";
Gfx::OGraphics headlessGfx = new Vulkan::Graphics();
GraphicsInitializer initializer;
initializer.headless = true; // skip GLFW init, WSI instance exts, and the swapchain device ext
headlessGfx->init(initializer);
std::cout << "[headless] Vulkan device constructed successfully.\n";
// A real (non-null) graphics handle, so Scene builds its GPU sub-systems for real.
OScene scene = new Scene(headlessGfx);
std::cout << "[headless] Scene constructed (LightEnvironment + FluidScene on real device).\n";
// A few entities with real transforms so the dump is meaningful. The display label is
// auto-derived from the entt id (Entity::getLabel -> "#<id>"), so no setLabel needed.
Entity* a = new Entity(scene);
a->attachComponent<Component::Transform>().transform.setPosition(glm::vec3(0.0f, 0.0f, 0.0f));
Entity* b = new Entity(scene);
b->attachComponent<Component::Transform>().transform.setPosition(glm::vec3(1.0f, 2.0f, -3.0f));
Entity* c = new Entity(scene);
// c intentionally has no components - exercises the "no components" roster row.
initComponentRegistry();
auto entities = enumerateEntities(scene);
std::cout << "\n[headless] entity roster: " << entities.size() << " entity(ies)\n";
for (const auto& e : entities) {
std::cout << "\n=== " << e.label << " ===\n";
std::cout << " components: " << e.componentSummary << "\n";
auto components = describeEntityComponents(scene, e.entity);
for (const auto& c : components) {
std::cout << " [ " << c.name << " ]\n";
// Indent the field text by 4 spaces for readability.
for (const auto& line : std::vector<std::string>{
[&] {
std::vector<std::string> out;
std::string cur;
for (char ch : c.fieldText) {
if (ch == '\n') { out.push_back(" " + cur); cur.clear(); }
else { cur += ch; }
}
if (!cur.empty()) { out.push_back(" " + cur); }
return out;
}()}) {
std::cout << " " << line << "\n";
}
}
}
std::cout << "\n[headless] tearing down (waitDeviceIdle + dispose)...\n";
headlessGfx->waitDeviceIdle();
delete a;
delete b;
delete c;
// scene (OScene) and headlessGfx (OGraphics) are OwningPtr (RAII): their destructors
// free the Scene / Graphics when the locals go out of scope at the end of this function.
// No manual delete - that would be a double-free. Order matters (entities before scene),
// which is already satisfied by the explicit deletes above.
std::cout << "[headless] OK - headless Vulkan path validated.\n";
return 0;
}
int main(int argc, char** argv) {
// --headless: build a real headless Vulkan device and exit (no window).
// --dump-entities: (implies --headless) also dump the entity roster to stdout.
bool wantHeadless = false, wantDump = false;
for (int i = 1; i < argc; ++i) {
std::string a = argv[i];
if (a == "--headless" || a == "--dump-entities") wantHeadless = true;
if (a == "--dump-entities") wantDump = true;
}
if (wantHeadless) {
if (wantDump) {
return runHeadlessDump();
}
// Headless device smoke test only (no dump).
Gfx::OGraphics h = new Vulkan::Graphics();
GraphicsInitializer init;
init.headless = true;
h->init(init);
std::cout << "[headless] device OK (no WSI). Tearing down.\n";
h->waitDeviceIdle();
// h is an OwningPtr (RAII) - the destructor frees the Graphics at end of scope.
// No manual delete (would be a double-free).
return 0;
}
std::string gameName = "MeshShadingDemo";
std::filesystem::path outputPath = fmt::format("/home/dynamitos/{0}Game/", gameName);
std::filesystem::path sourcePath = fmt::format("/home/dynamitos/{0}/", gameName);
@@ -86,6 +181,9 @@ int main() {
// };
// OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath);
// sceneView->setFocused();
// The windowed editor path has no pre-existing scene; the InspectorView's entity
// pane needs one to enumerate. Create a fresh Scene on the live (windowed) device.
OScene scene = new Scene(graphics);
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
ViewportCreateInfo{
.dimensions =
@@ -93,7 +191,8 @@ int main() {
.size = {1920, 1080},
.offset = {0, 0},
},
});
},
/* scene = */ scene);
inspectorView->setFocused();
window->show();