[Goto] Frame lock synchronization algorithm

Source: Internet
Author: User

Frame lock algorithm to solve game synchronization

What are the common synchronization strategies for early rts,xbox360 live games? Fighting games multiplayer How to ensure fluency and consistency? How can you write online games just like a single game? Watch "Frame Lock synchronization algorithm"

"Frame Lock synchronization Algorithm" Reproduced please specify the source: http://www.skywind.me/blog/archives/131

Algorithm Concepts

The algorithm generally requires the speed of the RTT to within 100MS, the general number of not more than 8 people, in such a case, can be like a single game to write online games. All clients logic is unified at any time, the disadvantage is a human card machine, all waiting.

1. The client uploads control information on a timed basis (e.g. every five frames).
2. The server receives all control information and broadcasts it to all customers.
3. The client uses the control information from the update message sent by the server to play the game.
4. Waits if the client does not receive an update message from the server when it is made to the next keyframe (after 5 frames).
5. If the client has received an update message from the server at the next keyframe, use the above data for the game and collect the current mouse and keyboard input to send to the server while continuing.
6. The next keyframe update message is sent again after the server collects all the data.

This process of waiting for keyframes to update data is called frame lock
Application examples: Most RTS games, Street Fighter II (XBOX360), Callus Simulator.

Algorithmic flow

Client logic:
1. Determine if the current frame f is a keyframe K1: if it is not a jump (7).
2. If it is a keyframe, see if there are any K1 update data, and if not, repeat the 2 wait.
3. The input of the current K1 is sent to the server as the CTRL data along with the K1 number
4. From update K1, get the number of the next keyframe K2 and the input data between the next key frame.
5. The virtual input between this keyframe and the next keyframe K2 is used by I.
6. Make K1 = K2.
7. Execute the Frame logic
8. Jump (1)

Service-side logic:
1. Collect all clients This keyframe K1 Ctrl data (ctrl-k) waits to know that the collection is complete for all ctrl-k.
2. Based on all ctrl-k, calculate the update for the next Keyframe K2, and then calculate the next keyframe's number K3.
3. Send update to all clients
4. Make K1=k2
5. Jump (1)

The server smooths out the number of the next keyframe based on the maximum RTT of all clients, allowing the delay to be adjusted automatically based on network conditions.

Algorithm Demo

I used the algorithm to modify the arcade simulator for a multiplayer version of the game, earlier there is a thing called Kaillera, can help the simulator to achieve multiplayer, but does not make frame lock, but simply the keyboard message to collect broadcast only, Later Capcom in the PSP and 360 have been out of the Street Fighter Network version, but the network effect is not ideal. This algorithm in fact the local area network is often used, but in recent years the public network speed, it is easy to find rtt<50ms server, so according to the above algorithm, in the average rtt=100ms (operating sensitivity of 1/10 seconds), the case, to ensure that the automatic calculation of key frames to adapt to various network conditions, You can develop online games like a single game, without the need for complex position/State synchronization on the state.

As you can see from the demo, the two emulator processes are running 1941 of the game, and the two sides use the algorithm to unify the logic in a single whole.

Finally this picture is run KOF99, the two sides are perfectly synchronized.

No wait improvements between frames

For the traditional frame lock algorithm speed slow will be stuck to the speed of the problem, practice midline action game usually with "timed not to wait" way again every time the interval clock occurs fixed to broadcast the operation to all users, do not rely on the specific each player has operation update:

1. Single user current keyboard up and down attack jump is pressed with a 32-bit integer description, the server describes a game of up to 8 players in the keyboard operation: int player_keyboards[8];

2. The server sends update messages to all clients 50 times per second (including all client-side operations and incremented frame numbers):

Update= (Frameid,player_keyboards)

3. The client plays the same kind of update messages that contain all player actions per frame, just like playing video games.

4. If the client does not have the update data, it must wait until new data arrives.

5. If the client receives a lot of continuous update at a sudden, fast forward playback.

6. The client will send a message to the server (rather than the keyboard at the beginning of each frame) only if the button is pressed or released, and the message contains only an integer. After receiving the server, rewrite player_keyboards

————–

Although the network speed of the player networks one card, may be fast speed of the player to give seconds (other games are similar). However, the slow speed of the player will not be stuck to fast players, will only feel their operation delay. On the other side, the local tyrants is generally faster and we have to take care of it.

The random number needs the service side to send the seed to each client in advance, each client calculates the logic to use this seed to generate the random number, moreover this example takes the keyboard operation as an example, actually may take the more advanced operation as an example, for example "is going to a point", "is attacking" and so on. The method is also successfully applied to some real-time action games.

[Goto] Frame lock synchronization algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.