Register multiple callbacks?

edited January 2015 in Help request
I'm engineering my code right now, working mostly on headers and stuff, figuring out where I want to place everything and where I want it to run.

There is one piece of information that is important for me to know now before I go any further though. Is it possible to have more that one callback registered for an event handler or for an update callback?

Right now, I have not defined any event handlers aside from a locale one, and I have no update function (which I actually forgot to make. I knew something was missing...).

Since my project is in C++, I figured it would be interesting and efficient to make update functions and callbacks on a per-class basis (the classes representing the state of the game, i.e. a class for stages, a class for menus, etc.) so that the update functions could be specific instead of generalized, and code that is only used in one part of the game isn't ever present.

If I were to do it this way, what is the overhead for having more than one callback registered for an event? (Specifically I'm thinking of the update loop. It might be useful/easy/lazy for certain things to be in a main update loop with some other, more specific code in the class's update loop. I am sure there will be overhead; I'm just not sure how much.)


  • edited February 2015
    Hi, sorry for the delay!

    That's an option yes. The overhead is simply the number of events x the number of callbacks.

    For your update scheme, why don't you have a single Update callback registered on a clock that would then dispatch to all your class instances? That's how it's done in Scroll.

    If you're using Scroll, you can simply use the ScrollObject::Update() method and have all your classes derive from ScrollObject (or any of its children).

    In my games, all the menus, stages, etc are just ScrollObjects (or derivative when I need custom code, but most of the time I handle everything with tracks).
  • edited February 2015
    I forgot about scroll! I should go install that.
Sign In or Register to comment.