diff --git a/.gitmodules b/.gitmodules index e69de29..532d6f0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Svelto.Common"] + path = Svelto.Common + url = https://github.com/sebas77/Svelto.Common.git diff --git a/Svelto.Common b/Svelto.Common index a1f5f55..5b756d5 160000 --- a/Svelto.Common +++ b/Svelto.Common @@ -1 +1 @@ -Subproject commit a1f5f55c8b28f66ed033fa02c425dfa16c3c30e6 +Subproject commit 5b756d57920c83a8e31dad9eedee8b629c6cb245 diff --git a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs index 00480be..ef83f92 100644 --- a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs +++ b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs @@ -115,22 +115,30 @@ namespace Svelto.ECS.Internal return new TypeSafeDictionary(); } - public void ExecuteOnEntityView(int entityGidEntityId, ref W value, ActionRef action) + public bool ExecuteOnEntityView(int entityGidEntityId, ref W value, ActionRef action) { uint findIndex; if (FindIndex(entityGidEntityId, out findIndex)) { action(ref _values[findIndex], ref value); + + return true; } + + return false; } - public void ExecuteOnEntityView(int entityGidEntityId, ActionRef action) + public bool ExecuteOnEntityView(int entityGidEntityId, ActionRef action) { uint findIndex; if (FindIndex(entityGidEntityId, out findIndex)) { action(ref _values[findIndex]); + + return true; } + + return false; } public uint FindElementIndex(int entityGidEntityId) diff --git a/Svelto.ECS/EntitiesDB.cs b/Svelto.ECS/EntitiesDB.cs index 7619fd4..3a0712e 100644 --- a/Svelto.ECS/EntitiesDB.cs +++ b/Svelto.ECS/EntitiesDB.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Security.Principal; using Svelto.DataStructures; using Svelto.Utilities; @@ -75,11 +74,20 @@ namespace Svelto.ECS.Internal return QueryEntities(entityGID.groupID, out count); } + public bool TryQueryEntitiesAndIndex(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct + { + if ((array = QueryEntitiesAndIndex(entityGid, out index)) != null) + return true; + + return false; + } + public T QueryEntityView(EGID entityGID) where T : class, IEntityStruct { T entityView; - TryQueryEntityViewInGroup(entityGID, out entityView); + if (TryQueryEntityViewInGroup(entityGID, out entityView) == false) + throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID)); return entityView; } @@ -87,19 +95,27 @@ namespace Svelto.ECS.Internal public void ExecuteOnEntity(EGID entityGID, ref W value, ActionRef action) where T : IEntityStruct { TypeSafeDictionary casted; - if (!FindSafeDictionary(entityGID, out casted)) return; + if (FindSafeDictionary(entityGID, out casted)) + { + if (casted != null) + if (casted.ExecuteOnEntityView(entityGID.entityID, ref value, action) == true) + return; + } - if (casted != null) - casted.ExecuteOnEntityView(entityGID.entityID, ref value, action); + throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID)); } public void ExecuteOnEntity(EGID entityGID, ActionRef action) where T : IEntityStruct { TypeSafeDictionary casted; - if (!FindSafeDictionary(entityGID, out casted)) return; + if (FindSafeDictionary(entityGID, out casted)) + { + if (casted != null) + if (casted.ExecuteOnEntityView(entityGID.entityID, action) == true) + return; + } - if (casted != null) - casted.ExecuteOnEntityView(entityGID.entityID, action); + throw new Exception("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID)); } public void ExecuteOnEntity(int id, ActionRef action) where T : IEntityStruct diff --git a/Svelto.ECS/EntityViewUtility.cs b/Svelto.ECS/EntityViewUtility.cs index 1fe591b..33d1840 100644 --- a/Svelto.ECS/EntityViewUtility.cs +++ b/Svelto.ECS/EntityViewUtility.cs @@ -52,7 +52,7 @@ static class EntityViewUtility #if DEBUG && !PROFILER else { - Utility.Console.LogError(NULL_IMPLEMENTOR_ERROR.FastConcat("Type ", entityDescriptorName, " entityView ", entityBuilder.GetEntityType().ToString())); + Utility.Console.Log(NULL_IMPLEMENTOR_ERROR.FastConcat("Type ", entityDescriptorName, " entityView ", entityBuilder.GetEntityType().ToString())); } #endif } diff --git a/Svelto.ECS/ExclusiveGroups.cs b/Svelto.ECS/ExclusiveGroups.cs index e02a001..d9c6980 100644 --- a/Svelto.ECS/ExclusiveGroups.cs +++ b/Svelto.ECS/ExclusiveGroups.cs @@ -6,7 +6,14 @@ public ExclusiveGroup() { - _id = _globalId++; + _id = _globalId; + _globalId += 1; + } + + public ExclusiveGroup(int range) + { + _id = _globalId; + _globalId += range; } public static explicit operator int(ExclusiveGroup group) // explicit byte to digit conversion operator @@ -15,6 +22,6 @@ } readonly int _id; - static int _globalId; + static int _globalId; } } \ No newline at end of file diff --git a/Svelto.ECS/IEntitiesDB.cs b/Svelto.ECS/IEntitiesDB.cs index 8efd084..54fdcdd 100644 --- a/Svelto.ECS/IEntitiesDB.cs +++ b/Svelto.ECS/IEntitiesDB.cs @@ -33,7 +33,9 @@ namespace Svelto.ECS //to use with EntityViews, EntityStructs and EntityViewStructs T[] QueryEntities(out int count) where T : IEntityStruct; T[] QueryEntities(int group, out int count) where T : IEntityStruct; + T[] QueryEntitiesAndIndex(EGID entityGid, out uint index) where T : IEntityStruct; + bool TryQueryEntitiesAndIndex(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct; //to use with EntityViews, EntityStructs and EntityViewStructs void ExecuteOnEntity(EGID egid, ref W value, ActionRef action) where T : IEntityStruct; diff --git a/Svelto.ECS/StaticEntityDescriptorInfo.cs b/Svelto.ECS/StaticEntityDescriptorInfo.cs index 47c43cf..8e85a32 100644 --- a/Svelto.ECS/StaticEntityDescriptorInfo.cs +++ b/Svelto.ECS/StaticEntityDescriptorInfo.cs @@ -23,7 +23,7 @@ namespace Svelto.ECS public static readonly StaticEntityDescriptorInfo descriptor = new StaticEntityDescriptorInfo(new TType()); } - public struct DynamicEntityDescriptorInfo where TType : IEntityDescriptor, new() + public struct DynamicEntityDescriptorInfo:IEntityDescriptor where TType : IEntityDescriptor, new() { public DynamicEntityDescriptorInfo(FasterList extraEntityViews) : this() { @@ -42,7 +42,7 @@ namespace Svelto.ECS public IEntityBuilder[] entitiesToBuild { get; private set; } } - public struct StaticEntityDescriptorInfo where TType : IEntityDescriptor + public struct StaticEntityDescriptorInfo: IEntityDescriptor where TType : IEntityDescriptor { internal StaticEntityDescriptorInfo(TType descriptor) : this() {