c++ - 处理 PVP 游戏中的延迟问题

标签 c++ networking cocos2d-iphone websocket cocos2d-x

我正在使用 cocos2d-x(C++) 和 node.js(websocket) 构建一个 1 对 1 俄罗斯方 block 游戏。
目前,我正在研究两个玩家之间的 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?

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

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 秒”。

关于c++ - 处理 PVP 游戏中的延迟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31868397/

相关文章:

c++ - 没有 SSL 验证的 HTTPs 对于本地应用程序是否安全?

c - 关于网络套接字编程中的listen()、accept()(3次握手)

ios - 使用 Core Graphics 绘制 UIImage?

iphone - 如何在cocos2d中设置CCLabelTTF的背景颜色

c++ - 学习 C++ 的视频类(class)

c++ - 在 clang 中实例化后的静态成员初始化

c++ - 派生类的模板特化问题

networking - 在 docker-compose.yml 中绑定(bind)主机端口时无法将服务扩展到多个容器

windows - 处理公司防火墙添加自签名证书

ios - 将 FaceBook 登录添加到 Cocos2d Xcode 项目