message improvements
parent
ed965d43a3
commit
bd7c316ea8
|
@ -8,28 +8,25 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
private readonly Dictionary<Type, List<IMessage>> messageTypeToMessages = new Dictionary<Type, List<IMessage>>();
|
private readonly Dictionary<Type, List<IMessage>> messageTypeToMessages = new Dictionary<Type, List<IMessage>>();
|
||||||
|
|
||||||
internal void AddMessage<TMessage>(TMessage message) where TMessage : struct, IMessage
|
internal void RegisterMessageType(Type messageType)
|
||||||
{
|
{
|
||||||
if (!messageTypeToMessages.ContainsKey(typeof(TMessage)))
|
if (!messageTypeToMessages.ContainsKey(messageType)) {
|
||||||
{
|
messageTypeToMessages.Add(messageType, new List<IMessage>());
|
||||||
messageTypeToMessages.Add(typeof(TMessage), new List<IMessage>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
messageTypeToMessages[typeof(TMessage)].Add(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AddMessage(IMessage message)
|
internal void AddMessage(IMessage message)
|
||||||
{
|
{
|
||||||
var type = message.GetType();
|
var type = message.GetType();
|
||||||
|
|
||||||
if (!messageTypeToMessages.ContainsKey(type))
|
|
||||||
{
|
|
||||||
messageTypeToMessages.Add(type, new List<IMessage>());
|
|
||||||
}
|
|
||||||
|
|
||||||
messageTypeToMessages[type].Add(message);
|
messageTypeToMessages[type].Add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void AddMessage<TMessage>(IMessage message) where TMessage : struct, IMessage
|
||||||
|
{
|
||||||
|
messageTypeToMessages[typeof(TMessage)].Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
internal void ClearMessages()
|
internal void ClearMessages()
|
||||||
{
|
{
|
||||||
foreach (var entry in messageTypeToMessages)
|
foreach (var entry in messageTypeToMessages)
|
||||||
|
|
|
@ -86,6 +86,11 @@ namespace Encompass
|
||||||
var messageReceiveTypes = engine.receiveTypes;
|
var messageReceiveTypes = engine.receiveTypes;
|
||||||
var messageSendTypes = engine.sendTypes;
|
var messageSendTypes = engine.sendTypes;
|
||||||
|
|
||||||
|
foreach (var messageType in messageReceiveTypes.Union(messageSendTypes))
|
||||||
|
{
|
||||||
|
messageManager.RegisterMessageType(messageType);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var messageType in messageReceiveTypes.Intersect(messageSendTypes))
|
foreach (var messageType in messageReceiveTypes.Intersect(messageSendTypes))
|
||||||
{
|
{
|
||||||
if ((messageType.IsGenericType && messageType.GetGenericTypeDefinition() == typeof(PendingComponentMessage<>)))
|
if ((messageType.IsGenericType && messageType.GetGenericTypeDefinition() == typeof(PendingComponentMessage<>)))
|
||||||
|
|
Loading…
Reference in New Issue