|
|
@ -8,8 +8,11 @@ namespace gaemstone.ECS; |
|
|
|
public static class ObserverExtensions |
|
|
|
public static class ObserverExtensions |
|
|
|
{ |
|
|
|
{ |
|
|
|
public static unsafe EntityRef InitObserver(this EntityRef entity, |
|
|
|
public static unsafe EntityRef InitObserver(this EntityRef entity, |
|
|
|
Entity @event, FilterDesc filter, Action<Iterator> callback) |
|
|
|
FilterDesc filter, Action<Iterator> callback, params Entity[] events) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (events.Length == 0) throw new ArgumentException("Must specify at least 1 event", 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; |
|
|
|
using var alloc = TempAllocator.Use(); |
|
|
|
using var alloc = TempAllocator.Use(); |
|
|
|
var desc = new ecs_observer_desc_t { |
|
|
|
var desc = new ecs_observer_desc_t { |
|
|
@ -19,7 +22,9 @@ public static class ObserverExtensions |
|
|
|
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 } }, |
|
|
|
}; |
|
|
|
}; |
|
|
|
desc.events[0] = @event; |
|
|
|
var span = desc.events; |
|
|
|
|
|
|
|
for (var i = 0; i < events.Length; i++) |
|
|
|
|
|
|
|
span[i] = events[i]; |
|
|
|
return new(world, new(ecs_observer_init(world, &desc))); |
|
|
|
return new(world, new(ecs_observer_init(world, &desc))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|