From dabc32d6a179933beb7359c938f25f2c1ed8b46c Mon Sep 17 00:00:00 2001 From: sebas77 Date: Thu, 28 Jun 2018 14:12:35 +0100 Subject: [PATCH] Add ExecuteOnEntities (careful this may change with c# 7 in future) --- Svelto.ECS/EntitiesDB.cs | 37 +++++++++++++++++++++++++++++++++++++ Svelto.ECS/IEntitiesDB.cs | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/Svelto.ECS/EntitiesDB.cs b/Svelto.ECS/EntitiesDB.cs index 72ca4a9..db67eff 100644 --- a/Svelto.ECS/EntitiesDB.cs +++ b/Svelto.ECS/EntitiesDB.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Security.Principal; using Svelto.DataStructures; using Svelto.Utilities; @@ -101,6 +102,42 @@ namespace Svelto.ECS.Internal casted.ExecuteOnEntityView(entityGID.entityID, action); } + public void ExecuteOnEntities(int groupID, ActionRef action) where T : IEntityStruct + { + int count; + var entities = QueryEntities(groupID, out count); + + for (int i = 0; i < count; i++) + action(ref entities[i]); + } + + public void ExecuteOnEntities(ActionRef action) where T : IEntityStruct + { + int count; + var entities = QueryEntities(out count); + + for (int i = 0; i < count; i++) + action(ref entities[i]); + } + + public void ExecuteOnEntities(int groupID, ref W value, ActionRef action) where T : IEntityStruct + { + int count; + var entities = QueryEntities(out count); + + for (int i = 0; i < count; i++) + action(ref entities[i], ref value); + } + + public void ExecuteOnEntities(ref W value, ActionRef action) where T : IEntityStruct + { + int count; + var entities = QueryEntities(out count); + + for (int i = 0; i < count; i++) + action(ref entities[i], ref value); + } + public bool Exists(EGID entityGID) where T : IEntityStruct { TypeSafeDictionary casted; diff --git a/Svelto.ECS/IEntitiesDB.cs b/Svelto.ECS/IEntitiesDB.cs index 0fe3395..359f33a 100644 --- a/Svelto.ECS/IEntitiesDB.cs +++ b/Svelto.ECS/IEntitiesDB.cs @@ -39,6 +39,12 @@ namespace Svelto.ECS void ExecuteOnEntity(EGID egid, ref W value, ActionRef action) where T : IEntityStruct; void ExecuteOnEntity(EGID egid, ActionRef action) where T : IEntityStruct; + void ExecuteOnEntities(int groupID, ActionRef action) where T : IEntityStruct; + void ExecuteOnEntities(ActionRef action) where T : IEntityStruct; + + void ExecuteOnEntities(int groupID, ref W value, ActionRef action) where T : IEntityStruct; + void ExecuteOnEntities(ref W value, ActionRef action) where T : IEntityStruct; + bool Exists(EGID egid) where T : IEntityStruct; bool HasAny() where T:IEntityStruct;