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