-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IIterator interface and refactor iterable apis
- Loading branch information
1 parent
e80eed6
commit 4404cff
Showing
5 changed files
with
339 additions
and
356 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
using static Flecs.NET.Bindings.flecs; | ||
|
||
namespace Flecs.NET.Core | ||
{ | ||
/// <summary> | ||
/// Interface for iterator structs. | ||
/// </summary> | ||
[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords")] | ||
public unsafe interface IIterator : IIterable | ||
{ | ||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Iter(Ecs.IterCallback callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Each(Ecs.EachEntityCallback callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Each(Ecs.EachIterCallback callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Run(Ecs.RunCallback callback); | ||
|
||
#if NET5_0_OR_GREATER | ||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Iter(delegate*<Iter, void> callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Each(delegate*<Entity, void> callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Each(delegate*<Iter, int, void> callback); | ||
|
||
/// <summary> | ||
/// Iterates the query using the provided callback. | ||
/// </summary> | ||
/// <param name="callback">The callback.</param> | ||
public void Run(delegate*<Iter, void> callback); | ||
#endif | ||
|
||
internal static void Iter<T>(ref T iterable, Ecs.IterCallback callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Iter(&iter, callback); | ||
} | ||
|
||
internal static void Each<T>(ref T iterable, Ecs.EachEntityCallback callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Each(&iter, callback); | ||
} | ||
|
||
internal static void Each<T>(ref T iterable, Ecs.EachIterCallback callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Each(&iter, callback); | ||
} | ||
|
||
internal static void Run<T>(ref T iterable, Ecs.RunCallback callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
Invoker.Run(&iter, callback); | ||
} | ||
|
||
#if NET5_0_OR_GREATER | ||
internal static void Iter<T>(ref T iterable, delegate*<Iter, void> callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Iter(&iter, callback); | ||
} | ||
|
||
internal static void Each<T>(ref T iterable, delegate*<Entity, void> callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Each(&iter, callback); | ||
} | ||
|
||
internal static void Each<T>(ref T iterable, delegate*<Iter, int, void> callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
while (iterable.GetNext(&iter)) | ||
Invoker.Each(&iter, callback); | ||
} | ||
|
||
internal static void Run<T>(ref T iterable, delegate*<Iter, void> callback) where T : unmanaged, IIterable | ||
{ | ||
ecs_iter_t iter = iterable.GetIter(); | ||
Invoker.Run(&iter, callback); | ||
} | ||
#endif | ||
} | ||
} |
This file contains 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
Oops, something went wrong.