Talk about online game synchronization

zhaozj2021-02-12  142

Synchronization is very important in online games, it guarantees that every player is generally the same. its

Really, the easiest way to solve synchronization problems is to broadcast each player's action to other players.

There are two problems in doing: 1. Which players broadcast, which news is broadcast. 2. What if the network is delayed. In fact

, The first question is a very simple question, but the reason why I raise this problem, it is reminding everyone to design it.

When you have a message structure, you need to take this factor in consideration. And for the second question, it is a troublesome question.

Question, everyone can come to see such examples:

For example, there is a player A to send an instruction to the server, saying that I am in P1 point, go to P2 point. Time issued by the instruction

Is T0, the server receives the time of T1, then broadcast this message to the surrounding player, the content of the message is "play

Home A From P1 to P2 "There is a player B near A. The time to receive the server is T2,

Then start drawing on the client, A from P1 to P2 points. There is a problem that does not synchronize at this time, player a

The time displayed on the screen of the player B is different from T2-T1. What should I do at this time?

There is a solution, I will give it a prediction to pull, although it is a bit weird, but basically everyone can come from literal

Understand it, understand it. To solve this problem, first define a value called: predict error. Then need on the server

Inside each player connection, add an attribute, called Timemodified, and then when the player logins, the client

The time and server time are compared, and the difference is saved in Timemodified. Still the above

An example, when the server broadcasts the message, calculates a client based on the TimeModifiedIfiedi to broadcast the object.

CurrentTime, then contain this CurrentTime in the message head, and then broadcast. And at the same time players

A The client establishes a queue locally, saves the message, only to obtain the server verification, from the unauthenticated message team

The message is deleted, and if the verification fails, it will be pulled back to P1. Then when the player B receives the server

The message "Player A From P1 to P2" checks the time and local time of the server in the server

To make a comparison, if it is greater than the defined prediction error, even if it is in the T2, the player A is walking on the screen.

P3, then pull the player A on the player B directly to P3, then continue to walk, so you can guarantee synchronization. more

Further, in order to ensure that the client is running more smooth, I don't recommend pulling the players directly, but count

Little P4 after P3, then use (P4-P1) / T (P4-P3) to calculate a very fast speed S, then let player A use speed

The degree S is quickly moved to P4, which is reasonable, and the original shape of this solution is called international.

(Full Plesiochronous), of course, the original shape has been tampered with a lot of synchronization of online games, so becomes

The so-called: predictive pull.

Another solution, I gave it name to verify synchronization, listen to the name, the general meaning is that each instruction is

After server verification, the action is performed later. The specific ideas are as follows: First, you need to connect to each player connection type.

Inside a Timemodified, then the client will not walk first at the same time on the client's mouse.

Move, but send a walking instruction to the server, then wait for the server to verify. After the server accepts this message, verify the logical layer, and then calculate the range of broadcasts, including player A, depending on each client.

Timemodified generates different messages, start broadcasting, this time this player's walking information is completely

Step. The advantage of this method is that the absolute synchronization between the clients can be guaranteed, and the disadvantage is that when the network delay is relatively large.

At the time, the player's client's behavior will become more uncomfortable, bringing the players very uncomfortable. This kind of solution

The original shape is known internationally, it is widely used in the 1980s.

Various areas of the network.

The last solution is an ideal solution that is known as Mutual Synchronization, a

A well-predicted solution for future network prospects. The reason here is to mention this plan, not to say we

This solution has been fully implemented, but only some of the ideas of this program in some aspects of the online game field.

miss you. I named this scheme: half server synchronization. The general design idea is as follows:

First of all, the client needs to establish a lot of broadcast lists when landing the world, these lists are in the client.

Do not synchronize in time, the reason why you want to build multiple lists, because the type to be broadcast is more than one, for example

Local Message, with Remote Message, and Global Message, etc., these lists need to be logged in client

It is time to establish a good news according to the message sent by the server. At the same time as a list, you will also need to get the broadcast object in each list.

TimeModified, and to maintain a complete user status list in the background, it is not in time and server

Synchronize, according to the local user status table, some decisions can be decided by the client, when the client sends this

When some decisions, the final decision is directly sent to the client in each broadcast list, and the school is

Yes, ensuring that the time of each client is receiving the message is pairing according to the local time. Then use forecasts

Pull the calculated advance amount, improve the method of speed walking, will make the synchronization very much SMOOTH.

The advantage of this program is not to synchronize between the client himself, and it is greatly reduced by the network delay.

The error is incorrect, and because most of the decisions can be done by the client, it also greatly reduces the resources of the server. thus

The drawbacks are because messages and decision rights are placed locally locally, so they provide a lot of multiplier.

Integrated the advantages and disadvantages of the three synchronization factions, combined with a complete solution about online game transmission synchronization

Decision, I call it a comprehensive synchronization method (Colligate Synchronization). The general design idea is as follows:

First of all, all messages need to synchronize from division a priority level, then divide important elimination according to the proportion of 3/4

Interest and non-important news, for non-important messages, put decision-making rights on the client, and establish relevant decisions on client logical

Institutions and various message cache, as well as the relevant message cache registration, as shown below:

Message cache

Decision-making body

Message management agency

source

Client passive behavior

Turn back to the server

Client a

Client B

Client C

Client D

The above figure briefly illustrates the general processing flow for non-important messages, and one of the clients is worthy of being worthy of passive behavior.

Everyone pays attention to the return of some of the verification code sent by the server to ensure that the messages in the message cache are consistent, thereby effectively preventing extensions from tampering up the local message cache. The source of the message is to include local

The client responds to the message of the player and the message passed by the remote server.

For important messages, such as the operation of fighting or some involve some sensitive data, use another one

Set of solutions, the program first needs to establish a set of ping system between the server and the client, then the server saves and

The timely ping value of the user, when the ping is relatively small, the response to the player's message will not perform the action, but first

Feed back this message to the server, and block, the server receives the message, and performs logic verification to all this detailed

The effective object of broadcast is broadcast (including the message initiator), and then the client receives the verification of the message before starting

Work. When Ping is relatively large, the client responds to the player's message, and the elimination

The feedback is given to the server, it is worth noting that this time you need to build a queue without verified messages locally,

Interesting team, waiting for the server to wait for the server to verify, but also save the current state. Please receive the client

After the request, logic verification is performed, and the message is given to each client, bringing local time to each client. Such as

If the verification is verified, the message initiator is notified, the message verification failed, and the client automatically put it in progress.

The action is canceled, restored the original state. If verified, the broadcast to each client is based on the proofreading from the server.

It is pulled between them to ensure synchronization before this behavior is completed.

carried out

wait

source

PING value

Big

small

Retreat to server verification

wait

Verification

Execute this action

Interrupt execution

Verification

Verification is not passed

At this point, a more mature online game synchronization mechanism has initially established, the next logic code is based on

The different game styles and side focus are written.

Synchronization is the most important issue of online games, how to synchronize and involve all aspects, such as game size, tour

Types of play and a variety of aspects, for a larger game, in synchronization, there are many indigenous works,

The news is very delicate, and different synchronization mechanisms are used for different messages, and for games with small scale,

You can use a general synchronization mechanism, how to synchronize, no parenteral, it is necessary to use your own disagreement

There are different synchronization decisions.

转载请注明原文地址:https://www.9cbs.com/read-7003.html

New Post(0)