Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Bump ext/flecs from b493564 to 7aeae22 #45

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flecs.sln
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Queries", "Queries", "{0465
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flecs.Examples.Queries.OptionalOr", "src\cs\examples\queries\Flecs.Examples.Queries.OptionalOr\Flecs.Examples.Queries.OptionalOr.csproj", "{4A8057DB-51F1-4BDB-B40C-1EAAD4620234}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Flecs.Examples.Entities.PrefabSlot", "src\cs\examples\entities\Flecs.Examples.Entities.PrefabSlot\Flecs.Examples.Entities.PrefabSlot.csproj", "{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -77,6 +79,10 @@ Global
{4A8057DB-51F1-4BDB-B40C-1EAAD4620234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A8057DB-51F1-4BDB-B40C-1EAAD4620234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A8057DB-51F1-4BDB-B40C-1EAAD4620234}.Release|Any CPU.Build.0 = Release|Any CPU
{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -94,6 +100,7 @@ Global
{EC0A2533-C10C-412F-8D98-7B37AB53FA28} = {3DA02832-2DA5-49CC-929D-6DB290DA28EC}
{04650426-AD83-4E99-B211-3C70309C6FCF} = {9E1476CE-E22E-44FD-ABC4-93625DDBBA99}
{4A8057DB-51F1-4BDB-B40C-1EAAD4620234} = {04650426-AD83-4E99-B211-3C70309C6FCF}
{B8C4D7B7-45C4-46A8-8C7E-03C36F5949B2} = {3DA02832-2DA5-49CC-929D-6DB290DA28EC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C4B6B4B9-1CB6-414C-BF33-521394D6CD71}
6 changes: 6 additions & 0 deletions src/c/production/flecs/include/flecs_pinvoke.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,12 @@ PINVOKE_API ecs_entity_t pinvoke_EcsChildOf()
return EcsChildOf;
}

PINVOKE_API ecs_entity_t pinvoke_EcsSlotOf()
{
return EcsSlotOf;
}


// Entity tags
PINVOKE_API ecs_entity_t pinvoke_EcsPrefab()
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- MSBuild settings -->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<!-- Project references -->
<ItemGroup>
<ProjectReference Include="..\..\..\production\Flecs\Flecs.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Runtime.InteropServices;
using static flecs_hub.flecs;
using System.Security.Cryptography;

namespace Flecs.Examples.Entities.PrefabSlot;


internal static class Program
{
private static int Main(string[] args)
{
var world = new World(args);
// ecs_world_t* ecs = ecs_init_w_args(argc, argv);

// // Create the same prefab hierarchy as from the hierarchy example, but now
// // with the SlotOf relationship.

var spaceShipPrefab = world.CreatePrefab("SpaceShip");
var enginePrefab = world.CreatePrefab("Engine");
enginePrefab.AddParent(spaceShipPrefab);
enginePrefab.AddSlotOf(spaceShipPrefab);

var cockpitPrefab = world.CreatePrefab("Cockpit");
cockpitPrefab.AddParent(spaceShipPrefab);
cockpitPrefab.AddSlotOf(spaceShipPrefab);

// Add an additional child to the Cockpit prefab to demonstrate how
// slots can be different from the parent. This slot could have been
// added to the Cockpit prefab, but instead we register it on the top
// level SpaceShip prefab.
var pilotSeat = world.CreatePrefab("PilotSeat");
pilotSeat.AddParent(cockpitPrefab);
pilotSeat.AddSlotOf(spaceShipPrefab);

// Create a prefab instance.
var shipInstance = world.CreateEntity("SpaceShipInstance");
shipInstance.IsA(spaceShipPrefab);


// Get the instantiated entities for the prefab slots
Entity engineInstance = shipInstance.GetTarget(enginePrefab);
Entity cockpitInstance = shipInstance.GetTarget(cockpitPrefab);
Entity pilotSeatInstance = shipInstance.GetTarget(pilotSeat);


Console.WriteLine($"Instance engine: {engineInstance.FullPathString()}");
Console.WriteLine($"Instance cockpit: {cockpitInstance.FullPathString()}");
Console.WriteLine($"Instance pilot seat: {pilotSeatInstance.FullPathString()}");

return world.Fini();
}
}
12 changes: 12 additions & 0 deletions src/cs/production/Flecs/Entity.cs
Original file line number Diff line number Diff line change
@@ -197,6 +197,12 @@ private ref TComp GetPairData<TComp>(Identifier first, Identifier second)
return ref Unsafe.AsRef<TComp>(pointer);
}

public Entity GetTarget(Entity relation)
{
var target = ecs_get_target(_world.Handle, _handle, relation._handle, 0);
return new Entity(_world, target);
}

public void AddParent(Entity entity)
{
var id = ecs_pair(EcsChildOf, entity._handle);
@@ -209,6 +215,12 @@ public void IsA(Entity entity)
ecs_add_id(_world.Handle, _handle, id);
}

public void AddSlotOf(Entity entity)
{
var id = ecs_pair(EcsSlotOf, entity._handle);
ecs_add_id(_world.Handle, _handle, id);
}

public void AddComponent<TComponent>()
where TComponent : unmanaged, IComponent
{
4 changes: 3 additions & 1 deletion src/cs/production/Flecs/flecs.Extensions.cs
Original file line number Diff line number Diff line change
@@ -15,7 +15,9 @@ public static unsafe partial class flecs
public static ecs_entity_t EcsIsA => pinvoke_EcsIsA();
public static ecs_entity_t EcsDependsOn => pinvoke_EcsDependsOn();
public static ecs_entity_t EcsChildOf => pinvoke_EcsChildOf();


public static ecs_entity_t EcsSlotOf => pinvoke_EcsSlotOf();

// Entity tags
public static ecs_entity_t EcsPrefab => pinvoke_EcsPrefab();

Loading