Closed guerro323 closed 3 years ago
Implemented in GameHost.Simulation.V3 (not yet in the repository) Usage:
world.AddEntityLayoutModule(); // this call may not be needed in the future
var componentTypeA = world.RegisterComponent("TypeA", new LinkedDataComponentBoard(sizeof(int), world));
var componentTypeB = world.RegisterComponent("TypeB", new LinkedDataComponentBoard(sizeof(int), world));
var layout = world.RegisterLayout("MyLayout", stackalloc[]
{
componentTypeA,
componentTypeB
});
var entity = world.CreateEntity();
// MyLayout
// TypeA
// TypeB
world.AddComponent(entity, layout);
// No components and no layout
world.RemoveComponent(entity, layout);
// MyLayout
// TypeA
// TypeB (overriden component)
world.AddComponent(entity, layout);
world.AddComponent(entity, componentTypeB);
// TypeB
//
// TypeA and MyLayout removed
world.RemoveComponent(entity, layout);
// MyLayout
// TypeA
// TypeB
//
// TypeB is not overriden anymore (the behavior may change in the future to keep the overridness)
world.AddComponent(entity, layout);
// MyLayout and TypeB removed on next archetype update
world.RemoveComponent(entity, componentTypeA);
// force the archetype update
world.GetArchetype(entity);
A layout is a specialized component, which enforce a strict component layout on an entity.
It will make it easier to create contextualized entities, and query them easily.
All layouts will be based on IEntityLayout, which provide a single method that get the required components.
Adding a layout will add the components to an entity, but removing it will not remove the components.