Skip to content

Commit

Permalink
Engine - ECS: make TreeNode blittable
Browse files Browse the repository at this point in the history
  • Loading branch information
friflo committed Jul 19, 2024
1 parent 1cf975a commit 06dbf6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion Engine/src/ECS/Components/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public struct TreeNode : IComponent // todo should be internal

// [Browse(Never)] internal int parentId; // 4 0 if entity has no parent
internal IdArray childIds; // 8
internal int[] dummy; // 8 todo remove

/// same as <see cref="IdArrayExtensions.GetSpan"/>
public ReadOnlySpan<int> GetChildIds(EntityStore store)
Expand Down
10 changes: 8 additions & 2 deletions Engine/src/ECS/Entity/Store/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ internal int CreateEntityInternal(Archetype archetype, int id)
/// <summary>
/// Create and return a clone of the passed <paramref name="entity"/> in the store.
/// </summary>
/// <returns></returns>
/// <remarks>
/// Child entities of the passed <paramref name="entity"/> are not copied to the cloned entity.<br/>
/// If doing this these child entities would be children of the passed entity <b>and</b> the clone.
/// </remarks>
public Entity CloneEntity(Entity entity)
{
var archetype = entity.archetype ?? throw EntityNullException(entity);
Expand All @@ -96,6 +99,9 @@ public Entity CloneEntity(Entity entity)
var scriptTypeByType = Static.EntitySchema.ScriptTypeByType;
// CopyComponents() must be used only in case all component types are blittable
Archetype.CopyComponents(archetype, entity.compIndex, clone.compIndex);
if (clone.HasComponent<TreeNode>()) {
clone.GetComponent<TreeNode>() = default; // clear child ids. See child entities note in remarks.
}
// --- clone scripts
foreach (var script in entity.Scripts) {
var scriptType = scriptTypeByType[script.GetType()];
Expand All @@ -110,7 +116,7 @@ public Entity CloneEntity(Entity entity)

// --- deserialize DataEntity
dataBuffer.pid = IdToPid(clone.Id);
dataBuffer.children = null; // child ids are not copied. If doing this these children would have two parents.
dataBuffer.children = null; // clear children. See child entities note in remarks.
// convert will use entity created above
converter.DataEntityToEntity(dataBuffer, this, out string error); // error == null. No possibility for mapping errors
AssertNoError(error);
Expand Down

0 comments on commit 06dbf6c

Please sign in to comment.