Data synchronization method and system for multi-player battle game

CN120358375AInactive Publication Date: 2025-07-22CHENGDU LURENWANG SPORTS TECH CO LTD
View PDF 6 Cites -1 Cited by

Patent Information

Application Number
CN202311670431.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-05
Publication Date
2025-07-22
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN120358375A_ABST
    Figure CN120358375A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data synchronization, in particular to a data synchronization method and system for a multi-player battle game, which is applied to a client in a scene in which at least two clients establish communication through a server, and comprises the following steps: monitoring an input event of a user; sending an operation instruction to the server, so that the server generates a synchronization frame according to the operation instruction and broadcasts the synchronization frame to all the clients; acquiring a synchronization frame broadcasted by a server, performing local state calculation of the synchronization frame based on the fixed-point number math library, and determining a local state synchronization frame rate according to a logic layer accumulation condition; logical layer events are listened, representations are provided based on the read local state, and a playback rate is determined based on the accumulation of the logical layer. According to the method, the state synchronization frequency between the logic layer and the presentation layer and the playing rate of the presentation layer can be dynamically adjusted while data synchronization is realized, and the data synchronization efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data synchronization, and more specifically, to a method and system for data synchronization in a multiplayer battle game. Background Art

[0002] In a multiplayer battle game, it is necessary to synchronize various input events between different clients. Among them, frame synchronization is a commonly used method. The client synchronizes input events between different users at a certain frame rate, and performs logical calculation processes locally on the client side, reducing the high requirements for the network environment, reducing the server pressure, and ensuring that various input events on different clients are synchronized.

[0003] Generally, the physical engine provided by the game engine Unity (such as PhysX) uses floating-point numbers for physical calculations. As the game progresses, the floating-point error will be relatively large, causing the game processes of each client to go to different branches, resulting in the game being unable to proceed normally.

[0004] In a multiplayer real-time game, it is usually divided into a presentation layer and a logic layer. The presentation layer refers to the display of the game screen and the acquisition of user input. The logic layer refers to the gameplay logic that is independent of rendering and only focuses on state changes and calculations. The logic layer and the presentation layer are ultimately data-oriented. For example, in a basketball game, the position of the player, the actions of the player, the position of the basketball, etc. These data are collectively referred to as states. The logic layer defines all states and inputs, and then implements the algorithm for state changes. In the related art, in the frame-locking synchronization scheme based on Unity, a fixed-point physical simulation operation is introduced, and a pre-calculated basketball curve is used for fitting instead of directly using the physical engine. This is to ensure that the operation results are strictly unified and reduce the consumption of physical operations. The logic layer strictly maintains the order of frames. After sending the states within a period to the presentation layer in the order of events and at a certain frame rate, without waiting for the message indicating the completion of execution from the presentation layer, it directly enters the next event loop. Therefore, it may cause the accumulation of synchronized frames received by the logic layer and the presentation layer due to the excessive amount of data within the period. To avoid this accumulation, the synchronization interval is usually shortened, that is: the logic layer and the presentation layer synchronize at a faster pace.

[0005] However, this frame-sending scheme will cause the amount of data transmitted between the logic layer and the presentation layer to always be at a high level. Summary of the Invention

[0006] The object of the present invention is to overcome the problem that the frame-sending scheme adopted in the prior art will cause the amount of data transmitted between the logic layer and the presentation layer to always be at a relatively high level, and to provide a method and system for data synchronization in a multiplayer battle game with dynamically adjustable synchronization frame rate.

[0007] Embodiments of the present invention are implemented through the following technical solutions: A data synchronization method for a multiplayer battle game, applied to a client in a communication scenario where at least two clients establish communication through a server. The steps are as follows:

[0008] Monitor the input events of the user;

[0009] Send an operation instruction to the server, so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients. The operation instruction includes the input event;

[0010] Obtain the synchronization frame broadcast by the server, perform local state calculation of the synchronization frame based on the fixed-point number math library, and determine the local state synchronization frame rate according to the stacking situation of the logic layer. The fixed-point number math library is constructed based on pre-sampled action files;

[0011] Monitor the logic layer events, provide performance based on the read local state, and determine the playback rate according to the stacking situation of the logic layer.

[0012] According to a preferred embodiment, the determining the state synchronization frame rate according to the stacking situation of the logic layer specifically includes:

[0013] Update the current time of the server according to the last frame of the server, the synchronization interval, and the time elapsed since the last frame of the server;

[0014] Update the current time of the client according to the current frame of the client, the synchronization interval, and the time elapsed since the current frame of the client;

[0015] Determine the lag time according to the current time of the client and the current time of the server;

[0016] Monitor the lag time;

[0017] If the lag time is greater than the delay threshold, adjust the local state synchronization frame rate according to the determined local state synchronization frame rate. The calculation expression of the local state synchronization frame rate is as follows:

[0018] pS = 1 + dT / PT

[0019] In the above formula, pS represents the local state synchronization frame rate, dT represents the lag time of the client compared to the server, and PT represents the expected catch-up time.

[0020] According to a preferred embodiment, the method further includes: encapsulating the logic layer and providing a read-only interface to the presentation layer.

[0021] According to a preferred embodiment, the method further includes: obtaining the authoritative state of the server synchronization calculation and reconciling the local state according to the authoritative state.

[0022] According to a preferred embodiment, before sending the operation instruction to the server, it further includes: performing serialization operation on the operation instruction, and performing deserialization operation on the synchronization frame.

[0023] According to a preferred embodiment, the method further includes: running the logic layer in an independent thread.

[0024] The present invention also provides a data synchronization method for a multiplayer battle game, which is applied to the server in a communication scenario where at least two clients establish communication through a server. The steps are as follows:

[0025] Receiving the operation instruction sent by the client;

[0026] Performing validity detection on the operation instruction;

[0027] Storing the operation instruction and sorting it according to the occurrence order of the input events;

[0028] Periodically generating a synchronization frame and broadcasting the synchronization frame to all clients, where the synchronization frame includes the operation instructions uploaded by all clients within the period.

[0029] The present invention also provides a data synchronization system for a multiplayer battle game, which is applied to the client and includes:

[0030] A listening module, which is used to listen to the user's input events;

[0031] An instruction uploading module, which is used to send the operation instruction to the server so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients, where the operation instruction includes the input event;

[0032] A synchronization frame processing module, which is used to obtain the synchronization frame broadcast by the server, perform local state calculation of the synchronization frame based on the fixed-point number math library, and determine the local state synchronization frame rate according to the accumulation situation of the logic layer;

[0033] A state update module, which is used to listen to the logic layer events, provide performance based on the read local state, and determine the playback rate according to the accumulation situation of the logic layer.

[0034] The present invention also provides a data synchronization system for a multiplayer battle game, which is applied to the server and includes:

[0035] An instruction acquisition module, which is used to receive the operation instruction sent by the client;

[0036] A detection module, which is used to perform validity detection on the operation instruction;

[0037] A storage module, which is used to store the operation instruction and sort it according to the occurrence order of the input events;

[0038] An operation instruction processing module, which is used to periodically generate synchronization frames and broadcast the synchronization frames to all clients, where the synchronization frames include the operation instructions uploaded by all clients within a period.

[0039] The technical solutions of a data synchronization method and system for a multiplayer battle game in an embodiment of the present invention at least have the following advantages and beneficial effects: A data synchronization method and system for a multiplayer battle game disclosed in this application, for clients in a communication scenario where at least two clients establish communication through a server, by listening to user input events, and then sending operation instructions to the server, so that the server generates synchronization frames according to the operation instructions and broadcasts them to all clients, and then obtains the synchronization frames broadcast by the server, performs local state calculation of the synchronization frames based on a fixed-point number math library and determines the local state synchronization frame rate according to the stacking situation of the logic layer, and finally listens to logic layer events, provides performance based on the read local state and determines the playback rate according to the stacking situation of the logic layer. Thus, while synchronizing data, it is possible to dynamically adjust the state synchronization frequency between the logic layer and the presentation layer and the playback rate of the presentation layer, improving the data synchronization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a schematic flowchart of a data synchronization method for a multiplayer battle game provided in Embodiment 1 of the present invention;

[0041] Figure 2 It is a communication timing diagram of a client and a server provided in Embodiment 1 of the present invention;

[0042] Figure 3 It is a schematic flowchart of server operation instruction processing provided in Embodiment 5 of the present invention;

[0043] Figure 4 It is a communication timing diagram between the logic layer and the presentation layer in the normal mode provided in Embodiment 4 of the present invention;

[0044] Figure 5 It is a communication timing diagram between the logic layer and the presentation layer in the thread mode provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0045] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Usually, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0046] Embodiment 1

[0047] Refer to Figure 1As shown in the figure, it is a schematic flowchart of a data synchronization method for a multiplayer game provided by Embodiment 1 of the present application. This method is applied to a client in a communication scenario where at least two clients establish communication through a server. As Figure 2 shown, at least two clients establish communication through a server. The client can be an electronic device such as a mobile phone, a pad, a notebook, a computer, etc., and the server can be a device such as a server. Data synchronization is performed between the client and the server through the established communication. Specifically, it can be data synchronization for one or more objects to be operated. For example, in a game application scenario, data of each character is synchronized between each player client and the game server. The technical solution in this embodiment is mainly used to improve data synchronization efficiency.

[0048] Specifically, the method in this embodiment may include the following steps:

[0049] Step 101: In a scenario where at least two clients establish communication through a server, listen for user input events;

[0050] Among them, the solution in this embodiment is applicable to Figure 2 any client shown. Therefore, the method in this embodiment is executed on each client. In this embodiment, one of the clients is taken as an example for illustration. Communication between the client and the server can be established through a wireless network or a wired network, which will not be elaborated here.

[0051] Specifically, this embodiment can listen for whether there is a state change in the object to be operated on the client. For example, whether the character object in the game is moved, and it can be determined that there is an operation instruction to be synchronized on the client. The operation instruction here may include an input event.

[0052] Step 102: Send the operation instruction to the server so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients.

[0053] It should be noted that in a multiplayer online game, each client in the game needs to keep the position information consistent at each moment. Common synchronization methods are divided into frame synchronization and state synchronization. In frame synchronization, the server does not need to perform game logic processing, but only forwards the operation instructions of the client, and then the client performs logical calculations by itself; in state synchronization, the server calculates the game logic and returns the character state to the client, and the client directly uses the state returned by the server. For the embodiment of the present application, frame synchronization is used.

[0054] For example, on client A that has monitored an input event to be synchronized, after generating an operation instruction containing the input event, the operation instruction is sent to the server through the communication established between client A and the server, and then the server sends it to all clients through the communications established between client A and client B and the server respectively, as shown in Figure 2 shown in Figure 2 , thereby realizing the synchronization of the operation instruction between the server and all clients.

[0055] It should be noted that the input event in the operation instruction is data such as moving the operated object 3 centimeters to the right by a mouse click. Further, in this embodiment, the data is converted into fixed-point number type data. For example, the operation instructions transmitted to all clients use fixed-point numbers instead of floating-point float type, thereby avoiding the inconsistent results caused by different data types between clients. For example, it avoids the situation where the moving distances of the operated objects on each player's client are different.

[0056] In addition, in this embodiment, before sending the operation instruction to the server, it further includes: serializing the operation instruction using ProtoBuf, and deserializing the synchronization frame for network transmission.

[0057] It should be noted that generally, in the game field, online multiplayer battle games based on frame synchronization generally do not use the floating-point-based physics engine provided by Unity (such as PhysX), but instead introduce an additional fixed-point-based physics engine, or choose to use simulated physics instead of real physics for fitting calculations.

[0058] Step 103: Obtain the synchronization frame broadcast by the server, and the logic layer performs local state calculation of the synchronization frame based on the fixed-point number math library, and the fixed-point number math library is constructed based on the pre-sampled action file. Among them, in this embodiment, the fixed-point number is used instead of the floating-point number for physical operations based on the fixed-point number math library to ensure that the random number seeds used for random operations by each client are consistent.

[0059] Generally, every time the synchronization interval duration is waited, step 103 is executed, that is, the synchronization frame broadcast by the server is obtained once, and the synchronization interval can be set according to requirements, such as 40 milliseconds or 50 milliseconds, etc. However, since there are not always operation instructions to be synchronized, or the data volume of the operation instructions to be synchronized each time is not necessarily the same, therefore, when there is no data to be synchronized or the synchronization data accumulates in the logic layer, the synchronization interval is adjusted.

[0060] In one implementation manner, in order to improve the data synchronization efficiency and avoid the accumulation of synchronization data, this embodiment determines the local state synchronization frame rate according to the accumulation situation of the logic layer. Specifically, the algorithm for determining the state synchronization frame rate according to the accumulation situation of the logic layer is as follows:

[0061] Update the current server time based on the last frame of the server, the synchronization interval, and the time elapsed since the last frame of the server. The expression is as follows:

[0062] tS = lRTID * ti + min(tSIT, ti)

[0063] In the above formula, tS represents the current server time, lRTID represents the last frame of the server, ti represents the synchronization interval, and tSIT represents the time elapsed since the last frame of the server;

[0064] Update the current client time based on the current frame of the client, the synchronization interval, and the time elapsed since the current frame of the client. The expression is as follows:

[0065] tC = tID * ti + tCIT

[0066] In the above formula, tC represents the current client time, tID represents the current frame of the client, and tCIT represents the time elapsed since the current frame of the client;

[0067] Determine the lag time based on the current client time and the current server time. The expression is as follows:

[0068] dT = tS - tC

[0069] In the above formula, dT represents the lag time of the client compared to the server;

[0070] Monitor the lag time;

[0071] If the lag time is greater than the delay threshold, adjust the local state synchronization frame rate according to the determined local state synchronization frame rate. The calculation expression of the local state synchronization frame rate is as follows:

[0072] pS = 1 + dT / PT

[0073] In the above formula, pS represents the local state synchronization frame rate, and PT represents the expected catch-up time.

[0074] Step 104, Listen for logic layer events. The presentation layer provides a presentation based on the read local state and determines the playback rate according to the accumulation of the logic layer; assume that the game executes 20 logic frames per second, then the frame rate is 50 ms / frame. When the logic frames accumulate, the frame rate can be adjusted.

[0075] In summary, for a data synchronization method and system for a multiplayer battle game disclosed in the present application, for clients in a communication scenario where at least two clients establish communication through a server, by listening to user input events, and then sending operation instructions to the server, so that the server generates a synchronization frame according to the operation instructions and broadcasts it to all clients, and then obtains the synchronization frame broadcast by the server, performs local state calculation of the synchronization frame based on a fixed-point number math library, and determines the local state synchronization frame rate according to the stacking situation of the logic layer. Finally, listen to logic layer events, provide performance based on the read local state, and determine the playback rate according to the stacking situation of the logic layer. Thus, while synchronizing data, it is possible to dynamically adjust the state synchronization frequency between the logic layer and the presentation layer and the playback rate of the presentation layer, improving data synchronization efficiency.

[0076] Embodiment 2

[0077] Based on Embodiment 1, in order to effectively decouple logic and presentation and reduce the coupling between components, in this embodiment, the logic layer is encapsulated, and a read-only interface is provided to the presentation layer, which improves the readability and maintainability of the code while preventing the logic layer from being affected by the presentation layer.

[0078] Embodiment 3

[0079] Based on the above embodiments, in the case of frame synchronization, when a player enters midway and needs to calculate from the beginning for frame chasing, in this embodiment, local frame chasing is performed by accelerating the operation of the logic layer and the playback of the presentation layer. The specific frame chasing method is as shown in steps 103 to 104 in Embodiment 2, which will not be elaborated here; in addition, when there is a disunity between the presentation layer and the logic layer due to network congestion, the state of the presentation layer is directly converted to match the logic layer.

[0080] Embodiment 3

[0081] Based on the above embodiments, in this embodiment, the operation of the logic layer can be divided into a normal mode and a thread mode. Refer to Figure 4 and Figure 5 As shown, in the thread mode, the logic layer runs in an independent thread.

[0082] In the thread mode, after the logic layer sends the serialized logic frame of the first frame to the event center of the main thread, it completes one cycle and then turns to process the second frame; the event center deserializes the received serialized logic frame to obtain deserialized events, the state mapping layer of the main thread updates the state, and the display layer (i.e., the presentation layer) caches the state and then completes one cycle, and then turns to process the event center listening for the second frame; the presentation layer reads the state from the cache every 50 ms and presents it, thus completing the synchronization of the first frame. In this way, the independent logic layer thread will not block the rendering and event processing of the client presentation layer, and the independent logic layer thread can also better manage the internal state and achieve thread safety.

[0083] Embodiment 4

[0084] This embodiment provides a data synchronization method for a multiplayer battle game, and this method is applied to the server in a communication scenario where at least two clients establish communication through a server. As Figure 3 shown, the steps of this method are as follows:

[0085] Step 201, receive the operation instruction sent by the client; among them, the solution in this embodiment is applicable to Figure 2 the server shown.

[0086] Step 202, perform validity detection on the operation instruction to ensure the legality and correctness of the operation, prevent the client from uploading illegal or incorrect operation instructions, so as to avoid inconsistent game states or cheating behaviors.

[0087] Step 203, store the operation instruction and sort it according to the occurrence order of the input event, so that the logic layer strictly maintains the order of the frames.

[0088] Step 204, periodically generate a synchronization frame and broadcast the synchronization frame to all clients, and the synchronization frame includes all operation instructions uploaded by all clients within the period.

[0089] Embodiment 5

[0090] This embodiment provides a data synchronization system for a multiplayer battle game, and this system is applied to the client in a communication scenario where at least two clients establish communication through a server, including:

[0091] A listening module, used to listen for the input events of the user;

[0092] An instruction uploading module, used to send an operation instruction to the server, so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients, and the operation instruction includes the input event;

[0093] A synchronization frame processing module, which is used to obtain the synchronization frame broadcast by the server, calculate the local state of the synchronization frame based on the fixed-point number math library, and determine the local state synchronization frame rate according to the stacking situation of the logic layer;

[0094] A state update module, which is used to listen for logic layer events, provide performance based on the read local state, and determine the playback rate according to the stacking situation of the logic layer.

[0095] Embodiment 6

[0096] This embodiment provides a data synchronization system for a multiplayer battle game. The system is applied to the server in a communication scenario where at least two clients establish communication through a server, and includes:

[0097] An instruction acquisition module, which is used to receive the operation instructions sent by the client;

[0098] A detection module, which is used to detect the validity of the operation instructions;

[0099] A storage module, which is used to store the operation instructions and sort them according to the occurrence order of the input events;

[0100] An operation instruction processing module, which is used to periodically generate synchronization frames and broadcast the synchronization frames to all clients. The synchronization frames include all the operation instructions uploaded by all clients within the period.

[0101] The above are only the preferred embodiments of the present invention and are not used to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims

1. A data synchronization method for a multiplayer battle game, applied to a client in a communication scenario where at least two clients establish communication through a server, characterized in that, The steps are as follows: Monitor the input events of the user; Send an operation instruction to the server so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients, and the operation instruction includes the input event; Obtain the synchronization frame broadcast by the server, perform local state calculation of the synchronization frame based on the fixed-point number math library, and determine the local state synchronization frame rate according to the stacking situation of the logic layer. The fixed-point number math library is built based on the pre-sampled action file; Monitor the logic layer events, provide performance based on the read local state, and determine the playback rate according to the stacking situation of the logic layer.

2. The data synchronization method for a multiplayer battle game according to claim 1, wherein The determination of the state synchronization frame rate according to the stacking situation of the logic layer specifically includes: Update the current time of the server according to the last frame of the server, the synchronization interval, and the time elapsed since the last frame of the server; Update the current time of the client according to the current frame of the client, the synchronization interval, and the time elapsed since the current frame of the client; Determine the lag time according to the current time of the client and the current time of the server; Monitor the lag time; If the lag time is greater than the delay threshold, adjust the local state synchronization frame rate according to the determined local state synchronization frame rate. The calculation expression of the local state synchronization frame rate is as follows: pS = 1 + dT / PT In the above formula, pS represents the local state synchronization frame rate, dT represents the lag time of the client compared to the server, and PT represents the expected chasing time.

3. The data synchronization method for a multiplayer battle game according to claim 1, characterized in that, The method further includes: encapsulating the logic layer and providing a read-only interface to the presentation layer.

4. The data synchronization method for a multi-player battle game according to claim 1, characterized in that, The method further includes: obtaining the authoritative state of the server synchronization calculation and reconciling the local state according to the authoritative state.

5. The data synchronization method for a multiplayer battle game according to any one of claims 1 to 4, characterized in that, Before sending the operation instruction to the server, it further includes: performing serialization operation on the operation instruction and deserialization operation on the synchronization frame.

6. The data synchronization method for a multiplayer battle game according to claim 5, wherein The method further includes: running the logic layer in an independent thread.

7. A data synchronization method for a multiplayer battle game, applied to a server in a communication scenario where at least two clients establish communication through a server, characterized in that, The steps are as follows: Receive the operation instruction sent by the client; Perform validity detection on the operation instruction; Store the operation instruction and sort it according to the occurrence order of the input events; Periodically generate a synchronization frame and broadcast the synchronization frame to all clients. The synchronization frame includes all the operation instructions uploaded by the clients within the period.

8. A data synchronization system for a multiplayer battle game, applied to a client, characterized in that, It includes: A monitoring module for monitoring the input events of the user; An instruction uploading module for sending an operation instruction to the server so that the server generates a synchronization frame according to the operation instruction and broadcasts it to all clients. The operation instruction includes the input event; A synchronization frame processing module for obtaining the synchronization frame broadcast by the server, performing local state calculation of the synchronization frame based on the fixed-point number math library, and determining the local state synchronization frame rate according to the stacking situation of the logic layer; A state update module for monitoring the logic layer events, providing performance based on the read local state, and determining the playback rate according to the stacking situation of the logic layer.

9. A data synchronization system for a multiplayer battle game, applied to a server side, characterized in that, It includes: An instruction obtaining module for receiving the operation instruction sent by the client; A detection module for performing validity detection on the operation instruction; A storage module for storing the operation instruction and sorting it according to the occurrence order of the input events; An operation instruction processing module for periodically generating a synchronization frame and broadcasting the synchronization frame to all clients. The synchronization frame includes all the operation instructions uploaded by the clients within the period.

Citation Information

Patent Citations

  • FBSG method used for game synchronization

    CN106034129A

  • Peer-to-peer computing based game interactive method and system for multi-user scenario

    CN108379833A

  • Frame synchronization method and device, equipment and medium

    CN111265854A

  • Game synchronization method and device, terminal, server and storage medium

    CN113521743A

  • State synchronization method and device, electronic equipment and storage medium

    CN117085313A