处理 PVP 游戏中的延迟问题

Handling a latency issue in PVP game

我正在使用 cocos2d-x(C++) 和 node.js(websocket) 构建一个 1 对 1 俄罗斯方块游戏。
目前,我正在研究两个玩家之间的 PVP 功能。

基本逻辑如下所示:

1. Client1 completes a horizontal line and destroy it.
2. In this case, Client1 sends an attack packet to a server.
3. A server sends an attack packet to client2.
4. Client 2 gets an additional line.

问题是,即使我使用每秒 10 帧的 update() 函数,这还是有点慢。延迟一定是路由长造成的(Client1 => server => Client2).

我在想直接把数据包发给对方
在这种情况下,client1需要知道client2的IP地址。

我的问题是:
1)在真实游戏中,client2让client1知道自己的IP地址不是很危险吗?
2) 一般来说,游戏开发者如何处理这种延迟问题?

1) In a real game, isn't it dangerous for client2 to let client1 know the IP address of his?

公开用户的 ip 通常不是一个好主意,至少在没有通知的情况下。虽然这是合法的(我不是律师),但如果有人做坏事,用户可能会生气并向您投诉。

2) In general, how do game developers handle this kind of latency issue?

首先,您测量的延迟是多少?您是否尝试过在本地网络上托管您的服务器,看看效果如何?为了解决这个问题,我们通常定义所需的延迟(例如 100ms、200ms、500ms),并设计游戏以延迟传播信息而不影响游戏体验.在您的攻击逻辑案例中,通常的技巧是制作一个充电计时器来发起攻击,以便两个客户端都同意使用相同的挂钟进行实际攻击。所以,

1. Client1 completes a horizontal line and destroy it.
2. In this case, Client1 sends an attack packet to a server, and start a 1 second charging timer (may show a charging bar)
3. A server sends an attack packet to client2.
4. Client 2 start a timer and show the bar. Note that you need to adjust the time to account for the round trip.
5. Client 2 gets an additional line after 1 second since 2. Client 1 show the exact scene at the same time.

请注意,客户端2实际上比您最初的设计更晚受到攻击,但是由于玩家看到了充电条,所以体验还是很流畅的。

您可能还想根据您的延迟要求调整“1 秒”。