2024-11-07 23:10:57 +00:00
|
|
|
|
namespace ExampleWorld;
|
2024-11-05 20:10:19 +00:00
|
|
|
|
|
2024-11-07 02:26:03 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2024-11-09 02:05:02 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2024-11-07 02:26:03 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2024-11-09 02:05:02 +00:00
|
|
|
|
using ExampleWorld.wit.imports.lyra.api;
|
2024-11-08 00:28:35 +00:00
|
|
|
|
using LyraApi;
|
|
|
|
|
using LyraApi.Ecs;
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
2024-11-08 00:28:35 +00:00
|
|
|
|
struct Vec3(float x, float y, float z) : IComponent
|
2024-11-05 20:10:19 +00:00
|
|
|
|
{
|
2024-11-07 23:10:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The X component.
|
|
|
|
|
/// </summary>
|
2024-11-07 02:26:03 +00:00
|
|
|
|
public float X { get; set; } = x;
|
2024-11-07 23:10:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Y component
|
|
|
|
|
/// </summary>
|
2024-11-07 02:26:03 +00:00
|
|
|
|
public float Y { get; set; } = y;
|
2024-11-07 23:10:57 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Z component
|
|
|
|
|
/// </summary>
|
2024-11-07 02:26:03 +00:00
|
|
|
|
public float Z { get; set; } = z;
|
2024-11-08 00:28:35 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
public static string HostName => "Vec3";
|
|
|
|
|
public static ulong HostSize => (ulong)Marshal.SizeOf<Vec3>();
|
|
|
|
|
public static ulong HostAlignment => (ulong)MarshalUtils.AlignmentOf<Vec3>();
|
|
|
|
|
public static ulong TypeId => 4124409524;
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
public static object? TakeFromBytes(byte[] bytes)
|
2024-11-07 02:26:03 +00:00
|
|
|
|
{
|
2024-11-09 02:05:02 +00:00
|
|
|
|
byte[] taken = bytes.Take((int)HostSize).ToArray();
|
|
|
|
|
return MarshalUtils.FromBytes<Vec3>(taken);
|
2024-11-07 02:26:03 +00:00
|
|
|
|
}
|
2024-11-09 02:05:02 +00:00
|
|
|
|
}
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
public class ExampleWorldImpl : IExampleWorld
|
|
|
|
|
{
|
2024-11-07 02:26:03 +00:00
|
|
|
|
public static void OnInit(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
|
2024-11-09 02:05:02 +00:00
|
|
|
|
{
|
2024-11-08 00:28:35 +00:00
|
|
|
|
var world = new World(gameWorld);
|
2024-11-09 02:05:02 +00:00
|
|
|
|
Entity entity = world.Spawn(new Vec3(7.0f, 30.0f, 18.0f));
|
|
|
|
|
Console.WriteLine("C#: Spawned entity with id {0}", entity.Id);
|
2024-11-07 02:26:03 +00:00
|
|
|
|
|
2024-11-09 02:05:02 +00:00
|
|
|
|
foreach ((Entity en, Vec3 comp) in world.View<Vec3>())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("C#: Found entity at ({0}, {1}, {2})", comp.X, comp.Y, comp.Z);
|
2024-11-07 02:26:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnUpdate(IEcs.EcsWorld gameWorld, IEcs.Entity owningEntity)
|
2024-11-05 20:10:19 +00:00
|
|
|
|
{
|
2024-11-07 02:26:03 +00:00
|
|
|
|
throw new NotImplementedException();
|
2024-11-05 20:10:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|