同步客户端 - 服务器游戏状态 [英] Synchronizing Client-Server game state

查看:158
本文介绍了同步客户端 - 服务器游戏状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个客户端服务器MMO风格的游戏。到目前为止,我有框架设置,以便服务器和客户端相互交互,以提供状态更新。服务器保持游戏状态并周期性地计算下一个状态,然后每隔一段时间(每n毫秒)向所有客户端发出新的状态。这种新状态能够被用户在客户端上查看和作出反应。这些操作然后被发送回服务器以进行处理并发送以用于下一次更新。



显然的问题是这些更新需要时间在服务器和客户。如果客户端采取行动来攻击敌人,则在更新返回到服务器时,服务器很可能已经进行了足够深的游戏状态,以至于敌人不再位于同一位置并超出范围。 / p>

为了解决这个问题,我一直在想出一个好的解决方案。我已经看了下面的内容,它已经帮助了一些,但不是完全: Mutli Player游戏同步。我已经得出结论,而不是只传输游戏的当前状态,我可以传输其他信息,如方向(或AI移动的目标位置)和速度。从这个,我有一部分需要'猜测',在客户端,实际的状态是什么(服务器看到它)通过进行游戏状态n毫秒到未来。



问题是确定进行状态的时间量,因为它将取决于服务器和客户端之间的滞后时间,这可能会有很大的变化。此外,我应该将游戏状态推进到客户端查看它时的状态(即只考虑更新到客户端所花费的时间),或者我应该将其进度足够长,以便在发送响应时



有任何建议吗?



要重申:



1)计算发送和接收之间的时间量的最佳方法是什么?



2)我是否应该将客户端状态提升到足以计算整个往返时间,或者只是将数据从服务器获取到客户端的时间?



EDIT:我到目前为止所做的事情



在客户端和服务器之间,如果我有,我不想添加到流量。目前,客户端向服务器发送状态更新数据包(UDP)〜150毫秒(仅当发生了变化时),然后由服务器接收和处理。目前,服务器不发送对这些数据包的响应。



开始,我将让客户端尝试估计他们的滞后时间。我将默认它像50到100毫秒。我建议大约每2秒(每个客户端),服务器将立即响应这些数据包之一,发送回在特殊的定时更新数据包中的数据包索引。如果客户端接收到定时分组,它将使用索引来计算发送该分组多长时间,然后使用分组之间的时间作为新的滞后时间。





听起来可以接受,还是有更好的方法?这仍然不能回答问题二。

解决方案



让我们假设服务器发送时间T0的状态,客户端在时间T1看到它,播放器在时间T2做出反应,并且服务器在时间T3获得他们的答案,并立即处理它。
这里,往返延迟是T1-T0 + T3-T2。在理想世界中,T0 = T1和T2 = T3,
,观察时间和玩家行动的处理之间的唯一延迟是玩家的反应时间,即T2-T1。
在现实世界中,它是T3-T0。
为了模拟理想世界,你需要减去整个往返延迟:

  T2-T1 = T3-T0 +(T1-T0 + T3-T2)

网络看到更高级的状态一个播放器在一个快速的网络。
然而,这对他们没有好处,因为它们的反应需要更长的时间。
当然,如果两个玩家坐在彼此并使用不同的速度网络,它可能会很有趣。
但是这是不太可能的情况,不是吗?



整个过程有一个问题:
你在未来进行外推这可能导致无意义的情况。 b b b b b b b 你可以把你的想法颠倒:
而不是预测,尝试在时间T3 - (T1-T0 + T3-T2)评估球员的行动。如果你确定一个人物会被这样击中,相应地减少它的生命值。
这可能比原来的想法更容易和更现实,或者可能更糟,或根本不适用。只是一个想法。






1 想象两个玩家彼此相反。
根据外推,他们在右边通过对方。
事实上,其中一个改变他们的方向,最后他们在左边彼此通过。


I am making a client server MMO style game. So far I have the framework set up so that the server and clients interact with each other in order to provide state updates. The server maintains the game state and periodically calculates the next state and then it every once in a while (every n milliseconds) it sends out the new state to all the clients. This new state is able to be viewed and reacted to on the client side by the user. These actions are then sent back to the server to be processed and sent out for the next update.

The obvious problem is that it takes time for these updates to travel between server and clients. If a client acts to attack an enemy, by the time that update has gotten back to the server, it's very possible the server has progressed the game state far enough that the enemy is no longer in the same spot, and out of range.

In order to combat this problem, I have been trying to come up with a good solution. I have looked at the follow, and it has helped some, but not completely: Mutli Player Game synchronization. I already came to the conclusion that instead of just transmitting the current state of the game, I can transmit other information such as direction (or target position for AI movement) and speed. From this, I have part of what is needed to 'guess', on the client side, what the actual state is (as the server sees it) by progressing the game state n milliseconds into the future.

The problem is determining the amount of time to progress the state, because it will depend on the lag time between server and client, which could vary considerably. Also, should I progress the game state to what it would currently be when the client views it (i.e. only account for the time it took the update to get to the client) or should I progress it far enough so that when its response is sent back to the server, it will be the correct state by then (account for both to and from journey).

Any suggestions?

To reiterate:

1) What is the best way to calculate the amount of time between send and receive?

2) Should I progress the client side state far enough to count for the entire round trip, or just the time it takes to get the data from the server to the client?

EDIT: What I have come up with so far

Since I already have many packets going back and forth between the clients and server, I do not want to add to that traffic if I have to. Currently, the clients send status update packets (UDP) to the server ~150 milliseconds (only if something has changed), and then these are receive and processed by the server. Currently, the server sends no response to these packets.

To start off, I will have the clients attempt to estimate their lag time. I will default it to something like 50 to 100 milliseconds. I am proposing that about every 2 seconds (per client) the server will immediately respond to one of these packets, sending back the packet index in a special timing update packet. If the client receives the timing packet, it will use the index to calculate how long ago this packet was sent, and then use the time between packets as the new lag time.

This should keep the clients reasonably up to date on their lag, with out too much excess network traffic.

Sound acceptable, or is there a better way? This still doesn't answer question two.

解决方案

2) Should I progress the client side state far enough to count for the entire round trip, or just the time it takes to get the data from the server to the client?

Let's assume that the server sends the state at time T0, the client sees it in time T1, the player reacts in time T2, and the server obtains their answer in time T3, and processes it instantly. Here, the round trip delay is T1-T0 + T3-T2. In an ideal world, T0=T1 and T2=T3, and the only delay between the observing time and the processing of the player's action is the player's reaction time, i.e., T2-T1. In the real world it's T3-T0. So in order to simulate the ideal world you need to subtract the whole round trip delay:

T2-T1 = T3-T0 + (T1-T0 + T3-T2)

This means that a player on a slower network sees more advanced state the a player on a fast network. However, this is no advantage for them, since it takes longer till their reaction gets processed. Of course, it could get funny in case of two players sitting next to each other and using different speed networks. But this is quite improbable scenario, isn't it?

There's a problem with the whole procedure: You're extrapolating in the future and this may lead to nonsensical situations. Some of them, like diving into walls can be easily prevented, but those depending on player's interaction can not.1

Maybe you could turn your idea upside down: Instead of forecasting, try to evaluate player's action at the time T3 - (T1-T0 + T3-T2). If you determine that a character would be hit this way, reduce its hit points accordingly. This may be easier and more realistic then the original idea, or it may be worse, or not applicable at all. Just an idea.


1 Imagine two players running against each other. According to the extrapolating they pass each other on the right side. In fact, one of them changes their direction, and at the end they passes each other on the left side.

这篇关于同步客户端 - 服务器游戏状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆