@@ -8,16 +8,60 @@ public class Entity : GeneratorBase
88{
99 public override void Generate ( )
1010 {
11+ AddSource ( "Entity.Id.g.cs" , Id . GenerateExtensions ( Type . Entity ) ) ;
12+ AddSource ( "Entity.Observe.g.cs" , GenerateObserveFunctions ( Type . Entity ) ) ;
13+
1114 for ( int i = 0 ; i < Generator . GenericCount ; i ++ )
1215 {
13- AddSource ( $ "Entity.Id.g.cs", Id . GenerateExtensions ( Type . Entity ) ) ;
1416 AddSource ( $ "Entity.ComponentCallbacks/T{ i + 1 } .g.cs", GenerateComponentCallbacks ( Type . Entity , i ) ) ;
1517 }
1618 }
1719
20+ public static string GenerateObserveFunctions ( Type type , int i = - 1 )
21+ {
22+ IEnumerable < string > untyped = Generator . GetObserveCallbacks ( )
23+ . Select ( ( Callback callback ) => $$ """
24+ /// <inheritdoc cref="IEntity{TEntity}.Observe(ulong, Ecs.ObserveEntityCallback)"/>
25+ public void Observe(ulong id, {{ Generator . GetCallbackType ( callback ) }} callback)
26+ {
27+ Ecs.Observe(this, id, callback, &Functions.{{ Generator . GetCallbackName ( callback ) }} );
28+ }
29+
30+ /// <inheritdoc cref="IEntity{TEntity}.Observe{T}(Ecs.ObserveEntityCallback)"/>
31+ public void Observe<T0>({{ Generator . GetCallbackType ( callback ) }} callback)
32+ {
33+ Ecs.Observe(this, Type<T0>.Id(World), callback, &Functions.{{ Generator . GetCallbackName ( callback ) }} );
34+ }
35+ """ ) ;
36+
37+ IEnumerable < string > typed = Generator . GetObserveCallbacks ( 0 )
38+ . Select ( ( Callback callback ) => $$ """
39+ /// <inheritdoc cref="IEntity{TEntity}.Observe{T}(Ecs.ObserveEntityCallback)"/>
40+ public void Observe<T0>({{ Generator . GetCallbackType ( callback ) }} callback)
41+ {
42+ Ecs.Observe(this, Type<T0>.Id(World), callback, &Functions.{{ Generator . GetCallbackName ( callback ) }} <T0>);
43+ }
44+ """ ) ;
45+
46+ return $$ """
47+ #pragma warning disable CS0693 // Type parameter has the same name as the type parameter from outer type
48+
49+ using System;
50+
51+ namespace Flecs.NET.Core;
52+
53+ public unsafe partial struct {{ Generator . GetTypeName ( type , i ) }}
54+ {
55+ {{ string . Join ( Separator . DoubleNewLine , untyped . Concat ( typed ) ) }}
56+ }
57+ """ ;
58+ }
59+
1860 public static string GenerateComponentCallbacks ( Type type , int i )
1961 {
20- IEnumerable < string > readAndWrite = Generator . CallbacksReadAndWrite . Select ( ( Callback callback ) => $$ """
62+ IEnumerable < string > readAndWrite = Generator . GetReadCallbacks ( )
63+ . Concat ( Generator . GetWriteCallbacks ( ) )
64+ . Select ( ( Callback callback ) => $$ """
2165 /// <summary>
2266 /// {{ Generator . GetInvokerName ( callback ) }} {{ i + 1 }} components using the provided callback. <br/><br/>
2367 ///
@@ -39,11 +83,11 @@ public static string GenerateComponentCallbacks(Type type, int i)
3983 /// <returns>True if the entity has the specified components.</returns>
4084 public bool {{ Generator . GetInvokerName ( callback ) }} <{{ Generator . TypeParameters [ i ] }} >({{ Generator . GetCallbackType ( callback , i ) }} callback)
4185 {
42- return Invoker.{{ Generator . GetInvokerName ( callback ) }} ( World, Id, callback);
86+ return {{ Generator . GetTypeName ( Type . Invoker , i ) }} .{{ Generator . GetInvokerName ( callback ) }} < {{ Generator . GetCallbackName ( callback , i ) }} >(new Entity( World, Id) , callback);
4387 }
4488 """ ) ;
4589
46- IEnumerable < string > insert = Generator . CallbacksInsert . Select ( ( Callback callback ) => $$ """
90+ IEnumerable < string > insert = Generator . GetInsertCallbacks ( ) . Select ( ( Callback callback ) => $$ """
4791 /// <summary>
4892 /// Ensures {{ i + 1 }} components using the provided callback.<br/><br/>
4993 ///
@@ -62,9 +106,9 @@ public static string GenerateComponentCallbacks(Type type, int i)
62106 /// <param name="callback">The callback.</param>
63107 /// {{ Generator . XmlTypeParameters [ i ] }}
64108 /// <returns>Reference to self.</returns>
65- public ref {{ type }} {{ Generator . GetInvokerName ( callback ) }} <{{ Generator . TypeParameters [ i ] }} >({{ Generator . GetCallbackType ( callback , i ) }} callback)
109+ public ref {{ Generator . GetTypeName ( type ) }} {{ Generator . GetInvokerName ( callback ) }} <{{ Generator . TypeParameters [ i ] }} >({{ Generator . GetCallbackType ( callback , i ) }} callback)
66110 {
67- Invoker.{{ Generator . GetInvokerName ( callback ) }} ( World, Id, callback);
111+ {{ Generator . GetTypeName ( Type . Invoker , i ) }} .{{ Generator . GetInvokerName ( callback ) }} < {{ Generator . GetCallbackName ( callback , i ) }} >(new Entity( World, Id) , callback);
68112 return ref this;
69113 }
70114 """ ) ;
@@ -74,7 +118,7 @@ public static string GenerateComponentCallbacks(Type type, int i)
74118
75119 namespace Flecs.NET.Core;
76120
77- public unsafe partial struct {{ type }}
121+ public unsafe partial struct {{ Generator . GetTypeName ( type ) }}
78122 {
79123 {{ string . Join ( Separator . DoubleNewLine , readAndWrite . Concat ( insert ) ) }}
80124 }
@@ -1707,48 +1751,6 @@ public bool IsChildOf<T>(T value) where T : Enum
17071751 return ref this;
17081752 }
17091753
1710- /// <inheritdoc cref="Entity.Observe(ulong, Action)"/>
1711- public ref {{ typeName }} Observe(ulong eventId, Action callback)
1712- {
1713- Entity.Observe(eventId, callback);
1714- return ref this;
1715- }
1716-
1717- /// <inheritdoc cref="Entity.Observe(ulong, Ecs.ObserveEntityCallback)"/>
1718- public ref {{ typeName }} Observe(ulong eventId, Ecs.ObserveEntityCallback callback)
1719- {
1720- Entity.Observe(eventId, callback);
1721- return ref this;
1722- }
1723-
1724- /// <inheritdoc cref="Entity.Observe{T}(Action)"/>
1725- public ref {{ typeName }} Observe<T>(Action callback)
1726- {
1727- Entity.Observe<T>(callback);
1728- return ref this;
1729- }
1730-
1731- /// <inheritdoc cref="Entity.Observe{T}(Ecs.ObserveEntityCallback)"/>
1732- public ref {{ typeName }} Observe<T>(Ecs.ObserveEntityCallback callback)
1733- {
1734- Entity.Observe<T>(callback);
1735- return ref this;
1736- }
1737-
1738- /// <inheritdoc cref="Entity.Observe{T}(Ecs.ObserveRefCallback{T})"/>
1739- public ref {{ typeName }} Observe<T>(Ecs.ObserveRefCallback<T> callback)
1740- {
1741- Entity.Observe(callback);
1742- return ref this;
1743- }
1744-
1745- /// <inheritdoc cref="Entity.Observe{T}(Ecs.ObserveEntityRefCallback{T})"/>
1746- public ref {{ typeName }} Observe<T>(Ecs.ObserveEntityRefCallback<T> callback)
1747- {
1748- Entity.Observe(callback);
1749- return ref this;
1750- }
1751-
17521754 /// <inheritdoc cref="Entity.EnsurePtr(ulong)"/>
17531755 public void* EnsurePtr(ulong id)
17541756 {
0 commit comments