我目前正在尝试计算cpp中循环的增量时间。 目前我使用此代码
#include <chrono> int main() { typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::duration<float> fsec; auto lastTime = Clock::now(); auto currentTime = Clock::now(); fsec passedTime = currentTime - lastTime; while (true) { lastTime = currentTime; printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); currentTime = Clock::now(); passedTime = currentTime - lastTime; printf("%i\n", passedTime.count()); } return 0; }这不是我在程序中使用的实际代码,但增量时间计算和输出与此示例中的完全相同。
它曾经很好地工作,并且当GLFW锁定到60个刻度/秒时输出大约约0.0167,并且在大约6k刻度/秒时输出更低的数字。
我的问题是我将所有东西从main函数转移到一个方法中,现在得到这个结果
似乎我错误地改变了一些东西,但我无法弄清楚我改变了什么。
I am currently trying to calculate the delta time of a loop in cpp. Currently i use this code
#include <chrono> int main() { typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::duration<float> fsec; auto lastTime = Clock::now(); auto currentTime = Clock::now(); fsec passedTime = currentTime - lastTime; while (true) { lastTime = currentTime; printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); currentTime = Clock::now(); passedTime = currentTime - lastTime; printf("%i\n", passedTime.count()); } return 0; }This is not the actual code i use in the program but the delta time calculation and the output is the exact same as in this sample.
It used to work fine and output a number of about ~0.0167 when locked to 60 ticks/s by GLFW and a ways lower number that at about 6k ticks/s.
My Problem is that I shifted everything out of the main function into a method and now get this result
It seems like I changed something by mistake but I can't figure out what I've changed.
最满意答案
你的printf错了,数据是浮点数,但printf格式是int。
Your printf is wrong, the data is a float, but the printf format is an int.
更多推荐
发布评论