Event Manager via Inheritance

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Event Manager via Inheritance

      Instead of using the app delegates I want to just use inheritance, just like the Process Manager I recently coded. Is a stream a good way to send data about the event, or would weak pointers to data/objects etc. do the job?
      Macoy Madson-http://www.augames.f11.us/
    • RE: Event Manager via Inheritance

      Send where? Across the network?

      If you don't want to use delegates, you can look at the event system from Game Coding Complete 3. This required all listeners to inherit from an EventListener class and implement a virtual ReceiveEvent() function. This function was called for all events that the class was registered to receive, so you'd have a switch/case block that handled the different events.

      Example:

      Source Code

      1. class EventListener
      2. {
      3. public:
      4. virtual void ReceiveEvent(EventData* pEvent) = 0;
      5. };
      6. class A : public EventListener
      7. {
      8. public:
      9. virtual void ReceiveEvent(EventData* pEvent);
      10. };
      11. void A::ReceiveEvent(EventData* pEvent)
      12. {
      13. EventType type = pEvent->GetType();
      14. switch (type)
      15. {
      16. case PLAYER_MOVED_EVENT:
      17. {
      18. PlayerMovedEvent* pCastEvent = static_cast<PlayerMovedEvent*>(pEvent);
      19. // Do player moved stuff....
      20. break;
      21. }
      22. case PLAYER_DIED_EVENT:
      23. {
      24. PlayerDiedEvent* pCastEvent = static_cast<PlayerDiedEvent*>(pEvent);
      25. // Do player died stuff....
      26. break;
      27. }
      28. default :
      29. {
      30. GCC_ERROR("Unknown event");
      31. break;
      32. }
      33. }
      Display All


      -Rez