struct TRendererObjectECSUtility

template<typename IdFragment, typename DirtyTag, typename TransformDirtyTag, RendererId (RendererScene::*AllocateFn)(ecs::Registry &, ecs::Entity), void (RendererScene::*DeallocateFn)(ecs::Registry &, ecs::Entity), typename ...DataFragments>

Provides generic ECS utility methods for renderer object types.

Handles the common pattern of creating data fragments, registering/unregistering with the renderer, managing dirty tags, and migrating fragments across scenes.

Fragment removal cleanup (ID deallocation, dirty tag removal) is handled automatically by OnWillRemove events subscribed in RendererScene. This template only needs to handle creation, registration, and migration.

Template parameters

IdFragment

The ID fragment type (e.g., ecs::LightId).

DirtyTag

The full-dirty tag type (e.g., ecs::LightDirty).

TransformDirtyTag

The transform-dirty tag type (e.g., ecs::LightTransformDirty).

AllocateFn

Pointer-to-member for RendererScene::Allocate*Id.

DeallocateFn

Pointer-to-member for RendererScene::Deallocate*Id.

DataFragments

The ECS data fragment types managed by this renderer object.

Public

Methods

staticCreateFragmentsIfMissing

static bool CreateFragmentsIfMissing(ecs::Registry &registry, ecs::Entity entity)

Ensures all data fragments exist on the entity.

Returns true if any fragment was newly created.

staticRegisterWithRenderer

static void RegisterWithRenderer(ecs::Registry &registry, ecs::Entity entity, const SPtr<RendererScene> &rendererScene)

Allocates a renderer ID and marks the entity dirty.

This ensures a render proxy for the entity is created on the render thread, and the entity can be rendered. Use Mark*Dirty() methods when changing data fragment properties to ensure render proxy has up-to-date information.

staticUnregisterFromRenderer

static void UnregisterFromRenderer(ecs::Registry &registry, ecs::Entity entity, const SPtr<RendererScene> &rendererScene)

Deallocates the renderer ID and removes dirty tags.

This deallocated the render proxy for the entity on the render thread, and the entity will no longer be rendered. Does not remove data fragments — the entity stays but is deactivated.

staticRemoveFragments

static void RemoveFragments(ecs::Registry &registry, ecs::Entity entity)

Removes all data fragments from the entity.

Cleanup (ID deallocation, dirty tag removal) is handled by the associated RendererScene when it is notified the fragment has been removed.

staticChangeScene

static void ChangeScene(SceneInstance *oldScene, ecs::Entity oldEntity, SceneInstance &newScene, ecs::Entity newEntity, bool registerWithRenderer)

Handles fragment migration when the entity moves between scenes.

Migrates data fragments from old entity to new (removal from old triggers OnWillRemove → auto-cleanup on old scene). Optionally registers in new renderer scene if is true (e.g. can be false if entity exists, but is currently not active/disabled).

staticMarkDirty

static void MarkDirty(ecs::Registry &registry, ecs::Entity entity)

Marks the entity as fully dirty, requiring a full sync to the render thread.

staticMarkTransformDirty

static void MarkTransformDirty(ecs::Registry &registry, ecs::Entity entity)

Marks only the transform as dirty.

No-op if the entity is already fully dirty.

staticMarkDirty

static void MarkDirty(ecs::Registry &registry, ecs::Entity entity, ComponentDirtyFlag flag)

Adds the appropriate dirty tag based on the flag type.

Transform-only changes use TransformDirtyTag (unless already full-dirty). Everything else uses DirtyTag.