Browse Source

force the use of explicit groups

tags/Rel25b
sebas77 6 years ago
parent
commit
96349ac83e
3 changed files with 33 additions and 16 deletions
  1. +7
    -9
      Svelto.ECS/EnginesRoot.GenericEntityFactory.cs
  2. +15
    -2
      Svelto.ECS/ExclusiveGroups.cs
  3. +11
    -5
      Svelto.ECS/IEntityFactory.cs

+ 7
- 9
Svelto.ECS/EnginesRoot.GenericEntityFactory.cs View File

@@ -1,6 +1,4 @@
using Svelto.ECS.Internal;

#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
using Svelto.ECS.Profiler;
#endif

@@ -22,9 +20,9 @@ namespace Svelto.ECS
return _weakEngine.Target.BuildEntity<T>(new EGID(entityID), implementors);
}

public EntityStructInitializer BuildEntity<T>(int entityID, int groupID, object[] implementors) where T : IEntityDescriptor, new()
public EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroups groupID, object[] implementors) where T : IEntityDescriptor, new()
{
return _weakEngine.Target.BuildEntity<T>(new EGID(entityID, groupID), implementors);
return _weakEngine.Target.BuildEntity<T>(new EGID(entityID, (int)groupID), implementors);
}

public EntityStructInitializer BuildEntity<T>(EGID egid, object[] implementors) where T : IEntityDescriptor, new()
@@ -42,9 +40,9 @@ namespace Svelto.ECS
return _weakEngine.Target.BuildEntity(egid, entityToBuild, implementors);
}

public EntityStructInitializer BuildEntity(int entityID, int groupID, IEntityBuilder[] entityToBuild, object[] implementors)
public EntityStructInitializer BuildEntity(int entityID, ExclusiveGroups groupID, IEntityBuilder[] entityToBuild, object[] implementors)
{
return _weakEngine.Target.BuildEntity(new EGID(entityID, groupID), entityToBuild, implementors);
return _weakEngine.Target.BuildEntity(new EGID(entityID, (int)groupID), entityToBuild, implementors);
}
public void PreallocateEntitySpace<T>(int size) where T : IEntityDescriptor, new()
@@ -52,9 +50,9 @@ namespace Svelto.ECS
_weakEngine.Target.Preallocate<T>(ExclusiveGroups.StandardEntity, size);
}
public void PreallocateEntitySpace<T>(int groupID, int size) where T : IEntityDescriptor, new()
public void PreallocateEntitySpace<T>(ExclusiveGroups groupID, int size) where T : IEntityDescriptor, new()
{
_weakEngine.Target.Preallocate<T>(groupID, size);
_weakEngine.Target.Preallocate<T>((int)groupID, size);
}
}
}

+ 15
- 2
Svelto.ECS/ExclusiveGroups.cs View File

@@ -1,7 +1,20 @@
namespace Svelto.ECS.Internal
namespace Svelto.ECS
{
static class ExclusiveGroups
public class ExclusiveGroups
{
internal const int StandardEntity = int.MaxValue;

public ExclusiveGroups()
{
_id = _globalId++;
}
public static explicit operator int(ExclusiveGroups group) // explicit byte to digit conversion operator
{
return group._id;
}

readonly int _id;
static int _globalId;
}
}

+ 11
- 5
Svelto.ECS/IEntityFactory.cs View File

@@ -6,18 +6,24 @@ namespace Svelto.ECS
/// an EnginesRoot reference cannot be held by anything else than the Composition Root
/// where it has been created. IEntityFactory and IEntityFunctions allow a weakreference
/// of the EnginesRoot to be passed around.
///
/// ExclusiveGroups must be used in your game like:
/// static class GameExclusiveGroup
///{
/// public static readonly ExclusiveGroups PlayerEntitiesGroup = new ExclusiveGroups();
///}
///
/// </summary>
public interface IEntityFactory
{

/// <summary>
/// <summary>
///where performance is critical, you may wish to pre allocate the space needed
///to store the entities
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="size"></param>
void PreallocateEntitySpace<T>(int size) where T : IEntityDescriptor, new();
void PreallocateEntitySpace<T>(int groupID, int size) where T : IEntityDescriptor, new();
void PreallocateEntitySpace<T>(ExclusiveGroups groupID, int size) where T : IEntityDescriptor, new();
/// <summary>
/// The EntityDescriptor doesn't need to be ever instantiated. It just describes the Entity
@@ -41,7 +47,7 @@ namespace Svelto.ECS
/// <param name="groupID"></param>
/// <param name="ed"></param>
/// <param name="implementors"></param>
EntityStructInitializer BuildEntity<T>(int entityID, int groupID, object[] implementors) where T:IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroups groupID, object[] implementors) where T:IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(EGID egid, object[] implementors) where T:IEntityDescriptor, new();

@@ -53,7 +59,7 @@ namespace Svelto.ECS
/// <param name="entityDescriptor"></param>
/// <param name="implementors"></param>
///
EntityStructInitializer BuildEntity(int entityID, int groupID, IEntityBuilder[] entityToBuild, object[] implementors);
EntityStructInitializer BuildEntity(int entityID, ExclusiveGroups groupID, IEntityBuilder[] entityToBuild, object[] implementors);
EntityStructInitializer BuildEntity(int entityID, IEntityBuilder[] entityToBuild, object[] implementors);
EntityStructInitializer BuildEntity(EGID egid, IEntityBuilder[] entityToBuild, object[] implementors);
}


Loading…
Cancel
Save