Update flecs-cs

wip/source-generators
copygirl 1 year ago
parent 51aa3ee2fe
commit b534d3db55
  1. 2
      src/flecs-cs
  2. 17
      src/gaemstone/ECS/Filter.cs
  3. 7
      src/gaemstone/ECS/Observer.cs
  4. 14
      src/gaemstone/ECS/System.cs

@ -1 +1 @@
Subproject commit 2e82db165948e073b813ac712bedd00c70627d03
Subproject commit a2047983917aa462a8c2f34d5315aea48502f4d8

@ -25,7 +25,7 @@ public unsafe sealed class Filter
public static void RunOnce(Universe universe, Delegate action)
{
var gen = IterActionGenerator.GetOrBuild(universe, action.Method);
var desc = new FilterDesc(gen.Terms.ToArray()) { Name = action.Method.Name };
var desc = new FilterDesc(gen.Terms.ToArray());
using var filter = new Filter(universe, desc);
foreach (var iter in filter.Iter()) gen.RunWithTryCatch(action.Target, iter);
}
@ -48,12 +48,6 @@ public class FilterDesc
public string? Expression { get; }
/// <summary>
/// Optional name of filter, used for debugging. If a filter is created
/// for a system, the provided name should match the system name.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// When true, terms returned by an iterator may either contain 1 or N
/// elements, where terms with N elements are owned, and terms with 1
@ -63,6 +57,11 @@ public class FilterDesc
/// </summary>
public bool Instanced { get; set; }
/// <summary>
/// Entity associated with query (optional).
/// </summary>
public Entity Entity { get; set; }
public FilterDesc(params Term[] terms)
=> Terms = terms;
public FilterDesc(string expression) : this()
@ -71,9 +70,9 @@ public class FilterDesc
public unsafe ecs_filter_desc_t ToFlecs(IAllocator allocator)
{
var desc = new ecs_filter_desc_t {
name = allocator.AllocateCString(Name),
expr = allocator.AllocateCString(Expression),
expr = allocator.AllocateCString(Expression),
instanced = Instanced,
entity = Entity,
};
var span = desc.terms;
if (Terms.Count > span.Length) {

@ -20,12 +20,12 @@ public class ObserverAttribute<TEvent> : ObserverAttribute
public static class ObserverExtensions
{
public static unsafe EntityRef RegisterObserver(this Universe universe,
FilterDesc filter, Entity @event, Action<Iterator> callback)
string? name, FilterDesc filter, Entity @event, Action<Iterator> callback)
{
using var alloc = TempAllocator.Use();
var desc = new ecs_observer_desc_t {
filter = filter.ToFlecs(alloc),
entity = universe.New((filter.Name != null) ? new(filter.Name) : null).Build(),
entity = universe.New((name != null) ? EntityPath.Parse(name) : null).Build(),
binding_ctx = (void*)CallbackContextHelper.Create((universe, callback)),
callback = new() { Data = new() { Pointer = &Callback } },
};
@ -55,9 +55,8 @@ public static class ObserverExtensions
iterAction = iter => gen.RunWithTryCatch(instance, iter);
}
filter.Name = method.Name;
var @event = universe.LookupOrThrow(attr.Event);
return universe.RegisterObserver(filter, @event, iterAction);
return universe.RegisterObserver(method.Name, filter, @event, iterAction);
}
[UnmanagedCallersOnly]

@ -30,12 +30,12 @@ public class ExpressionAttribute : Attribute
public static class SystemExtensions
{
private static unsafe EntityRef RegisterSystem(this Universe universe,
QueryDesc query, Entity phase, CallbackContext callback)
string? name, QueryDesc query, Entity phase, CallbackContext callback)
{
using var alloc = TempAllocator.Use();
var desc = new ecs_system_desc_t {
query = query.ToFlecs(alloc),
entity = universe.New((query.Name != null) ? new(query.Name) : null)
query = query.ToFlecs(alloc),
entity = universe.New((name != null) ? EntityPath.Parse(name) : null)
.Add<DependsOn>(phase).Add(phase).Build(),
binding_ctx = (void*)CallbackContextHelper.Create(callback),
// TODO: Use binding_ctx_free to remove clear the context.
@ -59,9 +59,9 @@ public static class SystemExtensions
callback = iter => gen.RunWithTryCatch(action.Target, iter);
}
query.Name = action.Method.Name;
var phase = universe.LookupOrThrow(attr?.Phase ?? typeof(SystemPhase.OnUpdate));
return universe.RegisterSystem(query, phase, new(universe, action.Method, callback));
return universe.RegisterSystem(action.Method.Name,
query, phase, new(universe, action.Method, callback));
}
public static EntityRef RegisterSystem(this Universe universe,
@ -83,9 +83,9 @@ public static class SystemExtensions
callback = iter => gen.RunWithTryCatch(instance, iter);
}
query.Name = method.Name;
var phase = universe.LookupOrThrow(attr?.Phase ?? typeof(SystemPhase.OnUpdate));
return universe.RegisterSystem(query, phase, new(universe, method, callback));
return universe.RegisterSystem(method.Name,
query, phase, new(universe, method, callback));
}
private class CallbackContext

Loading…
Cancel
Save