I need to IMPLEMENT(not to use some library/open source) an event/message system.
I have the following restrictions:
It must be fast. It will be use for games and speed is the main restriction. I think I can't create/delete message/event classes every time a new message/event is sent even if I use custom allocators for that.
I must be able to predict when a messages/event sent/created will be received.
It must be easy to use. Doesn't matter how complicated the implementations of the system will be, the programmer that uses it must have an easy to use interface.
I will prefer to avoid giant switches like on Windows messages, but I also want to avoid overriding a class for only one function - the event handler or something like this. I think something like the MFC style would be nice.
It must be able to handle lots (maybe 1000/frame at 60 frames/second, don't know exactly this) of messages/events without performance issues.
It can't use compilers hacks that are not available on other platforms. It must be portable. I will use C++ for implementation.
Any architecture/design/link/book that you think is suitable for/might help this would be highly appreciated. Thanks!
Let me address your points one by one:
It must be fast. It will be use for games and speed is the main restriction. I think I can't create/delete message/event classes every time a new message/event is sent even if I use custom allocators for that.
It would suffice and perhaps be even more efficient (it was for me in one project) to reuse and refill existing messages. No need for a custom allocator.
I must be able to predict when a messages/event sent/created will be received.
You can make predictions but normal networks (you want portability) will make your predictions sometimes a bit off and sometimes way off.
It must be easy to use. Doesn't matter how complicated will be the implementations of the system, the programmer that uses it must have an easy to use interface.
That should be possible, albeit this could cost you some extra effort. Error handling and special cases (platform, networking) come to mind.
I will prefer to avoid giant switches like on Windows messages, but I also want to avoid overriding a class for only one function - the event handler or something like this. I think something like the MFC style would be nice.
Avoiding manually written giant switches is a thing I 100% subscribe to.
It must be able to handle lots (maybe 1000/frame at 60 frames/second, don't know exactly this) of messages/events without performance issues.
If you take care during implementation, you should only be bounded by the network.
It can't use compilers hacks that are not available on other platforms. It must be portable. I will use C++ for implementation.
Not even C++ is available on all platforms. Could you please list the platforms you are addressing?
精彩评论