2019-07-17 18:24:21 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
using Encompass;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Tests
|
|
|
|
{
|
|
|
|
public class ComponentTests
|
|
|
|
{
|
|
|
|
struct MockComponent : IComponent
|
|
|
|
{
|
|
|
|
public string myString;
|
|
|
|
public int myInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EntityMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IEnumerable<(Guid, MockComponent)> gottenMockComponentIDPairs = Enumerable.Empty<(Guid, MockComponent)>();
|
|
|
|
static (Guid, MockComponent) gottenMockComponentIDPair;
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(EntityMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class GetMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var entityMessage in ReadMessages<EntityMessage>())
|
|
|
|
{
|
|
|
|
gottenMockComponentIDPair = GetComponent<MockComponent>(entityMessage.entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AddComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public MockComponent mockComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AddComponentTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class AddComponentTestEngine : Engine
|
2019-07-17 18:24:21 +00:00
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var addComponentTestMessage in ReadMessages<AddComponentTestMessage>())
|
|
|
|
{
|
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(addComponentTestMessage.entity));
|
|
|
|
Assert.That(GetComponent<MockComponent>(addComponentTestMessage.entity).Item2, Is.EqualTo(addComponentTestMessage.mockComponent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
2019-07-18 21:02:57 +00:00
|
|
|
worldBuilder.AddEngine(new AddComponentTestEngine());
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
AddComponentTestMessage addComponentTestMessage;
|
|
|
|
addComponentTestMessage.entity = entity;
|
|
|
|
addComponentTestMessage.mockComponent = mockComponent;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(addComponentTestMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:02:57 +00:00
|
|
|
struct AddMockComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public MockComponent mockComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(AddMockComponentMessage))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class EmitMockComponentMessageEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public EmitMockComponentMessageEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 10;
|
|
|
|
mockComponent.myString = "four";
|
|
|
|
|
|
|
|
AddMockComponentMessage addMockComponentMessage;
|
|
|
|
addMockComponentMessage.entity = entity;
|
|
|
|
addMockComponentMessage.mockComponent = mockComponent;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(addMockComponentMessage);
|
2019-07-18 21:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Activates(typeof(MockComponent))]
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(AddMockComponentMessage))]
|
2019-07-18 21:02:57 +00:00
|
|
|
class AddMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var message in ReadMessages<AddMockComponentMessage>())
|
|
|
|
{
|
|
|
|
AddComponent(message.entity, message.mockComponent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Reads(typeof(MockComponent))]
|
|
|
|
class HasMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public HasMockComponentEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(entity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void AddComponentAndReadSameFrame()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
worldBuilder.AddEngine(new EmitMockComponentMessageEngine(entity));
|
|
|
|
worldBuilder.AddEngine(new AddMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new HasMockComponentEngine(entity));
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(EntityMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-19 00:50:38 +00:00
|
|
|
class GetMockComponentsEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
private Guid componentAID;
|
|
|
|
private Guid componentBID;
|
|
|
|
private Guid componentCID;
|
|
|
|
private MockComponent componentA;
|
|
|
|
private MockComponent componentB;
|
|
|
|
private MockComponent componentC;
|
|
|
|
|
|
|
|
public GetMockComponentsEngine(
|
|
|
|
Entity entity,
|
|
|
|
Guid componentAID,
|
|
|
|
MockComponent componentA,
|
|
|
|
Guid componentBID,
|
|
|
|
MockComponent componentB,
|
|
|
|
Guid componentCID,
|
|
|
|
MockComponent componentC
|
|
|
|
) {
|
|
|
|
this.entity = entity;
|
|
|
|
this.componentAID = componentAID;
|
|
|
|
this.componentA = componentA;
|
|
|
|
this.componentBID = componentBID;
|
|
|
|
this.componentB = componentB;
|
|
|
|
this.componentCID = componentCID;
|
|
|
|
this.componentC = componentC;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var entityMessage in ReadMessages<EntityMessage>())
|
|
|
|
{
|
|
|
|
var results = GetComponents<MockComponent>(entityMessage.entity);
|
|
|
|
results.Should().Contain((componentAID, componentA));
|
|
|
|
results.Should().Contain((componentBID, componentB));
|
|
|
|
results.Should().Contain((componentCID, componentC));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
[Test]
|
|
|
|
public void GetComponents()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponentA;
|
|
|
|
mockComponentA.myInt = 3;
|
|
|
|
mockComponentA.myString = "hello";
|
|
|
|
|
|
|
|
MockComponent mockComponentB;
|
|
|
|
mockComponentB.myInt = 5;
|
|
|
|
mockComponentB.myString = "wassup";
|
|
|
|
|
|
|
|
MockComponent mockComponentC;
|
|
|
|
mockComponentC.myInt = 1;
|
|
|
|
mockComponentC.myString = "howdy";
|
|
|
|
|
|
|
|
var componentAID = worldBuilder.AddComponent(entity, mockComponentA);
|
|
|
|
var componentBID = worldBuilder.AddComponent(entity, mockComponentB);
|
|
|
|
var componentCID = worldBuilder.AddComponent(entity, mockComponentC);
|
|
|
|
|
2019-07-19 00:50:38 +00:00
|
|
|
worldBuilder.AddEngine(new GetMockComponentsEngine(
|
|
|
|
entity,
|
|
|
|
componentAID,
|
|
|
|
mockComponentA,
|
|
|
|
componentBID,
|
|
|
|
mockComponentB,
|
|
|
|
componentCID,
|
|
|
|
mockComponentC
|
|
|
|
));
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
EntityMessage entityMessage;
|
|
|
|
entityMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(entityMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new GetMockComponentEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
var componentID = worldBuilder.AddComponent<MockComponent>(entity, mockComponent);
|
|
|
|
|
|
|
|
EntityMessage entityMessage;
|
|
|
|
entityMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(entityMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
|
|
|
|
Assert.AreEqual((componentID, mockComponent), gottenMockComponentIDPair);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HasComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(HasComponentTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class HasComponentTestEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var hasComponentTestEngine in ReadMessages<HasComponentTestMessage>())
|
|
|
|
{
|
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(hasComponentTestEngine.entity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new HasComponentTestEngine());
|
|
|
|
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
HasComponentTestMessage hasComponentTestMessage;
|
|
|
|
hasComponentTestMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(hasComponentTestMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HasComponentWhenInactiveTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(HasComponentWhenInactiveTestMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class HasComponentWhenInactiveTestEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var hasComponentTestEngine in ReadMessages<HasComponentWhenInactiveTestMessage>())
|
|
|
|
{
|
|
|
|
Assert.IsFalse(HasComponent<MockComponent>(hasComponentTestEngine.entity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponentWhenInactive()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
worldBuilder.AddEngine(new HasComponentWhenInactiveTestEngine());
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
var componentID = worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
HasComponentWhenInactiveTestMessage testMessage;
|
|
|
|
testMessage.entity = entity;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(testMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
worldBuilder.DeactivateComponent(componentID);
|
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RemoveComponentTestMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public Guid componentID;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(RemoveComponentTestMessage))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class RemoveComponentTestEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var removeComponentMessage in ReadMessages<RemoveComponentTestMessage>())
|
|
|
|
{
|
|
|
|
RemoveComponent(removeComponentMessage.componentID);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(RemoveComponentTestMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(CheckHasMockComponentMessage))]
|
2019-07-18 01:12:29 +00:00
|
|
|
class DoRemoveCheckEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
2019-07-17 18:24:21 +00:00
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
public DoRemoveCheckEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
if (SomeMessage<RemoveComponentTestMessage>())
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = true;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = false;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void RemoveComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
worldBuilder.AddEngine(new RemoveComponentTestEngine());
|
|
|
|
worldBuilder.AddEngine(new CheckHasMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new DoRemoveCheckEngine(entity));
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
var componentID = worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
RemoveComponentTestMessage removeComponentMessage;
|
|
|
|
removeComponentMessage.entity = entity;
|
|
|
|
removeComponentMessage.componentID = componentID;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(removeComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01f);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ActivateComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public Guid componentID;
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:02:57 +00:00
|
|
|
[Activates(typeof(MockComponent))]
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(ActivateComponentMessage))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class ActivateComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var activateComponentMessage in ReadMessages<ActivateComponentMessage>())
|
|
|
|
{
|
2019-07-18 21:02:57 +00:00
|
|
|
ActivateComponent<MockComponent>(activateComponentMessage.componentID);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CheckHasMockComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public bool shouldHaveComponent;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(ActivateComponentMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(CheckHasMockComponentMessage))]
|
2019-07-18 01:12:29 +00:00
|
|
|
class DoActivateCheckEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public DoActivateCheckEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
if (SomeMessage<ActivateComponentMessage>())
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = true;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(CheckHasMockComponentMessage))]
|
|
|
|
[Reads(typeof(MockComponent))]
|
2019-07-18 01:12:29 +00:00
|
|
|
class CheckHasMockComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var checkHasMockComponentMessage in ReadMessages<CheckHasMockComponentMessage>())
|
|
|
|
{
|
2019-07-19 00:50:38 +00:00
|
|
|
Assert.IsTrue(HasComponent<MockComponent>(checkHasMockComponentMessage.entity));
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void ActivateComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
worldBuilder.AddEngine(new ActivateComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new CheckHasMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new DoActivateCheckEngine(entity));
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
var componentID = worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
worldBuilder.DeactivateComponent(componentID);
|
|
|
|
|
|
|
|
ActivateComponentMessage activateMessage;
|
|
|
|
activateMessage.entity = entity;
|
|
|
|
activateMessage.componentID = componentID;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(activateMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
world.Update(0.01);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct DeactivateComponentMessage : IMessage
|
|
|
|
{
|
|
|
|
public Entity entity;
|
|
|
|
public Guid componentID;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(DeactivateComponentMessage))]
|
2019-07-17 18:24:21 +00:00
|
|
|
class DeactivateComponentEngine : Engine
|
|
|
|
{
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
foreach (var deactivateComponentMessage in ReadMessages<DeactivateComponentMessage>())
|
|
|
|
{
|
|
|
|
DeactivateComponent(deactivateComponentMessage.componentID);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:47:17 +00:00
|
|
|
[Receives(typeof(DeactivateComponentMessage))]
|
2019-07-19 01:20:38 +00:00
|
|
|
[Sends(typeof(CheckHasMockComponentMessage))]
|
2019-07-18 01:12:29 +00:00
|
|
|
class DoDeactivateCheckEngine : Engine
|
|
|
|
{
|
|
|
|
private Entity entity;
|
|
|
|
|
|
|
|
public DoDeactivateCheckEngine(Entity entity)
|
|
|
|
{
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Update(double dt)
|
|
|
|
{
|
|
|
|
if (SomeMessage<DeactivateComponentMessage>())
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = true;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-18 01:12:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CheckHasMockComponentMessage checkHasMockComponentMessage;
|
|
|
|
checkHasMockComponentMessage.entity = entity;
|
|
|
|
checkHasMockComponentMessage.shouldHaveComponent = false;
|
2019-07-19 03:31:31 +00:00
|
|
|
SendMessage(checkHasMockComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeactivateComponent()
|
|
|
|
{
|
|
|
|
var worldBuilder = new WorldBuilder();
|
|
|
|
var entity = worldBuilder.CreateEntity();
|
|
|
|
|
2019-07-18 01:12:29 +00:00
|
|
|
worldBuilder.AddEngine(new DeactivateComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new CheckHasMockComponentEngine());
|
|
|
|
worldBuilder.AddEngine(new DoDeactivateCheckEngine(entity));
|
|
|
|
|
2019-07-17 18:24:21 +00:00
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
var componentID = worldBuilder.AddComponent(entity, mockComponent);
|
|
|
|
|
|
|
|
DeactivateComponentMessage deactivateComponentMessage;
|
|
|
|
deactivateComponentMessage.entity = entity;
|
|
|
|
deactivateComponentMessage.componentID = componentID;
|
2019-07-19 04:07:26 +00:00
|
|
|
worldBuilder.SendMessage(deactivateComponentMessage);
|
2019-07-17 18:24:21 +00:00
|
|
|
|
|
|
|
var world = worldBuilder.Build();
|
|
|
|
|
|
|
|
world.Update(0.01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|