Frame synchronization can be found on the Internet less information, about the game is not, but the principle of implementation is relatively simple, in recent days wrote a document about frame synchronization, as to colleagues to sweep literacy, by the way also hair, you can give other people reference
-by Fox
Frame Synchronization
--Competition Network game design Scheme
First, preface
Frame synchronization, according to the definition of wiki encyclopedia, a synchronization source for the pixel-level synchronous display of processing technology, for the network of multiple APS, a signal will be sent through the host synchronization to other people, and synchronously displayed on each terminal. Synchronization signals can be pixel data per frame, or they can be key event information that affects data changes.
The application of frame synchronization in the network game, the design is different from the traditional MMORPG game, because can carry a lot of background computation, realize the effect of class single-machine, so it can be applied in similar shooting class, aircraft class to achieve the bomb screen calculation or fighting class of high-precision percussion experience
This article will mainly introduce the similarities and differences between the frame synchronization and the traditional MMORPG design framework, and the related design schemes, finally, the analysis of one of the implementation schemes is carried out, and the related technical difficulties such as anti-Plug and disconnection mechanism are not discussed in this paper.
second, the application of frame synchronization in the game
In the network game, the game service architecture can be divided into 2 modes, namely CS mode and peer
CS Mode framework as shown in Figure 1(c for customer, GSS for game state server)
Figure 1
As shown in Figure 1, the Game state Server (GSS) is deployed separately and is responsible for providing services to each of the providers on the network, sending State synchronization to each recipient when the GSS status changes.
The peer mode framework is shown in figure 2(c for customer, GSS for Game state server):
Figure 2
In Figure 2 , the game state server exists on each client host, and the game state changes directly from the input of each client.
of the above 2 service frameworks, CS mode, because the GSS server only one, the game state can guarantee absolute consistency, but GSS may serve tens of thousands of players at the same time, due to machine performance and network bandwidth and other hardware resource constraints, the server for most of the situation can not be very strict inspection and processing The peer mode is relative to CS mode, while the connected players are limited, so it is possible to perform more sophisticated operations, such as shooting class, aircraft type of bomb screen calculation or fighting class of high-precision percussion experience , but, due to the end-to-end communication mode, with simultaneous access to the user's increase, Traffic exponential growth, so that the number of simultaneous access will be more restrictive, suitable for a small amount of the same-screen games such as athletics.
In-peer mode, due to the existence of multiple GSS, how to ensure that each GSS consistent also needs special consideration, the application of frame synchronization algorithm in the game is mainly to solve the GSS consistency problem in peer-to-peer mode. The implementation principle is to refine the game into frames, for each frame, in the same running environment, to ensure the same input situation, will get the same output results.
Figure 3
Figure 3 , the initial state is 1, the second frame of the sequence frame, the input plus 1 operation, the state becomes 2, the third frame without input, the state is unchanged, the fourth frame, the input plus 1 operation, The status changes to 3. For each client of the same operating environment, the same input condition will result in the relevant output, as shown in figure 4 .
Figure 4
In general, the GSS is set to 20 to 30 frames in order for the user's input to respond in a timely manner and the excessive state of the game can be smoothed. Also, because of the client machine performance or settings differences, the GSS state can not be matched with the game render frame implementation one by one, so the GSS and the presentation layer must be completely separated, otherwise, because some small error is magnified eventually resulting in the game will appear completely different results.
Figure 5
As shown in Figure 5, the output of the non-deterministic render layer is fully driven by the GSS, and the GSS guarantees a stable frame count, even if there is a network delay, and the processing of that frame must be done after ensuring that all input to the frame is received.
Implementation of the scheme, roughly can be divided into 3 kinds, respectively, there is no host structure, host structure, server host structure
U No host structure
In the topology of figure 2 , all GSS functions are equivalent, and the scenario requires special frame handling to ensure that all clients are synchronized and receive all input. However, because each client on the network is fully peering, the scenario is simple and fair but the experience is easily limited , as soon as a user's network condition is delayed or interrupted, and other exceptions are affected by the user's operational experience.
U has host structure
Figure 6
As shown in Figure 6, randomly select one GSS as the host in each client, and also be responsible for frame control and input/output management, other GSS only communicates with GSS host, and GSS does not communicate with each other. The benefit of this scenario is that the game experience is only affected by the host and local network and the condition of the machine, and any other GSS failures will not affect others, and when the GSS host is completely out of contact, other GSS can also re-arbitrate the new GSS host, but the infrastructure host on the client, Easy to plug in the opportunity, the input to the frame and other can be special treatment, resulting in a loss of fairness in the game. This scheme guarantees a player experience, but is less secure
U Server Host Structure
The server host structure is the control of the GSS host in the structure of figure 6 and the input and output management functions on the server, reducing the objective impact of the GSS client, to ensure the experience of most players, and among them, players cheat, can immediately detect, To ensure the fairness of the game, but the structure has been off-peer design, communication traffic with the user increase, the negative amount of exponential growth. The scheme has high security and guarantees the player experience, but it has certain requirements for the service load.
U Other
converged with/without host and server host structure. Server host structure is characterized by control in the service side, in a state of the network game, can effectively prevent game data modification, game acceleration and other plug-in, in the service side of the hardware resources, can increase the host structure to reduce the burden, most of the functions with/without host structure processing, key operations by the server host structure processing, etc. To enable the GSS host and server host to work together
third, the server host structure design
The characteristics of the server host structure as described above, the analysis and design of the structure is further developed here.
Server Design
Figure 7
The server mainly plays the control function, carries on the client's frame control and the input and output management. As shown in Figure 7, each frame of the server is driven by a frame-driven client to perform frame processing, and when the client has input received by the server, the input is synchronously output to each client within the current frame of the server.
On the network due to the various conditions of the client, the number of client frames may not keep up with the server, as shown in figure 8 , if the client has dropped frame, you need to speed up execution after receiving the driver frame, to catch up with the speed of other clients, Users who avoid dropping frames are always responding to past events.
The game should give priority to ensure the normal user experience, so when there is a player card frame situation, should not choose to pause other players, but let him slowly catch up, design, the server can take the normal speed of the client, frame-driven client, but when the network has a sudden situation, as shown 9, when the communication is abnormal, 2 clients are missing the frame number 2, if the server is running as usual, to restore the network condition, the situation is, each client has been stuck a few frames, the acceleration pulled a few frames. Therefore, in response to this situation, increase the client's frame operation, that is, the client executes frame 1th, with the server said can play the second frame, and then the server started to drive the second frame action, consider the network delay situation, can advance to frame nth frame, the effect as shown in figure 9, The second frame operation on the left side of the client causes the server to start pushing the second frames, while the second frame action on the right side of the client does not actually play any role