Skip to content

Commit

Permalink
Engine - ECS: moved EntityStoreExtensions.CreateEntity() overload to …
Browse files Browse the repository at this point in the history
…Extension folder
  • Loading branch information
friflo committed Apr 2, 2024
1 parent c73a703 commit ea92e23
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
34 changes: 34 additions & 0 deletions Engine/src/ECS/Entity/Store/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Diagnostics.CodeAnalysis;
using Friflo.Engine.ECS.Serialize;
using static Friflo.Engine.ECS.NodeFlags;
using static Friflo.Engine.ECS.StoreOwnership;
using static Friflo.Engine.ECS.TreeMembership;

// ReSharper disable UseNullPropagation
// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
Expand All @@ -23,6 +25,38 @@ public partial class EntityStore
/// </summary>
public static EntitySchema GetEntitySchema()=> Static.EntitySchema;

/// <summary>
/// Create and return a new <see cref="Entity"/> in the entity store.<br/>
/// See <a href="https://github.com/friflo/Friflo.Json.Fliox/blob/main/Engine/README.md#entity">Example.</a>
/// </summary>
/// <returns>An <see cref="attached"/> and <see cref="floating"/> entity</returns>
public Entity CreateEntity()
{
var id = NewId();
CreateEntityInternal(defaultArchetype, id);
var entity = new Entity(this, id);

// Send event. See: SEND_EVENT notes
CreateEntityEvent(entity);
return entity;
}

/// <summary>
/// Create and return a new <see cref="Entity"/> with the passed <paramref name="id"/> in the entity store.
/// </summary>
/// <returns>an <see cref="attached"/> and <see cref="floating"/> entity</returns>
public Entity CreateEntity(int id)
{
CheckEntityId(id);
CreateEntityInternal(defaultArchetype, id);
var entity = new Entity(this, id);

// Send event. See: SEND_EVENT notes
CreateEntityEvent(entity);
return entity;
}


internal void CheckEntityId(int id)
{
if (id < Static.MinNodeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,10 @@
// See LICENSE file in the project root for full license information.


using static Friflo.Engine.ECS.StoreOwnership;
using static Friflo.Engine.ECS.TreeMembership;

// ReSharper disable UseNullPropagation
// ReSharper disable once CheckNamespace
namespace Friflo.Engine.ECS;

public partial class EntityStore
{
/// <summary>
/// Create and return a new <see cref="Entity"/> in the entity store.<br/>
/// See <a href="https://github.com/friflo/Friflo.Json.Fliox/blob/main/Engine/README.md#entity">Example.</a>
/// </summary>
/// <returns>An <see cref="attached"/> and <see cref="floating"/> entity</returns>
public Entity CreateEntity()
{
var id = NewId();
CreateEntityInternal(defaultArchetype, id);
var entity = new Entity(this, id);

// Send event. See: SEND_EVENT notes
CreateEntityEvent(entity);
return entity;
}

/// <summary>
/// Create and return a new <see cref="Entity"/> with the passed <paramref name="id"/> in the entity store.
/// </summary>
/// <returns>an <see cref="attached"/> and <see cref="floating"/> entity</returns>
public Entity CreateEntity(int id)
{
CheckEntityId(id);
CreateEntityInternal(defaultArchetype, id);
var entity = new Entity(this, id);

// Send event. See: SEND_EVENT notes
CreateEntityEvent(entity);
return entity;
}
}

/// <summary>
/// Provide generic <c>CreateEntity()</c> overloads to create entities with passed components without any structural change.
Expand Down

0 comments on commit ea92e23

Please sign in to comment.