简单的网络游戏,客户端-服务器架构规划
我正在编写简单的游戏,我计划将其制作为多人游戏(通过网络)作为我的大学项目。 我正在考虑客户端-服务器通信的两种场景:
物理(它们是微不足道的!事实上我应该称之为“碰撞测试”:))仅在服务器计算机上处理。因此,通信看起来就像
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!
服务器接收事件并将其广播给所有其他客户端。
Client1->Server: Pressed "UP"
Server->Clients: Client1 pressed "UP", recalculate his position!!
[Client1 receives this one as well!]
哪一个更好?或者也许他们都没有?
I'm coding simple game which I plan to make multiplayer (over the network) as my university project.
I'm considering two scenarios for client-server communication:
The physics (they're trivial! I should call it "collision tests" in fact :) ) are processed on server machine only. Therefore the communication looks like
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!
server receives the event and broadcasts it to all the other clients.
Client1->Server: Pressed "UP"
Server->Clients: Client1 pressed "UP", recalculate his position!!
[Client1 receives this one as well!]
Which one is better? Or maybe none of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常的方法是发送以下信息:
然后客户端可以使用航位推算来估计其他玩家在哪里,这样网络延迟就会减少对游戏的干扰。仅当玩家改变其移动方向或速度(其他客户端无法预测)时才需要发送更新,因此也将节省网络带宽。
以下是一些有关航位推算的链接。相同的网站可能还包含更多相关文章。
http://www.gamasutra.com/view/feature/3230/dead_reckoning_latency_hiding_for_.php
http://www.gamedev.net/reference/articles/article1370.asp
The usual approach is to send this information:
Then the clients can use dead reckoning to estimate where the other players are, so that the network latency will disturb the game less. Updates need to be send only when the player changes his direction or speed of movement (which the other clients cannot predict), so also network bandwidth will be saved.
Here are some links on dead reckoning. The same web sites contain probably also more articles on it.
http://www.gamasutra.com/view/feature/3230/dead_reckoning_latency_hiding_for_.php
http://www.gamedev.net/reference/articles/article1370.asp
我认为第一种方法更好。这样您就可以在所有客户端上获得相同的数据。
当物理原理很简单并且计算结果始终相同时,第二种方法也可以。但如果有可能存在随机数,您将对所有客户产生不同的影响。
i think the first approach is better. so you have equal data on all clients.
when the physics are simple and the results of the calculations are always the same the second approach is ok too. but if there are random numbers possible you will have different effects on all clients.