I'm developing a game engine in C++ that allows Python scripting. Here's an example of how functions can be defined in Python that are then called by the an event manager whenever a certain event occurs:
# Import some classes defined in C++
from cpp.event import PlayerDiesEvent, EventManager
def onPlayerDeath(event):
pass
em = EventManager()
em.connect(PlayerDiesEvent, onPlayerDeath)
em.post(PlayerDiesEvent(...)) # Will call `onPlayerDeath`
The user can also define new types of events:
from cpp.event import Event, EventManager
class CustomEvent(Event):
pass
def onCustomEvent(event):
pass
em = EventManager()
em.connect(CustomEvent, onCustomEvent)
em.post(CustomEvent())
However, I would also like the messaging system to work with inheritance, which it currently does not. Here's what I mean:
from cpp.event import PlayerDiesEvent, EventManager
class CustomEvent(PlayerDiesEvent):
pass
def onPlayerDeath(event):
pass
def onCustomEvent(event):
pass
em = EventManager()
em.connect(PlayerDiesEvent, onPlayerDeath)
em.connect(CustomEvent, onCustomEvent)
# This notifies both functions, because `CustomEvent` is a `PlayerDiesEvent`
em.post(CustomEvent(...))
# This notifies only `onPlayerDeath`
em.post(PlayerDiesEvent(...))
tld;dr: Is there any C++ library that would allow me to more easily create a custom RTTI system that works with inheritance? If not, any ideas how I might implement this more easily and perhaps more generally (preferably in a way that is agnostic to my actual use case)?