diff --git a/Svelto.ECS/EGID.cs b/Svelto.ECS/EGID.cs index d30830a..cda04eb 100644 --- a/Svelto.ECS/EGID.cs +++ b/Svelto.ECS/EGID.cs @@ -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); + } } } \ No newline at end of file diff --git a/Svelto.ECS/EntitiesDB.cs b/Svelto.ECS/EntitiesDB.cs index 983f3f9..ffed7cf 100644 --- a/Svelto.ECS/EntitiesDB.cs +++ b/Svelto.ECS/EntitiesDB.cs @@ -100,6 +100,16 @@ namespace Svelto.ECS.Internal return TryQueryEntitiesAndIndex(new EGID(id, group), out index, out array); } + public T[] QueryEntitiesAndIndex(int id, int @group, out uint index) where T : IEntityStruct + { + return QueryEntitiesAndIndex(new EGID(id, group), out index); + } + + public bool TryQueryEntitiesAndIndex(int id, int @group, out uint index, out T[] array) where T : IEntityStruct + { + return TryQueryEntitiesAndIndex(new EGID(id, group), out index, out array); + } + public T QueryEntityView(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(int id, int groupid) where T : IEntityStruct { - //search for the group - return _groupEntityViewsDB.ContainsKey((int) @gid); + return Exists(new EGID(id, groupid)); + } + + //search for the group + public bool Exists(ExclusiveGroup.ExclusiveGroupStruct gid) + { + return _groupEntityViewsDB.ContainsKey(@gid); } public bool HasAny(int @group) where T : IEntityStruct diff --git a/Svelto.ECS/ExclusiveGroups.cs b/Svelto.ECS/ExclusiveGroups.cs index 8550e87..bcc254d 100644 --- a/Svelto.ECS/ExclusiveGroups.cs +++ b/Svelto.ECS/ExclusiveGroups.cs @@ -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, IComparable, IEqualityComparer { - 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(); } diff --git a/Svelto.ECS/IEntitiesDB.cs b/Svelto.ECS/IEntitiesDB.cs index 50c1841..13741b1 100644 --- a/Svelto.ECS/IEntitiesDB.cs +++ b/Svelto.ECS/IEntitiesDB.cs @@ -85,6 +85,8 @@ namespace Svelto.ECS bool TryQueryEntitiesAndIndex(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct; T[] QueryEntitiesAndIndex(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index) where T : IEntityStruct; bool TryQueryEntitiesAndIndex(int id, ExclusiveGroup.ExclusiveGroupStruct group, out uint index, out T[] array) where T : IEntityStruct; + T[] QueryEntitiesAndIndex(int id, int group, out uint index) where T : IEntityStruct; + bool TryQueryEntitiesAndIndex(int id, int group, out uint index, out T[] array) where T : IEntityStruct; /// /// 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 /// /// void ExecuteOnEntity(EGID egid, EntityAction action) where T : IEntityStruct; - void ExecuteOnEntity(int id, int groupid, EntityAction action) where T : IEntityStruct; + void ExecuteOnEntity(int id, int groupid, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, EntityAction action) where T : IEntityStruct; - void ExecuteOnEntity(EGID egid, ref W value, EntityAction action) where T : IEntityStruct; - void ExecuteOnEntity(int id, int groupid, ref W value, EntityAction action) where T : IEntityStruct; + void ExecuteOnEntity(EGID egid, ref W value, EntityAction action) where T : IEntityStruct; + void ExecuteOnEntity(int id, int groupid, ref W value, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, ExclusiveGroup.ExclusiveGroupStruct groupid, ref W value, EntityAction action) where T : IEntityStruct; bool Exists(EGID egid) where T : IEntityStruct; + bool Exists(int id, int groupid) where T : IEntityStruct; bool Exists (ExclusiveGroup.ExclusiveGroupStruct gid); bool HasAny(int group) where T:IEntityStruct; diff --git a/Svelto.ECS/IEntityFactory.cs b/Svelto.ECS/IEntityFactory.cs index 48b9a22..8ef811a 100644 --- a/Svelto.ECS/IEntityFactory.cs +++ b/Svelto.ECS/IEntityFactory.cs @@ -22,7 +22,8 @@ namespace Svelto.ECS /// /// /// - void PreallocateEntitySpace(ExclusiveGroup.ExclusiveGroupStruct groupStructId, int size) where T : IEntityDescriptor, new(); + void PreallocateEntitySpace(ExclusiveGroup.ExclusiveGroupStruct groupStructId, int size) + where T : IEntityDescriptor, new(); /// /// The EntityDescriptor doesn't need to be ever instantiated. It just describes the Entity @@ -38,8 +39,11 @@ namespace Svelto.ECS /// /// /// - EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, object[] implementors) where T:IEntityDescriptor, new(); - EntityStructInitializer BuildEntity(EGID egid, object[] implementors) where T:IEntityDescriptor, new(); + EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, + object[] implementors = null) + where T : IEntityDescriptor, new(); + EntityStructInitializer BuildEntity(EGID egid, object[] implementors = null) + where T:IEntityDescriptor, new(); /// /// 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 /// /// /// - EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, T descriptorEntity, object[] implementors) where T:IEntityDescriptor; - EntityStructInitializer BuildEntity(EGID egid, T entityDescriptor, object[] implementors) where T:IEntityDescriptor; + EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, + T descriptorEntity, + object[] implementors = null) + where T : IEntityDescriptor; + EntityStructInitializer BuildEntity(EGID egid, T entityDescriptor, object[] implementors = null) + where T : IEntityDescriptor; } }