Hey all,
I'm working on a message based game engine, and I'm having handlers identify their messages with the "is" keyword. How much of a performance hit is this going to cost me?
Here's basically what the heirarchy looks like:
IMessage
IEntityMessage
CreateEntityMessage
KillEntityMessage
ISoundMessage
PlaySoundMessage
Every message is posted to a singleton Message Centre and the handlers subscribe to that centre to listen for messages. This gives the added benefit of handlers able to react to certain things. For example, the sound message might have a location and the entity handler might have AI react to the sound.
Here's the gist of how I check message types:
public class EntityHandler : BaseMessageHandler
{
public static EntityCreateMessage createMessage = new EntityCreateMessage();
public override void Receive(IMessage message)
{
if(message is EntityCreateMessage)
{
EntityCreateMessage msg = (EntityCreateMessage)message;
System.Windows.Forms.MessageBox.Show("Message Received!");
}
}
}
I'm thinking that the "if(message is EntityCreateMessage)" is really going to end up being a bottleneck, since it's a lot of boxing / unboxing comparisons. Potentially, 100s of messages could be flying around every second.
Any ideas?