adds SomeComponent to Engine and renames Some to SomeMessage
parent
c344ab0c67
commit
918621db73
|
@ -205,7 +205,7 @@ namespace Encompass
|
||||||
return messageManager.GetMessagesByType<TMessage>();
|
return messageManager.GetMessagesByType<TMessage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool Some<TMessage>() where TMessage : struct, IMessage
|
protected bool SomeMessage<TMessage>() where TMessage : struct, IMessage
|
||||||
{
|
{
|
||||||
if (!readTypes.Contains(typeof(TMessage)))
|
if (!readTypes.Contains(typeof(TMessage)))
|
||||||
{
|
{
|
||||||
|
@ -215,6 +215,16 @@ namespace Encompass
|
||||||
return messageManager.GetMessagesByType<TMessage>().Any();
|
return messageManager.GetMessagesByType<TMessage>().Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
|
||||||
|
{
|
||||||
|
if (!readTypes.Contains(typeof(TComponent)))
|
||||||
|
{
|
||||||
|
throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", this.GetType().Name, typeof(TComponent).Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentManager.GetActiveComponentsByType<TComponent>().Any();
|
||||||
|
}
|
||||||
|
|
||||||
protected void Destroy(Guid entityID)
|
protected void Destroy(Guid entityID)
|
||||||
{
|
{
|
||||||
entityManager.MarkForDestroy(entityID);
|
entityManager.MarkForDestroy(entityID);
|
||||||
|
|
|
@ -292,20 +292,20 @@ namespace Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Reads(typeof(MockMessage))]
|
[Reads(typeof(MockMessage))]
|
||||||
class SomeTestEngine : Engine
|
class SomeMessageTestEngine : Engine
|
||||||
{
|
{
|
||||||
public override void Update(double dt)
|
public override void Update(double dt)
|
||||||
{
|
{
|
||||||
someTest = this.Some<MockMessage>();
|
someTest = this.SomeMessage<MockMessage>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Some()
|
public void SomeMessage()
|
||||||
{
|
{
|
||||||
var worldBuilder = new WorldBuilder();
|
var worldBuilder = new WorldBuilder();
|
||||||
worldBuilder.AddEngine(new EmitMockMessageEngine());
|
worldBuilder.AddEngine(new EmitMockMessageEngine());
|
||||||
worldBuilder.AddEngine(new SomeTestEngine());
|
worldBuilder.AddEngine(new SomeMessageTestEngine());
|
||||||
|
|
||||||
var world = worldBuilder.Build();
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
@ -314,26 +314,70 @@ namespace Tests
|
||||||
Assert.That(someTest, Is.True);
|
Assert.That(someTest, Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
class UndeclaredSomeEngine : Engine
|
class UndeclaredSomeMessageEngine : Engine
|
||||||
{
|
{
|
||||||
public override void Update(double dt)
|
public override void Update(double dt)
|
||||||
{
|
{
|
||||||
someTest = this.Some<MockMessage>();
|
someTest = this.SomeMessage<MockMessage>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IllegalSome()
|
public void UndeclaredSomeMessage()
|
||||||
{
|
{
|
||||||
var worldBuilder = new WorldBuilder();
|
var worldBuilder = new WorldBuilder();
|
||||||
worldBuilder.AddEngine(new EmitMockMessageEngine());
|
worldBuilder.AddEngine(new EmitMockMessageEngine());
|
||||||
worldBuilder.AddEngine(new UndeclaredSomeEngine());
|
worldBuilder.AddEngine(new UndeclaredSomeMessageEngine());
|
||||||
|
|
||||||
var world = worldBuilder.Build();
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
Assert.Throws<IllegalReadException>(() => world.Update(0.01f));
|
Assert.Throws<IllegalReadException>(() => world.Update(0.01f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Reads(typeof(MockComponent))]
|
||||||
|
class SomeComponentTestEngine : Engine
|
||||||
|
{
|
||||||
|
public override void Update(double dt)
|
||||||
|
{
|
||||||
|
Assert.IsTrue(SomeComponent<MockComponent>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SomeComponent()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
|
||||||
|
var entity = worldBuilder.CreateEntity();
|
||||||
|
worldBuilder.AddComponent(entity, new MockComponent());
|
||||||
|
|
||||||
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
world.Update(0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
class UndeclaredSomeComponentEngine : Engine
|
||||||
|
{
|
||||||
|
public override void Update(double dt)
|
||||||
|
{
|
||||||
|
SomeComponent<MockComponent>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UndeclaredSomeComponent()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
worldBuilder.AddEngine(new UndeclaredSomeComponentEngine());
|
||||||
|
|
||||||
|
var entity = worldBuilder.CreateEntity();
|
||||||
|
worldBuilder.AddComponent(entity, new MockComponent());
|
||||||
|
|
||||||
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
Assert.Throws<IllegalReadException>(() => world.Update(0.01));
|
||||||
|
}
|
||||||
|
|
||||||
static ValueTuple<Guid, MockComponent> pairA;
|
static ValueTuple<Guid, MockComponent> pairA;
|
||||||
static ValueTuple<Guid, MockComponent> pairB;
|
static ValueTuple<Guid, MockComponent> pairB;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue