Created
May 21, 2020 13:52
-
-
Save korchoon/4f72eeede2ec79b69b92cd3f13f04d55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
using Leopotam.Ecs; | |
public static class EcsWorldExt | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static bool InFilter(this EcsEntity e, EcsFilter f) | |
{ | |
ref var entityData = ref e.Owner.GetEntityData(e); | |
foreach (var typeId in f.IncludedTypeIndices) | |
if (!entityData.HasType(typeId)) | |
return false; | |
foreach (var typeId in f.ExcludedTypeIndices) | |
if (entityData.HasType(typeId)) | |
return false; | |
return true; | |
} | |
public static void Invoke(ref this EcsEntity e, Action t) | |
{ | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static bool HasTypeIndex(ref this EcsEntity e, int typeId) | |
{ | |
ref var entityData = ref e.Owner.GetEntityData(e); | |
return entityData.HasType(typeId); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
static bool HasType(ref this EcsWorld.EcsEntityData entityData, int typeIdx) | |
{ | |
var entityDataComponents = entityData.Components; | |
for (int i = 0, iMax = entityData.ComponentsCountX2; i < iMax; i += 2) | |
{ | |
if (entityDataComponents[i] == typeIdx) | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment