I’m creating small engine/framework for making games. It’s kind of simple question but I haven’t found an answer so I’d like to consult you.
There are some classes derived from Graphic with the Draw(...) function. Draw() will be called dozens or maybe even hundreds of times (if there are many sprites to render). Draw() is too big to be inline (10-20 lines).
- I’d like it to be
virtual(sometimes but rather rarely I’ll be using polymorphism*). I think it shouldn’t affect greatly on performance but do you think it should bevirtual? - Should it have some arguments (2-6) describing position to render (etc)? I don’t have an idea if passing many arguments will make it slower. Maybe every drawable object should have its own position/area data?
The most important question is 2.
*ex. with animations
Any object which needs to be drawn will be affecting a large number of pixels; it is likely that drawing itself will take much more time than calling the drawing function, so the calling overhead will be negligible. Don’t worry about it until profiling shows it to be a bottleneck.