|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
using System; |
|
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
using gaemstone.ECS.Internal; |
|
|
|
|
using gaemstone.ECS.Utility; |
|
|
|
|
using static flecs_hub.flecs; |
|
|
|
|
|
|
|
|
@ -15,11 +14,12 @@ public static class ObserverExtensions |
|
|
|
|
if (events.Length > 8) throw new ArgumentException("Must specify at most 8 events", nameof(events)); |
|
|
|
|
|
|
|
|
|
var world = entity.World; |
|
|
|
|
var internalCallback = (nint iterPtr) => callback(new((ecs_iter_t*)iterPtr)); |
|
|
|
|
using var alloc = TempAllocator.Use(); |
|
|
|
|
var desc = new ecs_observer_desc_t { |
|
|
|
|
entity = entity, |
|
|
|
|
filter = filter.ToFlecs(alloc), |
|
|
|
|
binding_ctx = (void*)CallbackContextHelper.Create((world, callback)), |
|
|
|
|
binding_ctx = (void*)CallbackContextHelper.Create(internalCallback), |
|
|
|
|
binding_ctx_free = new() { Data = new() { Pointer = &FreeContext } }, |
|
|
|
|
callback = new() { Data = new() { Pointer = &Callback } }, |
|
|
|
|
}; |
|
|
|
@ -33,11 +33,9 @@ public static class ObserverExtensions |
|
|
|
|
|
|
|
|
|
[UnmanagedCallersOnly] |
|
|
|
|
private static unsafe void Callback(ecs_iter_t* iter) |
|
|
|
|
{ |
|
|
|
|
var (world, callback) = CallbackContextHelper |
|
|
|
|
.Get<(World, Action<Iterator>)>((nint)iter->binding_ctx); |
|
|
|
|
callback(new Iterator(iter)); |
|
|
|
|
} |
|
|
|
|
=> CallbackContextHelper |
|
|
|
|
.Get<Action<nint>>((nint)iter->binding_ctx) |
|
|
|
|
.Invoke((nint)iter); |
|
|
|
|
|
|
|
|
|
[UnmanagedCallersOnly] |
|
|
|
|
private static unsafe void FreeContext(void* context) |
|
|
|
|