diff --git a/.gitmodules b/.gitmodules index 532d6f0..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "Svelto.Common"] - path = Svelto.Common - url = https://github.com/sebas77/Svelto.Common.git diff --git a/README.md b/README.md index e74f30a..0d3f59b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Note: I included the IoC articles just to show how I shifted over the years from **Official Chat** -* https://discord.gg/3qAdjDb +* https://gitter.im/Svelto-ECS/Lobby +* https://discord.gg/3qAdjDb (Discord chat is under test, if it will become more popular I will drop gitter support) **NED-Studio Svelto ECS inspector (WIP)** diff --git a/Svelto.Common b/Svelto.Common deleted file mode 160000 index 5548758..0000000 --- a/Svelto.Common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 554875838f1743017981df428243bba80fe3ece1 diff --git a/Svelto.ECS/EGID.cs b/Svelto.ECS/EGID.cs index e4e5612..857acc9 100644 --- a/Svelto.ECS/EGID.cs +++ b/Svelto.ECS/EGID.cs @@ -24,11 +24,11 @@ namespace Svelto.ECS _GID = MAKE_GLOBAL_ID(entityID, groupID); } - public EGID(int entityID) : this() + public EGID(int entityID, ExclusiveGroup groupID) : this() { - _GID = MAKE_GLOBAL_ID(entityID, ExclusiveGroup.StandardEntitiesGroup); + _GID = MAKE_GLOBAL_ID(entityID, (int) groupID); } - + static long MAKE_GLOBAL_ID(int entityId, int groupId) { return (long)groupId << 32 | ((long)(uint)entityId & 0xFFFFFFFF); diff --git a/Svelto.ECS/EnginesRoot.Engines.cs b/Svelto.ECS/EnginesRoot.Engines.cs index 45a3085..36fe83d 100644 --- a/Svelto.ECS/EnginesRoot.Engines.cs +++ b/Svelto.ECS/EnginesRoot.Engines.cs @@ -40,11 +40,10 @@ namespace Svelto.ECS _otherEngines = new FasterList(); _groupEntityDB = new Dictionary>(); - _groupEntityDB[ExclusiveGroup.StandardEntitiesGroup] = new Dictionary(); _groupedGroups = new Dictionary>(); _groupedEntityToAdd = new DoubleBufferedEntitiesToAdd>>(); - _DB = new entitiesDB(_groupEntityDB, _groupedGroups); + _DB = new EntitiesDB(_groupEntityDB, _groupedGroups); _scheduler = entityViewScheduler; _scheduler.Schedule(new WeakAction(SubmitEntityViews)); diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index 3ba4a9c..381074a 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Diagnostics; using Svelto.DataStructures.Experimental; using Svelto.ECS.Internal; @@ -213,7 +214,7 @@ namespace Svelto.ECS return new EGID(firstID, toGroupId); } - readonly entitiesDB _DB; + readonly EntitiesDB _DB; int _newEntitiesBuiltToProcess; } diff --git a/Svelto.ECS/EnginesRoot.GenericEntityFactory.cs b/Svelto.ECS/EnginesRoot.GenericEntityFactory.cs index 1288ce0..9f3739d 100644 --- a/Svelto.ECS/EnginesRoot.GenericEntityFactory.cs +++ b/Svelto.ECS/EnginesRoot.GenericEntityFactory.cs @@ -1,4 +1,4 @@ -#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR +#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR using Svelto.ECS.Profiler; #endif @@ -15,11 +15,6 @@ namespace Svelto.ECS _weakEngine = weakReference; } - public EntityStructInitializer BuildEntity(int entityID, object[] implementors) where T : IEntityDescriptor, new() - { - return _weakEngine.Target.BuildEntity(new EGID(entityID), implementors); - } - public EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup groupID, object[] implementors) where T : IEntityDescriptor, new() { return _weakEngine.Target.BuildEntity(new EGID(entityID, (int)groupID), implementors); @@ -30,11 +25,6 @@ namespace Svelto.ECS return _weakEngine.Target.BuildEntity(egid, implementors); } - public EntityStructInitializer BuildEntity(int entityID, IEntityDescriptor descriptorEntity, object[] implementors) - { - return _weakEngine.Target.BuildEntity(new EGID(entityID), descriptorEntity, implementors); - } - public EntityStructInitializer BuildEntity(EGID egid, IEntityDescriptor descriptorEntity, object[] implementors) { return _weakEngine.Target.BuildEntity(egid, descriptorEntity, implementors); @@ -45,11 +35,6 @@ namespace Svelto.ECS return _weakEngine.Target.BuildEntity(new EGID(entityID, (int)groupID), descriptorEntity, implementors); } - public void PreallocateEntitySpace(int size) where T : IEntityDescriptor, new() - { - _weakEngine.Target.Preallocate(ExclusiveGroup.StandardEntitiesGroup, size); - } - public void PreallocateEntitySpace(ExclusiveGroup groupID, int size) where T : IEntityDescriptor, new() { _weakEngine.Target.Preallocate((int)groupID, size); diff --git a/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs b/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs index 31b2ba0..f689306 100644 --- a/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs +++ b/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs @@ -1,4 +1,4 @@ -using Svelto.ECS.Internal; +using Svelto.ECS.Internal; #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR using Svelto.ECS.Profiler; @@ -17,16 +17,16 @@ namespace Svelto.ECS _weakReference = weakReference; } - public void RemoveEntity(int entityID) where T : IEntityDescriptor, new() - { - _weakReference.Target.MoveEntity(new EGID(entityID)); - } - public void RemoveEntity(int entityID, int groupID) where T : IEntityDescriptor, new() { _weakReference.Target.MoveEntity(new EGID(entityID, groupID)); } + public void RemoveEntity(int entityID, ExclusiveGroup groupID) where T : IEntityDescriptor, new() + { + _weakReference.Target.MoveEntity(new EGID(entityID, (int) groupID)); + } + public void RemoveEntity(EGID entityEGID) where T : IEntityDescriptor, new() { _weakReference.Target.MoveEntity(entityEGID); @@ -37,25 +37,40 @@ namespace Svelto.ECS _weakReference.Target.RemoveGroupAndEntitiesFromDB(groupID); } + public void RemoveGroupAndEntities(ExclusiveGroup groupID) + { + _weakReference.Target.RemoveGroupAndEntitiesFromDB((int) groupID); + } + public EGID SwapEntityGroup(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new() { return _weakReference.Target.SwapEntityGroup(entityID, fromGroupID, toGroupID); } - public EGID SwapEntityGroup(EGID id, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new() + public EGID SwapEntityGroup(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new() + { + return _weakReference.Target.SwapEntityGroup(entityID, (int) fromGroupID, (int) toGroupID); + } + + public EGID SwapEntityGroup(EGID id, int toGroupID) where T : IEntityDescriptor, new() { return _weakReference.Target.SwapEntityGroup(id.entityID, id.groupID, toGroupID); } - public EGID SwapEntityGroup(int entityID, int toGroupID) where T : IEntityDescriptor, new() + public EGID SwapEntityGroup(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new() { - return _weakReference.Target.SwapEntityGroup(entityID, ExclusiveGroup.StandardEntitiesGroup, toGroupID); + return _weakReference.Target.SwapEntityGroup(id.entityID, id.groupID, (int) toGroupID); } public EGID SwapFirstEntityGroup(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new() { return _weakReference.Target.SwapFirstEntityInGroup( fromGroupID, toGroupID); } + + public EGID SwapFirstEntityGroup(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new() + { + return _weakReference.Target.SwapFirstEntityInGroup( (int) fromGroupID, (int) toGroupID); + } } } } \ No newline at end of file diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index 8ecd994..7d103f2 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Svelto.DataStructures.Experimental; using Svelto.ECS.Internal; @@ -19,14 +19,16 @@ namespace Svelto.ECS //are there new entities built to process? while ( _newEntitiesBuiltToProcess > 0) { - _newEntitiesBuiltToProcess = 0; //use other as source from now on //current will be use to write new entityViews _groupedEntityToAdd.Swap(); - //Note: if N entity of the same type are added on the same frame the Add callback is called N times on - //the same frame. if the Add calback builds a new entity, that entity will not be available in the - //database until the N callbacks are done. + //Note: if N entity of the same type are added on the same frame + //the Add callback is called N times on the same frame. + //if the Add calback builds a new entity, that entity will not + //be available in the database until the N callbacks are done + //solving it could be complicated as callback and database update + //must be interleaved. if (_groupedEntityToAdd.other.Count > 0) AddEntityViewsToTheDBAndSuitableEngines(_groupedEntityToAdd.other); @@ -36,6 +38,7 @@ namespace Svelto.ECS if (numberOfReenteringLoops > 5) throw new Exception("possible infinite loop found creating Entities inside IEntityViewsEngine Add method, please consider building entities outside IEntityViewsEngine Add method"); + _newEntitiesBuiltToProcess = 0; numberOfReenteringLoops++; } } diff --git a/Svelto.ECS/EntitiesDB.cs b/Svelto.ECS/EntitiesDB.cs index aa9fa6d..42431a5 100644 --- a/Svelto.ECS/EntitiesDB.cs +++ b/Svelto.ECS/EntitiesDB.cs @@ -2,24 +2,18 @@ using System; using System.Collections.Generic; using Svelto.DataStructures; using Svelto.DataStructures.Experimental; -using Svelto.Utilities; namespace Svelto.ECS.Internal { - partial class entitiesDB : IEntitiesDB + partial class EntitiesDB : IEntitiesDB { - internal entitiesDB(Dictionary> groupEntityViewsDB, + internal EntitiesDB(Dictionary> groupEntityViewsDB, Dictionary> groupedGroups) { _groupEntityViewsDB = groupEntityViewsDB; _groupedGroups = groupedGroups; } - public ReadOnlyCollectionStruct QueryEntityViews() where T:class, IEntityStruct - { - return QueryEntityViews(ExclusiveGroup.StandardEntitiesGroup); - } - public ReadOnlyCollectionStruct QueryEntityViews(int @group) where T:class, IEntityStruct { TypeSafeDictionary typeSafeDictionary; @@ -28,11 +22,6 @@ namespace Svelto.ECS.Internal return typeSafeDictionary.FasterValues; } - public T[] QueryEntities(out int count) where T : IEntityStruct - { - return QueryEntities(ExclusiveGroup.StandardEntitiesGroup, out count); - } - public T[] QueryEntities(int @group, out int count) where T : IEntityStruct { TypeSafeDictionary typeSafeDictionary; @@ -41,12 +30,12 @@ namespace Svelto.ECS.Internal return typeSafeDictionary.GetFasterValuesBuffer(out count); } - - public EGIDMapper QueryMappedEntities() where T : IEntityStruct + + public T[] QueryEntities(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct { - return QueryMappedEntities(ExclusiveGroup.StandardEntitiesGroup); + return QueryEntities((int) @group, out targetsCount); } - + public EGIDMapper QueryMappedEntities(int groupID) where T : IEntityStruct { TypeSafeDictionary typeSafeDictionary; @@ -63,6 +52,11 @@ namespace Svelto.ECS.Internal return mapper; } + public EGIDMapper QueryMappedEntities(ExclusiveGroup groupID) where T : IEntityStruct + { + return QueryMappedEntities((int) groupID); + } + public T[] QueryEntitiesAndIndex(EGID entityGID, out uint index) where T : IEntityStruct { T[] array; @@ -98,11 +92,6 @@ namespace Svelto.ECS.Internal return casted != null && casted.ContainsKey(entityGID.entityID); } - public bool HasAny() where T : IEntityStruct - { - return HasAny(ExclusiveGroup.StandardEntitiesGroup); - } - public bool HasAny(int @group) where T : IEntityStruct { int count; @@ -110,6 +99,11 @@ namespace Svelto.ECS.Internal return count > 0; } + public bool HasAny(ExclusiveGroup @group) where T : IEntityStruct + { + return HasAny((int) group); + } + public bool TryQueryEntityView(EGID entityegid, out T entityView) where T : class, IEntityStruct { return TryQueryEntityViewInGroupInternal(entityegid, out entityView); diff --git a/Svelto.ECS/ExclusiveGroups.cs b/Svelto.ECS/ExclusiveGroups.cs index 2984efd..6c3b906 100644 --- a/Svelto.ECS/ExclusiveGroups.cs +++ b/Svelto.ECS/ExclusiveGroups.cs @@ -1,4 +1,4 @@ -namespace Svelto.ECS +namespace Svelto.ECS { /// /// Exclusive Groups guarantee that the GroupID is unique. @@ -13,8 +13,6 @@ public class ExclusiveGroup { - internal const int StandardEntitiesGroup = int.MaxValue; - public ExclusiveGroup() { _id = _globalId; diff --git a/Svelto.ECS/ExecuteOnEntitiesDB.cs b/Svelto.ECS/ExecuteOnEntitiesDB.cs index a32b9d0..aa37e15 100644 --- a/Svelto.ECS/ExecuteOnEntitiesDB.cs +++ b/Svelto.ECS/ExecuteOnEntitiesDB.cs @@ -1,10 +1,14 @@ using Svelto.DataStructures.Experimental; -using Svelto.Utilities; namespace Svelto.ECS.Internal { - partial class entitiesDB + partial class EntitiesDB { + public void ExecuteOnEntity(int id, ExclusiveGroup groupid, EntityAction action) where T : IEntityStruct + { + ExecuteOnEntity(id, (int)groupid, action); + } + public void ExecuteOnEntity(EGID entityGID, ref W value, EntityAction action) where T : IEntityStruct { TypeSafeDictionary casted; @@ -35,49 +39,25 @@ namespace Svelto.ECS.Internal .FastConcat(entityGID.groupID)); } - public void ExecuteOnEntity(int id, EntityAction action) where T : IEntityStruct - { - ExecuteOnEntity(new EGID(id, ExclusiveGroup.StandardEntitiesGroup), action); - } - public void ExecuteOnEntity(int id, int groupid, EntityAction action) where T : IEntityStruct { ExecuteOnEntity(new EGID(id, groupid), action); } - public void ExecuteOnEntity(int id, ref W value, EntityAction action) where T : IEntityStruct - { - ExecuteOnEntity(new EGID(id, ExclusiveGroup.StandardEntitiesGroup), ref value, action); - } - public void ExecuteOnEntity(int id, int groupid, ref W value, EntityAction action) where T : IEntityStruct { ExecuteOnEntity(new EGID(id, groupid), ref value, action); } - - //---------------------------------------------------------------------------------------------------------- - public void ExecuteOnEntities(int groupID, EntitiesAction action) where T : IEntityStruct + public void ExecuteOnEntity(int id, ExclusiveGroup groupid, ref W value, EntityAction action) where T : IEntityStruct { - int count; - TypeSafeDictionary typeSafeDictionary; - if (QueryEntitySafeDictionary(@groupID, out typeSafeDictionary) == false) return; - - var entities = typeSafeDictionary.GetFasterValuesBuffer(out count); - - for (var i = 0; i < count; i++) - action(ref entities[i], i); - - SafetyChecks(typeSafeDictionary, count); + ExecuteOnEntity(id, (int)groupid, ref value, action); } - public void ExecuteOnEntities(EntitiesAction action) where T : IEntityStruct - { - ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, action); - } + //---------------------------------------------------------------------------------------------------------- - public void ExecuteOnEntities(int groupID, ref W value, EntitiesAction action) where T : IEntityStruct + public void ExecuteOnEntities(int groupID, EntitiesAction action) where T : IEntityStruct { int count; TypeSafeDictionary typeSafeDictionary; @@ -86,76 +66,38 @@ namespace Svelto.ECS.Internal var entities = typeSafeDictionary.GetFasterValuesBuffer(out count); for (var i = 0; i < count; i++) - action(ref entities[i], ref value, i); + action(ref entities[i], this, i); SafetyChecks(typeSafeDictionary, count); } - public void ExecuteOnEntities(ref W value, EntitiesAction action) where T : IEntityStruct + public void ExecuteOnEntities(ExclusiveGroup groupID, EntitiesAction action) where T : IEntityStruct { - ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action); + ExecuteOnEntities((int)groupID, action); } - public void ExecuteOnEntities(W value, EntitiesAction action) - where T : IEntityStruct where T1 : IEntityStruct - { - ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action); - } - - public void ExecuteOnEntities(int group, EntitiesAction action) - where T : IEntityStruct where T1 : IEntityStruct - { - int count; - TypeSafeDictionary typeSafeDictionary; - if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return; - - var entities = typeSafeDictionary.GetFasterValuesBuffer(out count); - - EGIDMapper map = QueryMappedEntities(@group); - - for (var i = 0; i < count; i++) - { - uint index; - action(ref entities[i], ref map.entities(entities[i].ID, out index)[index], i); - } - - SafetyChecks(typeSafeDictionary, count); - } - - public void ExecuteOnEntities(int group, ref W value, EntitiesAction action) - where T : IEntityStruct where T1 : IEntityStruct + public void ExecuteOnEntities(int groupID, ref W value, EntitiesAction action) where T : IEntityStruct { int count; TypeSafeDictionary typeSafeDictionary; - if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return; + if (QueryEntitySafeDictionary(@groupID, out typeSafeDictionary) == false) return; var entities = typeSafeDictionary.GetFasterValuesBuffer(out count); - EGIDMapper map = QueryMappedEntities(@group); - for (var i = 0; i < count; i++) - { - uint index; - action(ref entities[i], ref map.entities(entities[i].ID, out index)[index], ref value, i); - } + action(ref entities[i], ref value, this, i); SafetyChecks(typeSafeDictionary, count); } - public void ExecuteOnEntities(EntitiesAction action) where T : IEntityStruct where T1 : IEntityStruct + public void ExecuteOnEntities(ExclusiveGroup groupID, ref W value, EntitiesAction action) where T : IEntityStruct { - ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, action); + ExecuteOnEntities((int)groupID, ref value, action); } - public void ExecuteOnEntities(ref W value, EntitiesAction action) - where T : IEntityStruct where T1 : IEntityStruct - { - ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action); - } - //----------------------------------------------------------------------------------------------------------- - public void ExecuteOnAllEntities(EntityAction action) where T : IEntityStruct + public void ExecuteOnAllEntities(ExclusiveGroup[] damageableGroups, AllEntitiesAction action) where T : IEntityStruct { var type = typeof(T); FasterDictionary dic; @@ -174,14 +116,14 @@ namespace Svelto.ECS.Internal var entities = casted.GetFasterValuesBuffer(out innerCount); for (int i = 0; i < innerCount; i++) - action(ref entities[i]); + action(ref entities[i], this); SafetyChecks(casted, innerCount); } } } - public void ExecuteOnAllEntities(ref W value, EntityAction action) where T : IEntityStruct + public void ExecuteOnAllEntities(ref W value, AllEntitiesAction action) where T : IEntityStruct { var type = typeof(T); FasterDictionary dic; @@ -200,13 +142,27 @@ namespace Svelto.ECS.Internal var entities = casted.GetFasterValuesBuffer(out innerCount); for (int i = 0; i < innerCount; i++) - action(ref entities[i], ref value); + action(ref entities[i], ref value, this); SafetyChecks(casted, innerCount); } } } + public void ExecuteOnAllEntities(ExclusiveGroup[] groups, EntitiesAction action) where T : IEntityStruct + { + foreach (var group in groups) + { + ExecuteOnEntities(group, action); + } + } + public void ExecuteOnAllEntities(ExclusiveGroup[] groups, ref W value, EntitiesAction action) where T : IEntityStruct + { + foreach (var group in groups) + { + ExecuteOnEntities(group, ref value, action); + } + } } } \ No newline at end of file diff --git a/Svelto.ECS/Extensions/Unity/UnitySumbmissionEntityViewScheduler .cs b/Svelto.ECS/Extensions/Unity/UnityEntitySubmissionScheduler.cs similarity index 63% rename from Svelto.ECS/Extensions/Unity/UnitySumbmissionEntityViewScheduler .cs rename to Svelto.ECS/Extensions/Unity/UnityEntitySubmissionScheduler.cs index 9d66549..fbaa798 100644 --- a/Svelto.ECS/Extensions/Unity/UnitySumbmissionEntityViewScheduler .cs +++ b/Svelto.ECS/Extensions/Unity/UnityEntitySubmissionScheduler.cs @@ -5,17 +5,12 @@ using UnityEngine; namespace Svelto.ECS.Schedulers.Unity { - //The EntityViewSubmissionScheduler has been introduced to make - //the entityView submission logic platform indipendent. - //Please don't be tempted to create your own submission to - //adapt to your game level code design. For example, - //you may be tempted to write a submission logic to submit - //the entityViews immediatly just because convenient for your game - //logic. This is not how it works. + //The EntitySubmissionScheduler has been introduced to make the entity views submission logic platform independent + //You can customize the scheduler if you wish - public class UnitySumbmissionEntityViewScheduler : EntitySubmissionScheduler + public class UnityEntitySubmissionScheduler : EntitySubmissionScheduler { - public UnitySumbmissionEntityViewScheduler() + public UnityEntitySubmissionScheduler() { GameObject go = new GameObject("ECSScheduler"); diff --git a/Svelto.ECS/IEntitiesDB.cs b/Svelto.ECS/IEntitiesDB.cs index c5571da..ef3caf3 100644 --- a/Svelto.ECS/IEntitiesDB.cs +++ b/Svelto.ECS/IEntitiesDB.cs @@ -4,12 +4,6 @@ namespace Svelto.ECS { public interface IEntitiesDB { - /// - /// All the EntityView related methods are left for back compatibility, but - /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct - /// over EntityView - /// - ReadOnlyCollectionStruct QueryEntityViews() where T : class, IEntityStruct; /// /// All the EntityView related methods are left for back compatibility, but /// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct @@ -36,8 +30,8 @@ namespace Svelto.ECS /// /// /// - T[] QueryEntities(out int count) where T : IEntityStruct; - T[] QueryEntities(int group, out int count) where T : IEntityStruct; + T[] QueryEntities(int group, out int count) where T : IEntityStruct; + T[] QueryEntities(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct; /// /// this version returns a mapped version of the entity array so that is possible to find the /// index of the entity inside the returned buffer through it's EGID @@ -48,7 +42,7 @@ namespace Svelto.ECS /// /// EGIDMapper QueryMappedEntities(int groupID) where T : IEntityStruct; - EGIDMapper QueryMappedEntities() where T : IEntityStruct; + EGIDMapper QueryMappedEntities(ExclusiveGroup groupID) where T : IEntityStruct; /// /// Execute an action on entities. Be sure that the action is not capturing variables /// otherwise you will allocate memory which will have a great impact on the execution performance. @@ -60,31 +54,22 @@ namespace Svelto.ECS /// /// void ExecuteOnEntities(int groupID, EntitiesAction action) where T : IEntityStruct; - void ExecuteOnEntities(EntitiesAction action) where T : IEntityStruct; + void ExecuteOnEntities(ExclusiveGroup groupID, EntitiesAction action) where T : IEntityStruct; void ExecuteOnEntities(int groupID, ref W value, EntitiesAction action) where T : IEntityStruct; - void ExecuteOnEntities(ref W value, EntitiesAction action) where T : IEntityStruct; - /// - /// This specialized version allows to execute actions on multiple entity views or entity structs - /// Safety checks are in place. This function doesn't guarantee cache - /// friendliness even if just EntityStructs are used. - /// - /// - /// - /// - /// - void ExecuteOnEntities(int groupID, EntitiesAction action) where T : IEntityStruct where T1 : IEntityStruct; - void ExecuteOnEntities(EntitiesAction action) where T : IEntityStruct where T1 : IEntityStruct; - void ExecuteOnEntities(int groupID, ref W value, EntitiesAction action) where T : IEntityStruct where T1 : IEntityStruct; - void ExecuteOnEntities(ref W value, EntitiesAction action) where T : IEntityStruct where T1 : IEntityStruct; + void ExecuteOnEntities(ExclusiveGroup groupID, ref W value, EntitiesAction action) where T : IEntityStruct; + /// /// Execute an action on ALL the entities regardless the group. This function doesn't guarantee cache /// friendliness even if just EntityStructs are used. /// Safety checks are in place /// + /// /// /// - void ExecuteOnAllEntities(EntityAction action) where T : IEntityStruct; - void ExecuteOnAllEntities(ref W value, EntityAction action) where T : IEntityStruct; + void ExecuteOnAllEntities(ExclusiveGroup[] damageableGroups, AllEntitiesAction action) where T : IEntityStruct; + void ExecuteOnAllEntities(ref W value, AllEntitiesAction action) where T : IEntityStruct; + void ExecuteOnAllEntities(ExclusiveGroup[] groups, EntitiesAction action) where T : IEntityStruct; + void ExecuteOnAllEntities(ExclusiveGroup[] groups, ref W value, EntitiesAction action) 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 @@ -106,21 +91,24 @@ namespace Svelto.ECS /// /// void ExecuteOnEntity(EGID egid, EntityAction action) where T : IEntityStruct; - void ExecuteOnEntity(int id, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(int id, int groupid, EntityAction action) where T : IEntityStruct; + void ExecuteOnEntity(int id, ExclusiveGroup groupid, EntityAction action) where T : IEntityStruct; void ExecuteOnEntity(EGID egid, ref W value, EntityAction action) where T : IEntityStruct; - void ExecuteOnEntity(int id, 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 groupid, ref W value, EntityAction action) where T : IEntityStruct; bool Exists(EGID egid) where T : IEntityStruct; - bool HasAny() where T:IEntityStruct; bool HasAny(int group) where T:IEntityStruct; + bool HasAny(ExclusiveGroup group) where T:IEntityStruct; } - public delegate void EntityAction(ref T target, ref W value); - public delegate void EntityAction(ref T target); - public delegate void EntitiesAction(ref T target, ref T1 target1, ref W value, int index); - public delegate void EntitiesAction(ref T target, ref W value, int index); - public delegate void EntitiesAction(ref T target, int index); + public delegate void EntityAction(ref T target, ref W value); + public delegate void EntityAction(ref T target); + + public delegate void AllEntitiesAction(ref T target, ref W value, IEntitiesDB entitiesDb); + public delegate void AllEntitiesAction(ref T target, IEntitiesDB entitiesDb); + + public delegate void EntitiesAction(ref T target, ref W value, IEntitiesDB entitiesDb, int index); + public delegate void EntitiesAction(ref T target, IEntitiesDB entitiesDb, int index); } \ No newline at end of file diff --git a/Svelto.ECS/IEntityFactory.cs b/Svelto.ECS/IEntityFactory.cs index 1aa7b3c..0b54848 100644 --- a/Svelto.ECS/IEntityFactory.cs +++ b/Svelto.ECS/IEntityFactory.cs @@ -22,7 +22,6 @@ namespace Svelto.ECS /// /// /// - void PreallocateEntitySpace(int size) where T : IEntityDescriptor, new(); void PreallocateEntitySpace(ExclusiveGroup groupID, int size) where T : IEntityDescriptor, new(); /// @@ -30,15 +29,7 @@ namespace Svelto.ECS /// itself in terms of EntityViews to build. The Implementors are passed to fill the /// references of the EntityViews components. Please read the articles on my blog /// to understand better the terminologies - /// - /// - /// - /// - EntityStructInitializer BuildEntity(int entityID, object[] implementors) where T:IEntityDescriptor, new(); - - - /// - /// Using this function is like building a normal entity, but the entityViews + /// Using this function is like building a normal entity, but the entity views /// are grouped by groupID to be more efficently processed inside engines and /// improve cache locality. Either class entityViews and struct entityViews can be /// grouped. @@ -49,8 +40,6 @@ namespace Svelto.ECS /// EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup groupID, object[] implementors) where T:IEntityDescriptor, new(); EntityStructInitializer BuildEntity(EGID egid, object[] implementors) 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. @@ -60,7 +49,6 @@ namespace Svelto.ECS /// /// EntityStructInitializer BuildEntity(int entityID, ExclusiveGroup groupID, IEntityDescriptor descriptorEntity, object[] implementors); - EntityStructInitializer BuildEntity(int entityID, IEntityDescriptor descriptorEntity, object[] implementors); EntityStructInitializer BuildEntity(EGID egid, IEntityDescriptor descriptorEntity, object[] implementors); } } diff --git a/Svelto.ECS/IEntityFunctions.cs b/Svelto.ECS/IEntityFunctions.cs index b95b6d1..434fbc2 100644 --- a/Svelto.ECS/IEntityFunctions.cs +++ b/Svelto.ECS/IEntityFunctions.cs @@ -7,15 +7,18 @@ namespace Svelto.ECS //being entity ID globally not unique, the group must be specified when //an entity is removed. Not specificing the group will attempt to remove //the entity from the special standard group. - void RemoveEntity(int entityID) where T : IEntityDescriptor, new(); void RemoveEntity(int entityID, int groupID) where T : IEntityDescriptor, new(); + void RemoveEntity(int entityID, ExclusiveGroup groupID) where T : IEntityDescriptor, new(); void RemoveEntity(EGID entityegid) where T : IEntityDescriptor, new(); void RemoveGroupAndEntities(int groupID); + void RemoveGroupAndEntities(ExclusiveGroup groupID); - EGID SwapEntityGroup(int entityID, int fromGroupID, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new(); - EGID SwapEntityGroup(EGID id, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new(); - EGID SwapEntityGroup(int entityID, int toGroupID) where T : IEntityDescriptor, new(); - EGID SwapFirstEntityGroup(int fromGroupID = ExclusiveGroup.StandardEntitiesGroup, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new(); + EGID SwapEntityGroup(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new(); + EGID SwapEntityGroup(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new(); + EGID SwapEntityGroup(EGID id, int toGroupID) where T : IEntityDescriptor, new(); + EGID SwapEntityGroup(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new(); + EGID SwapFirstEntityGroup(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new(); + EGID SwapFirstEntityGroup(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new(); } } \ No newline at end of file diff --git a/Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs b/Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs index ae9f263..882a29a 100644 --- a/Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs +++ b/Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED using System; using UnityEditor; using UnityEngine; diff --git a/Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs b/Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs index 48ba030..12089ed 100644 --- a/Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs +++ b/Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED using System.Linq; using UnityEditor; using UnityEngine; diff --git a/Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs b/Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs index e9b2044..c3c04b3 100644 --- a/Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs +++ b/Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED using UnityEditor; using UnityEngine; diff --git a/Svelto.ECS/Profiler/Editor/Svelto.ECS.Profiler.asmdef b/Svelto.ECS/Profiler/Editor/Svelto.ECS.Profiler.asmdef deleted file mode 100644 index 7004a52..0000000 --- a/Svelto.ECS/Profiler/Editor/Svelto.ECS.Profiler.asmdef +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "Svelto.ECS.Profiler", - "references": [ - "Svelto.ECS", - "Svelto.Common" - ], - "optionalUnityReferences": [], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false -} \ No newline at end of file