gpt4 book ai didi

java - 为 RTS 游戏实现多人游戏

转载 作者:行者123 更新时间:2023-11-30 07:14:51 25 4
gpt4 key购买 nike

我正在尝试为我的 RTS 游戏实现多人游戏。它不是回合制的,所以我认为我应该使用 UDP,对吧?

对于应该从客户端发送到服务器的内容,我也有点困惑。游戏中显示的每个对象(建筑物、树木、单位等)都在 GameObject 类型的 ArrayList 中(跟踪位置和所有好东西)。因此,一种方法是让客户端将其 ArrayList 发送到服务器,并将其与其他 ArrayList 合并,然后将其发回。另一种方法是将客户端输入(他点击的位置和选择的内容等)发送到服务器并让服务器决定应该发生什么。这会导致在向单位或其他任何人发出命令时出现延迟。

所以我想我的问题是,除了关于使用 UDP/TCP 的问题,我应该如何构建多人游戏部分?客户端应该向服务器发送什么等等。

最佳答案

您所描述的网络类型最适合实时游戏,其中几乎没有可处理丢失数据(FPS 等)的移动部件。 RTS 游戏的问题在于,它们通常涉及太多单元,无法使用标准 UDP 状态复制模型进行复制。相反,大多数 RTS 游戏使用所谓的锁步。这是通过在每台机器之间同步游戏状态,然后将鼠标单击事件传输给游戏的所有玩家来实现的。给定相同的初始游戏状态,并应用相同的事件,游戏对所有玩家来说看起来都是一样的。可以使用 TCP 或 UDP 协议(protocol)来实现此目的,尽管 TCP 可能更容易。

阅读《帝国时代》中的步调一致:

1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond

Rather than passing the status of each unit in the game, the expectation was to run the exact same simulation on each machine, passing each an identical set of commands that were issued by the users at the same time. The PCs would basically synchronize their game watches in best war-movie tradition, allow players to issue commands, and then execute in exactly the same way at the same time and have identical games.

关于java - 为 RTS 游戏实现多人游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18300390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com