游戏服务器的剑圣宝石

发布于 2024-12-27 03:44:31 字数 743 浏览 5 评论 0原文

这是关于最新的 Juggernaut gem (https://github.com/maccman/juggernaut)

我正在考虑架构,比如说“点游戏”。这个元游戏非常简单:每个登录用户(订阅频道,就 Juggernaut 而言)都是 JS 画布上的一个随机颜色的点。用户可以向任何方向移动他的点。就是这样。

Juggernaut 应该为连接的客户端传输和推送所有数据。

目前我将架构想象为:

1) 客户端将点的坐标和玩家的 id ([1, [10,299]]) 作为 ajax 推送到 Rails 等。

2) Rails 将此数据推送到 Juggernaut

3) Juggernaut 将坐标推送回所有收听此频道的客户端。

Juggernaut.publish("coordinates_channel", [1, [10,299]])

问题:

1)当我需要在 js 画布上逐像素移动“点”对象时,我需要发送太多 AJAX 请求。例如,如果我的点每秒移动 20 个像素,那么我每秒需要发送 20 个请求。不可接受的。

2)我应该将 Juggernaut.publish 包装到异步循环中(例如使用 EventMachine)吗?因为,想象一下 1000 个客户端(1000 个点,以及具有更新坐标的持续数据流)...

或者也许我使用 Juggernaut gem 得到了错误的客户端-服务器?您对这个实施有何看法?

谢谢。

It's about latest Juggernaut gem (https://github.com/maccman/juggernaut)

I'm thinking of architecture, for, let's say, 'Dots games'. This meta-game is very simple: each logged in user (subscribed to channel, in terms of Juggernaut) is a dot of random color on JS canvas. User can move his dot any direction. That's it.

Juggernaut should transport and push all data for clients connected.

Currently i immagine architecture as:

1) Client(s) pushes coordinates of dot and player's id ([1, [10,299]]) as ajax to, for example, Rails.

2) Rails pushes this data to Juggernaut

3) Juggernaut push coordinates back to all clients who listen to this channel.

Juggernaut.publish("coordinates_channel", [1, [10,299]])

Problems:

1) When i need to pixel-by-pixel movement for 'dot' object on js canvas, i'll need to send too many AJAX requests. For example, if my dot moves 20 pixels per second, i'll need to send 20 requests per second. Unacceptable.

2) Should i wrap Juggernaut.publish into asynchronous loop (using EventMachine for example)? Because, just immagine 1000 of clients (1000 of dots, and constant flow of data with updated coordinates)...

Or maybe i get wrong client-server using Juggernaut gem? What do you think of this implementation?

Thank you.

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

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

发布评论

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

评论(1

丑疤怪 2025-01-03 03:44:31

WebSockets/长轮询/其他彗星技术具有低延迟,你的游戏会滞后。我见过通过网络套接字实现实时游戏,它们要么滞后,要么游戏机制变得具体,比如让玩家移动非常慢以考虑低延迟。经典 AJAX 绝对是不可能的。

以下是一些有关改善延迟的资源
Valve Source 多人游戏网络
虚幻源多人网络

WebSockets/Long polling/other comet techniques have low latency, your game will lag. I have seen implementations of real time games via websockets, they either lag, either game mechanics are made specific, like making the players move really slow to account for low latency. Classic AJAX is definitively out of the question.

Here's some resources on improving lag
Valve Source Multiplayer Networking
Unreal Source Multiplayer Networking

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