MoonTools.ECS/src/System.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2022-04-08 05:52:03 +00:00
using System;
2022-03-05 02:01:44 +00:00
2022-04-08 05:52:03 +00:00
namespace MoonTools.ECS
2022-03-05 02:01:44 +00:00
{
public abstract class System : Manipulator
2022-03-07 07:17:05 +00:00
{
internal MessageDepot MessageDepot => World.MessageDepot;
2022-03-07 07:17:05 +00:00
public System(World world) : base(world) { }
2022-03-07 07:17:05 +00:00
2022-04-08 05:52:03 +00:00
public abstract void Update(TimeSpan delta);
2022-03-05 02:01:44 +00:00
protected ReadOnlySpan<TMessage> ReadMessages<TMessage>() where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return MessageDepot.All<TMessage>();
}
2022-03-07 07:17:05 +00:00
protected TMessage ReadMessage<TMessage>() where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return MessageDepot.First<TMessage>();
}
2022-03-07 07:17:05 +00:00
protected bool SomeMessage<TMessage>() where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return MessageDepot.Some<TMessage>();
}
2022-03-18 19:50:59 +00:00
protected ReverseSpanEnumerator<TMessage> ReadMessagesWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return MessageDepot.WithEntity<TMessage>(entity.ID);
}
2022-03-18 19:50:59 +00:00
protected ref readonly TMessage ReadMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return ref MessageDepot.FirstWithEntity<TMessage>(entity.ID);
}
2022-03-18 19:50:59 +00:00
protected bool SomeMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
2022-04-08 05:52:03 +00:00
{
return MessageDepot.SomeWithEntity<TMessage>(entity.ID);
}
2022-03-07 18:56:53 +00:00
protected void Send<TMessage>(in TMessage message) where TMessage : unmanaged => World.Send(message);
protected void Send<TMessage>(in Entity entity, in TMessage message) where TMessage : unmanaged => World.Send(entity, message);
2022-03-05 02:01:44 +00:00
}
}