有关游戏循环,滴答和实时编程的一些问题 [英] Some questions regarding game loop, tick and real time programming

查看:100
本文介绍了有关游戏循环,滴答和实时编程的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要为我的近似英语(我是法国人)道歉.我目前正在使用LWJGL在Java中制作实时游戏. 我对游戏循环有一些疑问:

First I want to apologize for my approximate English, as I'm French. I'm currently making a real-time game in java, using LWJGL. I have some questions regarding game loops:

  • 我正在线程中运行渲染例程.这是个好主意吗?通常,渲染例程相当慢,并且不应该减慢世界更新(刻度)例程的速度,这一点更为重要.因此,我想在这里使用线程似乎是个好主意(减去使用线程带来的复杂性).
  • 在世界更新例程中,我正在使用当前时间更新实体列表.然后,每个实体都可以计算自己的deltaTime(对应于上次更新时间).这不同于通常的更新循环,后者用相同的deltaTime更新列表中的每个实体.由于线程渲染,这似乎是适当的.这是个好主意吗?我应该改用第二种方法吗?如果是这样,是否仍需要线程渲染?如果是这样,我是否必须添加最大的deltaTime?
  • 总的来说,有一个最大的deltaTime是个好主意吗?

感谢您的时间!

推荐答案

这个问题已有几年历史了……

Though this question is a few years old…

AFAIK,

渲染通常在单独的处理器(GPU)中完成,因此它们已经是一个单独的线程.但是,在将绘图命令分配给GPU之前,必须先通过图形驱动程序(在CPU中运行)对其进行处理,并且可以通过多线程来保存此处理.无论如何,在这种情况下,您有责任管理逻辑与渲染线程之间的同步.

Rendering is usually done in separated processor — GPU, so they're already a separated thread. But, drawing command must be processed by graphics driver (which is running in CPU) before dispatched to GPU, and this processing may be saved by being multi-threaded. Anyway in this case, you're responsible to manage synchronization between logics and rendering thread.

通常来说,游戏都是关于对象之间的交互的,很难将状态图划分为完全独立的部分.结果,整个游戏状态通常变为单个图形,并且该图形在渲染时无法更新.在这种情况下,多线程是没有好处的.

Generally speaking, games are all about interactions between objects, and it's very hard to divide state-graph into fully separated divisions. As a result, whole game state usually becomes single graph, and this graph cannot be updated while being rendered. In this case, you have no benefit by being multi-threaded.

如果您可以保留单独的不可变数据进行渲染,那么从单独的线程中进行渲染可能会获得一些好处.但是否则,我不建议这样做.

If you can keep a separated immutable data for rendering, than you may gain some benefit from rendering in separated thread. But otherwise, I don't recommend it.

此外,如果您确实想要实时游戏,则应考虑使用GC.与GC相关的性能问题通常是制作实时内容的最大障碍.

In addition, you should consider GC if you truly want a realtime game. GC related performance issues usually the biggest obstacles to make realtime stuffs.

这篇关于有关游戏循环,滴答和实时编程的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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