rename EmitMessage to SendMessage and add special case for component self-cycle
parent
168846093a
commit
0639eef118
|
@ -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)))
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Encompass.Engines
|
|||
componentMessage.entity = entity;
|
||||
componentMessage.componentID = componentID;
|
||||
componentMessage.component = component;
|
||||
EmitMessage(componentMessage);
|
||||
SendMessage(componentMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Tests
|
|||
{
|
||||
public override void Update(double dt)
|
||||
{
|
||||
EmitMessage(new SpawnMessageA());
|
||||
SendMessage(new SpawnMessageA());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue