I am creating a Rendering Engine. And theres 2 ways of me creating a task management system. Creating my own custom call backs that get called before and after render, Or implementing a task management system in which I would have to derive a class from a parent TaskClass and then throw it into queue.
Honestly I feel creating callbacks is better because it allows me to create task management subsystem that is independent from the actual rendering engine. This allows me to focus more on the rendering engine and worry about task management later.
But my question is… “is it costly to use callbacks ?”
Is it a practice that is common in a processor intense environment such as a game engine.
First of all, costly is relative, if you’ll call these callbacks at 10000Hz, yes, some callback implementations can be too costly. However, a simple function-pointer based callback will actually have almost no overhead.
But most important: this is an example of premature optimization, certainly as it looks you’re going to call these callbacks only 60 times per seconds on an average 30 fps game. In most games there will be much more crucial performance issues. Start with one method, profile it when you have performance issues and if it really does not suffice then optimize it. You’ll probably loose much more cpu cycles on math or AI functions anyway.
Finally: in many games, the bottleneck is the GPU, not the CPU ;).