unparameterized SendMessage
parent
27c5a9e73e
commit
ed965d43a3
|
@ -269,6 +269,19 @@ namespace Encompass
|
||||||
messageManager.AddMessage(message);
|
messageManager.AddMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unparameterized version to enable dynamic dispatch
|
||||||
|
protected void SendMessage(IMessage message)
|
||||||
|
{
|
||||||
|
var type = message.GetType();
|
||||||
|
|
||||||
|
if (!sendTypes.Contains(type) || !type.IsValueType)
|
||||||
|
{
|
||||||
|
throw new IllegalSendException("Engine {0} tried to send undeclared Message {1}", GetType().Name, type.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
messageManager.AddMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
protected IEnumerable<TMessage> ReadMessages<TMessage>() where TMessage : struct, IMessage
|
protected IEnumerable<TMessage> ReadMessages<TMessage>() where TMessage : struct, IMessage
|
||||||
{
|
{
|
||||||
if (!receiveTypes.Contains(typeof(TMessage)))
|
if (!receiveTypes.Contains(typeof(TMessage)))
|
||||||
|
|
|
@ -18,6 +18,18 @@ namespace Encompass
|
||||||
messageTypeToMessages[typeof(TMessage)].Add(message);
|
messageTypeToMessages[typeof(TMessage)].Add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void AddMessage(IMessage message)
|
||||||
|
{
|
||||||
|
var type = message.GetType();
|
||||||
|
|
||||||
|
if (!messageTypeToMessages.ContainsKey(type))
|
||||||
|
{
|
||||||
|
messageTypeToMessages.Add(type, new List<IMessage>());
|
||||||
|
}
|
||||||
|
|
||||||
|
messageTypeToMessages[type].Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
internal void ClearMessages()
|
internal void ClearMessages()
|
||||||
{
|
{
|
||||||
foreach (var entry in messageTypeToMessages)
|
foreach (var entry in messageTypeToMessages)
|
||||||
|
|
Loading…
Reference in New Issue