rename EmitMessage to SendMessage and add special case for component self-cycle

pull/5/head
Evan Hemsley 2019-07-18 20:31:31 -07:00
parent 168846093a
commit 0639eef118
7 changed files with 30 additions and 25 deletions

View File

@ -118,7 +118,7 @@ namespace Encompass
componentMessage.entity = entity;
componentMessage.componentID = componentID;
componentMessage.component = component;
EmitMessage(componentMessage);
SendMessage(componentMessage);
return componentID;
}
@ -136,7 +136,7 @@ namespace Encompass
componentMessage.entity = entity;
componentMessage.componentID = componentID;
componentMessage.component = component;
EmitMessage(componentMessage);
SendMessage(componentMessage);
return componentID;
}
@ -155,7 +155,7 @@ namespace Encompass
componentMessage.entity = entity;
componentMessage.componentID = componentID;
componentMessage.component = component;
EmitMessage(componentMessage);
SendMessage(componentMessage);
componentManager.Activate(componentID);
}
@ -205,7 +205,7 @@ namespace Encompass
UpdateComponentInWorld(componentID, newComponentValue);
}
protected void EmitMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
protected void SendMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
{
if (!sendTypes.Contains(typeof(TMessage)))
{

View File

@ -23,7 +23,7 @@ namespace Encompass.Engines
componentMessage.entity = entity;
componentMessage.componentID = componentID;
componentMessage.component = component;
EmitMessage(componentMessage);
SendMessage(componentMessage);
}
}
}

View File

@ -80,13 +80,18 @@ namespace Encompass
engine.sendTypes.Add(activateType);
}
var messageReadTypes = engine.readTypes.Where((type) => type.GetInterfaces().Contains(typeof(IMessage)));
var messageReadTypes = engine.readTypes;
var messageSendTypes = engine.sendTypes;
if (messageReadTypes.Intersect(messageSendTypes).Any())
foreach (var messageType in messageReadTypes.Intersect(messageSendTypes))
{
var type = messageReadTypes.Intersect(messageSendTypes).First();
throw new EngineMessageSelfCycleException("Engine {0} both reads and writes Message {1}", engine.GetType().Name, type.Name);
// ComponentMessages can safely self-cycle
// this does introduce a gotcha though: if you AddComponent and then HasComponent or GetComponent you will receive a false negative
// there is no point to doing this but it is a gotcha i suppose
if (!(messageType.IsGenericType && messageType.GetGenericTypeDefinition() == typeof(ComponentMessage<>)))
{
throw new EngineMessageSelfCycleException("Engine {0} both reads and writes Message {1}", engine.GetType().Name, messageType.Name);
}
}
if (messageSendTypes.Any())

View File

@ -104,7 +104,7 @@ namespace Tests
AddMockComponentMessage addMockComponentMessage;
addMockComponentMessage.entity = entity;
addMockComponentMessage.mockComponent = mockComponent;
EmitMessage(addMockComponentMessage);
SendMessage(addMockComponentMessage);
}
}
@ -376,14 +376,14 @@ namespace Tests
CheckHasMockComponentMessage checkHasMockComponentMessage;
checkHasMockComponentMessage.entity = entity;
checkHasMockComponentMessage.shouldHaveComponent = true;
EmitMessage(checkHasMockComponentMessage);
SendMessage(checkHasMockComponentMessage);
}
else
{
CheckHasMockComponentMessage checkHasMockComponentMessage;
checkHasMockComponentMessage.entity = entity;
checkHasMockComponentMessage.shouldHaveComponent = false;
EmitMessage(checkHasMockComponentMessage);
SendMessage(checkHasMockComponentMessage);
}
}
}
@ -457,7 +457,7 @@ namespace Tests
CheckHasMockComponentMessage checkHasMockComponentMessage;
checkHasMockComponentMessage.entity = entity;
checkHasMockComponentMessage.shouldHaveComponent = true;
EmitMessage(checkHasMockComponentMessage);
SendMessage(checkHasMockComponentMessage);
}
}
}
@ -538,14 +538,14 @@ namespace Tests
CheckHasMockComponentMessage checkHasMockComponentMessage;
checkHasMockComponentMessage.entity = entity;
checkHasMockComponentMessage.shouldHaveComponent = true;
EmitMessage(checkHasMockComponentMessage);
SendMessage(checkHasMockComponentMessage);
}
else
{
CheckHasMockComponentMessage checkHasMockComponentMessage;
checkHasMockComponentMessage.entity = entity;
checkHasMockComponentMessage.shouldHaveComponent = false;
EmitMessage(checkHasMockComponentMessage);
SendMessage(checkHasMockComponentMessage);
}
}
}

View File

@ -208,7 +208,7 @@ namespace Tests
MockMessage message;
message.myString = "howdy";
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -242,7 +242,7 @@ namespace Tests
MockMessage message;
message.myString = "howdy";
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -292,7 +292,7 @@ namespace Tests
MockMessage message;
message.myString = "howdy";
this.EmitMessage(message);
this.SendMessage(message);
}
}

View File

@ -19,7 +19,7 @@ namespace Tests
{
public override void Update(double dt)
{
EmitMessage(new SpawnMessageA());
SendMessage(new SpawnMessageA());
}
}

View File

@ -20,7 +20,7 @@ namespace Tests
public override void Update(double dt)
{
BMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -31,7 +31,7 @@ namespace Tests
public override void Update(double dt)
{
AMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -60,7 +60,7 @@ namespace Tests
public override void Update(double dt)
{
BMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -71,7 +71,7 @@ namespace Tests
public override void Update(double dt)
{
CMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -82,7 +82,7 @@ namespace Tests
public override void Update(double dt)
{
DMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}
@ -93,7 +93,7 @@ namespace Tests
public override void Update(double dt)
{
AMessage message;
this.EmitMessage(message);
this.SendMessage(message);
}
}