Browse Source

Now it's mandatory to specify the group in all the functions, I will write an article about why this makes the code much better

renamed UnityEntiySubmissionScheduler
tags/2.6a
sebas77 6 years ago
parent
commit
f828e266b9
20 changed files with 133 additions and 224 deletions
  1. +0
    -3
      .gitmodules
  2. +2
    -1
      README.md
  3. +0
    -1
      Svelto.Common
  4. +3
    -3
      Svelto.ECS/EGID.cs
  5. +1
    -2
      Svelto.ECS/EnginesRoot.Engines.cs
  6. +3
    -2
      Svelto.ECS/EnginesRoot.Entities.cs
  7. +1
    -16
      Svelto.ECS/EnginesRoot.GenericEntityFactory.cs
  8. +24
    -9
      Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs
  9. +8
    -5
      Svelto.ECS/EnginesRoot.Submission.cs
  10. +16
    -22
      Svelto.ECS/EntitiesDB.cs
  11. +1
    -3
      Svelto.ECS/ExclusiveGroups.cs
  12. +36
    -80
      Svelto.ECS/ExecuteOnEntitiesDB.cs
  13. +4
    -9
      Svelto.ECS/Extensions/Unity/UnityEntitySubmissionScheduler.cs
  14. +22
    -34
      Svelto.ECS/IEntitiesDB.cs
  15. +1
    -13
      Svelto.ECS/IEntityFactory.cs
  16. +8
    -5
      Svelto.ECS/IEntityFunctions.cs
  17. +1
    -1
      Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs
  18. +1
    -1
      Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs
  19. +1
    -1
      Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs
  20. +0
    -13
      Svelto.ECS/Profiler/Editor/Svelto.ECS.Profiler.asmdef

+ 0
- 3
.gitmodules View File

@@ -1,3 +0,0 @@
[submodule "Svelto.Common"]
path = Svelto.Common
url = https://github.com/sebas77/Svelto.Common.git

+ 2
- 1
README.md View File

@@ -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)**



+ 0
- 1
Svelto.Common

@@ -1 +0,0 @@
Subproject commit 554875838f1743017981df428243bba80fe3ece1

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

@@ -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);


+ 1
- 2
Svelto.ECS/EnginesRoot.Engines.cs View File

@@ -40,11 +40,10 @@ namespace Svelto.ECS
_otherEngines = new FasterList<IEngine>();

_groupEntityDB = new Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>();
_groupEntityDB[ExclusiveGroup.StandardEntitiesGroup] = new Dictionary<Type, ITypeSafeDictionary>();
_groupedGroups = new Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>>();
_groupedEntityToAdd = new DoubleBufferedEntitiesToAdd<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>>();

_DB = new entitiesDB(_groupEntityDB, _groupedGroups);
_DB = new EntitiesDB(_groupEntityDB, _groupedGroups);

_scheduler = entityViewScheduler;
_scheduler.Schedule(new WeakAction(SubmitEntityViews));


+ 3
- 2
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -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;
}


+ 1
- 16
Svelto.ECS/EnginesRoot.GenericEntityFactory.cs View File

@@ -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<T>(int entityID, object[] implementors) where T : IEntityDescriptor, new()
{
return _weakEngine.Target.BuildEntity<T>(new EGID(entityID), implementors);
}

public EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup groupID, object[] implementors) where T : IEntityDescriptor, new()
{
return _weakEngine.Target.BuildEntity<T>(new EGID(entityID, (int)groupID), implementors);
@@ -30,11 +25,6 @@ namespace Svelto.ECS
return _weakEngine.Target.BuildEntity<T>(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<T>(int size) where T : IEntityDescriptor, new()
{
_weakEngine.Target.Preallocate<T>(ExclusiveGroup.StandardEntitiesGroup, size);
}
public void PreallocateEntitySpace<T>(ExclusiveGroup groupID, int size) where T : IEntityDescriptor, new()
{
_weakEngine.Target.Preallocate<T>((int)groupID, size);


+ 24
- 9
Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs View File

@@ -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<T>(int entityID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(new EGID(entityID));
}
public void RemoveEntity<T>(int entityID, int groupID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(new EGID(entityID, groupID));
}

public void RemoveEntity<T>(int entityID, ExclusiveGroup groupID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(new EGID(entityID, (int) groupID));
}

public void RemoveEntity<T>(EGID entityEGID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(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<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(entityID, fromGroupID, toGroupID);
}

public EGID SwapEntityGroup<T>(EGID id, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new()
public EGID SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(entityID, (int) fromGroupID, (int) toGroupID);
}

public EGID SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(id.entityID, id.groupID, toGroupID);
}

public EGID SwapEntityGroup<T>(int entityID, int toGroupID) where T : IEntityDescriptor, new()
public EGID SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(entityID, ExclusiveGroup.StandardEntitiesGroup, toGroupID);
return _weakReference.Target.SwapEntityGroup<T>(id.entityID, id.groupID, (int) toGroupID);
}

public EGID SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapFirstEntityInGroup<T>( fromGroupID, toGroupID);
}

public EGID SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapFirstEntityInGroup<T>( (int) fromGroupID, (int) toGroupID);
}
}
}
}

+ 8
- 5
Svelto.ECS/EnginesRoot.Submission.cs View File

@@ -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++;
}
}


+ 16
- 22
Svelto.ECS/EntitiesDB.cs View File

@@ -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<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsDB,
internal EntitiesDB(Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsDB,
Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>> groupedGroups)
{
_groupEntityViewsDB = groupEntityViewsDB;
_groupedGroups = groupedGroups;
}

public ReadOnlyCollectionStruct<T> QueryEntityViews<T>() where T:class, IEntityStruct
{
return QueryEntityViews<T>(ExclusiveGroup.StandardEntitiesGroup);
}

public ReadOnlyCollectionStruct<T> QueryEntityViews<T>(int @group) where T:class, IEntityStruct
{
TypeSafeDictionary<T> typeSafeDictionary;
@@ -28,11 +22,6 @@ namespace Svelto.ECS.Internal
return typeSafeDictionary.FasterValues;
}

public T[] QueryEntities<T>(out int count) where T : IEntityStruct
{
return QueryEntities<T>(ExclusiveGroup.StandardEntitiesGroup, out count);
}
public T[] QueryEntities<T>(int @group, out int count) where T : IEntityStruct
{
TypeSafeDictionary<T> typeSafeDictionary;
@@ -41,12 +30,12 @@ namespace Svelto.ECS.Internal

return typeSafeDictionary.GetFasterValuesBuffer(out count);
}
public EGIDMapper<T> QueryMappedEntities<T>() where T : IEntityStruct
public T[] QueryEntities<T>(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct
{
return QueryMappedEntities<T>(ExclusiveGroup.StandardEntitiesGroup);
return QueryEntities<T>((int) @group, out targetsCount);
}
public EGIDMapper<T> QueryMappedEntities<T>(int groupID) where T : IEntityStruct
{
TypeSafeDictionary<T> typeSafeDictionary;
@@ -63,6 +52,11 @@ namespace Svelto.ECS.Internal
return mapper;
}

public EGIDMapper<T> QueryMappedEntities<T>(ExclusiveGroup groupID) where T : IEntityStruct
{
return QueryMappedEntities<T>((int) groupID);
}

public T[] QueryEntitiesAndIndex<T>(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<T>() where T : IEntityStruct
{
return HasAny<T>(ExclusiveGroup.StandardEntitiesGroup);
}

public bool HasAny<T>(int @group) where T : IEntityStruct
{
int count;
@@ -110,6 +99,11 @@ namespace Svelto.ECS.Internal
return count > 0;
}

public bool HasAny<T>(ExclusiveGroup @group) where T : IEntityStruct
{
return HasAny<T>((int) group);
}

public bool TryQueryEntityView<T>(EGID entityegid, out T entityView) where T : class, IEntityStruct
{
return TryQueryEntityViewInGroupInternal(entityegid, out entityView);


+ 1
- 3
Svelto.ECS/ExclusiveGroups.cs View File

@@ -1,4 +1,4 @@
namespace Svelto.ECS
namespace Svelto.ECS
{
/// <summary>
/// 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;


+ 36
- 80
Svelto.ECS/ExecuteOnEntitiesDB.cs View File

@@ -1,10 +1,14 @@
using Svelto.DataStructures.Experimental;
using Svelto.Utilities;

namespace Svelto.ECS.Internal
{
partial class entitiesDB
partial class EntitiesDB
{
public void ExecuteOnEntity<T>(int id, ExclusiveGroup groupid, EntityAction<T> action) where T : IEntityStruct
{
ExecuteOnEntity(id, (int)groupid, action);
}

public void ExecuteOnEntity<T, W>(EGID entityGID, ref W value, EntityAction<T, W> action) where T : IEntityStruct
{
TypeSafeDictionary<T> casted;
@@ -35,49 +39,25 @@ namespace Svelto.ECS.Internal
.FastConcat(entityGID.groupID));
}

public void ExecuteOnEntity<T>(int id, EntityAction<T> action) where T : IEntityStruct
{
ExecuteOnEntity(new EGID(id, ExclusiveGroup.StandardEntitiesGroup), action);
}

public void ExecuteOnEntity<T>(int id, int groupid, EntityAction<T> action) where T : IEntityStruct
{
ExecuteOnEntity(new EGID(id, groupid), action);
}

public void ExecuteOnEntity<T, W>(int id, ref W value, EntityAction<T, W> action) where T : IEntityStruct
{
ExecuteOnEntity(new EGID(id, ExclusiveGroup.StandardEntitiesGroup), ref value, action);
}

public void ExecuteOnEntity<T, W>(int id, int groupid, ref W value, EntityAction<T, W> action)
where T : IEntityStruct
{
ExecuteOnEntity(new EGID(id, groupid), ref value, action);
}
//----------------------------------------------------------------------------------------------------------

public void ExecuteOnEntities<T>(int groupID, EntitiesAction<T> action) where T : IEntityStruct
public void ExecuteOnEntity<T, W>(int id, ExclusiveGroup groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct
{
int count;
TypeSafeDictionary<T> 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<T>(EntitiesAction<T> action) where T : IEntityStruct
{
ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, action);
}
//----------------------------------------------------------------------------------------------------------

public void ExecuteOnEntities<T, W>(int groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct
public void ExecuteOnEntities<T>(int groupID, EntitiesAction<T> action) where T : IEntityStruct
{
int count;
TypeSafeDictionary<T> 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<T, W>(ref W value, EntitiesAction<T, W> action) where T : IEntityStruct
public void ExecuteOnEntities<T>(ExclusiveGroup groupID, EntitiesAction<T> action) where T : IEntityStruct
{
ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action);
ExecuteOnEntities((int)groupID, action);
}

public void ExecuteOnEntities<T, T1, W>(W value, EntitiesAction<T, T1, W> action)
where T : IEntityStruct where T1 : IEntityStruct
{
ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action);
}

public void ExecuteOnEntities<T, T1>(int group, EntitiesAction<T, T1> action)
where T : IEntityStruct where T1 : IEntityStruct
{
int count;
TypeSafeDictionary<T> typeSafeDictionary;
if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return;

var entities = typeSafeDictionary.GetFasterValuesBuffer(out count);

EGIDMapper<T1> map = QueryMappedEntities<T1>(@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<T, T1, W>(int group, ref W value, EntitiesAction<T, T1, W> action)
where T : IEntityStruct where T1 : IEntityStruct
public void ExecuteOnEntities<T, W>(int groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct
{
int count;
TypeSafeDictionary<T> typeSafeDictionary;
if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return;
if (QueryEntitySafeDictionary(@groupID, out typeSafeDictionary) == false) return;

var entities = typeSafeDictionary.GetFasterValuesBuffer(out count);

EGIDMapper<T1> map = QueryMappedEntities<T1>(@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<T, T1>(EntitiesAction<T, T1> action) where T : IEntityStruct where T1 : IEntityStruct
public void ExecuteOnEntities<T, W>(ExclusiveGroup groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct
{
ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, action);
ExecuteOnEntities((int)groupID, ref value, action);
}

public void ExecuteOnEntities<T, T1, W>(ref W value, EntitiesAction<T, T1, W> action)
where T : IEntityStruct where T1 : IEntityStruct
{
ExecuteOnEntities(ExclusiveGroup.StandardEntitiesGroup, ref value, action);
}
//-----------------------------------------------------------------------------------------------------------
public void ExecuteOnAllEntities<T>(EntityAction<T> action) where T : IEntityStruct
public void ExecuteOnAllEntities<T>(ExclusiveGroup[] damageableGroups, AllEntitiesAction<T> action) where T : IEntityStruct
{
var type = typeof(T);
FasterDictionary<int, ITypeSafeDictionary> 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<T, W>(ref W value, EntityAction<T, W> action) where T : IEntityStruct
public void ExecuteOnAllEntities<T, W>(ref W value, AllEntitiesAction<T, W> action) where T : IEntityStruct
{
var type = typeof(T);
FasterDictionary<int, ITypeSafeDictionary> 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<T>(ExclusiveGroup[] groups, EntitiesAction<T> action) where T : IEntityStruct
{
foreach (var group in groups)
{
ExecuteOnEntities(group, action);
}
}

public void ExecuteOnAllEntities<T, W>(ExclusiveGroup[] groups, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct
{
foreach (var group in groups)
{
ExecuteOnEntities(group, ref value, action);
}
}
}
}

Svelto.ECS/Extensions/Unity/UnitySumbmissionEntityViewScheduler .cs → Svelto.ECS/Extensions/Unity/UnityEntitySubmissionScheduler.cs View File

@@ -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");


+ 22
- 34
Svelto.ECS/IEntitiesDB.cs View File

@@ -4,12 +4,6 @@ namespace Svelto.ECS
{
public interface IEntitiesDB
{
/// <summary>
/// All the EntityView related methods are left for back compatibility, but
/// shouldn't be used anymore. Always pick EntityViewStruct or EntityStruct
/// over EntityView
/// </summary>
ReadOnlyCollectionStruct<T> QueryEntityViews<T>() where T : class, IEntityStruct;
/// <summary>
/// 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
/// <param name="count"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
T[] QueryEntities<T>(out int count) where T : IEntityStruct;
T[] QueryEntities<T>(int group, out int count) where T : IEntityStruct;
T[] QueryEntities<T>(int group, out int count) where T : IEntityStruct;
T[] QueryEntities<T>(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct;
/// <summary>
/// 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
/// <typeparam name="T"></typeparam>
/// <returns></returns>
EGIDMapper<T> QueryMappedEntities<T>(int groupID) where T : IEntityStruct;
EGIDMapper<T> QueryMappedEntities<T>() where T : IEntityStruct;
EGIDMapper<T> QueryMappedEntities<T>(ExclusiveGroup groupID) where T : IEntityStruct;
/// <summary>
/// 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
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
void ExecuteOnEntities<T>(int groupID, EntitiesAction<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T>(EntitiesAction<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T>(ExclusiveGroup groupID, EntitiesAction<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T, W>(int groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;
void ExecuteOnEntities<T, W>(ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;
/// <summary>
/// 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.
/// </summary>
/// <param name="groupID"></param>
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T1"></typeparam>
void ExecuteOnEntities<T, T1>(int groupID, EntitiesAction<T, T1> action) where T : IEntityStruct where T1 : IEntityStruct;
void ExecuteOnEntities<T, T1>(EntitiesAction<T, T1> action) where T : IEntityStruct where T1 : IEntityStruct;
void ExecuteOnEntities<T, T1, W>(int groupID, ref W value, EntitiesAction<T, T1, W> action) where T : IEntityStruct where T1 : IEntityStruct;
void ExecuteOnEntities<T, T1, W>(ref W value, EntitiesAction<T, T1, W> action) where T : IEntityStruct where T1 : IEntityStruct;
void ExecuteOnEntities<T, W>(ExclusiveGroup groupID, ref W value, EntitiesAction<T, W> action) where T : IEntityStruct;

/// <summary>
/// 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
/// </summary>
/// <param name="damageableGroups"></param>
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
void ExecuteOnAllEntities<T>(EntityAction<T> action) where T : IEntityStruct;
void ExecuteOnAllEntities<T, W>(ref W value, EntityAction<T, W> action) where T : IEntityStruct;
void ExecuteOnAllEntities<T>(ExclusiveGroup[] damageableGroups, AllEntitiesAction<T> action) where T : IEntityStruct;
void ExecuteOnAllEntities<T, W>(ref W value, AllEntitiesAction<T, W> action) where T : IEntityStruct;
void ExecuteOnAllEntities<T>(ExclusiveGroup[] groups, EntitiesAction<T> action) where T : IEntityStruct;
void ExecuteOnAllEntities<T, W>(ExclusiveGroup[] groups, ref W value, EntitiesAction<T, W> action) 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
@@ -106,21 +91,24 @@ 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, 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 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, 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 groupid, ref W value, EntityAction<T, W> action) where T : IEntityStruct;

bool Exists<T>(EGID egid) where T : IEntityStruct;
bool HasAny<T>() where T:IEntityStruct;
bool HasAny<T>(int group) where T:IEntityStruct;
bool HasAny<T>(ExclusiveGroup group) where T:IEntityStruct;
}

public delegate void EntityAction<T, W>(ref T target, ref W value);
public delegate void EntityAction<T>(ref T target);
public delegate void EntitiesAction<T, T1, W>(ref T target, ref T1 target1, ref W value, int index);
public delegate void EntitiesAction<T, W>(ref T target, ref W value, int index);
public delegate void EntitiesAction<T>(ref T target, int index);
public delegate void EntityAction<T, W>(ref T target, ref W value);
public delegate void EntityAction<T>(ref T target);

public delegate void AllEntitiesAction<T, W>(ref T target, ref W value, IEntitiesDB entitiesDb);
public delegate void AllEntitiesAction<T>(ref T target, IEntitiesDB entitiesDb);
public delegate void EntitiesAction<T, W>(ref T target, ref W value, IEntitiesDB entitiesDb, int index);
public delegate void EntitiesAction<T>(ref T target, IEntitiesDB entitiesDb, int index);
}

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

@@ -22,7 +22,6 @@ namespace Svelto.ECS
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="size"></param>
void PreallocateEntitySpace<T>(int size) where T : IEntityDescriptor, new();
void PreallocateEntitySpace<T>(ExclusiveGroup groupID, int size) where T : IEntityDescriptor, new();
/// <summary>
@@ -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
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entityID"></param>
/// <param name="implementors"></param>
EntityStructInitializer BuildEntity<T>(int entityID, object[] implementors) where T:IEntityDescriptor, new();


/// <summary>
/// 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
/// <param name="implementors"></param>
EntityStructInitializer BuildEntity<T>(int entityID, ExclusiveGroup groupID, object[] implementors) where T:IEntityDescriptor, new();
EntityStructInitializer BuildEntity<T>(EGID egid, object[] implementors) 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.
@@ -60,7 +49,6 @@ namespace Svelto.ECS
/// <param name="implementors"></param>
///
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);
}
}

+ 8
- 5
Svelto.ECS/IEntityFunctions.cs View File

@@ -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<T>(int entityID) where T : IEntityDescriptor, new();
void RemoveEntity<T>(int entityID, int groupID) where T : IEntityDescriptor, new();
void RemoveEntity<T>(int entityID, ExclusiveGroup groupID) where T : IEntityDescriptor, new();
void RemoveEntity<T>(EGID entityegid) where T : IEntityDescriptor, new();

void RemoveGroupAndEntities(int groupID);
void RemoveGroupAndEntities(ExclusiveGroup groupID);
EGID SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(EGID id, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(int entityID, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapFirstEntityGroup<T>(int fromGroupID = ExclusiveGroup.StandardEntitiesGroup, int toGroupID = ExclusiveGroup.StandardEntitiesGroup) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
EGID SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
}
}

+ 1
- 1
Svelto.ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs View File

@@ -1,4 +1,4 @@
#if UNITY_EDITOR
#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED
using System;
using UnityEditor;
using UnityEngine;


+ 1
- 1
Svelto.ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs View File

@@ -1,4 +1,4 @@
#if UNITY_EDITOR
#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED
using System.Linq;
using UnityEditor;
using UnityEngine;


+ 1
- 1
Svelto.ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs View File

@@ -1,4 +1,4 @@
#if UNITY_EDITOR
#if UNITY_EDITOR && ENGINE_PROFILER_ENABLED
using UnityEditor;
using UnityEngine;



+ 0
- 13
Svelto.ECS/Profiler/Editor/Svelto.ECS.Profiler.asmdef View File

@@ -1,13 +0,0 @@
{
"name": "Svelto.ECS.Profiler",
"references": [
"Svelto.ECS",
"Svelto.Common"
],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false
}

Loading…
Cancel
Save