主游戏循环中的时间计算 [英] Time calculation in the main game loop

查看:39
本文介绍了主游戏循环中的时间计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

雷神之锤2主游戏循环实现中有代码:

There is the code in the Quake 2 main game loop implementation:

if (!initialized)
{   // let base retain 16 bits of effectively random data
    base = timeGetTime() & 0xffff0000;
    initialized = true;
}
curtime = timeGetTime() - base;

我想知道 base = timeGetTime() &0xffff0000.为什么他们在检索到的时间应用 0xffff0000 掩码?为什么不只使用:

I'm wondering about the line base = timeGetTime() & 0xffff0000. Why are they applying the 0xffff0000 mask on the retrieved time? Why not to use just:

if (!initialized)
{   // let base retain 16 bits of effectively random data
    initialTime = timeGetTime();
    initialized = true;
}
curtime = timeGetTime() - initialTime;

???那个面具的作用是什么?

??? What is the role of that mask?

推荐答案

if (!initialized) 检查只会通过一次.因此,curtime 会随着每个游戏循环而变大,而建议的重写不会出现这种情况,因为在足够多的游戏循环后,上层字可能会增加.

The if (!initialized) check will only pass once. Therefore curtime will become larger with each gameloop, which wouldn't be the case with suggested rewrite, since the upper word may increase after sufficiently many gameloops.

这很可能是在准备 int-to-float 转换,其中较小的数字会导致更高的准确度.(例如调整两帧之间的时间和随着时间的推移对游戏状态进行数值整合;还可以渲染流畅的动画)

Likely this is in preparation of an int-to-float conversion where smaller numbers result in higher accuracy. (Such as adjusting for the time between two frames and numerically integrating game states over time; but also rendering smooth animations)

这篇关于主游戏循环中的时间计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆