我正在编写简单的游戏,我计划将多人游戏(通过网络)作为我的大学项目.我正在考虑两种客户端 - 服务器通信方案:
物理(他们是微不足道的!我应该称之为"碰撞测试"实际上:))仅在服务器机器上处理.因此沟通看起来像
Client1->Server: Pressed "UP"
Server->Clients: here you go, Client1 position is now [X,Y]
Client2->Server: Pressed "fire"
Server->Clients: Client1 hit Client2, make Client2 disappear!
Run Code Online (Sandbox Code Playgroud)
服务器接收事件并将其广播给所有其他客户端.
Client1->Server: Pressed "UP"
Server->Clients: Client1 pressed "UP", recalculate his position!!
[Client1 receives this one as well!]
Run Code Online (Sandbox Code Playgroud)
哪一个更好?或者也许没有?:)
通常的方法是发送此信息:
然后,客户可以使用航位推算来估计其他玩家的位置,这样网络延迟就会减少对游戏的干扰.只有当玩家改变其移动方向或移动速度(其他客户无法预测)时才需要发送更新,因此也将节省网络带宽.
以下是航位推算的一些链接.相同的网站可能还包含更多文章. http://www.gamasutra.com/view/feature/3230/dead_reckoning_latency_hiding_for_.php http://www.gamedev.net/reference/articles/article1370.asp