You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a pretty nasty looking query that because of its nature I'm getting the list of components from the entity directly in the query. It's pretty well set in stone now, so I was converting it to an inline query and had to write some extensions so that I could use it. Below is the code I used to accomplish it.
Required Interface:
public interface IForEachWithEntity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Update(Entity entity);
}
My Extension to use the above interface:
public static void InlineEntityQuery<T>(this World world, in QueryDescription description)
where T : struct, IForEachWithEntity
{
T iForEach = new();
QueryChunkEnumerator enumerator = world.Query(in description).GetEnumerator();
while (enumerator.MoveNext())
{
ref Chunk current = ref enumerator.Current;
_ = current.Size;
ref Entity source = ref current.Entity(0);
EntityEnumerator enumerator2 = current.GetEnumerator();
while (enumerator2.MoveNext())
{
int current2 = enumerator2.Current;
Entity entity = Unsafe.Add(ref source, current2);
iForEach.Update(entity);
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a pretty nasty looking query that because of its nature I'm getting the list of components from the entity directly in the query. It's pretty well set in stone now, so I was converting it to an inline query and had to write some extensions so that I could use it. Below is the code I used to accomplish it.
Required Interface:
My Extension to use the above interface:
And the resulting inline query I needed it for:
Beta Was this translation helpful? Give feedback.
All reactions