简体   繁体   English

我应该在网络游戏中使用固定时间还是动态时间?

[英]Should I use fixed or dynamic time step in a networking game?

I am currently developing a online networking game using Box2D JS and Vert.x as the server->client framework. 我目前正在使用Box2D JS和Vert.x作为服务器->客户端框架来开发在线网络游戏。

I have searched for pros and cons of each and I really believe that a dynamic time step is much better since it does not assume that each client has the same processing power, however, there are some (many) people that think fixed time step is much better. 我搜索了每种方法的优缺点,我真的相信动态时间步长会更好,因为它不假设每个客户端都具有相同的处理能力,但是,有很多人认为固定时间步长是好多了。

Please enlighten me. 请赐教。

You can basically throw determinism out the window if your timesteps are not synchronized. 如果您的时间步未同步,则基本上可以将确定性排除在外。 Even when they are, determinism is difficult. 即使是这样,确定性也是困难的。

Spending less computation on simulation will have real costs that may not initially be apparent. 在模拟上花费较少的计算将具有最初可能并不明显的实际成本。 For each different setting (and in the case of dynamic timesteps/iterations, for each different individual execution) the resulting behavior on the same input can be different. 对于每个不同的设置(在动态时间步/迭代的情况下,对于每个不同的单独执行),同一输入上的结果行为可能不同。 You can have a user run on really slow hardware that can potentially completely cheat through your levels. 您可以让用户在速度很慢的硬件上运行,该硬件可能会完全欺骗您的关卡。

Determinism is perhaps marginally less important outside of a multiplayer engine context, however simply not having a deterministic system will make it significantly more difficult to reason about pretty much anything (gameplay mechanics, game difficulty, exploits) which can impact nearly every kind of game I can think of. 在多人游戏引擎的环境之外,确定性也许没有那么重要,但是,如果没有确定性系统,就很难对几乎可以影响我所从事的所有游戏的任何事物(游戏机制,游戏难度,漏洞利用)进行推理。可以想到的。 Imagine a puzzle game that wasn't deterministic. 想象一下不确定的益智游戏。

I really believe fixing the timestep is the best way to go. 我真的相信确定时间表是最好的方法。 I can't remember clearly enough but in one of our games we were having troubles with dynamic timesteps during collisions. 我记不太清楚了,但是在我们的一款游戏中,我们在碰撞过程中遇到了动态时间步的问题。 Ofcourse most people would say our collision detection code was either not well written or we could use some advanced techniques like ray casting, but we ended up landing on fixed timestep with a for loop that would do the physics update whenever the delay seemed longer due to slow processing power of device or some other reason (CPU busy?), etc. The process was simple enough and we were all happy with the results :) 当然,大多数人会说我们的碰撞检测代码写得不好,或者我们可以使用一些高级技术,例如射线投射,但是我们最终在固定的时间步上以for循环着陆,只要延迟时间较长,该循环就可以进行物理更新。设备处理速度慢或其他原因(CPU忙吗?)等。该过程非常简单,我们对结果都很满意:)

I think the creator of Box2D himself is in favour of fixed timestep, I read it somewhere although can't find the resource atm. 我认为Box2D的创建者本人赞成固定时间步长,尽管找不到资源atm,但我在某处阅读了它。

Can we assume that you are trying to get the same results for the simulation on all clients? 我们是否可以假设您尝试在所有客户端上获得相同的模拟结果? If so I think you need to explain your reasoning why having them all doing different calculations would be a good idea! 如果是这样,我认为您需要解释您的理由,为什么让他们都进行不同的计算将是一个好主意!

Or perhaps you meant that all clients will do the same calculations, but the timestep will vary during as the simulation progresses, but that is quite the headache to implement and debug. 或者,也许你的意思是所有的客户端会做同样的计算,但时间步长将在作为模拟的进展各不相同,但是那是相当实施和调试头痛。 For each client to come up with the same (or at least similar) result, they will need to be using the same length timestep for each step, so you will need to send this across the network too, eg. 为了使每个客户端得出相同(或至少相似)的结果,他们需要为每个步骤使用相同长度的时间步长,因此,例如,您也需要通过网络发送该时间步长。 physics step 32241 is 16ms, step 32242 is 18ms. 物理步骤32241为16毫秒,步骤32242为18毫秒。 Apart from requiring extra network traffic, each client does not know what length timestep to use until it receives this information. 除了需要额外的网络流量外,每个客户端在收到此信息之前都不知道要使用多长时间。 And where does it receive it from? 它是从哪里收到的? Presumably the slowest client will dictate how fast everybody should be going? 大概最慢的客户会决定每个人应该走多快? I can't see it working any other way. 我看不到它有任何其他作用。 So client also have to continuously let the server know how much processing they can handle, and the faster clients will be dragged down to that level of performance. 因此,客户端还必须不断地让服务器知道他们可以处理的处理量,而更快的客户端将被拖到该性能水平。

But as Steven says, there will also be other problems even after these technical difficulties have been taken care of. 但是正如史蒂文所说,即使在解决了这些技术难题之后,也会出现其他问题。 Most notably the effect of gravity changes with different timestep lengths, so for example in a platformer, the height your players can jump would be continuously changing. 最引人注目的是重力的影响会随时间步长的不同而变化,例如,在平台游戏中,玩家可以跳跃的高度会不断变化。 If there are platforms that are normally just reachable, they might suddenly become unreachable when a slower client joins. 如果存在通常只能访问的平台,则当较慢的客户端加入时,它们可能突然变得无法访问。

If you really did mean that each client will use just whatever timestep length it feels like, that would work but the server would need to send out an official snapshot of the world state at very very frequent intervals to get all clients snyced. 如果确实的确意味着每个客户端将使用任何感觉的时间步长,那都可以工作,但是服务器需要以非常频繁的时间间隔发送世界状态的官方快照,以使所有客户端都被监视。 Technically this would be much easier to implement, and each client would run as smooth as it could, but with more jerkiness as the world state is corrected to the official one, for clients that run either faster or slower than the server does. 从技术上讲,这将更容易实现,并且每个客户端都将尽可能平稳地运行,但是对于运行速度比服务器更快或更慢的客户端,由于将世界状态更正为官方状态,因此更具挑战性。 Hm... maybe this is the best way after all. 嗯...也许这毕竟是最好的方法。 You might be interested in this article explaining how Quake3 does something like this: http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/Quake3Networking 您可能对这篇文章感兴趣,解释了Quake3如何执行类似的操作: http : //trac.bookofhook.com/bookofhook/trac.cgi/wiki/Quake3Networking

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java脚本中的游戏。 我应该使用帆布吗? - A game in java script. Should I use canvas? 我应该将websockets或webRTC用于4player游戏 - should I use websockets or webRTC for 4player game 我应该用什么来创建一个带有 JS(跑步游戏)的 2D 游戏? - What should I use to create a 2D game with JS (runner game)? 我什么时候应该使用div? 我应该什么时候使用框架? 我什么时候应该使用其他形式的动态内容? - When should I use div? When should I use frame? When should I use other forms of dynamic content? 我应该使用什么技术将内容加载到动态div中? - What technologies should I use to load content into a dynamic div? 我应该使用 eval() 来使变量声明动态化吗? - Should I use eval() to make variable declaration dynamic? 如何在 Material UI 中为卡片内容设置固定高度? 我应该使用 CSS 吗? - How to set fixed height for Card content in Material UI? Should I use CSS? 我应该在我的 Javascript 游戏引擎中使用 DOM 片段作为 Shadow dom 吗? - Should I use a DOM fragment as a Shadow dom in my Javascript game engine? 我应该重新编写游戏服务器,编写转发器还是使用新的插件? - Should I re-write my game server, write a forwarder, or use a new plugin? 我应该如何并行使用requestAnimationFrame和setTimeout来制作更好的游戏循环? - How should I use requestAnimationFrame and setTimeout in parallel to make a better game loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM