WO2022022140A1 - 数据包的同步方法、装置、设备及存储介质 - Google Patents

数据包的同步方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2022022140A1
WO2022022140A1 PCT/CN2021/100479 CN2021100479W WO2022022140A1 WO 2022022140 A1 WO2022022140 A1 WO 2022022140A1 CN 2021100479 W CN2021100479 W CN 2021100479W WO 2022022140 A1 WO2022022140 A1 WO 2022022140A1
Authority
WO
WIPO (PCT)
Prior art keywords
data packet
frame
message queue
client
identifier
Prior art date
Application number
PCT/CN2021/100479
Other languages
English (en)
French (fr)
Inventor
赵坤
徐国培
Original Assignee
腾讯科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Priority to EP21851414.9A priority Critical patent/EP4095693A4/en
Publication of WO2022022140A1 publication Critical patent/WO2022022140A1/zh
Priority to US17/884,431 priority patent/US20220379202A1/en

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/30Interconnection arrangements between game servers and game devices; Interconnection arrangements between game devices; Interconnection arrangements between game servers
    • A63F13/31Communication aspects specific to video games, e.g. between several handheld game devices at close range
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/30Interconnection arrangements between game servers and game devices; Interconnection arrangements between game devices; Interconnection arrangements between game servers
    • A63F13/35Details of game servers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F15/00Digital computers in general; Data processing equipment in general
    • G06F15/16Combinations of two or more digital computers each having at least an arithmetic unit, a program unit and a register, e.g. for a simultaneous processing of several programs
    • G06F15/163Interprocessor communication
    • G06F15/173Interprocessor communication using an interconnection network, e.g. matrix, shuffle, pyramid, star, snowflake
    • G06F15/17306Intercommunication techniques
    • G06F15/17325Synchronisation; Hardware support therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/50Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers
    • A63F2300/53Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers details of basic data processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Definitions

  • the present application relates to the field of data communication, in particular to data packet synchronization.
  • the game client When the user plays the game through the game client, the game client generates a data packet according to the user's operation, and sends the data packet to the server.
  • the server performs the game logic operation according to the data packet, and synchronizes the data packet after the game logic operation to the participating games. of all game clients.
  • the server needs to send the calculated game logic to each game client according to the sequence of the received data packets.
  • a message queue is allocated to each game client participating in the game, the data packets generated by each game client are written into their corresponding message queues in sequence, and the server reads the data packets of each game client when reading. no sequence error occurs.
  • the embodiments of the present application provide a data packet synchronization method, device, device, and storage medium. By assigning a corresponding message queue to each logical thread, the memory occupied by the message queue in the server is reduced.
  • the technical solution is as follows:
  • a method for synchronizing data packets is provided.
  • the method is applied to a server.
  • the server is provided with k logical threads and k message queues, where k is a positive integer.
  • the message queues are in one-to-one correspondence, the logical threads are divided according to the type of logical operations, and the method includes:
  • the data packet carries a thread identifier and a frame identifier, the thread identifier is added by the client according to the type of logical operation required by the data packet, and the frame identifier is used to identify a trigger The picture frame of the data packet;
  • the calculated data packet is written into the message queue corresponding to the logical thread;
  • the calculated data packet is read from the message queue according to the frame identifier, and the calculated data packet is synchronized to an associated client of the client.
  • a data packet synchronization device comprising:
  • a receiving module configured to receive a data packet sent by a client, where the data packet carries a thread identifier and a frame identifier, and the thread identifier is added by the client according to the logical operation type required by the data packet, and the frame The identification is used to identify the picture frame when the data packet is triggered;
  • a writing module configured to send the data packet to a logical thread corresponding to the thread identifier for logical operation, and write the calculated data packet into a message queue corresponding to the logical thread;
  • a reading module configured to read the calculated data packet from the message queue according to the frame identifier, and synchronize the calculated data packet to an associated client of the client.
  • a computer device includes a processor and a memory, and the memory stores at least one instruction, at least a piece of program, code set or instruction set, the at least one instruction .
  • the at least one piece of program, the code set or the instruction set is loaded and executed by the processor to implement the method for synchronizing data packets according to the above aspects.
  • a computer-readable storage medium where a computer program is stored in the readable storage medium, and the computer program is used to execute the data packet synchronization method described in the above aspects.
  • a computer program product or computer program comprising computer instructions stored in a computer readable storage medium.
  • the processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the method for synchronizing data packets as described in the above aspects.
  • the server By assigning the corresponding message queues to the logical threads divided according to the logical operation types, the server writes the data packets after logical thread operations into the message queues corresponding to each logical thread, avoiding the occurrence of multiple threads sharing a message queue. At the same time, the number of message queues is reduced, the server memory occupied by the message queues is reduced, and the cost of managing messages is reduced.
  • FIG. 1 is a frame diagram of a computer system provided by an exemplary embodiment of the present application.
  • FIG. 2 is a schematic diagram of a state synchronization technology provided by an exemplary embodiment of the present application
  • FIG. 3 is a flowchart of a data packet synchronization method provided by an exemplary embodiment of the present application.
  • FIG. 4 is a schematic diagram of a framework of a data packet synchronization method provided by an exemplary embodiment of the present application.
  • FIG. 5 is a flowchart of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 6 is a schematic diagram of a framework of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 7 is a flowchart of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 8 is a schematic diagram of a framework of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 9 is a schematic diagram of a framework of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 10 is a flowchart of a data packet synchronization method provided by another exemplary embodiment of the present application.
  • FIG. 11 is a schematic diagram of m visual fields provided by an exemplary embodiment of the present application.
  • FIG. 12 is a schematic diagram of a screen in a client provided by an exemplary embodiment of the present application.
  • FIG. 13 is a structural block diagram of an apparatus for synchronizing a data packet provided by an exemplary embodiment of the present application.
  • FIG. 14 is a schematic diagram of an apparatus structure of a server provided by an exemplary embodiment of the present application.
  • Message Queue It refers to a communication method between applications to store messages (or data).
  • the message queue follows the principle of first-in, first-out. For example, message 1 is written to the message before message 2. In the queue, when reading a message, message 1 is read before message 2.
  • the producer of the message (the message publisher) publishes the message to the message queue, and the consumer of the message (the active acquirer of the message) obtains the message from the message queue, and the producer and the consumer do not interfere with each other.
  • Cyclic Barrier It means that under the condition of multi-threading, multiple threads cooperate with each other to complete a task. It is necessary to coordinate among multiple threads through the synchronization barrier to avoid the problem of timing disorder in multiple threads.
  • the frame identifier of a frame image is used as the synchronization fence. When each message queue reads the same frame identifier (synchronization fence), it proves that the data packet corresponding to the frame image has been read, and the following can be read. A data packet corresponding to a frame of picture.
  • Dirty flag It is used to identify whether the current data is consistent with the original data. If the current data is inconsistent with the original data, recalculate the current data and change the dirty flag from 0 to 1, and reset a dirty flag (the dirty flag is 0) for the calculated result; if the current data is consistent with the original data, then Keep the dirty flag at 1 to continue using the original data (current data).
  • a dirty flag of 0 means that the data has not changed, and a dirty flag of 1 means that the data has changed.
  • a dirty flag is set for the life value of the virtual object.
  • the dirty flag changes from 0 to 1; when the life value of the virtual object does not change, the dirty flag is still 0.
  • Cloud Computing refers to the delivery and use mode of IT infrastructure, which refers to obtaining the required resources in an on-demand and easily scalable manner through the network;
  • cloud computing in a broad sense refers to the delivery and use mode of services, which refers to the on-demand and easy-to-expand through network , easily scalable way to obtain the required services.
  • Such services can be IT and software, Internet-related, or other services.
  • Cloud computing is grid computing (Grid Computing), distributed computing (Distributed Computing), parallel computing (Parallel Computing), utility computing (Utility Computing), network storage (Network Storage Technologies), virtualization (Virtualization), load balancing ( Load Balance) and other traditional computer and network technology development and integration products.
  • Cloud computing has grown rapidly with the development of the Internet, real-time data streaming, the diversity of connected devices, and the need for search services, social networking, mobile commerce, and open collaboration. Different from the parallel distributed computing in the past, the emergence of cloud computing will promote revolutionary changes in the entire Internet model and enterprise management model.
  • the data synchronization method provided by the embodiment of the present application can be applied to a cloud server. By assigning a corresponding message queue to each logical thread, when the cloud server reads data packets, the order of the data packets will not be disordered, so that the correct The packets are sent to each client in order, reducing the cost of managing messages.
  • FIG. 1 shows a structural block diagram of a computer system provided by an exemplary embodiment of the present application.
  • the computer system 100 includes: a first terminal 120 , a server 140 and a second terminal 160 .
  • the first terminal 120 has an application program supporting a virtual environment installed and running.
  • the application can be a virtual reality application, a three-dimensional map program, a military simulation program, an FPS game, a MOBA game, a Massive Multiplayer Online Role-Playing Game (MMORPG), a multiplayer gunfight survival game, Any of a battle royale shooting game, a Virtual Reality (VR) application, or an Augmented Reality (AR) program.
  • the first terminal 120 is a terminal used by the first user, and the first user uses the first terminal 120 to control the first virtual object located in the virtual environment to perform activities, including but not limited to: adjusting body posture, walking, running, jumping, At least one of ride, aim, pick up, release skills, change skins, attack other virtual objects.
  • the first virtual object is a first virtual character, such as a simulated character object or an anime character object.
  • the first terminal 120 is connected to the server 140 through a wireless network or a wired network.
  • the server 140 may be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, or may provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, Cloud servers for basic cloud computing services such as middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms.
  • the server 140 includes a processor 144 and a memory 142, and the memory 142 further includes a receiving module 1421, a control module 1422 and a sending module 1423, and the receiving module 1421 is configured to receive data packets sent by the client, such as the i-th frame of the virtual environment picture.
  • the generated data packet; the control module 1422 is used to read the data packet from the message queue; the sending module 1423 is used to send the data packet to each client.
  • the server 140 is also used to provide background services, such as information saving services, for applications supporting a three-dimensional virtual environment.
  • the server 140 undertakes the main computing work, and the first terminal 120 and the second terminal 160 undertake the secondary computing work; or, the server 140 undertakes the secondary computing work, and the first terminal 120 and the second terminal 160 undertake the main computing work;
  • the server 140 , the first terminal 120 and the second terminal 160 use a distributed computing architecture to perform collaborative computing.
  • the server 140 may adopt a synchronization technology to make the display performance of multiple clients consistent.
  • the synchronization technology adopted by the server 140 includes: a state synchronization technology or a frame synchronization technology.
  • the data packet synchronization method provided in the embodiment of the present application may be implemented based on a state synchronization technology.
  • the server 140 uses a state synchronization technology to synchronize with multiple clients.
  • the battle logic runs in the server 140 .
  • the server 140 sends the state synchronization result to all clients, such as clients 1 to 10 .
  • the client 1 sends a request to the server 140, the request is used to request the virtual object 1 to attack the virtual object 2, the server 140 determines whether the virtual object 1 can attack the virtual object 2, and when the virtual object 1 executes the attack on the virtual object During the operation of 2, the remaining life value of virtual object 2. Then, the server 140 sends the remaining life value of the virtual object 2 to all clients, and all the clients update local data and interface performance according to the remaining life value of the virtual object 2 .
  • the second terminal 160 has an application program supporting a virtual environment installed and running.
  • the application can be a virtual reality application, a three-dimensional map program, a military simulation program, an FPS game, a MOBA game, an MMORPG game, a multiplayer gun battle survival game, a battle royale type shooting game, a VR application, or an AR program. any kind.
  • the second terminal 160 is a terminal used by the second user, and the second user uses the second terminal 160 to control the second virtual object located in the virtual environment to perform activities, including but not limited to: adjusting body posture, walking, running, jumping, At least one of riding, aiming, casting skills, changing skins, picking up, and attacking other virtual objects.
  • the second virtual object is a second virtual character, such as a simulated character object or an anime character object.
  • first avatar object and the second avatar object are in the same virtual environment.
  • first avatar object and the second avatar object may belong to the same team, the same organization, the same camp, have a friendship relationship or have temporary communication rights.
  • first virtual character and the second virtual object may also belong to different camps, different teams, different organizations, or have an adversarial relationship.
  • the applications installed on the first terminal 120 and the second terminal 160 are the same, or the applications installed on the two terminals are the same type of applications on different operating system platforms (Android or IOS).
  • the first terminal 120 may generally refer to one of multiple terminals
  • the second terminal 160 may generally refer to one of multiple terminals.
  • This embodiment only takes the first terminal 120 and the second terminal 160 as examples for illustration.
  • the device types of the first terminal 120 and the second terminal 160 are the same or different, and the device types include: smart phones, tablet computers, e-book readers, MP3 players, MP4 players, laptop computers and desktop computers. at least one.
  • the following embodiments take the terminal including a smart phone as an example for illustration.
  • the number of the above-mentioned terminals may be more or less.
  • the above-mentioned terminal may be only one, or the above-mentioned terminal may be dozens or hundreds, or more.
  • the embodiments of the present application do not limit the number of terminals and device types.
  • FIG. 3 shows a flowchart of a data packet synchronization method provided by an exemplary embodiment of the present application. This embodiment is described by taking the method used for the server 140 in the computer system 100 shown in FIG. 1 as an example.
  • the server 140 is provided with k logical threads and k message queues, where k is a positive integer, and the logical threads and message queues One-to-one correspondence, logical threads are divided according to the types of logical operations, and the method includes the following steps:
  • Step 301 Receive a data packet sent by a client.
  • the data packet carries a thread identifier and a frame identifier.
  • the thread identifier is added by the client according to the type of logical operation required by the data packet.
  • the frame identifier is used to identify the picture frame when the data packet is triggered.
  • the client is the client that sends data packets to the server.
  • the game client when the user performs some operations in the game client, the game client generates a data packet according to the user's operation, and sends the data packet to the server.
  • the server is connected to multiple game clients, and multiple game clients can send data packets to the server.
  • the data package includes control data generated by the user's operation, data corresponding to the property change of the virtual object, data corresponding to the object operated by the operation (such as the object to be aimed or attacked), the data of the animation special effect, and the change of the virtual environment screen. at least one of the data.
  • the client adds a thread identifier to the data packet according to the type of logical operation that needs to be performed on the data in the data packet.
  • the types of logical operations include skill logical operations, attribute logical operations, positional logical operations, operation logical operations, and animation effect logical operations. at least one of them.
  • the data packets generated by the client include various types of data, and different types of data require different types of logical threads to perform logical operations.
  • the data in one data packet belongs to the same type of data, that is, the same type of logic operation needs to be performed as an example.
  • the thread identifier is the number of the thread, for example, the thread identifier is thread 1, thread 2, ... thread k, and k is a positive integer.
  • the client generates a data packet according to each frame of the picture frame, and the data packet carries the frame identification of the frame of the picture frame, which is used to distinguish different picture frames, and the frame identification is the picture frame in chronological order. 's identification.
  • the frame identifier is the sequence number of the frame, for example, the frame identifier is frame 1 (first frame), frame 2 (second frame), ... frame j (jth frame), where j is a positive integer.
  • Step 302 After the data packet is sent to the logical thread corresponding to the thread identifier for logical operation, the data packet after the operation is written into the message queue corresponding to the logical thread.
  • the server When the server receives the data packet, it needs to perform logical operations according to the data in the data packet.
  • the data in the data packet is the data about the user-controlled virtual object (the virtual character controlled by the user in the game) releasing the skills.
  • the data packet performs the logical operation of the skill type, that is, the logical operation of the skill type is performed on the data packet through the logical thread of the skill type. Therefore, the data packet carries the thread identifier of the logical thread of the skill type.
  • each logical thread Since each logical thread is allocated a corresponding message queue, the logical thread directly writes the data packet after the logical operation into the message queue corresponding to the logical thread.
  • FIG 4 it shows 7 logical threads and 7 message queues, and the arrows on the left represent multiple logical threads (the arrows are only for illustration and do not represent the actual number of logical threads).
  • the data packets are written into 7 message queues respectively.
  • the server further includes a message queue for receiving data packets, the message queue is used for receiving data packets sent by the client, and each logical thread reads the corresponding data packets from the message queue according to thread identifiers carried in the data packets .
  • a client can send one or more data packets.
  • the types of logical operations required by the multiple data packets can be the same or different.
  • Packets may be distributed among logical threads. There may be packets sent by each client in various logical threads.
  • Step 303 Read the calculated data packet from the message queue according to the frame identifier, and synchronize the calculated data packet to the associated client of the client.
  • the calculated data packets are read from the message queue according to the timestamp sequence corresponding to the frame identifier, and the calculated data packets are synchronized to at least one associated client.
  • the server reads the data packets from the message queue, in order to avoid the disorder of the picture frames corresponding to the data packets received by the client, the server reads the data packets frame by frame from the message queue.
  • the corresponding timestamp order is generated, that is, the order from early to late. Therefore, the frame identifiers carried by each data packet are also sorted in the order of timestamps.
  • the server when the server reads the data packets in the message queue, it reads the data packets in a frame-by-frame manner, that is, after reading the data packets corresponding to the first frame, read the data packets corresponding to the second frame. , the time when the second frame is generated is later than the time when the first frame is generated.
  • the server performs logical operations on the data packets corresponding to each frame of the picture frame, sends the calculated data packets to the associated client, and the associated client processes the calculated data packets to obtain the corresponding picture frame.
  • the data packets corresponding to one frame of picture frame may be scattered in each message queue.
  • the server reads the data packets corresponding to one frame of picture frame, it needs to The data packets corresponding to the frame in the queue have been read.
  • the data packets corresponding to the frame in all message queues have been read, the data packets corresponding to the frame have been read, and the server will read Completed packets are sent synchronously to at least one associated client.
  • the server further includes a packet sending thread, and the packet sending thread is a single thread, which ensures that the data of calling an application programming interface (Application Programming Interface, API) for sending data packets is safe.
  • API Application Programming Interface
  • the associated client refers to a client that has an associated relationship with the client that sends the data packet.
  • the client that sends the data packet and the associated client are clients that participate in the same game.
  • the user account logged in by the client sending the data packet has a friend relationship with the user account logged in by the associated client, and the user account logged in by the client sending the data packet and the user account logged in by the associated client are in the same temporary session in a message or in the same group chat.
  • the server by allocating corresponding message queues to logical threads divided according to the types of logical operations, the server writes the data packets after logical thread operations into the message queues corresponding to each logical thread. , which avoids the conflict of writing data packets when multiple logical threads share a message queue; at the same time, it reduces the number of message queues and the server memory occupied by the message queues, thereby reducing the cost of managing messages.
  • FIG. 5 shows a flowchart of a data packet synchronization method provided by another exemplary embodiment of the present application. This embodiment is described by taking the method used for the server 140 in the computer system 100 shown in FIG. 1 as an example.
  • the server 140 is provided with k logical threads and k message queues, where k is a positive integer, and the logical threads and message queues One-to-one correspondence, logical threads are divided according to types of logical operations, and the method includes the following steps.
  • Step 501 receive the data packet sent by the client, the data packet carries a thread identifier and a frame identifier, the thread identifier is added by the client according to the logical operation type required by the data packet, and the frame identifier is used to identify the picture frame when the data packet is triggered.
  • Step 502 send the data packet to the i-th logical thread in the k logical threads according to the thread identifier, and the i-th logical thread corresponds to the i-th message queue in the k message queues one-to-one, and i is A positive integer with i ⁇ k.
  • the server assigns a data packet to a corresponding logical thread according to the thread identifier in the data packet. For example, a data packet carries the thread identifier of the i-th logical thread, and the server allocates the data packet to the i-th logical thread. It can be understood that a client can send one or more data packets. When a client sends multiple data packets, the types of logical operations required by the multiple data packets can be the same or different. Packets may be distributed among logical threads. There may be packets sent by each client in various logical threads.
  • the server further includes a message queue for receiving data packets, the message queue is used for receiving data packets sent by the client, and each logical thread reads the corresponding data packets from the message queue according to the thread identifier.
  • Step 503 Perform a logical operation on the data packet through the i-th logical thread to obtain the data packet after the operation.
  • the data packet sent by the game client to the server includes operation data, and the operation data is used to record the operation of the user in the game client.
  • the data packet is allocated to the i-th logical thread, and the i-th logical thread performs logical operations according to the data in the data packet.
  • the logical operation performed by the i-th logical thread is the scope of action and Effect (whether the health of the virtual object affected by this skill will be reduced, and how much).
  • the logic thread generates a data packet after the operation of the data corresponding to the scope of action and the action effect after the release of the skill.
  • Step 504 Write the calculated data packet into the i-th message queue.
  • one message queue may include one or more data packets sent by the target client, and one message queue may include one data packet or multiple data packets corresponding to one frame of picture frame.
  • Step 505 Determine the frame identifiers currently consumed by the k message queues.
  • the server is provided with a message queue consumption rule
  • the consumption rule stipulates that the i-th message queue shall prevail, and the frame ID of the data packet currently consumed by the i-th message queue is required by all the data packets currently consumed by the message queues.
  • Has the frame identifier, i is a positive integer, and i ⁇ k.
  • the server includes 8 message queues, namely the first message queue, the second message queue...the eighth message queue.
  • the consumption rules stipulate that the first message queue shall prevail, and the frames currently consumed by the first message queue have frames.
  • the identifier is the frame identifier that the data packets currently consumed by all message queues must have, and the frame identifier of the data packets currently consumed by the first message queue is the frame identifier (frame 1) corresponding to the first frame picture frame, then the currently consumed frame identifier For frame 1, the rest of the message queues also consume packets with frame ID frame 1.
  • Step 506 from the k message queues, read the data packets corresponding to the currently consumed frame identifiers.
  • the server reads the data packet with the frame identifier as frame 1 from the k message queues.
  • Step 507 Synchronize the data packet corresponding to the currently consumed frame identifier to the associated client of the client.
  • the server also includes a packet sending thread (shown by the arrow on the right), the packet sending thread is a single thread, the server sends the data packet corresponding to the currently consumed frame ID to the packet sending thread, and the The data packets corresponding to the currently consumed frame identifiers are synchronized to at least one associated client.
  • the packet issuing thread actively reads the data packets from the message queue, and synchronizes the read data packets to each associated client.
  • packet A1 and packet C3 are written in message queue 1
  • packet B2 is written in message queue 2
  • the writing sequence is: packet A1 ⁇ packet B2 ⁇ packet C3.
  • the data packet A1, the data packet C3, and the data packet B2 belong to different picture frames, respectively
  • the packet sending sequence of the packet sending thread is: data packet A1 ⁇ data packet B2 ⁇ data packet C3.
  • the logical thread for processing the data packet is determined by the thread identifier carried in the data packet, so as to ensure that the problem of timing error will not occur when the calculated data packet is subsequently written to the message queue.
  • all message queues can uniformly read the data packets corresponding to the picture frames with the same frame ID, thus ensuring that even if the data packets of the same frame are not in the same message queue, cross-frame transmission will not occur.
  • the phenomenon of data packets avoids timing errors when the client receives data packets.
  • the method for reading data packets from the message queue includes the following two methods.
  • step 506 can be replaced with the following steps, as shown in FIG. 7 .
  • Step 5061a in response to the frame identification currently consumed is the target frame identification, sequentially read the data packets with the target frame identification from the k message queues, until the k message queues have the target frame identification. The data packets have been read.
  • the server inserts synchronization barriers into k message queues respectively.
  • the frames corresponding to the picture frames are identified as synchronization barriers.
  • the target frame identifier of the jth frame picture, the target frame identifier is a synchronization fence, and j is a positive integer.
  • the target frame identifier is the frame identifier (frame 3) of the third frame picture
  • the server reads the data packet with the frame identifier as frame 3 from the first message queue.
  • the data packet corresponding to the third picture frame in the first message queue is read, the data packet corresponding to the third picture frame is read from the second message queue.
  • a synchronization fence 11 and a synchronization fence 12 are inserted into the message queue.
  • the synchronization fence 11 is used to read data packets corresponding to the first frame of the picture frame from the message queue
  • the synchronization fence 12 is used for Read the data packets corresponding to the second frame from the message queue.
  • the message queue corresponding to the second frame. the data package.
  • the position of the synchronization barrier shown in FIG. 8 is only for illustration, and the position of the synchronization barrier corresponding to the same frame of picture frame in each message queue may be the same or different in the message queue, and the position depends on the message queue. The number of packets belonging to the same frame of picture frame.
  • Sequentially reading from the k message queues may be: after the data packet corresponding to the third frame in the first message queue is read, read the data packet corresponding to the third frame from the second message queue. Data packet, when the data packet corresponding to the third frame in the second message queue is read, read the data packet corresponding to the third frame from the third message queue, and so on, until all The data packet corresponding to the third frame in the message queue has been read.
  • the above step 506 may be: according to the respective duration thresholds of the k message queues, sequentially reading the data packets corresponding to the currently consumed frame identifiers from the k message queues.
  • nth message queue in the k message queues includes:
  • Step 5061b Obtain the duration threshold corresponding to the nth message queue.
  • the server inserts synchronization barriers into k message queues respectively.
  • the frames corresponding to the picture frames are identified as synchronization barriers.
  • the target frame identifier of the jth frame picture, the target frame identifier is a synchronization fence, and j is a positive integer.
  • the server when the server reads the data packets in one message queue, other message queues are always in a waiting state, especially the last message queue, which needs to wait for the data packets in all previous message queues to be read. Only the data packets in the message queue can be read, and the server will also continuously write the data packets in the logical thread into the message queue, which is easy to cause the message queue to block. Therefore, the server sets a time-length threshold for the message queue, and k message queues are respectively Corresponding to have their own duration threshold. The duration thresholds corresponding to each message queue can be equal or unequal.
  • the duration threshold is obtained from the consumption duration corresponding to the message queue, and the consumption duration is the estimated duration of reading a data packet corresponding to a frame from the message queue.
  • the server estimates the time required for the message queue to consume the frame data packets according to the number of data packets with the same frame identifier in the consumption queue, and obtains the consumption time, then the server divides the consumption time to obtain the time duration threshold.
  • the consumption durations corresponding to the same message queue may be equal or unequal, and the multiple duration thresholds corresponding to the same message queue may be equal or unequal.
  • the consumption durations corresponding to different message queues can be equal or unequal, and the duration thresholds corresponding to different message queues can be equal or unequal.
  • the duration threshold of each message queue is represented by the divided time slice 13 (dotted line in Figure 9), that is, the consumption duration of the message queue where the data packets corresponding to the same frame of picture frame are consumed is divided.
  • Time Slice also known as "quantum” or "Processor Slice” is a microscopic section of the Central Processing Unit (Central Processing Unit) that the time-sharing operating system assigns to each running thread. CPU) time. It should be noted that, the time slices 13 obtained after division may be divided equally or unequally, and the positions of the time slices 13 in FIG. 9 are for illustration only.
  • the duration threshold corresponding to the nth message queue is 100 seconds.
  • Step 5062b Read the data packet with the target frame identifier in the nth message queue.
  • the server reads the data packet with the target frame identifier in the nth message queue within the duration threshold.
  • the duration threshold corresponding to the third message queue is 100 seconds, and the server reads the data packet corresponding to the third frame in the third message queue within 100 seconds.
  • Step 5063b in response to the read duration of the nth message queue exceeding the duration threshold corresponding to the nth message queue, start to read the data packet with the target frame identifier from the n+1th message queue.
  • the countdown is performed when reading the data packets in the message queue. For example, when the server starts to read the data packets corresponding to the third frame in the third message queue, the countdown is started for 100 seconds. When the 100-second countdown ends, the server stops reading the data packet corresponding to the third frame in the third message queue, and starts to read the data packet corresponding to the third frame from the fourth message queue.
  • positive timing is performed when reading the data packets in the message queue. For example, when the server starts to read the data packets corresponding to the third frame in the third message queue, the timer is started. When the timing exceeds (or equals to) 100 seconds, the server stops reading the data packet corresponding to the third frame in the third message queue, and starts to read the data corresponding to the third frame from the fourth message queue. Bag.
  • the duration thresholds corresponding to each message queue are equal to 100 seconds, then read the data packet corresponding to the third frame in the first message queue within 100 seconds, and then re-time for 100 seconds, Read the data packet corresponding to the 3rd picture frame from the 2nd message queue within 100 seconds, then re-time for 100 seconds, and read the 3rd picture frame from the 3rd message queue within 100 seconds.
  • the data packet corresponding to the frame if the first message queue does not have the data packet corresponding to the third frame picture frame pair, read the data packet corresponding to the third frame picture frame from the second message queue. Similarly, it is necessary to judge Whether the second message queue still has data packets corresponding to the third picture frame. And so on, until all the data packets corresponding to the third frame in the message queue have been read.
  • the server when the server reads the data packets belonging to the same frame of picture frames in each message queue, when the data packets corresponding to one frame of picture frame are read After fetching, the data packet of the next frame of picture frame can be read, so as to avoid the situation of sending data packets across frames.
  • the server By dividing the consumption time corresponding to each message queue, the server only reads part of the data packets belonging to the same frame in each message queue each time, so as to avoid waiting too long for the message queues in the later order, thereby avoiding the message
  • the queue is blocked by constantly writing packets.
  • some data packets carry more data, so that when the client receives the data packets, it needs to consume more resources to load the data packets.
  • the terminal used by the user is a smart phone.
  • the user plays the MMORPG game on the smart phone, he needs to use a network, such as a wireless fidelity network (Wireless Fidelity, WiFi) in a wireless network, or a mobile communication network ( network traffic provided by the network operator).
  • a network such as a wireless fidelity network (Wireless Fidelity, WiFi) in a wireless network
  • a mobile communication network network traffic provided by the network operator.
  • a mobile communication network if the data packet contains more data, the more network traffic needs to be consumed. Therefore, in order to avoid consuming more network traffic, the data contained in the data packet is filtered.
  • the client is limited by its own field of view, and only a small part of the virtual objects in the field of view are displayed as models. For example, there are 80 virtual objects in the field of view, and the user can only see 10 virtual objects. The complete model, and the rest Of the 70 virtual objects, only nicknames (or user accounts) are displayed. The client will display the nicknames and health values of 70 virtual objects, and no special effects will be displayed. Since the effect cannot be displayed, packets related to its skills do not need to be sent to the associated client.
  • the filtering method for data packets is three-level filtering, and the filtering method includes the following steps, as shown in FIG. 10 .
  • Step 210 According to the first position coordinates, the picture frame identified by the currently consumed frame identifier is divided into view areas to obtain m view areas, where m is a positive integer.
  • the server stores the first position coordinates of the first virtual object controlled by the client, the data packet corresponding to the currently consumed frame identifier includes the first type of data packet, and the first type of data packet carries the information of the second virtual object in the picture frame. Second location coordinates.
  • the first type of data package is a battle package, and the battle package is used to include data about the release skills of the virtual objects, data about the virtual objects participating in the battle, data about changing skills or changing weapons, and the like.
  • Step 220 in response to the second position coordinate not being located in the specified viewing area in the m viewing areas, filter out the first type of data packets from the data packets corresponding to the currently consumed frame identifiers.
  • the position coordinates of the second virtual object are not within the m visual field area, and the first type of data packets are filtered out from the data packets corresponding to the currently consumed frame identifiers. That is, the server sends the data packets corresponding to the virtual objects located in the m visual fields to the client that controls the first virtual object. As shown in FIG. 11 , m is 9, and the visual field of the first virtual object 14 includes A, There are four virtual objects B, C and D, then the data packets corresponding to virtual object A, virtual object B, virtual object C and virtual object D are sent to the client that controls the first virtual object 14, and the client displays the virtual objects A, virtual object B, virtual object C and virtual object D. It should be noted that the Jiugongge field of view is not displayed on the client.
  • the server sends other virtual objects in the first grid
  • the corresponding data packet is sent to the client of the first virtual object 14 .
  • Step 230 Obtain a view list corresponding to the m view areas, where the view list includes q second virtual objects located in the m view areas, where q is a positive integer.
  • the upper limit of the number of virtual objects in the m view areas is set through the view list. .
  • the number of acquired second virtual objects may be limited by a preset upper limit of the number.
  • Step 240 in response to that the second virtual object corresponding to the first type of data packet does not belong to the second virtual object in the field of view list, filter out the first type of data packet from the data packet corresponding to the currently consumed frame identifier.
  • m is 9.
  • the server transfers the first type of data packet from the frame ID corresponding to the current consumption. Filter out the packets. That is, the data packets corresponding to the second virtual object are filtered out, and the client controlling the first virtual object will not display the second virtual object.
  • Step 250 Obtain the positional relationship between the first position coordinates and the second position coordinates.
  • Step 260 in response to the location relationship satisfying the preset condition, filter out the first type of data packets from the data packets corresponding to the currently consumed frame identifiers.
  • the preset conditions include at least one of the following conditions:
  • the distance between the first virtual object and the second virtual object is greater than the distance threshold
  • the second virtual object is located outside the field of view of the first virtual object.
  • the direction the first virtual object 14 faces is the direction pointed by the arrow
  • the virtual object A and the virtual object B are located in front of the first virtual object
  • the virtual object C and the virtual object D are located in front of the first virtual object. behind the first virtual object 14 .
  • the virtual object D is the second virtual object
  • the distance between the virtual object D and the first virtual object 14 is greater than the distance threshold, then the first type of data packet is filtered out from the data packet corresponding to the currently consumed frame identifier, that is, The client corresponding to the first virtual object 14 does not display the virtual object D.
  • the virtual object C is the second virtual object, and the virtual object C is located outside the field of view of the first virtual object 14, then the first type of data packet, that is, the first type of data packet, is filtered out from the data packet corresponding to the currently consumed frame identifier.
  • the client corresponding to the virtual object 14 does not display the virtual object D.
  • the virtual object C and the virtual object D do not display the models of the virtual object C and the virtual object D and their names in the client corresponding to the first virtual object 14, and the virtual object C and the virtual object D are not displayed. Activities that interact with each other (such as attacking each other) are also not displayed in the client.
  • this screen is a display screen triggered by the client receiving a data packet after filtering out the first type of data packet.
  • a limited number of virtual objects are displayed on the screen, and the screen is controlled by the client A picture formed by the visual field of the first virtual object.
  • the virtual object 21 that is closer to the first virtual object displays a more detailed image model
  • the virtual objects 22 and 23 that are far away from the first virtual object display a schematic image model, so as to reduce the loading of data packets by the client. resources to be consumed.
  • the method provided in this embodiment reduces the data included in the data packets synchronized to the associated client by filtering the data packets corresponding to the currently consumed frame identifiers.
  • the client is loading the filtered data packets. Packets reduce the resources consumed by the client.
  • the resource consumed by the client when loading the data packet is reduced by instructing the client to reduce the sending frequency.
  • the data packet corresponding to the currently consumed frame identifier further includes a second type of data packet, and the second type of data packet carries attribute parameters of the virtual object.
  • the attribute parameters include at least one data of the virtual object's life value, energy value, magic value, and attack power.
  • the client In response to the attribute parameter not changing, the client is instructed to reduce the transmission frequency of the second type of data packets.
  • the server sets a dirty flag for the attribute parameter, and uses the dirty flag to determine whether the attribute parameter of the virtual object has changed. For example, the dirty flag is checked every 500 milliseconds. If the dirty flag has not changed, it proves that the second type of data packet has not changed, and the second type of data packet is not sent to the client; if the dirty flag changes, it is proved that the second type of data packet has not changed. When the packet changes, the second type of data packet is sent to the client, and the dirty flag is re-set to the attribute parameter corresponding to the second type of data packet. .
  • the method provided in this embodiment determines whether the attribute parameter has changed by using the change of the dirty flag, so that when the attribute parameter does not change, the sending frequency of the second type of data packet is reduced, thereby reducing the loading of the first type of data packet by the client.
  • the above-mentioned step of trimming or reducing the frequency of sending the first type of data packets may be filtered out by a logical thread, and then written into the message queue, or, after the message queue is read, read from the message queue. The incoming packets are filtered out.
  • the overall flow of the data packet synchronization method includes the following flow.
  • the server includes a plurality of logic threads, and the logic threads are used for computing logic according to the data packets sent by the client.
  • each logic thread in the server is used for computing game logic.
  • the server allocates a message queue to each logical thread, and the client participating in the game will generate a large number of data packets.
  • the client sends a data packet corresponding to a frame of virtual environment picture to the server.
  • the server writes a data packet corresponding to a frame of virtual environment picture into each message queue according to the thread identifier carried in the data packet.
  • the server also records the receiving sequence of each data packet when receiving the data packet, and writes the data packet into each message queue according to the receiving sequence, that is, the sequence between the data packets written in the same message queue is fixed.
  • the server inserts the frame identifier of each frame of the virtual environment picture frame into each message queue as a synchronization fence, and the server designates a message queue to consume data packets of a certain frame. For example, the server designates the first message queue to consume the data packets corresponding to the i-th virtual environment picture frame, and uses the i-th frame identifier as a synchronization fence. Starting from the first message queue, read the i-th virtual environment picture frame corresponding to the i-th frame. The data packet, and the game logic operation is performed according to the data packet, and the calculated data packet is sent to each client.
  • the server reads the second message queue, performs game logic operations on the data packets in the second message queue before the synchronization barrier, and sends the calculated data packets to each client. And so on, until the data packets corresponding to the i-th virtual environment picture frame in all message queues have been read.
  • the data packet corresponding to the i-th virtual environment picture frame After the data packet corresponding to the i-th virtual environment picture frame has been read, the data packet corresponding to the i+1-th virtual environment picture frame is read, and the i+1-th virtual environment picture frame corresponding data packet is read. It is the same as the way of reading the data packet corresponding to the ith frame of the virtual environment picture frame.
  • the server allocates a time slice to the message queue, and the time slice has an estimated duration corresponding to the message queue consuming a real data packet of one frame of the virtual environment image, and the server divides the time slice of the message queue to obtain a message queue at least two divided time slices, and the divided time slices may have equal or unequal durations.
  • the server reads the data packet corresponding to the ith frame of the virtual environment picture frame according to the duration of the divided time slice.
  • the divided time slice of the first message queue has a duration of 60 seconds
  • the divided time slice of the second message queue has a duration of 100 seconds.
  • the server starts from the first message queue and uses 60 seconds. It takes 100 seconds to read the data packet corresponding to the i-th virtual environment picture frame in the first message queue.
  • the server uses 100 seconds to read the second message queue.
  • the data packets corresponding to the i-th virtual environment picture frame in the first message queue may all be read, or may be partially read. Similarly, within 100 seconds, the data packets corresponding to the i-th virtual environment picture frame in the second message queue may be fully read or partially read.
  • the server when it does not finish reading the data packet corresponding to the ith frame of the virtual environment picture frame in the first message queue within 60, when it traverses to the first message queue again, it continues to read the ith frame. Virtual environment frame.
  • a message queue is allocated to each logical thread, the number of message queues is reduced, and the cost of managing messages is reduced.
  • FIG. 13 is a structural block diagram of an apparatus for synchronizing data packets provided by an exemplary embodiment of the present application, and the apparatus includes:
  • the receiving module 1310 is used to receive the data packet sent by the client.
  • the data packet carries a thread identifier and a frame identifier.
  • the thread identifier is added by the client according to the logical operation type required by the data packet, and the frame identifier is used to identify the triggering data packet. picture frame;
  • the writing module 1320 is used to send the data packet to the logical thread corresponding to the thread identifier for logical operation, and then write the calculated data packet into the message queue corresponding to the logical thread;
  • the reading module 1330 is configured to read the calculated data packet from the message queue according to the frame identifier, and synchronize the calculated data packet to the associated client of the client.
  • the apparatus includes a sending module 1340 and a processing module 1350;
  • the sending module 1340 is configured to send the data packet to the i-th logical thread in the k logical threads according to the thread identifier, and the i-th logical thread corresponds to the i-th message queue in the k message queues one-to-one , i is a positive integer, and i ⁇ k;
  • the processing module 1350 is used to perform logical operations on the data packets through the i-th logical thread to obtain the calculated data packets;
  • the writing module 1320 is configured to write the calculated data packet into the i-th message queue.
  • the processing module 1350 is configured to determine the frame identifiers currently consumed by the k message queues
  • the reading module 1330 is used to read the data packets corresponding to the frame identifiers currently consumed from the k message queues;
  • the sending module 1340 is used for synchronizing the data packet corresponding to the currently consumed frame identifier to the associated client of the client.
  • data packets corresponding to the target frame identifiers are written in the k message queues
  • the reading module 1330 is configured to sequentially read the data packets with the target frame identifier from the k message queues in response to the current consumption frame identifier being the target frame identifier, until the k message queues have all the target frame identifiers. The data packets identified by the target frame are all read.
  • the data packets corresponding to the target frame identifiers are written in the k message queues, and the k message queues respectively correspond to their respective duration thresholds;
  • the processing module 1350 is configured to sequentially read the data packets corresponding to the currently consumed frame identifiers from the k message queues according to the respective duration thresholds of the k message queues; wherein, for the k message queues For the nth message queue in the message queues, the processing module 1350 is configured to: obtain the duration threshold corresponding to the nth message queue, where n is a positive integer, and n ⁇ k; The data packet identified by the target frame; in response to the read duration of the n-th message queue exceeding the duration threshold corresponding to the n-th message queue, start to read from the n+1-th message queue. The packet identified by the target frame.
  • the duration threshold is obtained from the consumption duration corresponding to the message queue, and the consumption duration is the estimated duration of reading a data packet corresponding to one frame of picture from the message queue.
  • the data packet corresponding to the currently consumed frame identifier includes a first-type data packet, and the first-type data packet carries the second position coordinates of the second virtual object in the picture frame;
  • the processing module 1350 is used to divide the view area of the picture frame identified by the currently consumed frame identifier according to the first position coordinates to obtain m view areas, where m is a positive integer; in response to the second position coordinates not being located in the m view areas The designated field of view area, the first type of data packets are filtered out from the data packets corresponding to the currently consumed frame ID.
  • the processing module 1350 is configured to obtain a view list corresponding to the m view areas, where the view list includes q second virtual objects located in the m view areas, and q is a positive integer; in response to the first If the second virtual object corresponding to the type data packet does not belong to the second virtual object in the field of view list, the first type data packet is filtered out from the data packet corresponding to the currently consumed frame identifier.
  • the server stores the first position coordinates of the first virtual object controlled by the client
  • the processing module 1350 is configured to acquire a position between the first position coordinates and the second position coordinates relationship; in response to the location relationship satisfying the preset condition, filtering out the first type of data packets in the data packets corresponding to the currently consumed frame identifiers.
  • the preset condition includes at least one of the following conditions:
  • the distance between the first virtual object and the second virtual object is greater than the distance threshold; or,
  • the second virtual object is located outside the field of view of the first virtual object.
  • the data packet corresponding to the currently consumed frame identifier includes a second type of data packet, and the second type of data packet carries attribute parameters of the virtual object;
  • the processing module 1350 is configured to instruct the client to reduce the frequency of sending attribute data packets in response to the attribute parameter not being changed.
  • the sending module 1330 is configured to send the data packet corresponding to the currently consumed frame identifier to the packet sending thread; the data packet is synchronized to the associated client of the client through the packet sending thread.
  • the device provided in this embodiment allocates corresponding message queues to logical threads divided according to logical operation types, so that the server writes the data packets after logical thread operations into the message queue corresponding to each logical thread. , which avoids the conflict of writing data packets when multiple threads share a message queue; at the same time, it reduces the number of message queues and the server memory occupied by the message queues, thereby reducing the cost of managing messages.
  • the logical thread for processing the data packet is determined by the thread identifier carried in the data packet, so as to ensure that the problem of timing error will not occur when the calculated data packet is subsequently written to the message queue.
  • all message queues can uniformly read the data packets corresponding to the picture frames with the same frame ID, so as to ensure that even if the data packets of the same frame are not in the same message queue, data will not be sent across frames. Packet phenomenon to avoid timing errors when the client receives data packets.
  • the server reads the data packets belonging to the same frame in each message queue, only when the data packets corresponding to one frame have been read can the next frame be read. data packets to avoid sending data packets across frames.
  • the server By dividing the consumption time corresponding to each message queue, the server only reads part of the data packets belonging to the same frame in each message queue each time, so as to avoid waiting too long for the message queues in the later order, so that the message The queue is blocked by writing packets.
  • the client By filtering the data packets corresponding to the currently consumed frame identifiers, the data included in the data packets synchronized to the associated client is reduced, and the client can reduce the resources consumed by the client when loading the filtered data packets.
  • the sending frequency of the second type data packet is reduced, and the resources consumed by the client to load the second type data packet are reduced.
  • the data packet synchronization device provided in the above-mentioned embodiments is only illustrated by the division of the above-mentioned functional modules. The internal structure is divided into different functional modules to complete all or part of the functions described above.
  • the apparatus for synchronizing data packets provided by the above embodiments and the embodiments of the method for synchronizing data packets belong to the same concept, and the specific implementation process thereof is detailed in the method embodiments, which will not be repeated here.
  • FIG. 14 shows a schematic structural diagram of a server provided by an exemplary embodiment of the present application.
  • the server can be the server 140 in the computer system 100 as shown in FIG. 1;
  • the server 140 includes a central processing unit (CPU, Central Processing Unit) 1401, a system memory 1404 including a random access memory (RAM, Random Access Memory) 1402 and a read only memory (ROM, Read Only Memory) 1403, and a connection system memory 1404 And the system bus 1405 of the central processing unit 1401.
  • the server 140 also includes a basic input/output system (I/O system, Input Output System) 1406 that facilitates the transfer of information between various devices within the computer, and a large database for storing the operating system 1413, application programs 1414 and other program modules 1415 capacity storage device 1407;
  • I/O system Input Output System
  • Basic input/output system 1406 includes a display 1408 for displaying information and input devices 1409 such as a mouse, keyboard, etc., for user input of information.
  • the display 1408 and the input device 1409 are both connected to the central processing unit 1401 through the input and output controller 1410 connected to the system bus 1405.
  • the basic input/output system 1406 may also include an input output controller 1410 for receiving and processing input from various other devices such as a keyboard, mouse, or electronic stylus.
  • input output controller 1410 also provides output to a display screen, printer, or other type of output device;
  • Mass storage device 1407 is connected to central processing unit 1401 through a mass storage controller (not shown) connected to system bus 1405 .
  • Mass storage device 1407 and its associated computer-readable media provide non-volatile storage for server 140 . That is, the mass storage device 1407 may include a computer-readable medium (not shown) such as a hard disk or a Compact Disc Read Only Memory (CD-ROM) drive.
  • CD-ROM Compact Disc Read Only Memory
  • Computer-readable media can include computer storage media and communication media.
  • Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data.
  • Computer storage media include RAM, ROM, Erasable Programmable Read Only Memory (EPROM, Erasable Programmable Read Only Memory), Electrically Erasable Programmable Read Only Memory (EEPROM, Electrically Erasable Programmable Read Only Memory), flash memory or other solid-state storage Its technology, CD-ROM, Digital Versatile Disc (DVD, Digital Versatile Disc) or Solid State Drives (SSD, Solid State Drives), other optical storage, tape cartridges, magnetic tape, disk storage or other magnetic storage devices.
  • EPROM Erasable Programmable Read Only Memory
  • EEPROM Electrically Erasable Programmable Read Only Memory
  • flash memory or other solid-state storage Its technology, CD-ROM, Digital Versatile Disc (DVD, Digital Versatile Disc) or Solid State
  • the random access memory may include a resistive random access memory (ReRAM, Resistance Random Access Memory) and a dynamic random access memory (DRAM, Dynamic Random Access Memory).
  • ReRAM resistive random access memory
  • DRAM Dynamic Random Access Memory
  • the computer storage medium is not limited to the above-mentioned types.
  • the system memory 1404 and the mass storage device 1407 described above may be collectively referred to as memory.
  • the server 140 may also operate on a remote computer connected to a network through a network such as the Internet. That is, the server 140 may be connected to the network 1412 through the network interface unit 1411 connected to the system bus 1405, or may also use the network interface unit 1411 to connect to other types of networks or remote computer systems (not shown).
  • the above-mentioned memory also includes one or more programs, and the one or more programs are stored in the memory and configured to be executed by the CPU.
  • a computer device in an optional embodiment, includes a processor and a memory, and the memory stores at least one instruction, at least one piece of program, code set or instruction set, at least one instruction, at least one piece of program , a code set or an instruction set is loaded and executed by the processor to implement the synchronization method of the data packets as described above.
  • a computer-readable storage medium stores at least one instruction, at least one piece of program, code set or instruction set, at least one instruction, at least one piece of program, code set or The instruction set is loaded and executed by the processor to implement the synchronization method of the data packets as described above.
  • the computer-readable storage medium may include: Read Only Memory (ROM, Read Only Memory), Random Access Memory (RAM, Random Access Memory), Solid State Drive (SSD, Solid State Drives), or an optical disc.
  • the random access memory may include a resistive random access memory (ReRAM, Resistance Random Access Memory) and a dynamic random access memory (DRAM, Dynamic Random Access Memory).
  • ReRAM resistive random access memory
  • DRAM Dynamic Random Access Memory
  • Embodiments of the present application also provide a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
  • the processor of the computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, and causes the computer device to perform the above-described data packet synchronization method.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Multimedia (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Mathematical Physics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

一种数据包的同步方法、装置、设备及存储介质,涉及数据通讯领域。该方法应用于服务器中,服务器设置有k个逻辑线程和k个消息队列,k为正整数,逻辑线程和消息队列一一对应,逻辑线程是根据逻辑运算类型划分的,该方法包括:接收客户端发送的数据包,数据包携带有线程标识和帧标识,线程标识是客户端根据数据包需要的逻辑运算类型添加的,帧标识用于标识触发数据包时的画面帧(301);将数据包发送至与线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与逻辑线程对应的消息队列中(302);根据帧标识从消息队列中读取运算后的数据包,将运算后的数据包同步至所述客户端的关联客户端中(303)。该方法减少了消息队列在服务器中所占的内存。

Description

数据包的同步方法、装置、设备及存储介质
本申请要求于2020年07月31日提交中国专利局、申请号为202010760504.9、申请名称为“数据包的同步方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据通讯领域,特别涉及数据包同步。
背景技术
用户通过游戏客户端进行游戏时,游戏客户端根据用户的操作生成数据包,并向服务器发送该数据包,服务器根据数据包进行游戏逻辑运算,并将游戏逻辑运算后的数据包同步至参与游戏的所有游戏客户端。
在游戏中,同一时间存在多个游戏客户端向服务器发送数据包,服务器需要根据接收到的数据包的顺序,向各个游戏客户端发送已计算的游戏逻辑,为了保证服务器向游戏客户端同步时不产生顺序错误,对每个参与游戏的游戏客户端分配一个消息队列,每个游戏客户端产生的数据包按照顺序写入自身对应的消息队列中,服务器在读取时各个游戏客户端的数据包时不会产生顺序错误。
发明内容
本申请实施例提供了一种数据包的同步方法、装置、设备及存储介质,通过对每个逻辑线程分配对应的消息队列,减少了消息队列在服务器中所占的内存。所述技术方案如下:
根据本申请的一方面,提供了一种数据包的同步方法所述方法应用于服务器中,所述服务器设置有k个逻辑线程和k个消息队列,k为正整数,所述逻辑线程和所述消息队列一一对应,所述逻辑线程是根据逻辑运算类型划分的,所述方法包括:
接收客户端发送的数据包,所述数据包携带有线程标识和帧标识,所述线程标识是所述客户端根据所述数据包需要的逻辑运算类型添加的,所述帧标识用于标识触发所述数据包时的画面帧;
将所述数据包发送至与所述线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与所述逻辑线程对应的消息队列中;
根据所述帧标识从所述消息队列中读取所述运算后的数据包,将所述运算后的数据包同步至所述客户端的关联客户端中。
根据本申请的另一方面,提供了一种数据包的同步装置,所述装置包括:
接收模块,用于接收客户端发送的数据包,所述数据包携带有线程标识和帧标识,所述线程标识是所述客户端根据所述数据包需要的逻辑运算类型添加的,所述帧标识用于标识触发所述数据包时的画面帧;
写入模块,用于将所述数据包发送至与所述线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与所述逻辑线程对应的消息队列中;
读取模块,用于根据所述帧标识从所述消息队列中读取所述运算后的数据包,将所述运算后的数据包同步至所述客户端的关联客户端中。
根据本申请的另一方面,提供了一种计算机设备,所述计算机设备包括处理器和存储 器,所述存储器中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由所述处理器加载并执行以实现如上述方面所述的数据包的同步方法。
根据本申请的另一方面,提供了一种计算机可读存储介质,所述可读存储介质中存储有计算机程序,所述计算机程序用于执行上述方面所述的数据包的同步方法。
根据本申请的另一方面,提供了一种计算机程序产品或计算机程序,所述计算机程序产品或计算机程序包括计算机指令,所述计算机指令存储在计算机可读存储介质中。计算机设备的处理器从所述计算机可读存储介质读取所述计算机指令,所述处理器执行所述计算机指令,使得所述计算机设备执行如上方面所述的数据包的同步方法。
本申请实施例提供的技术方案带来的有益效果至少包括:
通过对根据逻辑运算类型划分的逻辑线程分配对应的消息队列,使得服务器将经过逻辑线程运算后的数据包写入每个逻辑线程对应的消息队列中,避免了多个线程共用一个消息队列时产生数据包写入冲突的情况;同时,减少了消息队列的数量,减少了消息队列所占用的服务器内存,从而降低了管理消息的成本。
附图说明
图1是本申请一个示例性实施例提供的计算机***的框架图;
图2是本申请一个示例性实施例提供的状态同步技术的示意图;
图3是本申请一个示例性实施例提供的数据包的同步方法的流程图;
图4是本申请一个示例性实施例提供的数据包的同步方法的框架示意图;
图5是本申请另一个示例性实施例提供的数据包的同步方法的流程图;
图6是本申请另一个示例性实施例提供的数据包的同步方法的框架示意图;
图7是本申请另一个示例性实施例提供的数据包的同步方法的流程图;
图8是本申请另一个示例性实施例提供的数据包的同步方法的框架示意图;
图9是本申请另一个示例性实施例提供的数据包的同步方法的框架示意图;
图10是本申请另一个示例性实施例提供的数据包的同步方法的流程图;
图11是本申请一个示例性实施例提供的m个视野区域的示意图;
图12是本申请一个示例性实施例提供的客户端中的画面的示意图;
图13是本申请一个示例性实施例提供的数据包的同步装置的结构框图;
图14是本申请一个示例性实施例提供的服务器的装置结构示意图。
具体实施方式
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
首先,对本申请实施例涉及的名词进行介绍。
消息队列(Message Queue,MQ):是指一种应用程序间的通信方式,用于存放消息(或数据),消息队列遵循先进先出原则,比如,消息1先于消息2被写入至消息队列中,则在读取消息时,消息1先于消息2被读取。消息的生产者(消息发布者)将消息发布到消息队列中,消息的消费者(消息主动获取者)从消息队列中获取消息,生产者和消费者之间互不 干扰。
同步栅栏(Cyclic Barrier,CB):是指在多线程条件下,多个线程互相合作完成一项任务,需要通过同步栅栏在多个线程间进行协调,避免多个线程出现时序错乱的问题。本申请实施例以一帧境画面的帧标识作为同步栅栏,当各个消息队列均读取至同一帧标识时(同步栅栏),证明该帧画面对应的数据包被读取完,可读取下一帧画面对应的数据包。
脏标志:是指用于标识当前数据是否与原始数据一致。若当前数据与原始数据不一致,则重新计算当前数据并将脏标志由0变为1,针对计算后的结果重新设置一个脏标志(该脏标志为0);若当前数据与原始数据一致,则保留脏标志为1继续使用原始数据(当前数据)。脏标志为0代表数据没有改变,脏标志为1代表数据发生改变。本申请实施例以对虚拟对象的属性参数设置脏标志为例进行说明,属性参数是第二类型数据包(如属性数据包)的数据。示意性的,对虚拟对象的生命值设置脏标志,当虚拟对象的生命值发生变化(恢复或减少),脏标志由0变为1;当虚拟对象的生命值未发生变化,脏标志仍为0。
云计算(Cloud Computing):指IT基础设施的交付和使用模式,指通过网络以按需、易扩展的方式获得所需资源;广义云计算指服务的交付和使用模式,指通过网络以按需、易扩展的方式获得所需服务。这种服务可以是IT和软件、互联网相关,也可是其他服务。云计算是网格计算(Grid Computing)、分布式计算(Distributed Computing)、并行计算(Parallel Computing)、效用计算(Utility Computing)、网络存储(Network Storage Technologies)、虚拟化(Virtualization)、负载均衡(Load Balance)等传统计算机和网络技术发展融合的产物。
随着互联网、实时数据流、连接设备多样化的发展,以及搜索服务、社会网络、移动商务和开放协作等需求的推动,云计算迅速发展起来。不同于以往的并行分布式计算,云计算的产生从理念上将推动整个互联网模式、企业管理模式发生革命性的变革。本申请实施例提供的数据同步方法可应用于云服务器中,通过对每个逻辑线程分配对应的消息队列,使得云服务器在读取数据包时,数据包的顺序不会发生错乱,从而按照正确的顺序将数据包发送至各个客户端,降低了管理消息的成本。
图1示出了本申请一个示例性实施例提供的计算机***的结构框图。该计算机***100包括:第一终端120、服务器140和第二终端160。
第一终端120安装和运行有支持虚拟环境的应用程序。该应用程序可以是虚拟现实应用程序、三维地图程序、军事仿真程序、FPS游戏、MOBA游戏、大型多人在线角色扮演游戏(Massive Multiplayer Online Role-Playing Game,MMORPG)、多人枪战类生存游戏、大逃杀类型的射击游戏、虚拟现实(Virtual Reality,VR)应用程序、增强现实(Augmented Reality,AR)程序中的任意一种。第一终端120是第一用户使用的终端,第一用户使用第一终端120控制位于虚拟环境中的第一虚拟对象进行活动,该活动包括但不限于:调整身体姿态、行走、奔跑、跳跃、骑行、瞄准、拾取、释放技能、更换皮肤、攻击其他虚拟对象中的至少一种。示意性的,第一虚拟对象是第一虚拟人物,比如仿真人物对象或动漫人物对象。
第一终端120通过无线网络或有线网络与服务器140相连。
服务器140可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式***,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云 通信、中间件服务、域名服务、安全服务、内容分发网络(Content Delivery Network,CDN)、以及大数据和人工智能平台等基础云计算服务的云服务器。示意性的,服务器140包括处理器144和存储器142,存储器142又包括接收模块1421、控制模块1422和发送模块1423,接收模块1421用于接收客户端发送的数据包,如第i帧虚拟环境画面生成的数据包;控制模块1422用于从消息队列中读取数据包;发送模块1423用于向各个客户端发送数据包。服务器140还用于为支持三维虚拟环境的应用程序提供后台服务,如信息保存服务。可选地,服务器140承担主要计算工作,第一终端120和第二终端160承担次要计算工作;或者,服务器140承担次要计算工作,第一终端120和第二终端160承担主要计算工作;或者,服务器140、第一终端120和第二终端160三者之间采用分布式计算架构进行协同计算。
服务器140可以采用同步技术使得多个客户端之间的画面表现一致。示例性的,服务器140采用的同步技术包括:状态同步技术或帧同步技术。本申请实施例提供的数据包的同步方法可以基于状态同步技术实现。
在基于图1的可选实施例中,服务器140采用状态同步技术与多个客户端之间进行同步。在状态同步技术中,如图2所示,战斗逻辑运行在服务器140中。当虚拟环境中的某个虚拟对象发生状态变化时,由服务器140向所有的客户端,比如客户端1至10,发送状态同步结果。
在一个示例中,客户端1向服务器140发送请求,该请求用于请求虚拟对象1攻击虚拟对象2,则服务器140判断虚拟对象1是否能够攻击虚拟对象2,以及当虚拟对象1执行攻击虚拟对象2的操作时,虚拟对象2的剩余生命值。然后,服务器140将虚拟对象2的剩余生命值发送给所有的客户端,所有的客户端根据虚拟对象2的剩余生命值更新本地数据以及界面表现。
第二终端160安装和运行有支持虚拟环境的应用程序。该应用程序可以是虚拟现实应用程序、三维地图程序、军事仿真程序、FPS游戏、MOBA游戏、MMORPG游戏、多人枪战类生存游戏、大逃杀类型的射击游戏、VR应用程序、AR程序中的任意一种。第二终端160是第二用户使用的终端,第二用户使用第二终端160控制位于虚拟环境中的第二虚拟对象进行活动,该活动包括但不限于:调整身体姿态、行走、奔跑、跳跃、骑行、瞄准、释放技能、更换皮肤、拾取、攻击其他虚拟对象中的至少一种。示意性的,第二虚拟对象是第二虚拟人物,比如仿真人物对象或动漫人物对象。
可选地,第一虚拟人物对象和第二虚拟人物对象处于同一虚拟环境中。可选地,第一虚拟人物对象和第二虚拟人物对象可以属于同一个队伍、同一个组织、同一个阵营、具有好友关系或具有临时性的通讯权限。可选地,第一虚拟人物和第二虚拟对象也可以属于不同阵营、不同队伍、不同的组织或具有敌对关系。
可选地,第一终端120和第二终端160上安装的应用程序是相同的,或两个终端上安装的应用程序是不同操作***平台(安卓或IOS)上的同一类型应用程序。第一终端120可以泛指多个终端中的一个,第二终端160可以泛指多个终端中的一个,本实施例仅以第一终端120和第二终端160来举例说明。第一终端120和第二终端160的设备类型相同或不同,该设备类型包括:智能手机、平板电脑、电子书阅读器、MP3播放器、MP4播放器、膝上型便携计算机和台式计算机中的至少一种。以下实施例以终端包括智能手机来举例说明。
本领域技术人员可以知晓,上述终端的数量可以更多或更少。比如上述终端可以仅为一个,或者上述终端为几十个或几百个,或者更多数量。本申请实施例对终端的数量和设备类型不加以限定。
图3示出了本申请一个示例性实施例提供的数据包的同步方法的流程图。本实施例以该方法用于如图1所示的计算机***100中的服务器140为例进行说明,服务器140设置有k个逻辑线程和k个消息队列,k为正整数,逻辑线程和消息队列一一对应,逻辑线程是根据逻辑运算的类型进行划分的,该方法包括如下步骤:
步骤301,接收客户端发送的数据包,数据包携带有线程标识和帧标识,线程标识是客户端根据数据包需要的逻辑运算类型添加的,帧标识用于标识触发数据包时的画面帧。
终端上运行有各种客户端,客户端是指向服务器发送数据包的客户端。
以客户端为游戏客户端为例,当用户在游戏客户端中进行一些操作时,游戏客户端根据用户的操作生成数据包,并将数据包发送至服务器。可以理解的是,服务器与多个游戏客户端相连,多个游戏客户端均能够向服务器发送数据包。
示意性的,数据包中包括用户的操作产生的控制数据、虚拟对象的属性变化对应的数据、操作作用的对象对应的数据(如瞄准或攻击的对象)、动画特效的数据和虚拟环境画面变化的数据中的至少一种。客户端根据数据包中的数据需要进行的逻辑运算类型对数据包添加线程标识,示意性的,逻辑运算的类型包括技能逻辑运算、属性逻辑运算、位置逻辑运算、操作逻辑运算和动画效果逻辑运算中的至少一种。
示意性的,客户端生成的数据包中包括各类数据,不同种类的数据需要不同类型的逻辑线程进行逻辑运算。本申请实施例以一个数据包中的数据属于同一类型的数据,即需要进行同种类型的逻辑运算为例。线程标识为线程的编号,比如,线程标识为线程1、线程2、……线程k,k为正整数。
示意性的,客户端根据每帧画面帧生成数据包,该数据包中携带有该帧画面帧的帧标识,用于区分不同的画面帧,帧标识是按照时间顺序排列下的画面帧所具有的标识。示意性的,帧标识为帧的序号,比如,帧标识为帧1(第一帧)、帧2(第二帧)、……帧j(第j帧),j为正整数。
步骤302,将数据包发送至与线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与逻辑线程对应的消息队列中。
服务器在接收到数据包时需要根据数据包中的数据进行逻辑运算,比如,数据包中的数据是关于用户控制虚拟对象(游戏中被用户控制的虚拟角色)释放技能的数据,服务器需要对该数据包进行技能类型的逻辑运算,即通过技能类型的逻辑线程对数据包进行技能类型的逻辑运算。因此,该数据包中携带有关于技能类型的逻辑线程的线程标识。
由于每个逻辑线程分配有对应的消息队列,则逻辑线程直接将经过逻辑运算后的数据包写入与逻辑线程对应的消息队列。
如图4所示,其示出了7个逻辑线程和7个消息队列,左侧的多个箭头表示多个逻辑线程(箭头仅为示意不代表逻辑线程的实际数量),7个逻辑线程中的数据包分别写入7个消息队列中。
在一些实施例中,服务器还包括接收数据包的消息队列,该消息队列用于接收客户端发送的数据包,各个逻辑线程根据数据包携带的线程标识从该消息队列中读取对应的数据包。
可以理解的是,一个客户端可发送一个或多个数据包,当客户端发送多个数据包时,该多个数据包所需要进行的逻辑运算类型可以相同或不同,则一个客户端发送的数据包可能被分配在各个逻辑线程中。各个逻辑线程中可能有每个客户端发送的数据包。
步骤303,根据帧标识从消息队列中读取运算后的数据包,将运算后的数据包同步至该客户端的关联客户端中。
根据帧标识对应的时间戳顺序从消息队列中读取运算后的数据包,将运算后的数据包同步至至少一个关联客户端中。服务器从消息队列中读取数据包时,为了避免客户端接收到的数据包对应的画面帧的顺序是错乱的,服务器从消息队列中一帧一帧地读取数据包,数据包是按照画面对应的时间戳顺序产生的,即由早到晚的顺序。因此,每个数据包携带的帧标识也是按照时间戳顺序排序的。
示意性的,服务器在读取消息队列中的数据包时,是按照一帧一帧的方式读取的,即读取完第1帧画面帧对应的数据包,读取第2帧画面帧对应的数据包,第2帧画面产生的时间晚于第1帧画面产生的时间。服务器对每帧画面帧对应的数据包进行逻辑运算,将运算后的数据包发送至关联客户端,关联客户端对运算后的数据包进行处理,得到对应的画面帧。
可以理解的是,由于消息队列与逻辑线程一一对应,一帧画面帧对应的数据包可能分散在各个消息队列中,服务器在读取一帧画面帧对应的数据包时,需要将每个消息队列中的该帧画面帧对应的数据包均读取完,当全部消息队列中的该帧画面对应的数据包读取完毕,则该帧画面帧对应的数据包读取完毕,服务器将读取完的数据包同步发送至至少一个关联客户端中。
在一些实施例中,如图4所示,服务器还包括发包线程,该发包线程为单线程,保证调用发送数据包的应用程序接口(Application Programming Interface,API)的数据是安全的。
关联客户端是指与发送数据包的客户端具有关联关系的客户端,示意性的,发送数据包的客户端与关联客户端是参与同一局游戏的客户端。在一些实施例中,发送数据包的客户端登录的用户帐号与关联客户端登录的用户帐号具有好友关系,发送数据包的客户端登录的用户帐号与关联客户端登录的用户帐号在同一临时会话消息中或在同一群组聊天中。
综上所述,本实施例提供的方法,通过对根据逻辑运算类型划分的逻辑线程分配对应的消息队列,使得服务器将经过逻辑线程运算后的数据包写入每个逻辑线程对应的消息队列中,避免了多个逻辑线程共用一个消息队列时产生数据包写入冲突的情况;同时,减少了消息队列的数量,减少了消息队列所占用的服务器内存,从而降低了管理消息的成本。
图5示出了本申请另一个示例性实施例提供的数据包的同步方法的流程图。本实施例以该方法用于如图1所示的计算机***100中的服务器140为例进行说明,服务器140设置有k个逻辑线程和k个消息队列,k为正整数,逻辑线程和消息队列一一对应,逻辑线程是根据逻辑运算的类型进行划分的,该方法包括如下步骤。
步骤501,接收客户端发送的数据包,数据包携带有线程标识和帧标识,线程标识是客 户端根据数据包需要的逻辑运算类型添加的,帧标识用于标识触发数据包时的画面帧。
步骤502,根据线程标识将数据包发送至k个逻辑线程中的第i个逻辑线程,所述第i个逻辑线程与所述k个消息队列中的第i个消息队列一一对应,i为正整数,且i≤k。
服务器根据一个数据包中的线程标识将该数据包分配至对应的逻辑线程。比如,一个数据包中携带有第i个逻辑线程的线程标识,服务器将该数据包分配至该第i个逻辑线程。可以理解的是,一个客户端可发送一个或多个数据包,当客户端发送多个数据包时,该多个数据包所需要进行的逻辑运算类型可以相同或不同,则一个客户端发送的数据包可能分配在各个逻辑线程中。各个逻辑线程中可能有每个客户端发送的数据包。
在一些实施例中,服务器还包括接收数据包的消息队列,该消息队列用于接收客户端发送的数据包,各个逻辑线程根据线程标识从该消息队列中读取对应的数据包。
步骤503,通过第i个逻辑线程对数据包进行逻辑运算,得到运算后的数据包。
示意性的,以游戏客户端为例,游戏客户端向服务器发送的数据包中包括操作数据,该操作数据用于记录用户在游戏客户端中的操作,比如,该操作数据是关于用户控制虚拟对象释放技能的数据。该数据包被分配至第i个逻辑线程中,第i个逻辑线程根据该数据包中的数据进行逻辑运算,比如,第i个逻辑线程进行的逻辑运算是虚拟对象释放技能后的作用范围和作用效果(被该技能作用的虚拟对象的生命值是否会降低,降低多少)。逻辑线程将该释放技能后的作用范围和作用效果对应的数据生成运算后的数据包。
步骤504,将运算后的数据包写入第i个消息队列中。
由于逻辑线程与消息队列一一对应,则第i个逻辑线程对应的第i个消息队列中,服务器将运算后的数据包写入与第i个逻辑线程对应的第i个消息队列中。可以理解的是,一个消息队列中可能包括目标客户端发送的一个或多个数据包,一个消息队列中可能包括一帧画面帧对应的一个数据包或多个数据包。
步骤505,确定k个消息队列当前消费的帧标识。
示意性的,服务器设置有消息队列的消费规则,该消费规则规定以第i个消息队列为准,第i个消息队列当前消费的数据包具有的帧标识为所有消息队列当前消费的数据包所要具有的帧标识,i为正整数,且i≤k。比如,服务器包括8个消息队列,分别为第1消息队列、第2消息队列……第8消息队列,消费规则规定以第1消息队列为准,第1消息队列当前消费的数据包具有的帧标识为所有消息队列当前消费的数据包所要具有的帧标识,第1消息队列当前消费的数据包具有的帧标识为第1帧画面帧对应的帧标识(帧1),则当前消费的帧标识为帧1,其余消息队列也要消费具有帧标识为帧1的数据包。
步骤506,从k个消息队列中,读取与当前消费的帧标识对应的数据包。
示意性的,根据上述消费规则,服务器从k个消息队列中读取具有帧标识为帧1的数据包。
步骤507,将当前消费的帧标识对应的数据包同步至该客户端的关联客户端中。
示意性的,如图4所示,服务器还包括发包线程(右侧箭头所示),该发包线程为单线程,服务器将当前消费的帧标识对应的数据包发送至发包线程,通过发包线程将当前消费的帧标识对应的数据包同步至至少一个关联客户端中。在一些实施例中,发包线程从消息 队列中主动读取数据包,并将读取到的数据包同步至各个关联客户端中。
如图6所示,消息队列1中写入了数据包A1和数据包C3,消息队列2中写入了数据包B2,写入顺序为:数据包A1→数据包B2→数据包C3。示意性的,数据包A1、数据包C3和数据包B2分别属于不同的画面帧,则发包线程的发包顺序为:数据包A1→数据包B2→数据包C3。
综上所述,本实施例提供的方法,通过根据处理数据包的逻辑线程分配对应的消息队列,在将数据包写入每个逻辑线程对应的消息队列中时,避免了多个逻辑线程共用一个消息队列时产生写入冲突的情况;同时,减少了消息队列的数量,降低了消息队列占用服务器内存的情况,从而降低了管理消息的成本。
通过数据包携带的线程标识确定处理数据包的逻辑线程,从而保证后续将运算后的数据包写入消息队列时不会出现时序性错误的问题。
通过确定消息队列当前消费的帧标识,使得所有消息队列统一读取具有同一帧标识的画面帧对应的数据包,从而保证即使同一帧的数据包不在同一消息队列中,也不会出现跨帧发送数据包的现象,避免客户端在接收数据包时产生时序错误。
基于图5的可选实施例中,从消息队列中读取数据包的方法包括如下两种方式。
1、将一个消息队列中同一帧画面帧对应的数据包读取完毕,再读取下一个消息队列中该帧画面帧的数据包,以此类推,直到所有消息队列中该帧画面帧对应的数据包被读取完。
上述步骤506可以替换为如下步骤,如图7所示。
步骤5061a,响应于当前消费的帧标识是目标帧标识,从所述k个消息队列中依次读取具有所述目标帧标识的数据包,直至所述k个消息队列中具有所述目标帧标识的数据包均读取完毕。
为了防止同一帧画面帧对应的数据包跨帧发送,服务器在k个消息队列中分别***同步栅栏,示意性的,以画面帧对应的帧标识为同步栅栏,比如,将k个消息队列中***第j帧画面的目标帧标识,该目标帧标识为同步栅栏,j为正整数。
示意性的,目标帧标识为第3帧画面的帧标识(帧3),服务器从第1个消息队列中读取具有的帧标识为帧3的数据包。
示意性的,当第1个消息队列中第3帧画面帧对应的数据包读取完后,从第2个消息队列中读取第3帧画面帧对应的数据包。如图8所示,在消息队列中***同步栅栏11和同步栅栏12,示意性的,同步栅栏11用于从消息队列中读取属于第1帧画面帧对应的数据包,同步栅栏12用于从消息队列中读取属于第2帧画面帧对应的数据包,当所有消息队列中属于第1帧画面帧对应的数据包读取完毕时,再读取消息队列中属于第2帧画面帧对应的数据包。需要说明的是,图8示出的同步栅栏的位置仅为示意,每个消息队列中同一帧画面帧对应的同步栅栏在消息队列中的位置可能相同或不同,该位置取决于该消息队列中属于同一帧画面帧的数据包的数量。
从所述k个消息队列中依次读取可以为:第1个消息队列中的第3帧画面帧对应的数据包读取完毕,从第2个消息队列中读取第3帧画面帧对应的数据包,当第2个消息队列中的第3帧画面帧对应的数据包读取完毕,从第3个消息队列中读取第3帧画面帧对应的数据包,以 此类推,直到所有的消息队列中的第3帧画面帧对应的数据包被读取完毕。
2、从一个消息队列中读取同一帧画面帧对应的部分数据包,当该部分数据包读取完毕,再读取下一个消息队列中该帧画面帧对应的部分数据包,以此类推,直到所有消息队列中该帧画面帧对应的数据包被读取完。
上述步骤506可以为:根据所述k个消息队列分别对应的时长阈值,依次从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包。
其中,针对所述k个消息队列中的第n个消息队列,包括:
替换为如下步骤,如图7所示。
步骤5061b,获取第n个消息队列对应的时长阈值。
为了防止同一帧画面帧对应的数据包跨帧发送,服务器在k个消息队列中分别***同步栅栏,示意性的,以画面帧对应的帧标识为同步栅栏,比如,将k个消息队列中***第j帧画面的目标帧标识,该目标帧标识为同步栅栏,j为正整数。
此外,在服务器读取一个消息队列中的数据包时,其他消息队列一直处于等待状态,尤其是最后一个消息队列,需要等待前面所有的消息队列中的数据包被读取完毕后,该消息队列中的数据包才能被读取,而服务器还会将逻辑线程中的数据包不断地写入消息队列中,易于造成消息队列阻塞,因此,服务器为消息队列设置有时长阈值,k个消息队列分别对应有各自的时长阈值。每个消息队列对应的时长阈值可以相等或不等。
时长阈值是通过消息队列对应的消费时长得到的,消费时长是从消息队列中读取一帧画面帧对应的数据包的预估时长。示意性的,服务器根据消费队列中具有同一帧标识的数据包的数量对消息队列消费该帧数据包所要消耗的时长进行预估,得到消费时长,则服务器对该消费时长进行划分,得到时长阈值。示意性的,同一消息队列对应的消费时长可以相等或不等,同一消息队列对应的多个时长阈值可以相等或不等。不同消息队列对应的消费时长可以相等或不等,不同消息队列对应的时长阈值可以相等或不等。
如图9所示,每个消息队列的时长阈值以划分后的时间片13进行表示(图9中的虚线),即对消费同一帧画面帧对应的数据包所在的消息队列的消费时长进行划分。时间片(Time Slice)又称为“量子(quantum)”或“处理器片(Processor Slice)”是分时操作***分配给每个正在运行的线程微观上的一段中央处理器(Central Processing Unit,CPU)时间。需要说明的是,划分后得到的各个时间片13可以是被均等划分或被不均等划分,图9中时间片13的位置仅为示意。
示意性的,第n个消息队列对应的时长阈值为100秒。
步骤5062b,读取第n个消息队列中具有目标帧标识的数据包。
服务器在时长阈值内读取第n个消息队列中具有目标帧标识的数据包。比如,第3个消息队列对应的时长阈值为100秒,服务器在100秒内读取第3个消息队列中第3帧画面帧对应的数据包。
步骤5063b,响应于第n个消息队列的读取时长超过第n个消息队列对应的时长阈值,开始从第n+1个消息队列中读取具有目标帧标识的数据包。
示意性的,在读取消息队列中的数据包时进行倒计时,比如,当服务器开始读取第3 个消息队列中第3帧画面帧对应的数据包时,启动倒计时100秒。当100秒倒计时结束时,服务器停止读取第3个消息队列中的第3帧画面帧对应的数据包,并开始从第4个消息队列中读取第3帧画面帧对应的数据包。
示意性的,在读取消息队列中的数据包时进行正计时,比如,当服务器开始读取第3个消息队列中第3帧画面帧对应的数据包时,启动计时器,当计时器的计时超过(或等于)100秒时,服务器停止读取第3个消息队列中的第3帧画面帧对应的数据包,并开始从第4个消息队列中读取第3帧画面帧对应的数据包。
示意性的,每个消息队列对应的时长阈值相等,均为100秒,则在100秒内读取第1个消息队列中的第3帧画面帧对应的数据包,然后再重新计时100秒,在100秒内从第2个消息队列中读取第3帧画面帧对应的数据包,然后再重新计时100秒,在100秒内从第3个消息队列中读取第3帧画面帧对应的数据包,以此类推,当第k个消息队列也进行100秒内读取数据包的操作之后,再次从第1个消息队列中开始读取。首先判断第1个消息队列中是否还具有第3帧画面帧对应的数据包,若第1个消息队列中具有第3帧画面帧对应的数据包,则继续按照时长阈值读取第3帧画面帧对应的数据包,若第1个消息队列中不具有第3帧画面帧对对应的数据包,从第2个消息队列中读取第3帧画面帧对应的数据包,同样地,需要判断第2个消息队列中是否还具有第3帧画面帧对应的数据包。以此类推,直到所有的消息队列中的第3帧画面帧对应的数据包被读取完毕。
综上所述,本实施例提供的方法,通过利用帧标识作为同步栅栏,使得服务器在读取各个消息队列中属于同一帧画面帧的数据包时,当一帧画面帧对应的数据包被读取完,才能读取下一帧画面帧的数据包,避免出现跨帧发送数据包的情况。
通过对各个消息队列对应的消费时长进行划分,使得服务器每次只读取每个消息队列中属于同一帧画面帧的部分数据包,避免排序较后的消息队列等待的时间过长,从而避免消息队列因不断写入数据包而产生阻塞的现象。
基于上述发包机制,存在一些数据包携带的数据较多,使得客户端在接收到数据包时,需要消耗较多的资源去加载数据包。以游戏客户端为例,用户使用的终端是智能手机,用户在智能手机上玩MMORPG游戏时,需要使用网络,如无线网络中的无线保真网络(Wireless Fidelity,WiFi),或移动通信网络(网络运营商提供的网络流量)。以移动通信网络为例,若数据包包含的数据越多,则需要消耗的网络流量越大。因此,为了避免消耗较多网络流量,对数据包包含的数据进行过滤。
比如,客户端受限于自身视野,对于视野内的虚拟对象,只有一小部分显示成模型,比如视野内有80个虚拟对象,用户只能看见10个虚拟对象的是完整模型,而剩下的70个虚拟对象则只显示昵称(或用户帐号)。客户端会显示70个虚拟对象的昵称和生命值,不会展示特效。既然无法展示特效,那么其技能相关的数据包无需发送至关联客户端。
基于图5的可选实施例中,对数据包的过滤方式为三级过滤,过滤方式包括如下步骤,如图10所示。
1、第一级滤除。
步骤210,根据第一位置坐标对当前消费的帧标识所标识画面帧进行视野区域划分,得 到m个视野区域,m为正整数。
服务器存储有客户端控制的第一虚拟对象的第一位置坐标,与当前消费的帧标识对应的数据包包括第一类型数据包,第一类型数据包携带有画面帧中的第二虚拟对象的第二位置坐标。示意性的,第一类型数据包为战斗包,战斗包用于包括关于虚拟对象释放技能的数据、关于虚拟对象参与对战的数据、关于更换技能或更换武器的数据等。
步骤220,响应于第二位置坐标不位于m个视野区域中的指定视野区域,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
示意性的,第二虚拟对象的位置坐标不在m视野区域之内,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。即服务器将位于m个视野区域内的虚拟对象对应的数据包发送至控制第一虚拟对象的客户端,如图11所示,m取值为9,第一虚拟对象14的视野内包括A、B、C、D四个虚拟对象,则将虚拟对象A、虚拟对象B、虚拟对象C和虚拟对象D对应的数据包发送至控制第一虚拟对象14的客户端,该客户端显示有虚拟对象A、虚拟对象B、虚拟对象C和虚拟对象D。需要说明的是,客户端上不显示九宫格视野。
在另一个示例中,第二虚拟对象的位置坐标不在九宫格视野中的第一宫格内,即如图11所示的序号1对应的宫格,则服务器将第一宫格中的其他虚拟对象对应的数据包发送至第一虚拟对象14的客户端。
2、第二级滤除。
步骤230,获取m个视野区域对应的视野列表,视野列表包括位于m个视野区域内q个第二虚拟对象,q为正整数。
m个视野区域可能会存在多个虚拟对象,但m个视野区域中存在的多个虚拟对象不会全部显示在客户端,通过视野列表对m个视野区域中存在的虚拟对象的数量上限进行设置。当视野中虚拟对象过多时,可以通过预设的数量上限来限制获取第二虚拟对象的数量。
步骤240,响应于第一类型数据包对应的第二虚拟对象不属于视野列表中的第二虚拟对象,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
示意性的,m为9,当第二虚拟对象进入九宫格视野且第二虚拟对象在进入视野列表时,超过视野列表规定的数量,服务器将第一类型数据包从与当前消费的帧标识对应的数据包中滤除。即将第二虚拟对象对应的数据包滤除,控制第一虚拟对象的客户端将不显示第二虚拟对象。
3、第三级滤除。
步骤250,获取第一位置坐标和第二位置坐标之间的位置关系。
步骤260,响应于位置关系满足预设条件,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
示意性的,预设条件包括如下条件中的至少一种:
第一虚拟对象与二虚拟对象之间的距离大于距离阈值;
第二虚拟对象位于所述第一虚拟对象的视野外。
如图11所示,针对于第一虚拟对象14,第一虚拟对象14面向的方向是箭头指向的方向,虚拟对象A和虚拟对象B位于第一虚拟对象的前方,虚拟对象C和虚拟对象D位于第一虚拟 对象14的后方。示意性的,虚拟对象D为第二虚拟对象,虚拟对象D与第一虚拟对象14的距离大于距离阈值,则在与当前消费的帧标识对应的数据包中滤除第一类型数据包,即第一虚拟对象14对应的客户端不显示虚拟对象D。示意性的,虚拟对象C为第二虚拟对象,虚拟对象C位于第一虚拟对象14的视野外,则在与当前消费的帧标识对应的数据包中滤除第一类型数据包,即第一虚拟对象14对应的客户端不显示虚拟对象D。示意性的,虚拟对象C和虚拟对象D在第一虚拟对象14对应的客户端中不显示有虚拟对象C和虚拟对象D两者的模型以及两者的名字,且虚拟对象C和虚拟对象D之间进行交互(如互相攻击)的活动也不显示在该客户端中。
如图12所示,该画面为客户端接收了已滤除第一类型数据包后的数据包所触发的显示画面,在该画面上显示有有限个虚拟对象,该画面是以客户端控制的第一虚拟对象的视野形成的画面。示意性的,距离第一虚拟对象较近的虚拟对象21显示较为精细的形象模型,距离第一虚拟对象较远的虚拟对象22和虚拟对象23显示示意的形象模型,以降低客户端加载数据包时所要消耗的资源。
综上所述,本实施例提供的方法,通过对当前消费的帧标识对应的数据包进行滤除,减小同步至关联客户端中的数据包包括的数据,客户端在加载经过滤除的数据包可降低客户端消耗的资源。
可以理解的是,上述三级滤除的方式可分别单独实施,也可任意两两组合实施,还可以全部实施。
在一些实施例中,数据包包括一些不能被滤除的重要数据,则通过指示客户端降低发送频率来降低客户端加载数据包时消耗的资源。
示意性的,与当前消费的帧标识对应的数据包还包括第二类型数据包,第二类型的数据包携带有虚拟对象的属性参数。以第二类型包为属性数据包为例进行说明,属性参数包括虚拟对象的生命值、能量值、魔法值、攻击力中的至少一种数据。
响应于属性参数未发生改变,指示所述客户端降低第二类型数据包的发送频率。
示意性的,服务器针对属性参数设置有脏标志,利用脏标志判断虚拟对象的属性参数是否发生变化。比如,每500毫秒检查一次脏标志,若脏标志发生未变化,证明第二类型数据包未发生变化,则不向客户端发送第二类型数据包;若脏标志发生变化,证明第二类型数据包发生变化,则向客户端发送第二类型数据包,并重新对该第二类型数据包对应的属性参数设置脏标志。。
综上所述,本实施例提供的方法,通过利用脏标志的变化确定属性参数是否发生变化,从而当属性参数不发生变化时,降低第二类型数据包的发送频率,进而降低客户端加载第二类型的数据包所要消耗的资源。
在一些实施例中,上述对第一类型数据包进行裁剪或降频发送的步骤可以通过逻辑线程进行滤除处理后,再写入消息队列中,或者,从读取消息队列之后,从读取到的数据包中进行滤除。
在一个示例中,数据包的同步方法的整体流程包括如下流程。
服务器中包括多个逻辑线程,该逻辑线程用于根据客户端发送的数据包运算逻辑。
写入过程:
示意性的,以游戏为例,服务器中的每个逻辑线程用于运算游戏逻辑。服务器对每个逻辑线程分***息队列,参与游戏的客户端会产生大量的数据包,示意性的,客户端将一帧虚拟环境画面对应的数据包发送至服务器。服务器根据数据包中携带的线程标识将一帧虚拟环境画面对应的数据包写入各个消息队列中。服务器在接收数据包时还记录有各个数据包的接收顺序,按照接收顺序将数据包写入各个消息队列中,即写入同一消息队列中的数据包之间的顺序是固定的。
读取过程:
服务器将每一帧虚拟环境画面帧的帧标识作为同步栅栏***至各个消息队列中,服务器指定一个消息队列消费某一帧的数据包。比如,服务器指定第1个消息队列消费第i帧虚拟环境画面帧对应的数据包,并将第i帧标识作为同步栅栏,从第1个消息队列开始,读取第i帧虚拟环境画面帧对应的数据包,并根据该数据包进行游戏逻辑运算,将运算后的数据包发送至各个客户端。然后,服务器读取第2个消息队列,将第2个消息队列中位于同步栅栏之前的数据包,对该数据包进行游戏逻辑运算,将运算后的数据包发送至各个客户端。以此类推,直到所有消息队列中第i帧虚拟环境画面帧对应的数据包均被读取完。
当第i帧虚拟环境画面帧对应的数据包被读取完后,再读取第i+1帧虚拟环境画面帧对应的数据包,读取第i+1帧虚拟环境画面帧对应的数据包与读取第i帧虚拟环境画面帧对应的数据包的方式一致。
基于上述数据包的发送机制,服务器在消费一个消息队列中的数据包时,其他消息队列处于等待状态。对于最后一个消息队列,需要等待前面所有的消息队列中属于同一画面帧的数据包都被读取后,才会读取最后一个消息队列中的数据包。而消息队列中还在不断地写入客户端发送的数据包,易于造成消息队列的阻塞。
在一些实施例中,服务器对消息队列分配有时间片,时间片具有消息队列消费一帧虚拟环境画面真的数据包对应的预估时长,服务器对消息队列的时间片进行划分,得到一个消息队列的至少两个划分后的时间片,划分后的时间片具有的时长可以相等或不等。
示意性的,服务器从第1个消息队列开始,根据划分后的时间片具有的时长读取第i帧虚拟环境画面帧对应的数据包。比如,第1个消息队列的划分后的时间片具有的时长是60秒,第2个消息队列的划分后的时间片具有的时长是100秒,服务器从第1个消息队列开始,利用60秒的时间读取第1个消息队列中第i帧虚拟环境画面帧对应的数据包,当划分后的时间片具有的时长为0时,服务器利用100秒的时间读取第2个消息队列中第i帧虚拟环境画面帧对应的数据包。在60秒的时间内,第1个消息队列中第i帧虚拟环境画面帧对应的数据包可能全部被读取,也可能部分被读取。同理,在100秒的时间内,第2个消息队列中第i帧虚拟环境画面帧对应的数据包可能被全部读取,也可能被部分读取。
示意性的,当服务器在60内未将第1个消息队列中第i帧虚拟环境画面帧对应的数据包读取完,则当再次遍历至第1个消息队列时,继续读取第i帧虚拟环境画面帧。
基于上述方式,循环遍历所有消息队列,直至所有消息队列均读取到第i帧标识,则证明第i帧虚拟环境画面帧对应的数据包被读取完,服务器利用上述方式读取第i+1帧虚拟环境 画面帧对应的数据包。
通过本实施例提供的方法,对每个逻辑线程分***息队列,减少了消息队列的数量,降低了管理消息的成本,通过对消息队列中***同步栅栏,避免出现跨帧发送数据包的情况。
图13是本申请一个示例性实施例提供的数据包的同步装置的结构框图,该装置包括:
接收模块1310,用于接收客户端发送的数据包,数据包携带有线程标识和帧标识,线程标识是客户端根据数据包需要的逻辑运算类型添加的,帧标识用于标识触发数据包时的画面帧;
写入模块1320,用于将数据包发送至与线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与逻辑线程对应的消息队列中;
读取模块1330,用于根据帧标识从消息队列中读取运算后的数据包,将运算后的数据包同步至所述客户端的关联客户端中。
在一个可选的实施例中,该装置包括发送模块1340和处理模块1350;
发送模块1340,用于根据线程标识将数据包发送至k个逻辑线程中的第i个逻辑线程,所述第i个逻辑线程与所述k个消息队列中的第i个消息队列一一对应,i为正整数,且i≤k;
处理模块1350,用于通过第i个逻辑线程对数据包进行逻辑运算,得到运算后的数据包;
写入模块1320,用于将运算后的数据包写入第i个消息队列中。
在一个可选的实施例中,处理模块1350,用于确定k个消息队列当前消费的帧标识;
读取模块1330,用于从k个消息队列中,读取与当前消费的帧标识对应的数据包;
发送模块1340,用于将当前消费的帧标识对应的数据包同步至所述客户端的关联客户端中。
在一个可选的实施例中,k个消息队列中写入有目标帧标识对应的数据包;
读取模块1330,用于响应于当前消费的帧标识是目标帧标识,从所述k个消息队列中依次读取具有所述目标帧标识的数据包,直至所述k个消息队列中具有所述目标帧标识的数据包均读取完毕。
在一个可选的实施例中,k个消息队列中写入有目标帧标识对应的数据包,k个消息队列分别对应有各自的时长阈值;
处理模块1350,用于根据所述k个消息队列分别对应的时长阈值,依次从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包;其中,针对所述k个消息队列中的第n个消息队列,处理模块1350,用于:获取第n个消息队列对应的时长阈值,n为正整数,且n≤k;读取所述第n个消息队列中具有所述目标帧标识的数据包;响应于对所述第n个消息队列的读取时长超过所述第n个消息队列对应的时长阈值,开始从第n+1个消息队列中读取具有所述目标帧标识的数据包。
在一个可选的实施例中,时长阈值是通过消息队列对应的消费时长得到的,消费时长是从消息队列中读取一帧画面帧对应的数据包的预估时长。
在一个可选的实施例中,与当前消费的帧标识对应的数据包包括第一类型数据包,第一类型数据包携带有画面帧中的第二虚拟对象的第二位置坐标;
处理模块1350,用于根据第一位置坐标对当前消费的帧标识所标识画面帧进行视野区域划分,得到m个视野区域,m为正整数;响应于第二位置坐标不位于m个视野区域中的指定视野区域,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
在一个可选的实施例中,处理模块1350,用于获取m个视野区域对应的视野列表,视野列表包括位于m个视野区域内q个第二虚拟对象,q为正整数;响应于第一类型数据包对应的第二虚拟对象不属于视野列表中的第二虚拟对象,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
在一个可选的实施例中,所述服务器存储有所述客户端控制的第一虚拟对象的第一位置坐标,处理模块1350,用于获取第一位置坐标和第二位置坐标之间的位置关系;响应于位置关系满足预设条件,在与当前消费的帧标识对应的数据包中滤除第一类型数据包。
在一个可选的实施例中,预设条件包括如下条件中的至少一种:
第一虚拟对象与第二虚拟对象之间的距离大于距离阈值;或者,
第二虚拟对象位于第一虚拟对象的视野外。
在一个可选的实施例中,与当前消费的帧标识对应的数据包包括第二类型数据包,第二类型数据包携带有虚拟对象的属性参数;
处理模块1350,用于响应于属性参数未发生改变,指示所述客户端降低属性数据包的发送频率。
在一个可选的实施例中,发送模块1330,用于将当前消费的帧标识对应的数据包发送至发包线程中;通过发包线程将数据包同步至该客户端的关联客户端中。
综上所述,本实施例提供的装置,通过对根据逻辑运算类型划分的逻辑线程分配对应的消息队列,使得服务器将经过逻辑线程运算后的数据包写入每个逻辑线程对应的消息队列中,避免了多个线程共用一个消息队列时产生数据包写入冲突的情况;同时,减少了消息队列的数量,减少了消息队列所占用的服务器内存,从而降低了管理消息的成本。
通过数据包携带的线程标识确定处理数据包的逻辑线程,从而保证后续将运算后的数据包写入消息队列时不会出现时序性错误的问题。
通过确定消息队列当前消费的帧标识使得所有消息队列统一读取具有同一帧标识的画面帧对应的数据包,从而保证即使同一帧的数据包不在同一消息队列中,也不会出现跨帧发送数据包的现象,避免客户端在接收数据包时产生时序错误。
通过利用帧标识作为同步栅栏,使得服务器在读取各个消息队列中属于同一帧画面帧的数据包时,当一帧画面帧对应的数据包被读取完,才能读取下一帧画面帧的数据包,避免出现跨帧发送数据包的情况。
通过对各个消息队列对应的消费时长进行划分,使得服务器每次只读取每个消息队列中属于同一帧画面帧的部分数据包,避免排序较后的消息队列等待的时间过长,从而使得消息队列因写入数据包而产生阻塞。
通过对当前消费的帧标识对应的数据包进行滤除,减小同步至关联客户端中的数据包包括的数据,客户端在加载经过滤除的数据包可降低客户端消耗的资源。
通过利用脏标志的变化确定属性参数是否发生变化,从而当属性参数不发生变化时, 降低第二类型数据包的发送频率,降低客户端加载第二类型的数据包所要消耗的资源。
需要说明的是:上述实施例提供的数据包的同步装置,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的数据包的同步装置与数据包的同步方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
图14示出了本申请一个示例性实施例提供的服务器的结构示意图。该服务器可以如图1所示的计算机***100中的服务器140;
服务器140包括中央处理单元(CPU,Central Processing Unit)1401、包括随机存取存储器(RAM,Random Access Memory)1402和只读存储器(ROM,Read Only Memory)1403的***存储器1404,以及连接***存储器1404和中央处理单元1401的***总线1405。服务器140还包括帮助计算机内的各个器件之间传输信息的基本输入/输出***(I/O***,Input Output System)1406,和用于存储操作***1413、应用程序1414和其他程序模块1415的大容量存储设备1407;
基本输入/输出***1406包括有用于显示信息的显示器1408和用于用户输入信息的诸如鼠标、键盘之类的输入设备1409。其中显示器1408和输入设备1409都通过连接到***总线1405的输入输出控制器1410连接到中央处理单元1401。基本输入/输出***1406还可以包括输入输出控制器1410以用于接收和处理来自键盘、鼠标、或电子触控笔等多个其他设备的输入。类似地,输入输出控制器1410还提供输出到显示屏、打印机或其他类型的输出设备;
大容量存储设备1407通过连接到***总线1405的大容量存储控制器(未示出)连接到中央处理单元1401。大容量存储设备1407及其相关联的计算机可读介质为服务器140提供非易失性存储。也就是说,大容量存储设备1407可以包括诸如硬盘或者紧凑型光盘只读存储器(CD-ROM,Compact Disc Read Only Memory)驱动器之类的计算机可读介质(未示出)。
计算机可读介质可以包括计算机存储介质和通信介质。计算机存储介质包括以用于存储诸如计算机可读指令、数据结构、程序模块或其他数据等信息的任何方法或技术实现的易失性和非易失性、可移动和不可移动介质。计算机存储介质包括RAM、ROM、可擦除可编程只读存储器(EPROM,Erasable Programmable Read Only Memory)、带电可擦可编程只读存储器(EEPROM,Electrically Erasable Programmable Read Only Memory)、闪存或其他固态存储其技术,CD-ROM、数字通用光盘(DVD,Digital Versatile Disc)或固态硬盘(SSD,Solid State Drives)、其他光学存储、磁带盒、磁带、磁盘存储或其他磁性存储设备。其中,随机存取记忆体可以包括电阻式随机存取记忆体(ReRAM,Resistance Random Access Memory)和动态随机存取存储器(DRAM,Dynamic Random Access Memory)。当然,本领域技术人员可知计算机存储介质不局限于上述几种。上述的***存储器1404和大容量存储设备1407可以统称为存储器。
根据本申请的各种实施例,服务器140还可以通过诸如因特网等网络连接到网络上的远程计算机运行。也即服务器140可以通过连接在***总线1405上的网络接口单元1411连接到 网络1412,或者说,也可以使用网络接口单元1411来连接到其他类型的网络或远程计算机***(未示出)。
上述存储器还包括一个或者一个以上的程序,一个或者一个以上程序存储于存储器中,被配置由CPU执行。
在一个可选的实施例中,提供了一种计算机设备,该计算机设备包括处理器和存储器,存储器中存储有至少一条指令、至少一段程序、代码集或指令集,至少一条指令、至少一段程序、代码集或指令集由处理器加载并执行以实现如上所述的数据包的同步方法。
在一个可选的实施例中,提供了一种计算机可读存储介质,该存储介质中存储有至少一条指令、至少一段程序、代码集或指令集,至少一条指令、至少一段程序、代码集或指令集由处理器加载并执行以实现如上所述的数据包的同步方法。
可选地,该计算机可读存储介质可以包括:只读存储器(ROM,Read Only Memory)、随机存取记忆体(RAM,Random Access Memory)、固态硬盘(SSD,Solid State Drives)或光盘等。其中,随机存取记忆体可以包括电阻式随机存取记忆体(ReRAM,Resistance Random Access Memory)和动态随机存取存储器(DRAM,Dynamic Random Access Memory)。上述本申请实施例序号仅为了描述,不代表实施例的优劣。
本申请实施例还提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从该计算机可读存储介质读取该计算机指令,该处理器执行该计算机指令,使得该计算机设备执行如上所述的数据包的同步方法。
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。
以上所述仅为本申请的可选的实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。

Claims (16)

  1. 一种数据包的同步方法,所述方法由服务器执行,所述服务器设置有k个逻辑线程和k个消息队列,k为正整数,所述逻辑线程和所述消息队列一一对应,所述逻辑线程是根据逻辑运算类型划分的,所述方法包括:
    接收客户端发送的数据包,所述数据包携带有线程标识和帧标识,所述线程标识是所述客户端根据所述数据包需要的逻辑运算类型添加的,所述帧标识用于标识触发所述数据包时的画面帧;
    将所述数据包发送至与所述线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与所述逻辑线程对应的消息队列中;
    根据所述帧标识从所述消息队列中读取所述运算后的数据包,将所述运算后的数据包同步至所述客户端的关联客户端中。
  2. 根据权利要求1所述的方法,所述将所述数据包发送至与所述线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与所述逻辑线程对应的消息队列中,包括:
    根据所述线程标识将所述数据包发送至所述k个逻辑线程中的第i个逻辑线程,所述第i个逻辑线程与所述k个消息队列中的第i个消息队列一一对应,i为正整数,且i≤k;
    通过所述第i个逻辑线程对所述数据包进行逻辑运算,得到运算后的数据包;
    将所述运算后的数据包写入所述第i个消息队列中。
  3. 根据权利要求1所述的方法,所述根据所述帧标识从所述消息队列中读取所述运算后的数据包,将所述运算后的数据包同步至所述客户端的关联客户端中,包括:
    确定所述k个消息队列当前消费的帧标识;
    从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包;
    将所述当前消费的帧标识对应的数据包同步至所述客户端的关联客户端中。
  4. 根据权利要求3所述的方法,所述k个消息队列中写入有目标帧标识对应的数据包;
    所述从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包,包括:
    响应于所述当前消费的帧标识是所述目标帧标识,从所述k个消息队列中依次读取具有所述目标帧标识的数据包,直至所述k个消息队列中具有所述目标帧标识的数据包均读取完毕。
  5. 根据权利要求3所述的方法,所述k个消息队列中写入有目标帧标识对应的数据包,所述k个消息队列分别对应有各自的时长阈值;
    所述从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包,包括:
    根据所述k个消息队列分别对应的时长阈值,依次从所述k个消息队列中,读取与所述当前消费的帧标识对应的数据包,其中,针对所述k个消息队列中的第n个消息队列,包括:
    获取第n个消息队列对应的时长阈值,n为正整数,且n≤k;
    读取所述第n个消息队列中具有所述目标帧标识的数据包;
    响应于对所述第n个消息队列的读取时长超过所述第n个消息队列对应的时长阈值,开始从第n+1个消息队列中读取具有所述目标帧标识的数据包。
  6. 根据权利要求5所述的方法,所述时长阈值是通过所述消息队列对应的消费时长得 到的,所述消费时长是从所述消息队列中读取一帧画面帧对应的数据包的预估时长。
  7. 根据权利要求3至6任一所述的方法,,所述当前消费的帧标识对应的数据包中包括第一类型数据包,所述第一类型数据包携带有所述当前消费的帧标识所标识画面帧中的第二虚拟对象的第二位置坐标;
    所述方法还包括:
    根据所述第一位置坐标对所述当前消费的帧标识所标识画面帧进行视野区域划分,得到m个视野区域,m为正整数;
    响应于所述第二位置坐标不位于所述m个视野区域中的指定视野区域,在所述当前消费的帧标识对应的数据包中滤除所述第一类型数据包。
  8. 根据权利要求7所述的方法,所述方法还包括:
    获取所述m个视野区域对应的视野列表,所述视野列表包括位于所述m个视野区域内的q个第二虚拟对象,q为正整数;
    响应于所述第一类型数据包对应的第二虚拟对象不属于所述视野列表中的第二虚拟对象,在所述当前消费的帧标识对应的数据包中滤除所述第一类型数据包。
  9. 根据权利要求7所述的方法,所述服务器存储有所述客户端控制的第一虚拟对象的第一位置坐标,所述方法还包括:
    获取所述第一位置坐标和所述第二位置坐标之间的位置关系;
    响应于所述位置关系满足预设条件,在所述与所述当前消费的帧标识对应的数据包中滤除所述第一类型数据包。
  10. 根据权利要求9所述的方法,所述预设条件包括如下条件中的至少一种:
    所述第一虚拟对象与所述第二虚拟对象之间的距离大于距离阈值;或者,
    所述第二虚拟对象位于所述第一虚拟对象的视野外。
  11. 根据权利要求3至6任一所述的方法,所述当前消费的帧标识对应的数据包中包括第二类型数据包,所述第二类型数据包携带有虚拟对象的属性参数;
    所述方法还包括:
    响应于所述属性参数未发生改变,指示所述客户端降低所述第二类型数据包的发送频率。
  12. 根据权利要求3至6任一所述的方法,所述将所述当前消费的帧标识对应的数据包同步至所述客户端的关联客户端中,包括:
    将所述当前消费的帧标识对应的数据包发送至发包线程中;
    通过所述发包线程将所述数据包同步至所述客户端的关联客户端中。
  13. 一种数据包的同步装置,所述装置包括:
    接收模块,用于接收客户端发送的数据包,所述数据包携带有线程标识和帧标识,所述线程标识是所述客户端根据所述数据包需要的逻辑运算类型添加的,所述帧标识用于标识触发所述数据包时的画面帧;
    写入模块,用于将所述数据包发送至与所述线程标识对应的逻辑线程进行逻辑运算后,将运算后的数据包写入至与所述逻辑线程对应的消息队列中;
    读取模块,用于根据所述帧标识从所述消息队列中读取所述运算后的数据包,将所述运算后的数据包同步至所述客户端的关联客户端中。
  14. 一种计算机设备,所述计算机设备包括处理器和存储器,所述存储器中存储有至少一条指令、至少一段程序、代码集或指令集,所述至少一条指令、所述至少一段程序、所述代码集或指令集由所述处理器加载并执行以实现如权利要求1至12任一所述的数据包的同步方法。
  15. 一种计算机可读存储介质,所述可读存储介质中存储有计算机程序,所述计算机程序用于执行权利要求1至12任一所述的数据包的同步方法。
  16. 一种包括指令的计算机程序产品,当其在计算机上运行时,使得所述计算机执行权利要求1至12任一所述的数据包的同步方法。
PCT/CN2021/100479 2020-07-31 2021-06-17 数据包的同步方法、装置、设备及存储介质 WO2022022140A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP21851414.9A EP4095693A4 (en) 2020-07-31 2021-06-17 DATA PACKET SYNCHRONIZATION METHOD AND DEVICE, DEVICE AND STORAGE MEDIUM
US17/884,431 US20220379202A1 (en) 2020-07-31 2022-08-09 Data packet synchronization method and apparatus, device, and storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010760504.9A CN111737012B (zh) 2020-07-31 2020-07-31 数据包的同步方法、装置、设备及存储介质
CN202010760504.9 2020-07-31

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/884,431 Continuation US20220379202A1 (en) 2020-07-31 2022-08-09 Data packet synchronization method and apparatus, device, and storage medium

Publications (1)

Publication Number Publication Date
WO2022022140A1 true WO2022022140A1 (zh) 2022-02-03

Family

ID=72656961

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/100479 WO2022022140A1 (zh) 2020-07-31 2021-06-17 数据包的同步方法、装置、设备及存储介质

Country Status (4)

Country Link
US (1) US20220379202A1 (zh)
EP (1) EP4095693A4 (zh)
CN (1) CN111737012B (zh)
WO (1) WO2022022140A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115086714A (zh) * 2022-06-13 2022-09-20 京东科技信息技术有限公司 数据处理方法、装置、设备及存储介质

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111737012B (zh) * 2020-07-31 2020-12-04 腾讯科技(深圳)有限公司 数据包的同步方法、装置、设备及存储介质
CN112433999B (zh) * 2020-11-05 2023-12-22 北京浪潮数据技术有限公司 一种Janusgraph客户端遍历方法及相关组件
CN114630007B (zh) * 2020-12-11 2024-04-26 华为技术有限公司 显示同步的方法、电子设备以及可读存储介质
CN113626221B (zh) * 2021-08-10 2024-03-15 迈普通信技术股份有限公司 一种消息入队方法及装置
CN113722037B (zh) * 2021-09-03 2023-08-11 北京百度网讯科技有限公司 一种用户界面的刷新方法、装置、电子设备及存储介质
CN114904265A (zh) * 2022-04-20 2022-08-16 西安万像电子科技有限公司 数据处理方法、装置、存储介质及电子设备

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140177643A1 (en) * 2012-12-20 2014-06-26 Unbound Networks, Inc. Parallel processing using multi-core processor
CN104572290A (zh) * 2013-10-11 2015-04-29 中兴通讯股份有限公司 消息处理线程的控制方法及装置
CN109697123A (zh) * 2017-10-24 2019-04-30 腾讯科技(深圳)有限公司 游戏动画的渲染方法和装置、存储介质、电子装置
CN110162418A (zh) * 2019-05-30 2019-08-23 努比亚技术有限公司 应用冷启动方法、移动终端及计算机可读存储介质
CN111013133A (zh) * 2019-11-29 2020-04-17 北京奇艺世纪科技有限公司 数据处理方法及装置
CN111737012A (zh) * 2020-07-31 2020-10-02 腾讯科技(深圳)有限公司 数据包的同步方法、装置、设备及存储介质

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106330769B (zh) * 2016-11-15 2022-03-08 腾讯科技(深圳)有限公司 一种业务处理方法及服务器
CN109271447A (zh) * 2018-09-04 2019-01-25 中国平安人寿保险股份有限公司 数据同步方法、装置、计算机设备和存储介质
CN111282263A (zh) * 2020-03-03 2020-06-16 北京奇艺世纪科技有限公司 事件消息的处理方法、装置、电子设备及可读存储介质

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140177643A1 (en) * 2012-12-20 2014-06-26 Unbound Networks, Inc. Parallel processing using multi-core processor
CN104572290A (zh) * 2013-10-11 2015-04-29 中兴通讯股份有限公司 消息处理线程的控制方法及装置
CN109697123A (zh) * 2017-10-24 2019-04-30 腾讯科技(深圳)有限公司 游戏动画的渲染方法和装置、存储介质、电子装置
CN110162418A (zh) * 2019-05-30 2019-08-23 努比亚技术有限公司 应用冷启动方法、移动终端及计算机可读存储介质
CN111013133A (zh) * 2019-11-29 2020-04-17 北京奇艺世纪科技有限公司 数据处理方法及装置
CN111737012A (zh) * 2020-07-31 2020-10-02 腾讯科技(深圳)有限公司 数据包的同步方法、装置、设备及存储介质

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP4095693A4

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115086714A (zh) * 2022-06-13 2022-09-20 京东科技信息技术有限公司 数据处理方法、装置、设备及存储介质

Also Published As

Publication number Publication date
CN111737012A (zh) 2020-10-02
CN111737012B (zh) 2020-12-04
EP4095693A1 (en) 2022-11-30
EP4095693A4 (en) 2023-07-12
US20220379202A1 (en) 2022-12-01

Similar Documents

Publication Publication Date Title
WO2022022140A1 (zh) 数据包的同步方法、装置、设备及存储介质
CN110898428B (zh) 多虚拟对象交互的方法、装置、服务器及存储介质
CN113157418B (zh) 服务器资源分配方法和装置、存储介质及电子设备
WO2023279917A1 (zh) 弹幕显示方法、弹幕发送方法、装置、计算机设备、计算机可读存储介质及计算机程序产品
US11918893B2 (en) Massive multi-player compute
CN107092533A (zh) 基于ActiveMQ+Redis的同步消息队列
CN107026900A (zh) 一种拍摄任务分配方法及装置
CN107241418A (zh) 一种负载均衡方法、装置、设备和计算机可读存储介质
WO2023142587A1 (zh) 虚拟对象的控制方法、装置、设备、介质及程序产品
CN111013133A (zh) 数据处理方法及装置
CN114244602A (zh) 多用户在线的网络服务***、方法、装置及介质
CN113486042A (zh) 数据处理方法、装置、计算机可读介质及电子设备
KR102647075B1 (ko) 맵-리듀스를 사용하여 데이터 스큐를 해결하는 방법
US9302185B2 (en) Decision streams for synchronizing visual script language processing between networked computers
CN109561348B (zh) 一种基于直播的业务处理方法、装置、设备和存储介质
CN113713388B (zh) 一种游戏数据处理方法、装置、设备及存储介质
US9805067B1 (en) System and method for multiplayer network gaming
CN112156475B (zh) 一种业务数据处理方法、装置、电子设备及存储介质
CN112386906A (zh) 媒体资源播放方法和装置、存储介质及电子设备
US10178221B2 (en) Time synchronization method and apparatus
CN116351063B (zh) 技能释放处理方法、装置、电子设备及存储介质
CN107617216B (zh) 一种游戏人工智能任务的设计***和方法
WO2023155506A1 (zh) 虚拟对象在地图间转移的方法、装置、设备及介质
US20220072420A1 (en) Frame display method and apparatus in game application, terminal, and storage medium
CN116650942A (zh) 业务处理方法、装置、计算机设备和业务处理***

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21851414

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2021851414

Country of ref document: EP

Effective date: 20220823

NENP Non-entry into the national phase

Ref country code: DE