运行最基本的SFML应用程序时的性能
Performance-issue when running the most basic sfml application
我目前正在研究SFML项目,我过去曾做过一些。但是我现在遇到一个大问题。我有严重的性能问题。我用一个简单的主功能替换了我的所有代码,您可以在SFML网站上找到,但是该应用程序落后了很难,以至于永远需要再次关闭它。
我试图清洁解决方案,但这无济于事。通过查看任务管理器,我找不到任何问题。cpu-,gpu-,disk-,内存 - 似乎很好。运行我的一些较旧问题可以正常工作。没有任何laggs。
我添加了包含目录到"附加目录",我已经将库添加到"其他图书馆目录"中,我已经链接到我的其他依赖项(例如sfml-audio-d.lib(,我在调试/发行文件夹中粘贴了必要的DLL。
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
从信息中提供的信息很难从何处说。由于您在代码中没有时间步骤,因此可能以最大fps运行。我总是建议在执行图形时考虑时间步骤。时间步骤是不同帧之间的时间。有几种处理此问题的方法。修复您的时间段网页可以完美汇总它们。这是一种参考。
我进行了快速的代码改编,以为您提供一些指导。代码适用于Linux,但也应该在Visual Studio上工作。
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
window.setFramerateLimit(60);
// Timing
sf::Clock clock;
while (window.isOpen())
{
// Update the delta time to measure movement accurately
sf::Time dt = clock.restart();
// Convert to seconds to do the maths
float dtAsSeconds = dt.asSeconds();
// For debuging, print the time to the terminal
// It illustrates the differences
std::cout << "Time step: " << dtAsSeconds << 'n';
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
相关文章:
- Linux VM(重型多线程应用程序)的性能改进
- 运行最基本的SFML应用程序时的性能
- 在GO应用程序中使用C( )进行性能
- 谷歌性能工具可以用于分析C应用程序吗?
- 堆栈保留大小和堆栈提交大小的增加会提高应用程序性能吗
- 用于C++和性能关键型应用程序中的循环
- 对于高度优化的矩阵多应用程序代码,MSVC和GCC之间的性能差异
- 基于libpcap的应用程序是否会影响网络速度/性能
- 编译提升::数学的性能测试应用程序
- 嵌套函数或方法调用会降低应用程序的性能
- 适用于Android的纯c ++应用程序及其性能
- 当从应用程序多次调用数据库过程时,性能是否会受到影响
- 实时音频应用程序,提高性能
- 提高应用程序性能的简单方法
- 在Windows Kinect应用程序中使用c++和c#有什么不明显的区别吗?(例如,性能、特性)
- 相同的 Direct2D 应用程序在"slower"计算机上的性能更好
- cocoa是否限制了C/ c++ openGL应用程序的整体性能?
- Shared_Ptr影响应用程序的性能
- 在非托管c++应用程序中提高WPF对话框的性能
- 提高Windows应用程序的性能