Frame sync and state sync

With the rapid development of real-time games, synchronization technology has gradually become one of the core of the solution. This article briefly discusses frame synchronization and state synchronization.


frame sync

What is frame synchronization: Frame synchronization is often used in RTS (Real Time Strategy) games. What is synchronized in the game is the player's operation command, which contains the current frame index. The general process is that the client uploads the operation to the server, and the server does not calculate the game behavior after receiving it, but forwards it to all clients. The most important concept here is that same input + same timing = same output.

The process of realizing frame synchronization is generally as follows:

  1. Synchronized random number seed. (In general, the use of random numbers is designed in games. By synchronizing the random number seeds, the consistency of random numbers can be maintained)

  2. Client upload operation instructions. (Instructions include game operations and current frame index)

  3. The server broadcasts the actions of all clients. (If there is no operation, also broadcast a null command to drive the game frame forward).

Because of the frame synchronization feature, we can easily make battle playback: the server records all operations, and the client requests the operation file to execute it again.

The nature of frame synchronization results in a complete separation between the client's logic implementation and presentation implementation. Some method interfaces in Unity (such as Invoke, Update, animation system, etc.) are unreliable, so you need to implement a set of physics engine and math library yourself to separate logic and performance. In this way, even if Unity's rendering is asynchronous, the logic runs out of synchronization.

I once participated in a project of an airplane-like barrage game. Its synchronization scheme is frame synchronization, which can play and playback perfectly, and realize accelerated verification on the server.


state synchronization

What is state synchronization: What is synchronized is the various states in the game. The general process is that the client uploads the operation to the server, the server calculates the result of the game behavior after receiving it, and then broadcasts various states in the game, and the client receives the state and then displays the content according to the state. The most widespread application of state synchronization should be in turn-based games.

State synchronization is actually a kind of imprecise synchronization. In its idea, the consistency of the performance on the screen of different players is not an important indicator, as long as the result of each operation is the same. Therefore, state synchronization does not require high network latency. Like playing RPG games, a delay of 200-300ms is acceptable. But in RTS games, 50ms lag can hurt too.
As an example of movement, in state synchronization, the operation on client A requires to move from point A to point B, but on client B, the object A moves from point A to point C, and then from point C to point B. This is because when client B receives A's moving state, a delay has passed. In this process, client B needs to do some smooth processing locally, and finally achieve the result of moving to point B.

Therefore, in domestic RPG games, the special effects of animation are generally more gorgeous (large), and it feels like a hit when attacking. There is usually an animation before the skill is released, and the attack request is submitted to the server at the same time. When the server result returns, the animation is finished, and then the unified damage effect and settlement.


Comparison and selection of state sync and frame sync:

Compare:

state synchronization frame sync
flow relatively high relatively low
playback large log file small record file
safety Server implementation logic, high security The logic is on the client side, there is a lot of pressure on anti-plugging, and it is unavoidable to open the picture and hang
server pressure Big little
battle check Protocol encryption, memory confusion, and error checking cannot be completely solved. The server can restart and run the battle again.
network lag performance Teleport, return, inexplicable blood loss Fighting stuck
accomplish To optimize the state synchronization method, the client needs to perform interpolation processing. The client is developed in a stand-alone mode to ensure the separation of the logical layer and the presentation layer. Do not use floating-point numbers in the logic layer, and do not use logical structures of indeterminate order. Can't use Unity for physics engine and floating point calculations.

Choice: For real-time strategy games with many units, frame sync is a good choice. Conversely, if there are more players, the state synchronization is more suitable and the security is higher.


If there are any mistakes, please point them out.

email:dxmdxm1992#gmail.com

blog: http://blog.csdn.net/david_dai_1108

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325517222&siteId=291194637