开发者

Performance of drawing function

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 man开发者_如何学运维y sprites to render). Draw() is too big to be inline (10-20 lines).

  1. 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 be virtual?
  2. 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.


First you should choose in-memory, double-buffer drawing using BitBlt, StretchBlt functions.

  • If the base class declares virtual as pure-virtual, isn't a performance problem at all.
  • Yes, passing multiple arguments can make it slow - put them into structure, and pass reference/pointer of that structure; or use a shared area (private variables in class).
  • Yes, for redrawing (re-painting) would need all data related to object - that's obvious!
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜