绘图功能表现
我正在创建用于制作游戏的小型引擎/框架。这是一个简单的问题,但我没有找到答案,所以我想咨询一下你。
有一些使用 Draw(...)
函数从 Graphic
派生的类
。 Draw()
将被调用数十次甚至数百次(如果有许多精灵要渲染)。 Draw()
太大,无法内联(10-20 行)。
- 我希望它是虚拟的(有时但很少我会使用多态性*)。我认为它不会对性能产生太大影响,但你认为它应该是虚拟的吗?
- 它是否应该有一些参数(2-6)来描述渲染位置(等)?我不知道传递很多参数是否会使速度变慢。也许每个可绘制对象都应该有自己的位置/区域数据?
最重要的问题是 2.
*ex。带动画
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 class
es 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何需要绘制的物体都会影响大量的像素;绘图本身可能会比调用绘图函数花费更多的时间,因此调用开销可以忽略不计。在分析表明它是一个瓶颈之前,不要担心它。
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.
首先,您应该使用
BitBlt
、StretchBlt
函数选择内存中的双缓冲区绘图。First you should choose in-memory, double-buffer drawing using
BitBlt
,StretchBlt
functions.