Browse Source

Add ExecuteOnEntities (careful this may change with c# 7 in future)

tags/Rel25b
sebas77 6 years ago
parent
commit
dabc32d6a1
2 changed files with 43 additions and 0 deletions
  1. +37
    -0
      Svelto.ECS/EntitiesDB.cs
  2. +6
    -0
      Svelto.ECS/IEntitiesDB.cs

+ 37
- 0
Svelto.ECS/EntitiesDB.cs View File

@@ -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<T>(int groupID, ActionRef<T> action) where T : IEntityStruct
{
int count;
var entities = QueryEntities<T>(groupID, out count);

for (int i = 0; i < count; i++)
action(ref entities[i]);
}

public void ExecuteOnEntities<T>(ActionRef<T> action) where T : IEntityStruct
{
int count;
var entities = QueryEntities<T>(out count);

for (int i = 0; i < count; i++)
action(ref entities[i]);
}

public void ExecuteOnEntities<T, W>(int groupID, ref W value, ActionRef<T, W> action) where T : IEntityStruct
{
int count;
var entities = QueryEntities<T>(out count);

for (int i = 0; i < count; i++)
action(ref entities[i], ref value);
}

public void ExecuteOnEntities<T, W>(ref W value, ActionRef<T, W> action) where T : IEntityStruct
{
int count;
var entities = QueryEntities<T>(out count);

for (int i = 0; i < count; i++)
action(ref entities[i], ref value);
}

public bool Exists<T>(EGID entityGID) where T : IEntityStruct
{
TypeSafeDictionary<T> casted;


+ 6
- 0
Svelto.ECS/IEntitiesDB.cs View File

@@ -39,6 +39,12 @@ namespace Svelto.ECS
void ExecuteOnEntity<T, W>(EGID egid, ref W value, ActionRef<T, W> action) where T : IEntityStruct;
void ExecuteOnEntity<T>(EGID egid, ActionRef<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T>(int groupID, ActionRef<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T>(ActionRef<T> action) where T : IEntityStruct;
void ExecuteOnEntities<T, W>(int groupID, ref W value, ActionRef<T, W> action) where T : IEntityStruct;
void ExecuteOnEntities<T, W>(ref W value, ActionRef<T, W> action) where T : IEntityStruct;
bool Exists<T>(EGID egid) where T : IEntityStruct;
bool HasAny<T>() where T:IEntityStruct;


Loading…
Cancel
Save