[Reposted from csdn] frame lock synchronization algorithm

Source: Internet
Author: User

The original post address is http://blog.csdn.net/skywind/article/details/6179506. The original author skywind expressed his gratitude to the original author for a very good article.

---------------------------------

The online game synchronization algorithm is widely used in RTS games, xbox360 arcade games, and simulator battle platforms.

Http://blog.csdn.net/skywind


Algorithm Concept


This algorithm generally requires that the network speed RTT should be within Ms. Generally, the number of people cannot exceed 8. In this case, you can write online games like a single-host game. The logic of all clients is unified at any time, but the disadvantage is that one person gets stuck and everyone is waiting.

1. The client uploads control information at a scheduled time (for example, every five frames.
2. The server receives all control information and broadcasts it to all customers.
3. The client uses the control information in the update message sent from the server to play the game.
4. If the client does not receive the server update message from the next key frame (after five frames), it will wait.
5. if the client receives an update message from the server when it reaches the next key frame, the above data is used for the game, and the current mouse and keyboard input are collected and sent to the server.
6. The server collects all the data and sends the next key frame update message again.

This process of waiting for key frames to update data is called "frame lock"
Application Cases: Most of the RTS games, street bully II (xbox360), and callus simulators.

Algorithm flow 

Client logic:
1. Determine whether the current frame F is a key frame K1: if it is not a jump (7 ).
2. If it is a key frame, check whether there is any K1 update data. If not, repeat 2 for waiting.
3. Collect the input of the current K1 and send it to the server together with the CTRL data and K1 number.
4. Obtain the number K2 of the next key frame from Update K1 and the input data I between the next key frame.
5. I is used for the Virtual Input between the key frame and the next key frame K2.
6. Make k1 = k2.
7. Execute the frame Logic
8. Redirect (1)

Server logic:
1. Collect the Ctrl-k Data (CTRL-K) of the Key Frame k1 of all clients.
2. Calculate the update of the next key frame K2 based on all the CTRL-K, and calculate the number K3 of the next key frame.
3. Send update to all clients
4. Make k1 = k2
5. Redirect (1)

 


The server smoothly calculates the number of the next key frame based on the maximum RTT of all clients, so that the delay is automatically adjusted according to network conditions.


Algorithm demonstration


Based on this algorithm, I changed the arcade simulator to a version that can be used for multiplayer battles. In the early days, there was something called kaillera that could help the simulator to bring people online, but it didn't lock frames, it's just a simple process of collecting and broadcasting keyboard messages. Capcom later published the online version of street bully on PSP and 360, but the networking effect was not satisfactory. In fact, this algorithm is often used when the local area network is small, but in recent years the public network speed has improved, it is easy to find the RTT <50 ms server, so according to the above algorithm, when the average RTT = 100 ms (the operating sensitivity is 1/10 seconds), the system ensures that the automatically calculated key frame is adapted to various network conditions, and then can develop online games just like a single-host game, complex location/status synchronization is not required.

 

 

 

From the demo, we can see that both simulator processes are running the game 1941, and the clients on both sides use this algorithm to unify the logic in one whole.

 

 

The final figure is running kof99, and the two sides are perfectly synchronized.

------------------------------------

The algorithm mentioned in this article is similar to bucket synchronization (bucket synchronization). The core is to push the input to several frames (which the operator usually cannot feel ), make sure that the same input is generated within the same frame (the sequence number of the frame must be consistent.

[Reposted from csdn] 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.