Fix Observer not using new generic Iterator

wip/no-type-lookup
copygirl 2 years ago
parent b93beed5ec
commit f7d17d46ab
  1. 12
      src/gaemstone.ECS/Observer.cs
  2. 2
      src/gaemstone.ECS/System.cs

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

@ -12,7 +12,7 @@ public static class SystemExtensions
{ {
var world = entity.World; var world = entity.World;
var internalCallback = (nint iter) => var internalCallback = (nint iter) =>
callback(new Iterator<TContext>((ecs_iter_t*)iter)); callback(new((ecs_iter_t*)iter));
using var alloc = TempAllocator.Use(); using var alloc = TempAllocator.Use();
var desc = new ecs_system_desc_t { var desc = new ecs_system_desc_t {
entity = entity, entity = entity,

Loading…
Cancel
Save