网游同步解决方案(Synchronous solution for online games)_第1页
网游同步解决方案(Synchronous solution for online games)_第2页
网游同步解决方案(Synchronous solution for online games)_第3页
网游同步解决方案(Synchronous solution for online games)_第4页
网游同步解决方案(Synchronous solution for online games)_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、网游同步解决方案(Synchronous solution for online games)Because recently in the study of a thing, there is a difficult problem, that is, the problem of synchronization, has been on the Internet to find information, and finally found a few articles, feel good. The network game inside the synchronization probl

2、ems explained very clearly so stick out everyone to discuss and discuss. But I want this synchronization is not, it is now a little picture. Take a moment to calm down and think about it. This is so much.-I wonder if everyone has ever encountered this kind of situation. When a player sends out a fir

3、eball, the fireball has its own trajectory, so how do you determine if the fireball has hit someone? Most of the time, when planning to make this request, usually will be denied by the program, the reason is: too much trouble, ha ha. The complex also involves two fireballs colliding with each other.

4、So, is it really impossible to simulate this kind of simulation in online games?First of all, lets see what kind of trouble this simulation can cause:1, the server must trace the trajectory of the fireball, at first thought, very slow.2, network delays, delays, delays, delays, instability, and troub

5、le.3, there are two points can not be solved, and then do not want to think again.Well, actually, its much easier to simulate the fireball than to simulate the movement of the characters. The reason is simple. The direction of the fireball doesnt change. Heres a look at what specific structure to ac

6、hieve:Do not know if you remember Dead Reckoning algorithm I mentioned last year this time, we want to simulate key lies in a ball game called Moving Objects Tracing Server server, this server is what. The server receives the main game server sends the event registration information, such as a game

7、player, began to move, so the main game server to exercise PDU, the game player includes direction, speed, acceleration, starting point to MOTS (Moving Objects Tracing Server MOTS), then he started the operation simulation, when the game the server sent second PDU package, for each position of the o

8、bject is modified, and restart the simulation. So, whats the purpose of our simulation? Of course, when something happens, such as a crash, or a trap that falls into the map, the event is returned to the main logical server. The logical server then processes the event.Then, the fireball and other ga

9、me player, also the synchronization, when receiving the instruction after the ball game player, a fireball, and specifies its PDU registration information, the moving objects in MOTS. The NPC notifies the master logical server when the MOTS simulation itself hits the object and other players or obje

10、cts, and then the master logic server generates the action.What about delays? Some people might say, say, theres a fireball in front of me, and the local villain Ive been hiding is actually gone, but because the network is delayed, Im not hiding on the server, so what? Oh, do not know if you have no

11、t played StarCraft, when playing multiplayer mode in the stars that have a most special place, it is the control of a soldier, at a point on the map, but the soldier is not immediately began to move, but have a certain delay, but this is a little delay and can not cover the star classic, the same th

12、eory used here is also established. For client control, when the game player control the protagonist change PDU information, to ensure that the information is sent to the server, and then start to deal with local instructions, so that we can guarantee the prediction and the local server is almost no

13、t what error, even if the error is very small, on the server, this game player will not complain too much.-One of the details of online game synchronizationSynchronization is very important in online games, and it ensures that each player sees the same thing on the screen. In fact, the simplest way

14、to solve the synchronization problem is to broadcast each players actions to another player. Here are two questions: 1, which players are broadcast and which messages are broadcast?. 2, what happens if the network delays?. As a matter of fact, the first question is a very simple one,But the reason w

15、hy I ask this question is to remind you that you need to take this factor into account when designing your own message structure. As for the second question, it is a very troublesome problem, and you can look at an example:For example, there is a player A sent a command to the server, saying that I

16、am now at P1, go to the P2 point. Command is issued and the time is T0, the server receives the instruction and the time is T1, and then to the game player broadcast this message, the message is game player A has a A in the vicinity of the game player B from P1 to P2, the received broadcast server m

17、essage and the time is T2, and then start drawing in on the client, A from P1 to P2. This time there is a problem of asynchrony, the player A and the screen player B screen shows a difference of T2-T1 of time. What should I do at this time?Theres a solution. I call it predict pull, although its a bi

18、t weird, but basically we can literally understand what it means. To solve this problem, we must first define a value called prediction error. Then need to add an attribute in the server, each game player connection class named TimeModified, and then when the game player landing, the client and serv

19、er time compared with the time difference, it is stored in the TimeModified. The examples above, when the server broadcast message, according to radio object TimeModified, calculates a client CurrentTime, then including the CurrentTime in the message header, and then broadcast. And at the same time,

20、 the establishment of a queue in the A game player client, save the message, only to get the server authentication message queue has never been verified the message is deleted, if the validation fails, it will be pulled back to P1. Then when the game player B received the messages sent by the server

21、 game player A from P1 to P2 this time to check the message sent by the server in time and local time comparison, if the prediction error is greater than the definition, even at this time point T2, P3 game player A screen on the go, and then put the game player B screen game player A directly pulled

22、 to P3, and then continue to go on, so that we can guarantee the synchronization. Further, in order to ensure that the client is running up more smooth, I do not recommend directly to the game player pulls past, but calculated P3 after partial point P4, and (P4-P1) /T (P4-P3) to calculate a very fas

23、t rate of S, and then let the game player A S speed fast moving to P4, this method it is quite reasonable, the solution of the prototype in international is called (Full plesiochronous), of course, is the prototype I tamper with a lot to adapt synchronous online games, and so became the prediction:

24、pull.Another solution, I named it verification synchronization, and heard the name also know, in general, means that each instruction after the server verification, through the implementation of the action. The following specific ideas: first of all, also need in each game player connection type ins

25、ide the definition of a TimeModified, and then in response to the client game player mouse walking at the same time, the client will not move ahead, but a walk the instructions to the server, and then waiting for the server to verify. After the server receives this message, verify the logic layer, a

26、nd then calculate the range to broadcast, including game player A, according to the different client TimeModified generated header, different began broadcasting, this time the game player walking information is completely synchronized. The advantage of this method is to ensure the absolute synchroni

27、zation between clients, the drawback is that when the network delay is relatively large when the game player, client behavior will become more smooth, to bring the feeling of game player. The prototype of this solution has been called Hierarchical master-slave synchronization in the world. It was wi

28、dely used in various fields of network since 80s.The last solution is an idealized solution, known internationally as Mutual synchronization, as a promising solution to the future of the future network. The reason for this proposal does not mean that we have fully implemented this program, but rathe

29、r that some aspects of this program are applied to certain aspects of the online game domain. I named this scheme: half server synchronization. The general design idea is as follows:The client needs to establish many broadcasting list when it landed on the world, these lists in the client and server

30、 to the background is not timely synchronization, is to establish a list, because the type to broadcast is more than one, for example, local message, remote message, global and message etc.,These lists need to be set up when the client is landing, according to the messages sent by the server. In the

31、 establishment of the list at the same time, also need to obtain broadcast objects in each list of TimeModified, and to maintain a complete list of user status in the background of the synchronization is not timely and according to the local server, user status table, can be part of a decision by th

32、e client himself, when the client sends the decision the final decision will be directly sent to the broadcast list of the client, and proofread its time, time to ensure that each client in the received message is according to the local time of the school. Then, by using the amount of calculation me

33、ntioned earlier in the prediction pull, the method of improving the speed of walking past will make synchronization very smooth. The advantages of the scheme is not through the server, client synchronization between themselves, can greatly reduce the errors caused by network delay, and for most of t

34、he decision by the client can do, but also greatly reduces the server resources. The drawback is that the news and decision-making rights are placed on the client side of the local, so the plug-in provides a great opportunity.Synthesize the above three kinds of advantages and disadvantages about the

35、 network synchronization faction, synthesize a set of more complete solutions about network game transmission synchronization, I call it colligate synchronization. The general idea is as follows:The server needs all message synchronization from the division a priority, then according to the ratio of

36、 3/4 into an important message and non important news for non important news, the decision on the client, the decision mechanism and various related based on client logical message buffer, and message buffer management institutions, as shown below:A brief description of the above for non important n

37、ews, general process of client, which has a client passive behavior deserves the attention of everyone, including return on some server authentication code sent, to ensure that a message is in the cache and the server message is consistent, so as to effectively prevent the plug-in to tamper with the

38、 local message cache. The source is the local client, the message to the player, and the messages sent by the remote server.For important messages, such as fight or some game player involved in some of the more sensitive data operation, using another set of programs, the program first need to establ

39、ish a set of Ping System between the server and the client, then the server and users save time Ping value, when Ping is small, the response message of the game player at the same time not to action, but put the message back to the server, and the server block, after receiving the message, to all th

40、e logic verification with effective broadcast object (including broadcast message originator), then the client receives the message authentication, to perform an action. And when Ping is large, the response message at the same time the client game player immediately, and at the same time the message

41、 back to the server, it is worth noting that this time also need to establish a verification message queue in the local, the message enqueue, performs the validation action while waiting for the server, also need to save the current state. After receiving the clients request, the server performs log

42、ical verification and sends the message back to each client with the local time that the clients have checked. If the validation passes, however, the message originator is notified that the message validation failed and the client automatically cancels the action already in progress and restores the

43、 original state. If the authentication is passed, the clients broadcast to pull it up based on the collation time obtained from the server ensure that the synchronization is completed before the action is completed.At this point, a more mature network game synchronization mechanism has been initiall

44、y established, and the next logical code according to their different game style and focus to write.Synchronization is the most important issue in network game, how to synchronize also involves various aspects, such as the size of the game, the game type and variety, the relatively large size of the

45、 game, in terms of synchronization can be a lot of the time, the news had ten points and for different messages by synchronization different mechanisms, and for the relatively small size of the game, you can use the synchronization mechanism substantially the same, what is not a set of synchronizati

46、on, according to the different needs of their own to make different decisions online synchronization synchronization algorithm of navigation (Dead Reckoning) algorithm that:-网络游戏同步详解之二在了解该算法前,我们先来谈谈该算法的一些背景资料。大家都知道,在网络传输的时候,延迟现象是很普遍的,而在基于服务器/客户端结构下的网络游戏的同步也就成了很头疼的问题,在保证客户端响应用户本地指令流畅的情况下,没法有效的保证的同步的及

47、时性。同样,在军方也有类似的事情发生,即使是同一局域网里面的机器,也会因为传输的延迟,导致一些运算的失误,介于此,美国国防部投入了大量的资金用于研究一种比较的好的方案来解决分布式系统中的延迟问题,特别是一个叫分布式模拟运动(分布式交互仿真)的系统,这套系统呢,其中就提出了一套号称是隐藏延迟和带宽减少的方案,命名为航位推算。呵呵,来头很大吧,恩,那么我们下面就来看看这套系统的一些观点,以及我们如何把它运用到我们的网络游戏的同步中。首先,这套同步方案是基于我那篇网络游戏的同步一文中的互同步同步方案的,也就是说,它并不是服务器/客户端结构的,而是基于客户端之间的同步的。下面我们先来说一些本文中将用到

48、的名词概念:网状网络:客户端之间构成的网络节点:网状网络中的每个客户端极限误差:进行同步的时候可能产生的误差的极值恩,在探讨其原理的之前,我们先来看看我们需要一个什么样的环境。首先,需要一个网状网络,网状网络如何构成呢?当有新节点进入的时候,通知该网络里面的所有节点,各节点为该客户端在本地创建一个副本,登出的时候,则通知所有节点销毁本地关于该节点的副本。然后每个节点该保存一些什么数据呢?首先有一个很重要的包需要保存,叫做协议数据包(PDU协议数据单元PDU),包含节点的一些相关的运动信息,比如当前位置,速度,运动方向,或者还有加速度等一些信息。除PDU之外,还有其他信息需要保存,比如说节点客户

49、端人物的HP、MP之类的。然后8、保证每个节点在最少秒之内要向其它节点广播一次PDU信息。最后,设置一个极限误差值。到此,其环境就算搭建完成了下面,我们就来看看相关的具体算法:假设在节点一有一个小人(路人甲),开始跑路了,这个时候,就像所有的节点广播一次他的PDU信息,包括:速度(S),方向(O),加速度(一)。那么所有的节点就开始模拟路人甲的运动轨迹和路线,包括节点一本身(这点很重要),同时,路人甲在某某玩家的控制下,会不时的改变一下方向,让其跑路的路线变得不是那么正规。在跑路的过程中,节点一有一个值在不停的记录着其真实坐标和在后台模拟运动的坐标的差值,当差值大于极限误差的时候,则计算出当前

50、的速度,方向O和速度一(算法将在后面介绍),并广播给网络中其他所有节点。其他节点在收到这条消息之后呢,就可以用一些很平滑的移动把路人甲拉扯过去,然后重新调整模拟跑路的数据,让其继续在后台模拟跑路。很显然,如果极限误差定义得大了,其他节点看到的偏差就会过大,如果极限偏差定义得小了,网络带宽就会增大。如果定义这个极限误差,就该根据各种数据的重要性来设计了。如果是回合制的网络游戏,那么在走路上把极限误差定义得大些无所谓,可以减少带宽。但是如果是及时打斗的网络游戏,那么就得把极限误差定义得小一些,否则会出现某人看到某人老远把自己给砍死的情况。航位推算的主要算法有9种,但是只有两种是解决主要问题的,其他

51、的基本上只是针对不同的坐标系的一些不同的算法,这里就不一一介绍了。好,Well, lets look at the two most popular algorithms in the legend:First: target = origin + speed * time differenceSecond: target point = origin + speed * time difference + 1/2 * acceleration * time differenceOh, the legendary algorithms are very classic, although we

52、 have learned as early as junior high school physics.The algorithm is good, as it begins to say, Latency Hiding & Bandwidth Reduction, from the principle to solve the synchronization problem of network delays, and effectively reduces the bandwidth, good place is basically the algorithm can only be u

53、sed in moving in the same step, of course, mobile synchronization is the biggest problem of synchronization in network game.This method combines the framework of the integrated synchronization method proposed in the article synchronization of online games. It can basically solve the problem of walki

54、ng synchronization in online games. Related questions are welcome to discuss.Smoothing algorithms in Dead Reckoning:According to my last article introduces, in the node A receives the node B new PDU package, if the local coordinates and A on the B to simulate the movement of the inconsistency, how t

55、he A screen on the B pulled into the new PDU package described above to go, the above mentioned only by move very smooth B pulled in the past, so in practice should be how to operate? Four methods are introduced here.The first method, I named the direct pulling method, we listen to know the name, is

56、 directly to the B abruptly pulled the coordinates of the new PDU package that is described. The advantage of this method is simple. The downside is that you wont do this after looking at the following three ways.Second methods, called straight line (Linear), which allows B to coordinate the new PDU

57、 package that is described from its current coordinates to go straight, walk with the above described algorithm speed:Target point = origin + speed * time difference + 1/2 * acceleration * time difference is calculated:First calculate required from the current coordinates to the coordinates in the PDU package drawing time:T = Dest (TargetB - OriginB) / SpeedThen according to the new PDU package which depicts the coordinate information calculated in time after T, according to the motion information of

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论