unparameterized SendMessage

pull/5/head
Evan Hemsley 2019-07-28 22:25:34 -07:00
parent 27c5a9e73e
commit ed965d43a3
2 changed files with 25 additions and 0 deletions

View File

@ -269,6 +269,19 @@ namespace Encompass
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
{
if (!receiveTypes.Contains(typeof(TMessage)))

View File

@ -18,6 +18,18 @@ namespace Encompass
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()
{
foreach (var entry in messageTypeToMessages)