2

I'm trying to implement multiplayer to my RTS game. It's not turn-based so the way I see it I should go with UDP, right?

I'm also a little bit confused about what should be sent to the server from the client. Every object displayed in the game (buildings, trees, units etc) is in an ArrayList of type GameObject (that keeps track of positions and all that good stuff). So one way to go would be to have the clients send their ArrayList to the server, and merge it with the others and then send it back. An other way would be to send the clients input (where he clicks and what's selected etc) to the server and have the server decide what should happen. That would cause a delay though when giving orders to units or whatever.

So I guess my question is, except for the one about using UDP/TCP, how I should structure the multiplayer part? What should be sent from the client to the server and so on.

4

1 回答 1

4

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

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

28.8 上的 1500 名弓箭手:帝国时代及以后的网络编程

与其传递游戏中每个单元的状态,不如期望在每台机器上运行完全相同的模拟,传递用户同时发出的一组相同的命令。PC基本上会按照最好的战争电影传统同步他们的游戏手表,允许玩家发出命令,然后在同一时间以完全相同的方式执行并拥有相同的游戏。

于 2013-08-18T15:02:39.397 回答