简单的网络游戏,客户端-服务器架构规划

发布于 2024-09-01 17:02:23 字数 591 浏览 6 评论 0原文

我正在编写简单的游戏,我计划将其制作为多人游戏(通过网络)作为我的大学项目。 我正在考虑客户端-服务器通信的两种场景:

物理(它们是微不足道的!事实上我应该称之为“碰撞测试”:))仅在服务器计算机上处​​理。因此,通信看起来就像

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-09-08 17:02:23

通常的方法是发送以下信息:

  1. 玩家在哪里
  2. 他什么时间在那里(使用游戏的内部时间概念,不一定是实时)
  3. 玩家的运动矢量(方向和速度)

然后客户端可以使用航位推算来估计其他玩家在哪里,这样网络延迟就会减少对游戏的干扰。仅当玩家改变其移动方向或速度(其他客户端无法预测)时才需要发送更新,因此也将节省网络带宽。

以下是一些有关航位推算的链接。相同的网站可能还包含更多相关文章。
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:

  1. Where the player is
  2. At what time he is there (using the game's internal concept of time, not necessarily real time)
  3. The player's movement vector (direction and speed)

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

往日情怀 2024-09-08 17:02:23

我认为第一种方法更好。这样您就可以在所有客户端上获得相同的数据。

当物理原理很简单并且计算结果始终相同时,第二种方法也可以。但如果有可能存在随机数,您将对所有客户产生不同的影响。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文