在线游戏中实时同步多用户数据的设计模式建议

发布于 2024-11-30 16:51:54 字数 571 浏览 6 评论 0原文

我正在开发一个学习 Node.js 的项目,并正在寻找一些有关如何实时处理同步用户数据的建议。

假设您有一张 2D 矩形地图(大约 600x400),其中许多玩家占据该地图上的 x,y 位置。每个用户都可以使用箭头键进行导航,并以某种基本方式与其他用户交互。鉴于这将通过 HTTP 播放,在处理和同步用户数据方面最好的设计模式是什么,以提供最流畅、最快速的体验?

我可以想到几个选项,但希望有更多的想法/说明:

  1. 客户端将位置数据发送到服务器,服务器将所有位置分发给所有客户端,屏幕上呈现结果。重复。缺点是客户端在数据往返时间上有所滞后,但优点是它们与所有用户同步。

  2. 客户端不断地在它认为的位置进行渲染,将位置数据发送到服务器,服务器将所有位置分发给所有客户端,然后使用服务器数据纠正客户端数据的屏幕渲染。优点是响应更快,缺点是稍微失去同步。

  3. 两者的混合,但我们不使用 (x,y) 坐标,而是使用 [先前的 x/y 和时间、当前的 x/y 和时间、建议的时间间隔的 x/y] 向量然后可以用来绘制不断移动的射弹路径。看起来这实现起来很棘手。

有什么指点吗?

I'm working on a project to learn node.js, and was looking for some suggestions on how to handle syncing user data in real-time.

Say you have a 2D rectangular map (roughly 600x400), with a number of players occupying x,y positions on that map. Each user can navigate around with the arrow keys and interact with the others in some basic way. Given that this would be played over HTTP, what would be the best design pattern in terms of handling and syncing user data to give the smoothest, snappiest experience?

I can think of several options, but would appreciate some more ideas / clarification:

  1. Client sends positional data to server, server distributes all positions to all clients, screen is rendered with the result. Repeat. The downside would be that the client side is lagged by the time it takes for a data round-trip, but the upside is that they are synced with all users.

  2. Client renders where it thinks it is constantly, sends positional data to server, server distributes all positions to all clients, and then screen rendering from client data is corrected with server data. Upside is a snappier response, downside is a slight loss of sync.

  3. A blend of the two, but instead of using (x,y) co-ordinates we use a vector of [previous x/y and time, current x/y and time, suggested x/y at time interval] which can then be used to draw projectile paths that constantly shift. It seems like this would be tricky to implement.

Any pointers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2024-12-07 16:51:54

大多数游戏都使用某种形式的航位推算 http://en.wikipedia.org/wiki/Dead_reckoning它允许从服务器分发延迟更新,但在客户端上保留了一些实时更新的错觉。

最好的选择是 3。它并不是特别复杂 - 只需根据游戏机制跟踪您期望每个参与者的位置,当您从服务器收到更新时,您就会随着时间的推移使这两个状态保持一致。

如果您发现服务器发送给您的状态与客户端假设的状态相差太远(太远需要定义),那么您可以跳转到服务器状态并接受客户端上的不连续性。

Most games use some form of dead reckoning http://en.wikipedia.org/wiki/Dead_reckoning which allows for delayed updates distributed from the server but preserves some illusion of real time updates on the client.

The best option is 3. It's not particularly complex - just track where you expect each actor to be based on the mechanics of the game, and when you receive an update from the server you bring the two states in line over time.

If you find the server sends you a state that is too far from the state your client is assuming (too far needs to be defined) then you may just jump to the server state and accept the discontinuity on the client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文