Animation multi-thread updating method, system and equipment and storage medium
By acquiring and allocating skeletal animation data to the child thread task list in real time in the main thread, combined with an on-demand wake-up mechanism, the problem of insufficient parallelism in skeletal animation updates is solved, improving game performance and efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-01
- Publication Date
- 2026-03-10
AI Technical Summary
In 3D game development, insufficient parallelism in skeletal animation updates due to scene queries and asynchronous thread waiting affects game performance and efficiency.
By acquiring the skeletal animation data to be updated in real time in the main thread and distributing it to multiple child thread task lists, combined with an on-demand wake-up mechanism, the skeletal animation data is dynamically updated. Execution is triggered only when the child threads are idle, and the main thread synchronizes the data after completing the scene update.
It improves the efficiency of multi-threaded updates, reduces the idle time of child threads, makes full use of the main thread's idle time to synchronize generated data, and improves game frame rate and overall performance.
Smart Images

Figure CN121636098A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of game animation technology, and more specifically, to a method, system, device, and storage medium for multi-threaded animation updates. Background Technology
[0002] In 3D game development, skeletal animation is a widely used technique to achieve natural character movement. Its basic principle is to construct a virtual skeletal structure for the 3D model. By driving the rotation and displacement of these bones, the model mesh deforms accordingly, generating smooth character movements such as walking, jumping, and attacking. Since each character may contain dozens or even hundreds of bone nodes, each frame of animation requires a large amount of data computation. If this data and scene updates are performed in the same thread, it will affect game performance and reduce the frame rate. Therefore, skeletal animation updates are generally performed in an asynchronous thread.
[0003] To alleviate the pressure of scene updates and improve the overall efficiency of game operation, existing technologies typically employ a multi-threading mechanism. This separates the skeletal animation calculation task from the scene update thread and assigns it to a dedicated asynchronous thread for concurrent execution. For example, skeletal animation data for each character is collected first. Once all characters have been collected, the data is submitted to the asynchronous thread for calculation. At a certain point in time, the data is synchronized after the asynchronous thread completes its calculation.
[0004] However, there are many characters in the game, and querying all characters during scene updates is a relatively time-consuming operation. Submitting the query to the asynchronous thread after it is completed will cause the child thread to be idle during the query. Moreover, while waiting for the child thread to complete all calculations, the main thread can only wait passively and cannot make full use of the idle time to synchronize the generated data in advance, resulting in insufficient parallelism and reducing the efficiency of multi-threaded updates. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a multi-threaded animation update method, which, when a skeletal animation that needs to be updated is found in the main thread of scene update, immediately adds the skeletal animation that needs to be updated to the task data list and dynamically updates the number of skeletal animations to be updated, and combines an on-demand wake-up mechanism to trigger execution only when the child thread of skeletal update is idle, thereby improving the efficiency of multi-threaded update.
[0006] To achieve the above objectives, in a first aspect, embodiments of the present invention provide a multi-threaded animation update method. The method is applied to an electronic device, which runs a main thread and multiple sub-threads. The method includes: acquiring skeletal animation data to be updated during scene updates performed by the main thread; evenly distributing the skeletal animation data to be updated to task data lists corresponding to the multiple sub-threads; if a sub-thread is not currently in an update state, waking it up to update the skeletal animation data to be updated in the task data list; if a sub-thread is currently in an update state, using the sub-thread to update the skeletal animation data to be updated in the task data list; and synchronizing the updated skeletal animation data from the sub-threads to the main thread after the main thread's scene update is completed.
[0007] In this embodiment, the acquired skeletal animation data to be updated is added to the task data list during the scene update process in the main thread. This allows the child thread to start updating the skeletal animation data while the main thread is updating the scene. Simultaneously, when initiating the child thread's update, it is checked whether the child thread is already updating. If the child thread is updating, it is added to the task data list without being woken up. If the child thread is not updating, it is woken up to perform the update. Then, after the main thread completes the scene update, the skeletal animation data updated by the child thread is synchronized. This achieves simultaneous acquisition and updating, reducing the idle time of the child thread. Furthermore, the main thread synchronizes while waiting for the child thread to calculate, making full use of idle time to synchronize already generated data in advance, improving parallelism, and thus increasing the efficiency of multi-threaded updates.
[0008] In some embodiments, the task data list corresponds to a task end index and a completion index; the task end index represents the position index corresponding to the last skeletal animation data to be updated in the task data list, and the completion index represents the position index corresponding to the most recently updated skeletal animation data in the task data list; the method further includes: obtaining the current update identifier of the sub-thread; if the update identifier is a first preset value, and the completion index is less than the task end index, then the current update identifier of the sub-thread is updated from the first preset value to a second preset value; the first preset value represents that the sub-thread is not in an update state, and the second preset value represents that the sub-thread is in an update state; if the update identifier is the second preset value, and the completion index is equal to the task end index, then the current update identifier of the sub-thread is updated from the second preset value to the first preset value.
[0009] This configuration, by setting task end and completion indices and linking them with update flags, enables dynamic perception and precise control of the working state of sub-threads, reducing unnecessary thread wake-ups and lowering system scheduling overhead.
[0010] In some embodiments, the method further includes: updating the completion index corresponding to the task data list each time the sub-thread completes the update of a skeletal animation data to be updated; and updating the task end index corresponding to the task data list each time a new skeletal animation data to be updated is added to the task data list corresponding to the sub-thread.
[0011] This setup enables real-time tracking of task processing progress by updating the completion index and task end index each time a task is completed and added, providing an accurate data foundation for thread status judgment and data synchronization.
[0012] In some embodiments, the step of evenly distributing the skeletal animation data to be updated to the task data lists corresponding to the multiple sub-threads includes: obtaining the sorting order of the multiple sub-threads; and after obtaining the skeletal animation data to be updated each time, adding the skeletal animation data to be updated to the task data list of the corresponding sub-thread according to the sorting order of the multiple sub-threads.
[0013] This configuration, by allocating tasks in a round-robin fashion according to a fixed order, achieves load balancing among multiple sub-threads, avoids single-point overload, and improves the overall throughput of parallel processing.
[0014] In some embodiments, synchronizing the skeletal animation data updated by the sub-threads to the main thread includes: synchronizing the skeletal animation data updated by each of the sub-threads to the main thread according to the order in which the sub-threads are arranged.
[0015] This setup ensures the consistency of the logical timing of animation updates by synchronizing the completed skeletal animation data sequentially according to the order of the child threads, thereby improving the stability and predictability of data integration.
[0016] In some embodiments, synchronizing the skeletal animation data updated by the sub-thread to the main thread includes: if all the skeletal animation data to be updated in the task data list corresponding to the sub-thread has been updated, then synchronizing all the skeletal animation data updated by the sub-thread to the main thread; if not all the skeletal animation data to be updated in the task data list corresponding to the sub-thread has been updated, then synchronizing the currently updated skeletal animation data of the sub-thread to the main thread, and after the sub-thread has updated all the remaining skeletal animation data that has not been updated, synchronizing the updated remaining skeletal animation data to the main thread.
[0017] This setup, by distinguishing between complete and partial completion and implementing a step-by-step synchronization strategy, effectively reduces the main thread's waiting time, enables animation data to be available as early as possible, and improves frame generation efficiency.
[0018] Secondly, embodiments of the present invention provide an animation multi-threaded update system applied to an electronic device, wherein the electronic device runs a main thread and multiple sub-threads, and the system includes: The module includes an acquisition module for acquiring skeletal animation data to be updated during scene updates in the main thread; an asynchronous update module for evenly distributing the skeletal animation data to be updated to task data lists corresponding to multiple sub-threads; if a sub-thread is not currently in an update state, waking it up to update the skeletal animation data to be updated in the task data list; and if a sub-thread is currently in an update state, using it to update the skeletal animation data to be updated in the task data list. A synchronous update module is used to synchronize the skeletal animation data updated by the sub-threads to the main thread after the main thread's scene update is completed.
[0019] In some embodiments, the task data list corresponds to a task end index and a completion index; the task end index represents the position index corresponding to the last skeletal animation data to be updated in the task data list, and the completion index represents the position index corresponding to the most recently updated skeletal animation data in the task data list. The asynchronous update module is used to: obtain the current update identifier of the sub-thread; if the update identifier is a first preset value and the completion index is less than the task end index, then update the current update identifier of the sub-thread from the first preset value to a second preset value; the first preset value represents that the sub-thread is not in an update state, and the second preset value represents that the sub-thread is in an update state; if the update identifier is the second preset value and the completion index is equal to the task end index, then update the current update identifier of the sub-thread from the second preset value to the first preset value.
[0020] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the animation multithreaded update method as described in the first aspect.
[0021] Fourthly, embodiments of the present invention provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the animation multithreaded update method as described in the first aspect.
[0022] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0023] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 A flowchart of an animation multithreaded update method provided in an embodiment of the present invention; Figure 2 This is a flowchart of the sub-thread update state judgment process provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the task data list update process provided in an embodiment of the present invention; Figure 4 for Figure 1 Flowchart of sub-steps S201~S202 of step S200; Figure 5 for Figure 1 Flowcharts of sub-steps S401~S403 in step S400; Figure 6 This is a schematic diagram of the functional modules of the animation multi-threaded update system provided in an embodiment of the present invention; Figure 7 A block diagram of an electronic device provided in an embodiment of the present invention.
[0025] Icons: 1000 - Animated multi-threaded update system; 1100 - Acquisition module; 1200 - Asynchronous update module; 1300 - Synchronous update module; 2000 - Electronic device; 2100 - Processor; 2200 - Memory; 2300 - Bus; 2400 - Communication interface. Detailed Implementation
[0026] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0027] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0028] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0029] As described in the background technology, there are many characters in the game. When the scene is updated, querying all characters is a relatively time-consuming operation. After the query is completed, it is then submitted to the asynchronous thread, which will cause the child thread to be idle during the query. Moreover, while waiting for the child thread to complete all the calculations, the main thread can often only wait passively and cannot make full use of the idle time to synchronize the generated data in advance, resulting in insufficient parallelism and reducing the efficiency of multi-threaded updates.
[0030] To address this, this invention provides a multi-threaded animation update method. The method is applied to an electronic device that runs a main thread and multiple sub-threads. By immediately adding skeletal animations requiring updates to the task data list when the main thread of scene updates detects such animations and dynamically updating the number of skeletal animation data to be updated, and combining this with an on-demand wake-up mechanism that triggers execution only when the sub-threads updating skeletal animations are idle, the efficiency of multi-threaded updates is improved. (See also...) Figure 1 , Figure 1 This is a flowchart of an animation multi-threaded update method provided in an embodiment of the present invention. The animation multi-threaded update method includes steps S100~S400: S100: Obtain the skeletal animation data to be updated during the scene update process in the main thread.
[0031] In this embodiment, during scene updates, the main thread processes each movable entity in the scene, determining in real time whether each character has triggered animation playback conditions, such as receiving user input commands, entering a specific area, or satisfying behavior tree decision nodes. Specifically, when a 3D model needs to perform walking, jumping, or attacking actions, its bound animation controller is activated, and the skeletal pose parameter information required for the current frame is extracted. This information constitutes the core content of the skeletal animation data to be updated, including but not limited to joint transformation matrices, rotation quaternions, displacement offsets, and mixed weight values; the skeletal data to be updated for each character is denoted as Skeleton. During this process, the main thread does not wait for the child threads to complete their calculations but immediately begins to identify the next character that may need updating, thereby achieving scene updates while acquiring the skeletal animation data to be updated. This breaks the limitation of traditional serial mode, which requires collecting all tasks before unified scheduling, allowing subsequent multi-threaded calculations to start as early as possible.
[0032] S200: Distribute the skeletal animation data to be updated evenly to the task data lists corresponding to multiple sub-threads.
[0033] In this embodiment, after the main thread confirms that a character needs to update its skeletal animation, it immediately distributes the corresponding skeletal animation data to the task data list maintained by one of the multiple child threads. Specifically, a target child thread is selected based on a preset load balancing strategy to avoid a single child thread becoming a performance bottleneck due to task accumulation. The task data list is denoted as SkeletonList. The allocation method used here is based on a round-robin mechanism, maintaining a pointer that records the current allocation position, initially pointing to the first child thread. After each successful allocation of a task, the pointer advances sequentially to the next child thread. If the end is reached, it wraps back to the beginning, thus creating a cyclical amortization effect. It should be noted that each child thread independently manages its own task data list, and there are no shared write conflicts between them. Therefore, the main thread can efficiently complete data write operations in a lock-free state. During this process, the task data list is implemented using a dynamically expandable data structure to ensure that new tasks can be quickly appended to the end. For example, consider four sub-threads T0, T1, T2, and T3. When eight consecutive skeletal animation data items awaiting updates appear, they will be sequentially distributed among T0, T1, T2, T3, T0, T1, T2, and T3, ensuring that each sub-thread bears a similar amount of computational load. This allocation strategy not only improves resource utilization but also enhances scalability and stability, achieving a uniform distribution of tasks across multiple computational units and laying the foundation for subsequent parallel processing.
[0034] S300. If the child thread is not currently in the update state, wake up the child thread to update the skeletal animation data to be updated in the task data list; if the child thread is currently in the update state, use the child thread to update the skeletal animation data to be updated in the task data list.
[0035] In this embodiment, the child thread adopts a self-driven execution model. Once awakened, it enters a state of continuously checking the task queue. As long as the completion index is less than the task completion index, it will continue processing the next skeletal animation data to be updated. This mechanism effectively avoids the context switching overhead caused by repeated wake-ups, activating the child thread only when necessary. For example, when the main thread submits multiple tasks consecutively in a short period, as long as the child thread has not completed all processing, it remains in an update state, and subsequent tasks can be directly taken over by the currently running child thread without triggering another wake-up operation. Therefore, this design achieves fine-grained control of thread scheduling through state awareness, improving response efficiency.
[0036] S400: After the main thread scene update is completed, synchronize the skeletal animation data updated by the child thread to the main thread.
[0037] In this embodiment, after completing all scene logic processing, the main thread enters the data integration phase and begins to collect the results of completed calculations from each sub-thread. Specifically, the main thread sequentially accesses the task data list of each sub-thread and determines the task completion status by comparing its completion index with the task end index. If the completion index of a sub-thread equals the task end index, it means that all its skeletal animation data to be updated has been processed, and the main thread can read all the results at once and migrate them to its local memory space. If the completion index is still less than the task end index, it indicates that some tasks are still being processed. In this case, the main thread will not wait idly but will first synchronize the completed data so that it can be used for model skinning and drawing processes as soon as possible.
[0038] In some embodiments, see Figure 2 , Figure 2 The flowchart for determining the sub-thread update status provided in this embodiment of the invention includes a task data list with a task end index and a completion index. The task end index represents the position index of the last skeletal animation data to be updated in the task data list, and the completion index represents the position index of the most recently updated skeletal animation data in the task data list. The task end index can be UpdateStartIndex, and the completion index can be UpdateEndIndex. The multi-threaded animation update method also includes steps S510 to S530: S510, Get the current update flag of the child thread.
[0039] In this embodiment, the update flag serves as a core indicator variable reflecting the running status of a sub-thread. Its value is directly related to whether the sub-thread is currently executing a task to calculate skeletal animation data. After the main thread or scheduling logic adds new skeletal animation data to the task data list of a sub-thread, it needs to read the update flag of that sub-thread to determine its current working status. Specifically, the update flag is stored in the control structure corresponding to the sub-thread and can be safely accessed atomically, ensuring that misjudgments of the status will not occur due to contention for access in a multi-threaded concurrent environment. This process does not rely on external monitoring mechanisms but achieves lightweight status awareness through local variable lookups, reducing the overhead of cross-thread communication. It should be noted that the reading of the update flag occurs at a critical decision point in the task injection phase and is a prerequisite for determining whether to trigger a wake-up operation. For example, when the main thread adds a new task to a sub-thread, if its update flag is not obtained first, it is impossible to accurately determine whether the sub-thread needs to be reactivated, which may result in the already running sub-thread being repeatedly woken up, causing resource waste. This demonstrates that this step provides the necessary input for subsequent state transitions, enabling efficient identification of the activity of computing units.
[0040] S520. If the update flag is the first preset value and the completion index is less than the task end index, then the current update flag of the sub-thread is updated from the first preset value to the second preset value; the first preset value indicates that the sub-thread is not in the update state, and the second preset value indicates that the sub-thread is in the update state.
[0041] In this embodiment, after obtaining the update flag, a joint judgment is made based on the task processing progress information to determine whether to start the computation loop of the sub-thread. Specifically, when the update flag is detected to be a first preset value (e.g., false), it indicates that the sub-thread is not currently in an update state and may be in a suspended or dormant mode due to a lack of tasks. At the same time, the numerical relationship between the completion index and the task end index is further compared. If the former is less than the latter, it indicates that there are unprocessed data items in the task queue, and it is necessary to activate the sub-thread to continue completing the remaining work. Under this condition, the update flag is updated from the first preset value to a second preset value (e.g., true), and an operation-level thread wake-up mechanism is triggered, causing it to transition from a waiting state to a ready state, thereby gaining CPU scheduling execution rights. It can be understood that this state transition is not unconditional, but is based on the dual premise of having tasks but not yet processing them, avoiding empty wake-ups or invalid activations. For example, when the main thread submits a new task to a sub-thread that was originally idle, if its completion index is still lower than the task end index, it indicates that there are backlogged tasks to be processed. In this case, setting the update flag to the second preset value will prompt the sub-thread to immediately start iterative computation. As can be seen, this step, by introducing a dual-condition judgment mechanism, enhances the accuracy and responsiveness of thread scheduling, achieves precise activation control when a task exists and the sub-thread is idle, and ensures the timely allocation of computing resources.
[0042] S530. If the update flag is the second preset value and the completion index is equal to the task end index, then update the current update flag of the child thread from the second preset value to the first preset value.
[0043] In this embodiment, the task processing progress of the sub-thread is continuously monitored. Once it is confirmed that all assigned tasks have been completed, a state rollback operation is performed. Specifically, after the sub-thread completes the calculation of the last skeletal animation data to be updated, its completion index is incremented to the position equal to the task end index. At this point, the current value of the update flag is checked again. If the flag is still the second preset value (e.g., true), it indicates that the sub-thread is still considered to be in a running state, but in reality, there are no more tasks to process. In this case, the update flag is updated from the second preset value to the first preset value (e.g., false) to correctly reflect the change in its actual running state. It should be noted that this state reset action is usually completed by the sub-thread itself at the end of its main loop, and is part of its internal logic, rather than being forcibly intervened externally. During this process, after the state change, the sub-thread can actively enter a waiting mode, releasing CPU resources for other tasks, thereby improving the overall energy efficiency. For example, when a sub-thread finishes processing the 10th skeletal animation task and finds that the completion index equals the task end index, meaning no new tasks are being added, its update flag is set to the first preset value, allowing it to suspend and wait for the next wake-up signal. Therefore, this step constitutes a closed-loop feedback loop in thread lifecycle management, realizing the dynamic reset of the child thread's running state to zero, and creating the preparatory conditions for the next round of task allocation.
[0044] In some embodiments, to demonstrate that the completion index and task end index are updated in real time, see [link to documentation]. Figure 3 , Figure 3 This is a schematic diagram of the task data list update process provided in an embodiment of the present invention. The animation multi-threaded update method further includes steps S540 to S550: S540. When the child thread completes the update of each piece of skeletal animation data to be updated, update the completion index corresponding to the task data list.
[0045] S550. When a new skeletal animation data to be updated is added to the task data list corresponding to the sub-thread, update the task end index corresponding to the task data list.
[0046] In this embodiment, the completion index and the task end index are used to characterize two key dimensions of task processing progress, and their dynamic updates are the foundation for achieving multi-threaded collaborative control. Whenever a sub-thread successfully completes the calculation and update of a piece of skeletal animation data to be updated, it increments the completion index corresponding to the current task data list, pointing it to the next unprocessed data position. This operation is performed independently by the sub-thread within its main loop and is part of local state progression; it can be safely executed without synchronization with other threads. During this process, the increment of the completion index strictly follows the task processing order, ensuring that it always reflects the maximum continuous range of actual completions, providing an accurate basis for subsequent state judgments and data synchronization. Simultaneously, on the main thread side, whenever new skeletal animation data to be updated is written to a sub-thread's task data list, the task end index corresponding to that task data list is immediately incremented to mark the new boundary of the task queue. In specific implementation, the update of the task end index occurs during the main thread's task allocation process and only takes effect after the data is successfully appended to the task data list, thus ensuring that its value always remains consistent with the total number of submitted tasks. It's important to note that the update paths for these two indexes are independent: the completion index is updated unidirectionally by the child thread, while the task completion index is incremented on demand by the main thread. There is no lock contention or cross-thread write conflict between them, thus enabling efficient concurrent access without a mutual exclusion mechanism. For example, when the main thread rapidly injects multiple tasks, the task completion index grows rapidly, while the completion index gradually catches up with the processing speed of the child thread. The difference between the two directly reflects the number of backlogged tasks. Therefore, this dual-index update mechanism forms the core support for non-blocking task management. Based on the above description, this step, by updating the corresponding indexes when a task completes and when a new event occurs, achieves fine-grained tracking of the task lifecycle, providing a reliable technical foundation for thread state awareness and data synchronization.
[0047] In some embodiments, for step S200, the present invention provides a possible implementation method. For example... Figure 4 As shown, Figure 4 for Figure 1 The flowchart of sub-steps S201~S202 of step S200, wherein steps S201~S202 include: S201. Obtain the order of multiple child threads.
[0048] S202. After obtaining the skeletal animation data to be updated each time, add the skeletal animation data to be updated to the task data list of the corresponding sub-thread according to the order of the multiple sub-threads.
[0049] In this embodiment, to achieve a uniform distribution of computational load among multiple sub-threads and avoid situations where some threads are overloaded while others are idle due to uneven task allocation, a deterministic distribution strategy is adopted to guide the selection of task writing targets. First, during the initialization phase or before the first task scheduling, the order of multiple sub-threads is determined. This order is a preset fixed sequence, such as arranged in ascending order of sub-thread creation numbers, or based on a priority order set according to the resource topology. Specifically, after the main thread traverses scene objects and identifies a character requiring skeletal animation updates, it immediately extracts the corresponding skeletal animation data to be updated and, based on the currently recorded allocation position, writes this data into the task data list corresponding to the next specified sub-thread in the arrangement order. During this process, a circular pointer is maintained, initially pointing to the first sub-thread in the arrangement order. It increments by one position each time a task allocation is completed, automatically wrapping back to the beginning position when the end is reached, thus forming a round-robin distribution mechanism. It should be noted that this allocation process does not rely on the real-time load feedback of each sub-thread, but is based on the principle of uniform distribution over time, ensuring that the number of tasks received by each sub-thread is statistically consistent. For example, suppose there are four sub-threads arranged in the order T0, T1, T2, and T3. When eight consecutive skeletal animation data items awaiting updates appear, they will be assigned to T0, T1, T2, T3, T0, T1, T2, and T3 respectively, ensuring that each thread bears a similar workload. Therefore, this method, by introducing ordered polling logic, achieves good load balancing without requiring complex scheduling algorithms, improving the fairness and efficiency of task allocation in a multi-threaded environment.
[0050] In some embodiments, for step S400, the present invention provides a possible implementation. For example... Figure 5 As shown, Figure 5 for Figure 1 The flowchart of sub-steps S401~S403 of step S400, wherein steps S401~S403 include: S401. Synchronize the skeletal animation data updated by each sub-thread to the main thread according to the order of the multiple sub-threads.
[0051] In this embodiment, after the main thread completes the scene logic update, it needs to integrate the skeletal animation results calculated asynchronously by multiple sub-threads to ensure that the model pose can be correctly reflected in the subsequent rendering process. Therefore, the main thread does not randomly access the task data lists of each sub-thread, but strictly follows a predetermined order of sub-threads to read and synchronize data sequentially. Specifically, this order is consistent with the order used in the task allocation phase, forming a closed-loop path from distribution to recycling. During this process, the main thread iterates through each sub-thread, checks the task processing progress of each sub-thread, and extracts the updated skeletal animation data, migrating it to a memory area directly accessible to the main thread. It should be noted that this sequential synchronization mechanism helps maintain the logical continuity of animation data on the timeline, avoiding jumps or frame errors in character actions due to out-of-order integration. For example, if character A's task is first assigned to sub-thread T0, and character B's task is subsequently assigned to sub-thread T1, even if T1 completes its calculation first, the main thread will still prioritize synchronizing the result from T0, thus ensuring that the animation playback order conforms to the original scheduling intent. This demonstrates that the synchronization strategy not only improves the predictability of behavior but also provides a clear timeline for debugging and log tracing, enhancing the timing consistency and result stability in the multi-threaded collaboration process.
[0052] S402. If all the skeletal animation data to be updated in the task data list corresponding to the child thread has been updated, then synchronize all the skeletal animation data updated by the child thread to the main thread.
[0053] In this embodiment, when the main thread accesses the task data list of a sub-thread, it first determines the current task completion status based on a comparison of the completion index and the task end index. Specifically, when the completion index of the sub-thread equals the task end index, it indicates that all skeletal animation data to be updated in its task data list has been successfully calculated, and there are no unprocessed items. Under this condition, the main thread can read all the updated skeletal animation data in the corresponding task data list of the sub-thread at once and copy or reference them in batches to the animation state buffer in the main thread context for subsequent mesh deformation and drawing instruction generation. This operation is usually performed on contiguous memory blocks, which is beneficial for improving data migration efficiency by utilizing the CPU cache prefetching mechanism. This situation can be understood as representing an ideal workload matching state, that is, the sub-thread has completely completed all the computational tasks it undertakes, without waiting or residual dependencies. For example, when a sub-thread finishes processing the 8th skeletal animation task and no new tasks are added, its completion index and task end index are both 8, and the main thread can immediately synchronize all 8 sets of data without segmented processing. Therefore, this branch logic is suitable for scenarios where tasks have fully converged. It can complete data integration in the simplest way, and achieve efficient one-time synchronization by recognizing the full completion status, minimizing the number of cross-thread data interactions and latency.
[0054] S403. If the skeletal animation data to be updated in the task data list corresponding to the child thread has not been completely updated, then the skeletal animation data that has been updated in the child thread will be synchronized to the main thread. After the child thread has updated all the remaining skeletal animation data that has not been updated, the remaining skeletal animation data that has been updated will be synchronized to the main thread.
[0055] In this embodiment, when the main thread detects that the completion index of a sub-thread is less than the task end index, it determines that there are unfinished tasks. Instead of blocking and waiting, it immediately performs partial synchronization, reading all updated skeletal animation data from the starting position to the completion index and migrating it to the main thread's available space. This mechanism allows the main thread to utilize available results as early as possible, avoiding the overall process being slowed down by individual time-consuming tasks. After this, the main thread continues to advance other logic or process data from other sub-threads without pausing. Simultaneously, it maintains a monitoring state for the sub-thread, using condition variables, event flags, or polling mechanisms to detect its subsequent progress. When the sub-thread finally completes its remaining tasks, causing its completion index to catch up with the task end index, a new round of synchronization is triggered, supplementing the main thread with the remaining skeletal animation data that was previously missed. It should be noted that this process may involve multiple phased synchronizations, especially in scenarios where tasks are continuously and dynamically injected. For example, a sub-thread initially has 6 tasks. After the main thread synchronizes the first 4, it finds that 2 are still unfinished; after the subsequent 2 are calculated, a second synchronization is initiated to complete the finalization. This demonstrates that by introducing an incremental synchronization mechanism, data integrity is ensured while significantly reducing the main thread's idle waiting time, thereby improving overall response performance and resource utilization.
[0056] Based on the above method, embodiments of the present invention also provide a system corresponding to the above method, such as... Figure 6 As shown, Figure 6 This is a functional module diagram of the animation multi-threaded update system 1000 provided in this embodiment of the invention. It should be noted that the animation multi-threaded update system 1000 provided in this embodiment is applied to an electronic device 2000. The electronic device 2000 runs a main thread and multiple sub-threads. The basic principle and technical effects of the animation multi-threaded update system 1000 are the same as those in the above method embodiment. For the sake of brevity, parts not mentioned in this embodiment can be referred to the corresponding content in the method embodiment.
[0057] In this embodiment, the animation multi-threaded update system 1000 includes an acquisition module 1100, an asynchronous update module 1200, and a synchronous update module 1300. The acquisition module 1100 is used to acquire the skeletal animation data to be updated during the scene update process in the main thread. It can be understood that the acquisition module 1100 is used to perform the above-described step S100.
[0058] The asynchronous update module 1200 is used to evenly distribute the skeletal animation data to be updated to the task data lists corresponding to multiple sub-threads. If a sub-thread is not currently in an update state, it is woken up to update the skeletal animation data to be updated in the task data list; if a sub-thread is currently in an update state, it is used to update the skeletal animation data to be updated in the task data list. It can be understood that the asynchronous update module 1200 is used to execute the above steps S200~S300.
[0059] The synchronization update module 1300 is used to synchronize the skeletal animation data updated by the child thread to the main thread after the main thread scene update is completed. It can be understood that the synchronization update module 1300 is used to perform the above step S400.
[0060] In some embodiments, the task data list corresponds to a task end index and a completion index; the task end index represents the position index corresponding to the last skeletal animation data to be updated in the task data list, and the completion index represents the position index corresponding to the most recently updated skeletal animation data in the task data list. The asynchronous update module 1200 is used to: obtain the current update identifier of the sub-thread; if the update identifier is a first preset value and the completion index is less than the task end index, then update the current update identifier of the sub-thread from the first preset value to a second preset value; the first preset value represents that the sub-thread is not in an update state, and the second preset value represents that the sub-thread is in an update state; if the update identifier is the second preset value and the completion index is equal to the task end index, then update the current update identifier of the sub-thread from the second preset value to the first preset value. It can be understood that the asynchronous update module 1200 is also used to perform the above steps S510~S530.
[0061] In some embodiments, the asynchronous update module 1200 is used to update the completion index corresponding to the task data list each time the child thread completes the update of a piece of skeletal animation data to be updated; and to update the task end index corresponding to the task data list each time a piece of skeletal animation data to be updated is added to the task data list corresponding to the child thread. It can be understood that the asynchronous update module 1200 is also used to perform the above steps S540~S550.
[0062] In some embodiments, the asynchronous update module 1200 is further configured to obtain the arrangement order of multiple sub-threads; after obtaining the skeletal animation data to be updated each time, the skeletal animation data to be updated is added to the task data list of the corresponding sub-thread according to the arrangement order of the multiple sub-threads. It can be understood that the asynchronous update module 1200 is used to perform the above steps S201~S202.
[0063] In some embodiments, the synchronization update module 1300 is used to synchronize the skeletal animation data updated by each sub-thread to the main thread according to the order of the multiple sub-threads; if all the skeletal animation data to be updated in the task data list corresponding to the sub-thread has been updated, then the skeletal animation data updated by the sub-thread is synchronized to the main thread; if not all the skeletal animation data to be updated in the task data list corresponding to the sub-thread has been updated, then the skeletal animation data currently updated by the sub-thread is synchronized to the main thread, and after the sub-thread has updated all the remaining skeletal animation data that has not been updated, the remaining updated skeletal animation data is synchronized to the main thread. It can be understood that the synchronization update module 1300 is used to perform the above steps S401~S403.
[0064] Based on the same inventive concept disclosed above, the present invention also provides a block diagram of an electronic device 2000 performing the above method. Please refer to... Figure 7 , Figure 7 This is a block diagram of an electronic device 2000 provided in an embodiment of the present invention. The electronic device 2000 includes a processor 2100, a memory 2200, a bus 2300, and a communication interface 2400. The processor 2100 and the memory 2200 are connected via the bus 2300, and the processor 2100 communicates with external devices via the communication interface 2400.
[0065] Processor 2100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed through integrated logic circuits in the hardware of processor 2100 or through software instructions. The processor 2100 may be a general-purpose processor 2100, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0066] The memory 2200 is used to store computer programs. For example, the animation multi-threaded update system 1000 in this embodiment of the invention includes at least one software function module that can be stored in the memory 2200 in the form of software or firmware. After receiving the execution instruction, the processor 2100 executes the program to implement the animation multi-threaded update method in this embodiment of the invention.
[0067] The memory 2200 may include high-speed random access memory (RAM) or non-volatile memory. Optionally, the memory 2200 may be a storage device built into the processor 2100 or a storage device independent of the processor 2100.
[0068] Bus 2300 can be ISA bus 2300, PCI bus 2300 or EISA bus 2300, etc. Figure 7 It is indicated by only one double-headed arrow, but does not mean that there is only one bus 2300 or one type of bus 2300.
[0069] Electronic devices 2000 can be mobile phones, tablets, laptops, desktop computers, and other computer devices.
[0070] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer program thereon, which, when executed by processor 2100, implements the animation multi-threaded update method described above. This computer-readable storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0071] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An animated multithreaded update method, characterized by, The method is applied to an electronic device running a main thread and a plurality of sub-threads, and comprises: obtaining to-be-updated skeletal animation data in a process in which the main thread performs scene updating; equally distributing the to-be-updated skeletal animation data to a plurality of task data lists corresponding to the sub-threads; if the sub-thread is not currently in an updating state, waking up the sub-thread to update the to-be-updated skeletal animation data in the task data list, or if the sub-thread is currently in an updating state, using the sub-thread to update the to-be-updated skeletal animation data in the task data list; after the main thread completes scene updating, synchronizing the updated skeletal animation data of the sub-thread to the main thread.
2. The method of claim 1, wherein, The task data list corresponds to a task end index and a completion index; the task end index represents a position index corresponding to the last to-be-updated skeletal animation data in the task data list, and the completion index represents a position index corresponding to the most recently updated skeletal animation data in the task data list; the method further comprises: obtaining a current update identifier of the sub-thread; if the update identifier is a first preset value and the completion index is less than the task end index, updating the current update identifier of the sub-thread from the first preset value to a second preset value; the first preset value represents that the sub-thread is not in an updating state, and the second preset value represents that the sub-thread is in an updating state; if the update identifier is the second preset value and the completion index is equal to the task end index, updating the current update identifier of the sub-thread from the second preset value to the first preset value.
3. The method of claim 2, wherein, The method further comprises: updating the completion index corresponding to the task data list each time the sub-thread completes updating of one to-be-updated skeletal animation data; updating the task end index corresponding to the task data list each time one to-be-updated skeletal animation data is added to the task data list corresponding to the sub-thread.
4. The method of claim 1, wherein, The method further comprises: obtaining an arrangement order of the plurality of sub-threads; after obtaining the to-be-updated skeletal animation data each time, adding the to-be-updated skeletal animation data to the task data list of the corresponding sub-thread according to the arrangement order of the plurality of sub-threads.
5. The method of claim 4, wherein, The method further comprises: synchronizing the updated skeletal animation data of each sub-thread to the main thread according to the arrangement order of the plurality of sub-threads.
6. The method of claim 1, wherein, The method further comprises: if the to-be-updated skeletal animation data in the task data list corresponding to the sub-thread have all been updated, synchronizing the updated skeletal animation data of the sub-thread to the main thread. If the sub-thread corresponding to the task data list of the to-be-updated skeletal animation data is not all updated, the sub-thread currently updated skeletal animation data is synchronized to the main thread, and after the sub-thread updates the remaining skeletal animation data, the updated remaining skeletal animation data is synchronized to the main thread.
7. An animated multithreaded update system, characterized by The system is applied to an electronic device running a main thread and a plurality of sub-threads, and comprises: An acquisition module configured to acquire to-be-updated skeletal animation data during scene updating of the main thread; An asynchronous updating module configured to evenly distribute the to-be-updated skeletal animation data to a plurality of task data lists corresponding to the sub-threads, and if the sub-thread is not currently in an updating state, wake up the sub-thread to update the to-be-updated skeletal animation data in the task data list, and if the sub-thread is currently in the updating state, use the sub-thread to update the to-be-updated skeletal animation data in the task data list; A synchronous updating module configured to synchronize the sub-thread updated skeletal animation data to the main thread after the scene updating of the main thread is completed.
8. The animated multithreaded update system of claim 7, wherein, The task data list corresponds to a task end index and a completion index; the task end index represents a position index corresponding to the last to-be-updated skeletal animation data in the task data list, and the completion index represents a position index corresponding to the most recently updated skeletal animation data in the task data list; and the asynchronous updating module is configured to: Acquire a current update identifier of the sub-thread; If the update identifier is a first preset value and the completion index is less than the task end index, update the current update identifier of the sub-thread from the first preset value to a second preset value; the first preset value represents that the sub-thread is not in the updating state, and the second preset value represents that the sub-thread is in the updating state; If the update identifier is the second preset value and the completion index is equal to the task end index, update the current update identifier of the sub-thread from the second preset value to the first preset value.
9. An electronic device, comprising: A processor and a memory, the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the animation multi-thread updating method of any one of claims 1-6.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the animation multi-thread updating method of any one of claims 1-6.