bring back ReadsPending attribute
parent
c6192d5b4c
commit
c7cae0d9d1
|
@ -22,7 +22,6 @@ namespace Encompass
|
|||
}
|
||||
|
||||
this.readTypes.Add(typeof(ComponentMessage<>).MakeGenericType(readType));
|
||||
this.readTypes.Add(typeof(PendingComponentMessage<>).MakeGenericType(readType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Encompass.Exceptions;
|
||||
|
||||
namespace Encompass
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ReadsPending : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> readPendingTypes = new HashSet<Type>();
|
||||
|
||||
public ReadsPending(params Type[] readPendingTypes)
|
||||
{
|
||||
foreach (var readPendingType in readPendingTypes)
|
||||
{
|
||||
var isComponent = readPendingType.GetInterfaces().Contains(typeof(IComponent));
|
||||
|
||||
if (!isComponent)
|
||||
{
|
||||
throw new IllegalReadTypeException("{0} must be a Component", readPendingType.Name);
|
||||
}
|
||||
|
||||
this.readPendingTypes.Add(typeof(PendingComponentMessage<>).MakeGenericType(readPendingType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,12 @@ namespace Encompass
|
|||
{
|
||||
receiveTypes.UnionWith(readsAttribute.readTypes);
|
||||
}
|
||||
|
||||
var readsPendingAttribute = GetType().GetCustomAttribute<ReadsPending>(false);
|
||||
if (readsPendingAttribute != null)
|
||||
{
|
||||
receiveTypes.UnionWith(readsPendingAttribute.readPendingTypes);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AssignEntityManager(EntityManager entityManager)
|
||||
|
@ -181,6 +187,14 @@ namespace Encompass
|
|||
{
|
||||
return ExistingComponents<TComponent>().Union(PendingComponents<TComponent>());
|
||||
}
|
||||
else if (existingRead)
|
||||
{
|
||||
return ExistingComponents<TComponent>();
|
||||
}
|
||||
else if (pendingRead)
|
||||
{
|
||||
return PendingComponents<TComponent>();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, typeof(TComponent).Name);
|
||||
|
@ -217,11 +231,6 @@ namespace Encompass
|
|||
return ExistingComponentsOnEntity<TComponent>(entity);
|
||||
}
|
||||
|
||||
protected ValueTuple<Guid, TComponent> GetPendingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
||||
{
|
||||
return PendingComponentsOnEntity<TComponent>(entity).First();
|
||||
}
|
||||
|
||||
protected ValueTuple<Guid, TComponent> GetComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
||||
{
|
||||
return GetComponents<TComponent>(entity).First();
|
||||
|
@ -232,11 +241,6 @@ namespace Encompass
|
|||
return GetComponents<TComponent>(entity).Any();
|
||||
}
|
||||
|
||||
internal void ActivateComponentInWorld(Guid componentID)
|
||||
{
|
||||
componentManager.Activate(componentID);
|
||||
}
|
||||
|
||||
internal void UpdateComponentInWorld<TComponent>(Guid componentID, TComponent newComponent) where TComponent : struct, IComponent
|
||||
{
|
||||
componentManager.AddUpdateComponentOperation(componentID, newComponent);
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Reads(typeof(MockComponent))]
|
||||
[ReadsPending(typeof(MockComponent))]
|
||||
class HasMockComponentEngine : Engine
|
||||
{
|
||||
private Entity entity;
|
||||
|
@ -481,7 +481,7 @@ namespace Tests
|
|||
}
|
||||
|
||||
[Receives(typeof(CheckHasMockComponentMessage))]
|
||||
[Reads(typeof(MockComponent))]
|
||||
[ReadsPending(typeof(MockComponent))]
|
||||
class CheckHasPendingMockComponentEngine : Engine
|
||||
{
|
||||
public override void Update(double dt)
|
||||
|
|
Loading…
Reference in New Issue