小编S. *_*age的帖子

Steady_Clock在主游戏循环中的更新之间跳过

在试图在SFML中找到一个可靠的游戏循环的过程中,我遇到了这个我似乎无法弄清楚的问题.我能够删除所有SFML代码,仍然clock()在time.h中看到问题.然后我走得更远,仍然看到问题使用std::chrono::steady_clock.

问题:我总是看到跳过更新之间可以完成的工作量.每次更新应该花费1/60秒,剩下的时间用于Draw()尽可能多地完成绘图.有时抽奖量下降到0或1,没有明显的原因.这会以明显的口吃形式冒泡到实际应用中.除了"跳过"之外,完成的抽签次数非常一致.

这是一个图像(注意更新时间的跳转和绘制中的下降): 问题的控制台输出

一些代码:

#include <iostream>
#include <time.h>
#include <chrono>

using namespace std;
using namespace std::chrono;

void Draw()
{
    //for (int i = 0; i < 1000000; i++);
}

int main()
{
    steady_clock::time_point update_time;
    steady_clock::time_point update_next;
    int update_rate = 16666666; // 60 times a second (nanosecs)
    int updates;
    int max_updates = 5;
    int draws = 0;
    update_next = steady_clock::now();

    while (true)
    {
        updates = 0;
        update_time = steady_clock::now();
        while (duration_cast<nanoseconds>(update_time - update_next) > …
Run Code Online (Sandbox Code Playgroud)

c++ clock game-development game-engine game-loop

11
推荐指数
1
解决办法
293
查看次数

标签 统计

c++ ×1

clock ×1

game-development ×1

game-engine ×1

game-loop ×1