我对新的C++ chrono库肯定有点失落.
这里我有一个更新循环.它运行两个操作:
engine.Update()
engine.Render()
Run Code Online (Sandbox Code Playgroud)
这些都是长期操作,很难说它们有多长.
因此,我们测量他们花了多长时间,然后进行一些计算并找出在调用渲染之前逐渐调用更新的最佳方法.
为此,我正在使用C++ 11的Chrono功能.我选择它是因为它听起来很划算:更准确,更依赖于平台.我发现现在我遇到的问题比现在更多.
以下是我的代码,以及我的主要问题.非常需要任何有关问题或正确操作方法的帮助!
我直接在相关行旁边的注释中标记了我的问题,我将在下面重复这些问题.
头文件:
class MyClass
{
private:
typedef std::chrono::high_resolution_clock Clock;
Clock::time_point mLastEndTime;
milliseconds mDeltaTime;
}
Run Code Online (Sandbox Code Playgroud)
简化的更新循环
// time it took last loop
milliseconds frameTime;
// The highest we'll let that time go. 60 fps = 1/60, and in milliseconds, * 1000
const milliseconds kMaxDeltatime((int)((1.0f / 60.0f) * 1000.0f)); // It's hard to tell, but this seems to come out to some tiny number, not what I expected!
while (true)
{
// …Run Code Online (Sandbox Code Playgroud)