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