remove IHasEntity
parent
307577d399
commit
01a9211ff4
|
@ -1,7 +0,0 @@
|
|||
namespace MoonTools.ECS
|
||||
{
|
||||
public interface IHasEntity
|
||||
{
|
||||
Entity Entity { get; }
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace MoonTools.ECS
|
|||
{
|
||||
private Dictionary<Type, MessageStorage> storages = new Dictionary<Type, MessageStorage>();
|
||||
|
||||
private MessageStorage<TMessage> Lookup<TMessage>() where TMessage : struct
|
||||
private MessageStorage<TMessage> Lookup<TMessage>() where TMessage : unmanaged
|
||||
{
|
||||
if (!storages.ContainsKey(typeof(TMessage)))
|
||||
{
|
||||
|
@ -17,37 +17,42 @@ namespace MoonTools.ECS
|
|||
return storages[typeof(TMessage)] as MessageStorage<TMessage>;
|
||||
}
|
||||
|
||||
public void Add<TMessage>(in TMessage message) where TMessage : struct
|
||||
public void Add<TMessage>(in TMessage message) where TMessage : unmanaged
|
||||
{
|
||||
Lookup<TMessage>().Add(message);
|
||||
}
|
||||
|
||||
public bool Some<TMessage>() where TMessage : struct
|
||||
public void Add<TMessage>(int entityID, in TMessage message) where TMessage : unmanaged
|
||||
{
|
||||
Lookup<TMessage>().Add(entityID, message);
|
||||
}
|
||||
|
||||
public bool Some<TMessage>() where TMessage : unmanaged
|
||||
{
|
||||
return Lookup<TMessage>().Some();
|
||||
}
|
||||
|
||||
public ReadOnlySpan<TMessage> All<TMessage>() where TMessage : struct
|
||||
public ReadOnlySpan<TMessage> All<TMessage>() where TMessage : unmanaged
|
||||
{
|
||||
return Lookup<TMessage>().All();
|
||||
}
|
||||
|
||||
public TMessage First<TMessage>() where TMessage : struct
|
||||
public TMessage First<TMessage>() where TMessage : unmanaged
|
||||
{
|
||||
return Lookup<TMessage>().First();
|
||||
}
|
||||
|
||||
public IEnumerable<TMessage> WithEntity<TMessage>(int entityID) where TMessage : struct, IHasEntity
|
||||
public IEnumerable<TMessage> WithEntity<TMessage>(int entityID) where TMessage : unmanaged
|
||||
{
|
||||
return Lookup<TMessage>().WithEntity(entityID);
|
||||
}
|
||||
|
||||
public ref readonly TMessage FirstWithEntity<TMessage>(int entityID) where TMessage : struct, IHasEntity
|
||||
public ref readonly TMessage FirstWithEntity<TMessage>(int entityID) where TMessage : unmanaged
|
||||
{
|
||||
return ref Lookup<TMessage>().FirstWithEntity(entityID);
|
||||
}
|
||||
|
||||
public bool SomeWithEntity<TMessage>(int entityID) where TMessage : struct, IHasEntity
|
||||
public bool SomeWithEntity<TMessage>(int entityID) where TMessage : unmanaged
|
||||
{
|
||||
return Lookup<TMessage>().SomeWithEntity(entityID);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace MoonTools.ECS
|
|||
public abstract void Clear();
|
||||
}
|
||||
|
||||
internal class MessageStorage<TMessage> : MessageStorage where TMessage : struct
|
||||
internal class MessageStorage<TMessage> : MessageStorage where TMessage : unmanaged
|
||||
{
|
||||
private int count = 0;
|
||||
private int capacity = 128;
|
||||
|
@ -29,20 +29,20 @@ namespace MoonTools.ECS
|
|||
}
|
||||
|
||||
messages[count] = message;
|
||||
|
||||
if (message is IHasEntity entityMessage)
|
||||
{
|
||||
if (!entityToIndices.ContainsKey(entityMessage.Entity.ID))
|
||||
{
|
||||
entityToIndices.Add(entityMessage.Entity.ID, new List<int>());
|
||||
}
|
||||
|
||||
entityToIndices[entityMessage.Entity.ID].Add(count);
|
||||
}
|
||||
|
||||
count += 1;
|
||||
}
|
||||
|
||||
public void Add(int entityID, in TMessage message)
|
||||
{
|
||||
if (!entityToIndices.ContainsKey(entityID))
|
||||
{
|
||||
entityToIndices.Add(entityID, new List<int>());
|
||||
}
|
||||
entityToIndices[entityID].Add(count);
|
||||
|
||||
Add(message);
|
||||
}
|
||||
|
||||
public bool Some()
|
||||
{
|
||||
return count > 0;
|
||||
|
|
|
@ -43,17 +43,17 @@ namespace MoonTools.ECS
|
|||
return MessageDepot.Some<TMessage>();
|
||||
}
|
||||
|
||||
protected IEnumerable<TMessage> ReadMessagesWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged, IHasEntity
|
||||
protected IEnumerable<TMessage> ReadMessagesWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
|
||||
{
|
||||
return MessageDepot.WithEntity<TMessage>(entity.ID);
|
||||
}
|
||||
|
||||
protected ref readonly TMessage ReadMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged, IHasEntity
|
||||
protected ref readonly TMessage ReadMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
|
||||
{
|
||||
return ref MessageDepot.FirstWithEntity<TMessage>(entity.ID);
|
||||
}
|
||||
|
||||
protected bool SomeMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged, IHasEntity
|
||||
protected bool SomeMessageWithEntity<TMessage>(in Entity entity) where TMessage : unmanaged
|
||||
{
|
||||
return MessageDepot.SomeWithEntity<TMessage>(entity.ID);
|
||||
}
|
||||
|
@ -63,6 +63,11 @@ namespace MoonTools.ECS
|
|||
MessageDepot.Add(message);
|
||||
}
|
||||
|
||||
protected void Send<TMessage>(in Entity entity, in TMessage message) where TMessage : unmanaged
|
||||
{
|
||||
MessageDepot.Add(entity.ID, message);
|
||||
}
|
||||
|
||||
protected void Relate<TRelationKind>(in Entity entityA, in Entity entityB, TRelationKind relationData) where TRelationKind : unmanaged
|
||||
{
|
||||
RelationDepot.Set<TRelationKind>(new Relation(entityA, entityB), relationData);
|
||||
|
|
Loading…
Reference in New Issue