2019-06-17 00:56:36 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using Encompass;
|
|
|
|
using System.Collections.Generic;
|
2019-06-24 19:14:37 +00:00
|
|
|
using Encompass.Exceptions;
|
2019-08-20 02:05:18 +00:00
|
|
|
using System.Linq;
|
|
|
|
using FluentAssertions;
|
2019-06-17 00:56:36 +00:00
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
public class WorldBuilderTest
|
|
|
|
{
|
|
|
|
public class EngineCycleSimple
|
|
|
|
{
|
|
|
|
struct AMessage : IMessage { }
|
|
|
|
struct BMessage : IMessage { }
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(BMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
BMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(BMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
AMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EngineCycle()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 19:26:19 +00:00
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
2019-06-17 00:56:36 +00:00
|
|
|
|
|
|
|
Assert.Throws<EngineCycleException>(() => worldBuilder.Build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EngineCycleComplex
|
|
|
|
{
|
|
|
|
struct AMessage : IMessage { }
|
|
|
|
struct BMessage : IMessage { }
|
|
|
|
struct CMessage : IMessage { }
|
|
|
|
struct DMessage : IMessage { }
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(BMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
BMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(BMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(CMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
CMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(CMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(DMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class CEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
DMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(DMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class DEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
AMessage message;
|
2019-07-19 03:31:31 +00:00
|
|
|
this.SendMessage(message);
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EngineCycle()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 19:26:19 +00:00
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
|
|
|
worldBuilder.AddEngine(new CEngine());
|
|
|
|
worldBuilder.AddEngine(new DEngine());
|
2019-06-17 00:56:36 +00:00
|
|
|
|
|
|
|
Assert.Throws<EngineCycleException>(() => worldBuilder.Build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
public class MultipleEngineWriteConflict
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
struct AComponent : IComponent { }
|
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
[Writes(typeof(AComponent))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt) { }
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
[Writes(typeof(AComponent))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt) { }
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-08-21 02:25:59 +00:00
|
|
|
public void EngineWriteConflictException()
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-06-24 19:26:19 +00:00
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
2019-06-17 00:56:36 +00:00
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
Assert.Throws<EngineWriteConflictException>(() => worldBuilder.Build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MultipleEngineWriteWithPriority
|
|
|
|
{
|
2019-09-26 20:26:48 +00:00
|
|
|
struct SetMessage : IMessage
|
2019-08-21 02:25:59 +00:00
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:26:48 +00:00
|
|
|
struct AComponent : IComponent
|
2019-08-21 02:25:59 +00:00
|
|
|
{
|
|
|
|
public int myInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Receives(typeof(SetMessage))]
|
|
|
|
[Writes(typeof(AComponent), 0)]
|
2019-12-24 03:04:26 +00:00
|
|
|
[WritesImmediate(typeof(AComponent))]
|
2019-08-21 02:25:59 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
2019-09-26 20:26:48 +00:00
|
|
|
public override void Update(double dt)
|
2019-08-21 02:25:59 +00:00
|
|
|
{
|
|
|
|
foreach (var setMessage in ReadMessages<SetMessage>())
|
|
|
|
{
|
|
|
|
SetComponent(setMessage.entity, new AComponent { myInt = 0 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Receives(typeof(SetMessage))]
|
|
|
|
[Writes(typeof(AComponent), 1)]
|
2019-12-24 03:04:26 +00:00
|
|
|
[WritesImmediate(typeof(AComponent))]
|
2019-08-21 02:25:59 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
2019-09-26 20:26:48 +00:00
|
|
|
public override void Update(double dt)
|
2019-08-21 02:25:59 +00:00
|
|
|
{
|
|
|
|
foreach (var setMessage in ReadMessages<SetMessage>())
|
|
|
|
{
|
|
|
|
SetComponent(setMessage.entity, new AComponent { myInt = 1 });
|
|
|
|
}
|
2019-09-26 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static AComponent resultComponent;
|
|
|
|
|
2019-12-24 03:04:26 +00:00
|
|
|
[ReadsImmediate(typeof(AComponent))]
|
2019-09-26 20:26:48 +00:00
|
|
|
class ReadComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
resultComponent = ReadComponent<AComponent>();
|
2019-09-26 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void LowerPriorityWrites()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
worldBuilder.SendMessage(new SetMessage { entity = entity });
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
|
|
|
Assert.That(resultComponent.myInt, Is.EqualTo(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class DefaultWritePriority
|
|
|
|
{
|
|
|
|
struct SetMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AComponent : IComponent
|
|
|
|
{
|
|
|
|
public int myInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Receives(typeof(SetMessage))]
|
|
|
|
[Writes(typeof(AComponent))]
|
2019-12-24 03:04:26 +00:00
|
|
|
[WritesImmediate(typeof(AComponent))]
|
2019-12-06 08:36:54 +00:00
|
|
|
[Encompass.DefaultWritePriority(4)]
|
2019-09-26 20:26:48 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var setMessage in ReadMessages<SetMessage>())
|
|
|
|
{
|
2019-12-06 08:36:54 +00:00
|
|
|
SetComponent(setMessage.entity, new AComponent { myInt = 5 });
|
2019-09-26 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Receives(typeof(SetMessage))]
|
|
|
|
[Writes(typeof(AComponent), 3)]
|
2019-12-24 03:04:26 +00:00
|
|
|
[WritesImmediate(typeof(AComponent))]
|
2019-09-26 20:26:48 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var setMessage in ReadMessages<SetMessage>())
|
|
|
|
{
|
|
|
|
SetComponent(setMessage.entity, new AComponent { myInt = 1 });
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 02:25:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 08:36:54 +00:00
|
|
|
[Receives(typeof(SetMessage))]
|
|
|
|
[Writes(typeof(AComponent), 2)]
|
2019-12-24 03:04:26 +00:00
|
|
|
[WritesImmediate(typeof(AComponent))]
|
2019-12-06 08:36:54 +00:00
|
|
|
class CEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var setMessage in ReadMessages<SetMessage>())
|
|
|
|
{
|
|
|
|
SetComponent(setMessage.entity, new AComponent { myInt = 3 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:25:59 +00:00
|
|
|
static AComponent resultComponent;
|
|
|
|
|
2019-12-24 03:04:26 +00:00
|
|
|
[ReadsImmediate(typeof(AComponent))]
|
2019-08-21 02:25:59 +00:00
|
|
|
class ReadComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-11-21 03:01:29 +00:00
|
|
|
resultComponent = ReadComponent<AComponent>();
|
2019-08-21 02:25:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void LowerPriorityWrites()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
2019-12-06 08:36:54 +00:00
|
|
|
worldBuilder.AddEngine(new CEngine());
|
|
|
|
worldBuilder.AddEngine(new ReadComponentEngine());
|
2019-08-21 02:25:59 +00:00
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
worldBuilder.SendMessage(new SetMessage { entity = entity });
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
2019-12-06 08:36:54 +00:00
|
|
|
Assert.That(resultComponent.myInt, Is.EqualTo(3));
|
2019-07-16 18:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EngineMessageSelfCycle
|
|
|
|
{
|
|
|
|
struct AMessage : IMessage { }
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AMessage))]
|
2019-07-16 18:17:07 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
2019-09-26 20:26:48 +00:00
|
|
|
|
2019-07-16 18:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ThrowsError()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
2019-07-19 23:15:48 +00:00
|
|
|
Assert.Throws<EngineSelfCycleException>(() => worldBuilder.AddEngine(new AEngine()), "Engine both sends and receives Message AMessage");
|
2019-07-16 18:17:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IllegalReadType
|
|
|
|
{
|
|
|
|
struct ANonMessage { }
|
|
|
|
|
|
|
|
[Reads(typeof(ANonMessage))]
|
|
|
|
class MyEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ThrowsError()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
|
|
|
Assert.Throws<IllegalReadTypeException>(() => worldBuilder.AddEngine(new MyEngine()), "ANonMessage must be a Message or Component");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class IllegalWriteType
|
|
|
|
{
|
|
|
|
struct ANonMessage { }
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(ANonMessage))]
|
2019-07-16 18:17:07 +00:00
|
|
|
class MyEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ThrowsError()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
Assert.Throws<IllegalSendTypeException>(() => worldBuilder.AddEngine(new MyEngine()), "ANonMessage must be a Message or Component");
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-22 00:54:43 +00:00
|
|
|
public class PriorityConflict
|
|
|
|
{
|
|
|
|
[Writes(typeof(MockComponent), 2)]
|
|
|
|
class AEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Writes(typeof(MockComponent), 2)]
|
|
|
|
class BEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void PriorityConflictTest()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
|
|
|
|
|
|
|
Assert.Throws<EngineWriteConflictException>(() => worldBuilder.Build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EngineWriteConflict
|
|
|
|
{
|
|
|
|
[Writes(typeof(MockComponent))]
|
|
|
|
class AEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Writes(typeof(MockComponent), 2)]
|
|
|
|
class BEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EngineWriteConflictPriorityAndNoPriorityTest()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
|
|
|
|
|
|
|
Assert.Throws<EngineWriteConflictException>(() => worldBuilder.Build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 00:56:36 +00:00
|
|
|
public class LegalEngines
|
|
|
|
{
|
|
|
|
static List<Engine> order = new List<Engine>();
|
|
|
|
|
|
|
|
struct AComponent : IComponent { }
|
|
|
|
struct BComponent : IComponent { }
|
|
|
|
|
|
|
|
struct AMessage : IMessage { }
|
|
|
|
struct BMessage : IMessage { }
|
|
|
|
struct CMessage : IMessage { }
|
|
|
|
struct DMessage : IMessage { }
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class AEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(BMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class BEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AMessage), typeof(BMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(DMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class CEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(DMessage))]
|
2019-06-17 00:56:36 +00:00
|
|
|
class DEngine : Engine
|
|
|
|
{
|
2019-06-24 19:14:37 +00:00
|
|
|
public override void Update(double dt)
|
2019-06-17 00:56:36 +00:00
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EngineOrder()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
2019-10-24 20:13:43 +00:00
|
|
|
worldBuilder.AddEngine(new AEngine());
|
|
|
|
worldBuilder.AddEngine(new BEngine());
|
|
|
|
worldBuilder.AddEngine(new CEngine());
|
|
|
|
worldBuilder.AddEngine(new DEngine());
|
|
|
|
|
|
|
|
Assert.DoesNotThrow(() => worldBuilder.Build());
|
|
|
|
|
|
|
|
worldBuilder = new WorldBuilder();
|
|
|
|
|
2019-06-24 19:26:19 +00:00
|
|
|
var engineA = worldBuilder.AddEngine(new AEngine());
|
|
|
|
var engineB = worldBuilder.AddEngine(new BEngine());
|
|
|
|
var engineC = worldBuilder.AddEngine(new CEngine());
|
|
|
|
var engineD = worldBuilder.AddEngine(new DEngine());
|
2019-06-17 00:56:36 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
|
|
|
Assert.That(order.IndexOf(engineA), Is.LessThan(order.IndexOf(engineC)));
|
|
|
|
Assert.That(order.IndexOf(engineB), Is.LessThan(order.IndexOf(engineC)));
|
|
|
|
Assert.That(order.IndexOf(engineC), Is.LessThan(order.IndexOf(engineD)));
|
|
|
|
}
|
2019-08-20 02:05:18 +00:00
|
|
|
|
|
|
|
static List<AMessage> resultMessages = new List<AMessage>();
|
|
|
|
|
|
|
|
[Receives(typeof(AMessage))]
|
|
|
|
class ReadMessageEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
resultMessages = ReadMessages<AMessage>().ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SendMessageDelayed()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new ReadMessageEngine());
|
|
|
|
|
2019-11-26 03:37:03 +00:00
|
|
|
worldBuilder.SendMessage(new AMessage { }, 0.5);
|
2019-08-20 02:05:18 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
resultMessages.Should().BeEmpty();
|
|
|
|
|
|
|
|
world.Update(0.25);
|
|
|
|
|
|
|
|
resultMessages.Should().BeEmpty();
|
|
|
|
|
|
|
|
world.Update(0.25);
|
2019-09-26 20:26:48 +00:00
|
|
|
|
2019-08-20 02:05:18 +00:00
|
|
|
resultMessages.Should().NotBeEmpty();
|
|
|
|
resultMessages.First().Should().BeOfType<AMessage>();
|
|
|
|
}
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
2019-11-13 21:05:31 +00:00
|
|
|
|
|
|
|
public class MultipleMessagesBetweenEngines
|
|
|
|
{
|
|
|
|
static List<Engine> order = new List<Engine>();
|
|
|
|
|
|
|
|
struct AMessage : IMessage { }
|
|
|
|
struct BMessage : IMessage { }
|
|
|
|
|
|
|
|
[Sends(typeof(AMessage), typeof(BMessage))]
|
|
|
|
class AEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Receives(typeof(AMessage), typeof(BMessage))]
|
|
|
|
class BEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
order.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void WorldBuilderDoesNotThrowError()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
|
|
|
|
var engineA = worldBuilder.AddEngine(new AEngine());
|
|
|
|
var engineB = worldBuilder.AddEngine(new BEngine());
|
|
|
|
|
|
|
|
Assert.DoesNotThrow(() => worldBuilder.Build());
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
|
|
|
|
Assert.That(order.IndexOf(engineA), Is.LessThan(order.IndexOf(engineB)));
|
|
|
|
}
|
|
|
|
}
|
2019-06-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|