32 lines
813 B
C#
32 lines
813 B
C#
|
using System.Runtime.InteropServices.Swift;
|
||
|
using ExampleWorld.wit.imports.lyra.api;
|
||
|
|
||
|
namespace LyraApi.Ecs;
|
||
|
|
||
|
public class ViewResult
|
||
|
{
|
||
|
private List<Component> components;
|
||
|
private IEcs.EcsDynamicView inner;
|
||
|
|
||
|
internal ViewResult(List<Component> components, IEcs.EcsDynamicView inner)
|
||
|
{
|
||
|
this.components = components;
|
||
|
this.inner = inner;
|
||
|
}
|
||
|
|
||
|
public IEnumerable<(Entity, T1)> Get<T1>() where T1 : IComponent
|
||
|
{
|
||
|
(IEcs.Entity, byte[])? row = inner.Next();
|
||
|
|
||
|
if (row is (var entity, byte[] bytes))
|
||
|
{
|
||
|
byte[] compBytes = bytes.Take((int)T1.HostSize).ToArray();
|
||
|
var t1 = (T1?)T1.TakeFromBytes(compBytes);
|
||
|
|
||
|
if (t1 != null)
|
||
|
{
|
||
|
yield return (new Entity(entity), t1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|