Browse Source

add new method interfaces to allow groupID being stored inside entitystructs as int

experimenting with implementor parameters by default set to null to promote the use of entity structs for building entities
tags/2.7
sebas77 6 years ago
parent
commit
8994a3c653
5 changed files with 52 additions and 26 deletions
  1. +6
    -6
      Svelto.ECS/EGID.cs
  2. +18
    -3
      Svelto.ECS/EntitiesDB.cs
  3. +9
    -9
      Svelto.ECS/ExclusiveGroups.cs
  4. +6
    -3
      Svelto.ECS/IEntitiesDB.cs
  5. +13
    -5
      Svelto.ECS/IEntityFactory.cs

+ 6
- 6
Svelto.ECS/EGID.cs View File

@@ -17,11 +17,6 @@ namespace Svelto.ECS
get { return (int) (_GID >> 32); }
}

internal EGID(int entityID, int groupID) : this()
{
_GID = MAKE_GLOBAL_ID(entityID, groupID);
}

public static bool operator ==(EGID obj1, EGID obj2)
{
return obj1._GID == obj2._GID;
@@ -32,7 +27,7 @@ namespace Svelto.ECS
return obj1._GID != obj2._GID;
}
public EGID(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) : this()
public EGID(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) : this()
{
_GID = MAKE_GLOBAL_ID(entityID, groupID);
}
@@ -71,5 +66,10 @@ namespace Svelto.ECS
{
return _GID.CompareTo(other._GID);
}
internal EGID(int entityID, int groupID) : this()
{
_GID = MAKE_GLOBAL_ID(entityID, groupID);
}
}
}

+ 18
- 3
Svelto.ECS/EntitiesDB.cs View File

@@ -100,6 +100,16 @@ namespace Svelto.ECS.Internal
return TryQueryEntitiesAndIndex<T>(new EGID(id, group), out index, out array);
}

public T[] QueryEntitiesAndIndex<T>(int id, int @group, out uint index) where T : IEntityStruct
{
return QueryEntitiesAndIndex<T>(new EGID(id, group), out index);
}

public bool TryQueryEntitiesAndIndex<T>(int id, int @group, out uint index, out T[] array) where T : IEntityStruct
{
return TryQueryEntitiesAndIndex<T>(new EGID(id, group), out index, out array);
}

public T QueryEntityView<T>(EGID entityGID) where T : class, IEntityStruct
{
T entityView;
@@ -118,10 +128,15 @@ namespace Svelto.ECS.Internal
return casted != null && casted.ContainsKey(entityGID.entityID);
}

public bool Exists (ExclusiveGroup.ExclusiveGroupStruct gid)
public bool Exists<T>(int id, int groupid) where T : IEntityStruct
{
//search for the group
return _groupEntityViewsDB.ContainsKey((int) @gid);
return Exists<T>(new EGID(id, groupid));
}

//search for the group
public bool Exists(ExclusiveGroup.ExclusiveGroupStruct gid)
{
return _groupEntityViewsDB.ContainsKey(@gid);
}

public bool HasAny<T>(int @group) where T : IEntityStruct


+ 9
- 9
Svelto.ECS/ExclusiveGroups.cs View File

@@ -28,17 +28,17 @@ namespace Svelto.ECS
_group = new ExclusiveGroupStruct(range);
}
public static implicit operator ExclusiveGroupStruct (ExclusiveGroup group)
public static implicit operator ExclusiveGroupStruct(ExclusiveGroup group)
{
return group._group;
}
public static explicit operator int (ExclusiveGroup group)
public static explicit operator int(ExclusiveGroup group)
{
return @group._group;
}

public static ExclusiveGroupStruct operator + (ExclusiveGroup a, int b)
public static ExclusiveGroupStruct operator+(ExclusiveGroup a, int b)
{
return a._group + b;
}
@@ -49,32 +49,32 @@ namespace Svelto.ECS
public struct ExclusiveGroupStruct : IEquatable<ExclusiveGroupStruct>, IComparable<ExclusiveGroupStruct>,
IEqualityComparer<ExclusiveGroupStruct>
{
public static bool operator == (ExclusiveGroupStruct c1, ExclusiveGroupStruct c2)
public static bool operator ==(ExclusiveGroupStruct c1, ExclusiveGroupStruct c2)
{
return c1.Equals(c2);
}

public static bool operator != (ExclusiveGroupStruct c1, ExclusiveGroupStruct c2)
public static bool operator !=(ExclusiveGroupStruct c1, ExclusiveGroupStruct c2)
{
return c1.Equals(c2) == false;
}

public bool Equals (ExclusiveGroupStruct other)
public bool Equals(ExclusiveGroupStruct other)
{
return other._id == _id;
}

public int CompareTo (ExclusiveGroupStruct other)
public int CompareTo(ExclusiveGroupStruct other)
{
return other._id.CompareTo(_id);
}

public bool Equals (ExclusiveGroupStruct x, ExclusiveGroupStruct y)
public bool Equals(ExclusiveGroupStruct x, ExclusiveGroupStruct y)
{
return x._id == y._id;
}

public int GetHashCode (ExclusiveGroupStruct obj)
public int GetHashCode(ExclusiveGroupStruct obj)
{
return _id.GetHashCode();
}


+ 6
- 3
Svelto.ECS/IEntitiesDB.cs View File

@@ -85,6 +85,8 @@ namespace Svelto.ECS
bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct;
T[] QueryEntitiesAndIndex<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index) where T : IEntityStruct;
bool TryQueryEntitiesAndIndex<T>(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index, out T[] array) where T : IEntityStruct;
T[] QueryEntitiesAndIndex<T>(int id, int group, out uint index) where T : IEntityStruct;
bool TryQueryEntitiesAndIndex<T>(int id, int group, out uint index, out T[] array) where T : IEntityStruct;
/// <summary>
/// ECS is meant to work on a set of Entities. Working on a single entity is sometime necessary, but using
/// the following functions inside a loop would be a mistake as performance can be significantly impacted
@@ -95,13 +97,14 @@ namespace Svelto.ECS
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
void ExecuteOnEntity<T>(EGID egid, EntityAction<T> action) where T : IEntityStruct;
void ExecuteOnEntity<T>(int id, int groupid, EntityAction<T> action) where T : IEntityStruct;
void ExecuteOnEntity<T>(int id, int groupid, EntityAction<T> action) where T : IEntityStruct;
void ExecuteOnEntity<T>(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, EntityAction<T> action) where T : IEntityStruct;
void ExecuteOnEntity<T, W>(EGID egid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
void ExecuteOnEntity<T, W>(int id, int groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
void ExecuteOnEntity<T, W>(EGID egid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
void ExecuteOnEntity<T, W>(int id, int groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;
void ExecuteOnEntity<T, W>(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;

bool Exists<T>(EGID egid) where T : IEntityStruct;
bool Exists<T>(int id, int groupid) where T : IEntityStruct;
bool Exists (ExclusiveGroup.ExclusiveGroupStruct gid);
bool HasAny<T>(int group) where T:IEntityStruct;


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

@@ -22,7 +22,8 @@ namespace Svelto.ECS
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="size"></param>
void PreallocateEntitySpace<T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, int size) where T : IEntityDescriptor, new();
void PreallocateEntitySpace<T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, int size)
where T : IEntityDescriptor, new();
/// <summary>
/// The EntityDescriptor doesn't need to be ever instantiated. It just describes the Entity
@@ -38,8 +39,11 @@ namespace Svelto.ECS
/// <param name="groupStructId"></param>
/// <param name="ed"></param>
/// <param name="implementors"></param>
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, object[] implementors) where T:IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(EGID egid, object[] implementors) where T:IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId,
object[] implementors = null)
where T : IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(EGID egid, object[] implementors = null)
where T:IEntityDescriptor, new();
/// <summary>
/// When the type of the entity is not known (this is a special case!) an EntityDescriptorInfo
/// can be built in place of the generic parameter T.
@@ -48,7 +52,11 @@ namespace Svelto.ECS
/// <param name="entityDescriptor"></param>
/// <param name="implementors"></param>
///
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, T descriptorEntity, object[] implementors) where T:IEntityDescriptor;
EntityStructInitializer BuildEntity<T>(EGID egid, T entityDescriptor, object[] implementors) where T:IEntityDescriptor;
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId,
T descriptorEntity,
object[] implementors = null)
where T : IEntityDescriptor;
EntityStructInitializer BuildEntity<T>(EGID egid, T entityDescriptor, object[] implementors = null)
where T : IEntityDescriptor;
}
}

Loading…
Cancel
Save