Skip to content

Commit ce59360

Browse files
committed
add Native AOT support for: ILinkRelation
1 parent 19bda4e commit ce59360

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/ECS/Base/NativeAOT.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ public void RegisterRelation<T, TKey>()
188188
};
189189
}
190190
}
191+
192+
public void RegisterLinkRelation<T>()
193+
where T : struct, ILinkRelation
194+
{
195+
InitSchema();
196+
if (typeSet.Add(typeof(T)))
197+
{
198+
AddType(typeof(T), SchemaTypeKind.Component);
199+
RelationUtils.GetRelationKey<T,Entity>(default); // dummy call to prevent trimming required type info
200+
SchemaUtils.CreateRelationType<T>(0, null, null); // dummy call to prevent trimming required type info
201+
AbstractEntityRelations.CreateEntityRelationsNativeAot[typeof(T)] = (componentType, archetype, heap) => {
202+
return new EntityLinkRelations<T>(componentType, archetype, heap);
203+
};
204+
}
205+
}
191206

192207
public void RegisterTag<T>() where T : struct, ITag
193208
{

src/Tests-NativeAOT/ECS/Test_NativeAOT.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Test_AOT_AddComponent_unknown()
8888
entity.AddComponent(new MyComponent2());
8989
});
9090
}
91-
91+
#region IIndexedComponent<>
9292
[TestMethod]
9393
public void Test_AOT_IndexedComponents_class()
9494
{
@@ -161,8 +161,10 @@ public void Test_AOT_LinkComponents()
161161
entity3.DeleteEntity(); // 1 2
162162
entity2.HasComponent <AttackComponent>(); // false
163163
}
164-
165-
// [TestMethod] TODO
164+
#endregion
165+
166+
#region IRelation<>
167+
[TestMethod]
166168
public void Test_AOT_LinkRelations()
167169
{
168170
var store = new EntityStore();
@@ -212,6 +214,7 @@ public void Test_AOT_Relations()
212214
entity.RemoveRelation<InventoryItem,InventoryItemType>(InventoryItemType.Axe);
213215
entity.GetRelations <InventoryItem>(); // { Coin }
214216
}
217+
#endregion
215218

216219
struct Player : IIndexedComponent<string> // indexed field type: string
217220
{
@@ -249,7 +252,7 @@ private static EntitySchema CreateSchema()
249252
aot.RegisterIndexedComponentEntity<AttackComponent>();
250253

251254
aot.RegisterRelation<InventoryItem, InventoryItemType>();
252-
255+
aot.RegisterLinkRelation<AttackRelation>();
253256

254257
return schemaCreated = aot.CreateSchema();
255258
}

0 commit comments

Comments
 (0)