简体   繁体   English

C ++-SDL:消除性能问题

[英]C++ - SDL: Blitting performance issues

I am a beginner to C++ and SDL, but I have been developing games for several years. 我是C ++和SDL的初学者,但我从事游戏开发已有几年了。

I chose SDL for its simplicity since all I wanted was a 2D game, but I am not satisfied. 我之所以选择SDL是因为它很简单,因为我只想要2D游戏,但我不满意。 The functions working with surfaces eat a lot of power, way too much to be honest. 与曲面配合使用的功能会消耗大量能量,实在太过分了。

When I first started using SDL I got like 30 FPS. 刚开始使用SDL时,我得到了30 FPS。 Then I found out about optimizing surfaces, framerate jumped to 60. Also switching pixel format from 24-bit to 32-bit improved it to 100. 然后,我发现了有关优化曲面的信息,帧速率跃升至60。将像素格式从24位转换为32位也将其提高到100

In my opinion this performance compared to other libraries for game development and programming languages is weak. 在我看来,与其他用于游戏开发和编程语言的库相比,这种性能很弱。 I kept thinking it was still my fault and my FPS could skyrocket if I had everything set correctly. 我一直认为这仍然是我的错,如果一切设置正确,我的FPS可能会飙升。

So I kept testing to find that having no code running (excluding my FPS indicator) yields me 400 FPS. 因此,我不断进行测试以发现没有代码运行(不包括FPS指示器)可产生400 FPS。 However clearing the screen with SDL_FillRect() function drops it to 100. Then for every sprite drawn the framerate gets even lower and lower. 但是,使用SDL_FillRect()函数清除屏幕会将其降至100。然后,对于绘制的每个子画面,帧速率都会越来越低。

Is it really supposed to be this slow? 真的应该这么慢吗?

First off, 100 FPS is not slow. 首先,100 FPS并不慢。 Anything about 60 is irrelevant in most cases due to monitor refresh rates anyway. 无论如何,由于监视器刷新率的原因,大约60的值无关紧要。

Second, what kinds of surfaces are you blitting? 其次,您会刮擦哪种表面? I remember when I made a big SDL game, I was really surprised to discover that a particular image I had was taking forever to blit. 我记得当我做一个大型SDL游戏时,我真的很惊讶地发现我曾经永久使用过的某个特殊图像。 But fiddling with the quality a bit to remove dithering caused it to start blitting almost instantly again. 但是对质量稍加调动以消除抖动,使它几乎立即又开始发白。 I think SDL using run length encoding internally, so images that contain runs will blit faster. 我认为SDL在内部使用游程长度编码,因此包含游程的图像将更快地变色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM