Recently I’ve been working on an Event System in C++. You might be reading that right now and wonder why that small sentence makes it sound like a true endeavor. Well, it was. As many of you may know I’m a student at Champlain College, and in one of my classes, each of the students are tasked to use an event system or a messaging system in their game. The teacher provided us with one, and it’s really great and all, but I couldn’t help but feeling restricted, especially after having used C# for so long where the code is so forgiving, and easy.
I did some research and it turns out that a lot of event systems in C++ are organized in such a way that when you want to do events you must:
- Create an EventManager class (nothing wrong with this)
- Create an EventListener class (for setting up events)
- Create and Event base class
- Be restricted to use only one function to handle your events
- Create a huge enum holding a key for each of your events (Can hash it for speed)
I saw those and my heart dropped. I immediately thought that is way to restrictive, there must be an easier way to get events to work. And so the researching began.