当前位置: 首页> 汽车> 车展 > 微信小程序制作开发平台_中国新闻社招聘2023年_如何建立网页_网站优化排名的方法

微信小程序制作开发平台_中国新闻社招聘2023年_如何建立网页_网站优化排名的方法

时间:2025/7/10 8:16:57来源:https://blog.csdn.net/pingchangxin_6/article/details/143902984 浏览次数: 0次
微信小程序制作开发平台_中国新闻社招聘2023年_如何建立网页_网站优化排名的方法
#include <chrono>
#include <thread>void controlFrameRate(std::chrono::milliseconds frameDuration) {auto startTime = std::chrono::high_resolution_clock::now();// Your drawing/rendering logic hereauto endTime = std::chrono::high_resolution_clock::now();auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);std::this_thread::sleep_for(frameDuration - elapsedTime);
}int main() {const int framesPerSecond = 30;const std::chrono::milliseconds frameDuration(1000 / framesPerSecond);while (true) {controlFrameRate(frameDuration);}return 0;
}

1秒30帧,1秒等于1000毫秒,所以用1000除以30,得到平均一帧多长时间frameDuration

当处理完一帧图片的时候,得到elapsedTime。如果elapsedTime小于frameDuration,这个时候要让程序暂停一下,即std::this_thread::sleep_for,让进程睡一会,然后再进行下一次的工作;如果elapsedTime大于frameDuration,这样应该达不到1秒30帧的频率

这样就能控制好,是1秒30帧的频率。

全部写在主函数里,是下面的代码逻辑

#include <chrono>
#include <thread>int main() {const int framesPerSecond = 30;const std::chrono::milliseconds frameDuration(1000 / framesPerSecond);while (true) {auto startTime = std::chrono::high_resolution_clock::now();// Your drawing/rendering logic hereauto endTime = std::chrono::high_resolution_clock::now();auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);std::this_thread::sleep_for(frameDuration - elapsedTime);}return 0;
}

关键字:微信小程序制作开发平台_中国新闻社招聘2023年_如何建立网页_网站优化排名的方法

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: