Files
Seele/src/Editor/ComponentRegistry.h
T
coding-agent c5c66f8cf3 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.
2026-11-09 20:07:40 +01:00

84 lines
4.4 KiB
C++

#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