A game object rendering method, device, equipment and storage medium

By creating entity composition classes for the game engine, optimizing the rendering process, and utilizing caching strategies and off-screen canvas technology, the performance bottleneck of the lightweight engine when handling complex game objects was resolved, achieving efficient rendering performance and smoothness.

CN121349458BActive Publication Date: 2026-03-17CHANGAN AUTO FINANCE CO LTD
View PDF -1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-16
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing game engines suffer from poor rendering performance, wasted resources, and insufficient architectural abstraction when handling complex game objects. In particular, lightweight engines experience excessive CPU computation and application graphics rendering interface calls when dealing with composite objects composed of multiple sub-components, resulting in long loading times and high development barriers.

Method used

By creating an entity composition class that includes dirty flags, a list of sub-entities, an off-screen canvas, and a caching strategy, the rendering process of game objects is optimized. The caching strategy is used to determine the state of the dirty flags, clear the off-screen canvas, and draw the sub-entities after clearing it. The rendering state of the main canvas is obtained, and finally the off-screen cached image is drawn onto the main canvas, merging them into a single drawing call.

Benefits of technology

It significantly improves the rendering performance of the game engine, reduces the computational overhead of the central processing unit and the call frequency of the application's graphics drawing interface, ensures smoothness at high frame rates, and solves the core performance bottleneck of the lightweight game engine when dealing with complex scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121349458B_ABST
    Figure CN121349458B_ABST
Patent Text Reader

Abstract

The application discloses a game object rendering method and device, equipment and storage medium, relates to the technical field of rendering, and includes the following steps: obtaining an entity combination class of a target game object; the entity combination class has all transformation attributes of the target game object and includes the attributes of a dirty mark, a child entity list, an off-screen canvas in the memory and a cache strategy; judging whether the state of the dirty mark is true based on the cache strategy; if the state is true, emptying the off-screen canvas to obtain an emptied canvas; traversing all child entities in the child entity list, respectively drawing the child entities into the emptied canvas to obtain an off-screen cache image, and obtaining a rendering state of a main canvas; calling an image drawing function of the main canvas based on the transformation attributes, so as to directly draw the entire off-screen cache image to a specified position of the main canvas, and restoring the rendering state of the main canvas. The application can reduce the calculation overhead of the CPU and the calling frequency of the API, and improve the rendering performance of the game engine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of rendering technology, and in particular to a method, apparatus, device and storage medium for rendering game objects. Background Technology

[0002] With the popularization of web technologies, lightweight web games, interactive advertising, and educational applications based on HTML5 Canvas 2D (a graphics drawing element provided by the HTML5 standard, which uses JavaScript to achieve dynamic 2D / 3D image rendering on web pages, supporting scenarios such as game development, data visualization, and animation production) are becoming increasingly common. To improve development efficiency, developers typically use JavaScript (a lightweight programming language) game engines for game development.

[0003] However, current game engines suffer from two main problems: heavy-duty engines, while powerful, are complex and bulky, leading to over-design for lightweight applications, resulting in long loading times, steep learning curves, increased development barriers, and higher resource consumption. Lightweight or procedural engines, on the other hand, typically iterate through and draw all game objects one by one in the main rendering loop, but they have significant drawbacks when handling composite objects composed of multiple sub-components: First, rendering performance is poor, as each sub-component requires independent coordinate transformation and drawing calls per frame, causing the computational load on the Central Processing Unit (CPU) and the number of API calls to increase linearly with the number of sub-components. Second, caching strategies are rigid; even with off-screen caching, most redraws are unconditional per frame, failing to intelligently identify object state changes and wasting resources. Furthermore, insufficient architectural abstraction makes it difficult to transform and manage the lifecycle of composite objects as a whole, limiting the ability to build complex scenes.

[0004] Therefore, there is an urgent need for a game engine that does not rely on heavy technology and has a simple architecture to optimize the rendering performance of complex game objects. Summary of the Invention

[0005] In view of this, the purpose of this application is to provide a game object rendering method, apparatus, device, and storage medium, applied to a game engine, which can reduce the computational overhead of the central processing unit and the call frequency of the application's graphics drawing interface, significantly improve the rendering performance of the game engine, ensure smoothness at high frame rates, and solve the core performance bottleneck of lightweight game engines when handling complex scenes. The specific solution is as follows:

[0006] Firstly, this application discloses a game object rendering method, applied to a game engine, including:

[0007] Determine the target game object to be rendered and obtain the entity composition class of the target game object; the entity composition class has all the transformation attributes of the target game object, and includes attributes such as dirty flag, sub-entity list, off-screen canvas in memory and caching strategy;

[0008] Based on the caching strategy in the entity composition class, determine whether the state of the dirty flag is true. If the state of the dirty flag is true, clear the off-screen canvas in the entity composition class to obtain the cleared canvas.

[0009] Traverse all sub-entities in the sub-entity list and draw each sub-entity onto the cleared canvas to obtain the off-screen cached image, and obtain the current main canvas rendering state to obtain the current canvas rendering state.

[0010] The image drawing function of the main canvas is called based on the transformation attribute to draw the entire off-screen cached image directly to the specified position of the main canvas and restore the rendering state of the main canvas to the current canvas rendering state.

[0011] Optionally, the caching strategy includes resident caching mode, static caching mode, adaptive caching mode, and no caching mode;

[0012] Accordingly, the step of determining whether the state of the dirty flag is true based on the caching strategy in the entity composition class, and if the state of the dirty flag is true, then clearing the off-screen canvas in the entity composition class to obtain the cleared canvas, includes:

[0013] If the caching strategy is a persistent caching mode, then determine whether the dirty flag status in the entity composite class is true;

[0014] If the state of the dirty flag in the entity composition class is false, the previous frame cached image in the off-screen canvas is reused, and the image drawing function of the main canvas is called based on the transformation attribute to directly draw the previous frame cached image to the specified position of the main canvas.

[0015] If the state of the dirty flag is true, then clear the off-screen canvas in the entity composition class to obtain the cleared canvas;

[0016] Accordingly, after drawing each of the sub-entities onto the cleared canvas to obtain the off-screen cached image, the process further includes:

[0017] Reset the state of the dirty flag in the entity composition class to false.

[0018] Optionally, determining whether the state of the dirty flag is true based on the caching strategy in the entity composition class, and if the state of the dirty flag is true, then clearing the off-screen canvas in the entity composition class to obtain the cleared canvas includes:

[0019] If the caching strategy is a static caching mode, then determine whether the dirty flag status in the entity composite class is true;

[0020] If the state of the dirty flag is true, then clear the off-screen canvas in the entity composition class to obtain the cleared canvas;

[0021] Accordingly, after drawing each of the sub-entities onto the cleared canvas to obtain the off-screen cached image, the process further includes:

[0022] The state of the dirty flag in the entity composition class is reset to false, the current caching strategy is switched from the static caching mode to the no-caching mode, and the cleared canvas after drawing the sub-entity is destroyed.

[0023] Optionally, after obtaining the entity composition class of the target game object, the method further includes:

[0024] If the caching strategy is an adaptive caching mode, then monitor whether the state of the dirty mark becomes true within a first consecutive number of frames;

[0025] If the state of the dirty flag becomes true within a first number of consecutive frames, the current caching strategy is switched from the adaptive caching mode to the resident caching mode, an off-screen canvas is created, and the process jumps to the step of determining whether the state of the dirty flag in the entity composite class is true if the caching strategy is in the resident caching mode.

[0026] Optionally, after switching the current caching strategy from the adaptive caching mode to the persistent caching mode and creating the off-screen canvas, the method further includes:

[0027] If the caching strategy is a resident caching mode, and the state of the dirty flag does not become true within a second consecutive number of frames, then the current caching strategy is switched from the resident caching mode to the no-caching mode.

[0028] Optionally, the game object rendering method further includes:

[0029] If the caching strategy is a no-caching mode, then obtain the current main canvas rendering state to get the current canvas rendering state.

[0030] Iterate through all the sub-entities in the sub-entity list, draw each sub-entity to a specified position on the main canvas, and restore the state of the main canvas to the current canvas rendering state.

[0031] Optionally, the game object rendering method further includes:

[0032] When any change is detected in any sub-entity within the sub-entity list of the entity composition class, the state of the dirty flag in the entity composition class is set to true; the dirty flag is used to indicate whether the content in the off-screen canvas has expired.

[0033] Secondly, this application discloses a game object rendering apparatus for use in a game engine, comprising:

[0034] The determination module is used to determine the target game object to be rendered;

[0035] The composite class acquisition module is used to acquire the entity composite class of the target game object; the entity composite class has all the transformation attributes of the target game object, and includes attributes such as dirty flag, sub-entity list, off-screen canvas in memory, and caching strategy;

[0036] The judgment module is used to determine whether the state of the dirty mark is true based on the caching strategy in the entity composition class;

[0037] The clear module is used to clear the off-screen canvas in the entity composition class if the state of the dirty mark is true, so as to obtain the cleared canvas.

[0038] The traversal module is used to traverse all sub-entities in the sub-entity list and draw each sub-entity onto the cleared canvas to obtain an off-screen cached image.

[0039] The state acquisition module is used to obtain the current rendering state of the main canvas.

[0040] The calling module is used to call the image drawing function of the main canvas based on the transformation attribute, so as to draw the entire off-screen cached image directly to the specified position of the main canvas;

[0041] The state restoration module is used to restore the rendering state of the main canvas to the current canvas rendering state.

[0042] Thirdly, this application discloses an electronic device, including a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the aforementioned game object rendering method.

[0043] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned game object rendering method.

[0044] As can be seen, this application is applied to a game engine. First, the target game object to be rendered is determined, and the entity composition class of the target game object is obtained. The entity composition class has all the transformation attributes of the target game object, including attributes such as dirty flag, sub-entity list, off-screen canvas in memory, and caching strategy. Then, based on the caching strategy in the entity composition class, it is determined whether the state of the dirty flag is true. If the state of the dirty flag is true, the off-screen canvas in the entity composition class is cleared to obtain the cleared canvas. Then, all sub-entities in the sub-entity list are traversed, and each sub-entity is drawn onto the cleared canvas to obtain the off-screen cached image. Then, the rendering state of the current main canvas is obtained to obtain the current canvas rendering state. Finally, based on the transformation attributes, the image drawing function of the main canvas is called to directly draw the entire off-screen cached image onto the specified position of the main canvas, and the rendering state of the main canvas is restored to the current canvas rendering state. This application pre-creates corresponding entity composition classes for different game objects. These entity composition classes possess all the transformation attributes of the game objects, including attributes such as dirty flags, a list of child entities, an off-screen canvas in memory, and a caching strategy. This allows for real-time rendering of game objects directly based on the state of the dirty flags in the corresponding entity composition classes. Specifically, the rendering operation is performed based on the caching strategy to determine if the dirty flag state is true. If true, the content of the off-screen canvas is cleared, and all child entities in the child entity list are drawn on the cleared off-screen canvas, resulting in a pre-rendered static cached image. This static cached image is then drawn onto the main canvas all at once. The method of rendering game objects by combining entity composition classes and creating cached images on an off-screen canvas can encapsulate the internal structure of complex game objects in the pre-rendering stage of the off-screen canvas. All transformation attributes (such as rotation, scaling, and translation) only apply to the last drawing operation. This merges complex game objects that require N drawings and application graphics drawing interface calls into a single drawing call. This greatly reduces the computing overhead of the central processing unit and the frequency of application graphics drawing interface calls, and significantly improves the rendering performance of the game engine. At the same time, it ensures smoothness at high frame rates, thus solving the core performance bottleneck of lightweight game engines when handling complex scenes. Attached Figure Description

[0045] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0046] Figure 1This is a flowchart of a game object rendering method disclosed in this application;

[0047] Figure 2 This is a schematic diagram of the system core class structure of a specific game engine disclosed in this application;

[0048] Figure 3 This is a schematic diagram of a game object rendering device disclosed in this application;

[0049] Figure 4 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

[0050] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0051] This application discloses a game object rendering method, applied to a game engine; see [link to relevant documentation]. Figure 1 As shown, the method includes:

[0052] Step S11: Determine the target game object to be rendered and obtain the entity composition class of the target game object; the entity composition class has all the transformation attributes of the target game object, and includes attributes such as dirty flag, sub-entity list, off-screen canvas in memory and caching strategy.

[0053] It should be noted that the game object rendering scheme proposed in this application is applied to a lightweight game engine. It is entirely based on the native Canvas 2D API, without relying on heavyweight technologies such as WebGL (Web Graphics Library, a 3D drawing protocol). While maintaining the engine's lightweight nature and low barrier to entry, it can provide the same complex scene rendering capabilities as heavyweight game engines, thereby optimizing rendering performance and adapting to the development needs of lightweight 2D games in a web environment. Specifically, the game engine can be started by calling Engine.init(). After startup, the engine automatically completes initialization operations such as canvas creation, screen adaptation configuration, and resource loading. Furthermore, through the engine's built-in animation system (such as property animation and frame animation) and event listening mechanism, dynamic entity effects and user interaction logic can be implemented.

[0054] It's understandable that in a game rendering scene, there are three concepts: Entity, Object, and Class, and these three are logically related. An entity is a physical entity in the real world; an object is a logical mapping of an entity in the computer (i.e., an instance created in memory during program runtime, containing attributes (data) and methods (behaviors)); and a class is an abstract description of objects with the same attributes and behaviors (i.e., a template defining objects; an instance of a class is an object). These three form a hierarchical abstraction relationship from reality to code: Entity → Object → Class.

[0055] It should be noted that this application optimizes the system architecture of traditional lightweight game engines, resulting in a simpler core system architecture. Specifically, it comprises three main base classes: the Engine core base class, the Stage base class, and the Entity base class. The Engine core base class, as a static singleton, is responsible for global state management, resource loading, and driving the main rendering loop. The Stage base class manages all instances of the Entity base class (i.e., instances of the Game Entity base class) within a specific scene. The Entity base class is the base class for all renderable game objects, encapsulating common / basic transformation attributes such as position, size, and transformation, as well as drawing interfaces. For details, see [link to relevant documentation]. Figure 2 As shown, the engine core base class can directly manage the stage base class, and the stage base class contains the game entity base class. See also... Figure 2 As shown, alongside the EntityGroup class are other classes, such as the Text and Rect classes, all of which inherit from the game's Entity base class. Furthermore, the Engine core base class can also manage the WebSocket network communication module based on the HTTPS protocol (Hypertext Transfer Protocol Secure). If the game needs to implement real-time data interaction (such as leaderboards, multiplayer online games, etc.), it can establish a network connection through the WebSocket function encapsulated in the WebSocket network communication module.

[0056] Additionally, see Figure 2As shown, this application also pre-creates corresponding entity composition classes (EntityGroup) for different game objects. These entity composition classes (EntityGroup) inherit from the game entity base class (Entity), making them transformable independent entities themselves. They possess all the transformation attributes of an independent game object (such as position, rotation, scaling, and transparency). Furthermore, they extend the following core attributes:

[0057] EntityList: An array used to store all the child entities (which can be simple game entities or other entity composite classes) corresponding to any game object's child components.

[0058] Off-screen canvas (cacheCanvas): A canvas element created in memory that is detached from the main screen (i.e., the main canvas) and used as a dedicated drawing buffer;

[0059] The dirty flag (isDirty): A boolean flag used for selecting and switching dynamic caching strategies, and indicating whether the cached content in the off-screen canvas of the EntityGroup has expired;

[0060] Caching strategy: An enumeration property that defines the caching strategy of this object, specifically including four modes: resident caching mode, static caching mode, adaptive caching mode, and no caching mode.

[0061] It's worth noting that caching strategies can be automatically configured through an intelligent, multi-modal caching strategy state machine, dynamically selecting the optimal rendering path for each game object to achieve a balance between computational performance and memory usage. Furthermore, the caching strategy is transparent to developers or simple to configure, allowing them to benefit from intelligent rendering process optimization without needing to concern themselves with the underlying implementation details.

[0062] Additionally, when creating an EntityGroup, its off-screen canvas (cacheCanvas) and dirty flag (isDirty = true) must be initialized first. Since EntityGroup inherits from the game's base entity class (Entity), it can be seamlessly integrated into the architecture of traditional game engines. This allows developers to manipulate a complex EntityGroup as if it were a single sprite (i.e., a basic graphic), achieving logical consistency and code clarity, thus reducing development complexity. Furthermore, EntityGroup can nest entities of any type, providing powerful and flexible support for building complex UI (User Interface) panels, character animations, particle effect combinations, and more.

[0063] Furthermore, the EntityGroup class boasts a highly abstract architecture, facilitating flexible use. As a base class for game entities, EntityGroup can be seamlessly integrated into game engines and supports unlimited nesting. Developers can construct complex game objects like building blocks, enjoying unified transformation management and lifecycle control, resulting in clear code and extremely high maintainability. Moreover, the inheritance design of EntityGroup makes managing and transforming complex game objects no different from managing simple ones. Combined with a powerful nested transformation inheritance mechanism, it provides an intuitive and efficient tool for building extremely complex game scenes.

[0064] Specifically, the game entity base class can drive the main rendering loop using the browser's native API requestAnimationFrame (an API for optimizing animation effects), performing corresponding operations on each frame sequentially. For example: timestamp verification: calculating the time difference between the current frame and the previous frame to ensure the frame rate does not exceed the set maximum FPS (Frames Per Second); canvas clearing: clearing the content of the currently off-screen canvas; entity rendering: after sorting by entity hierarchy, calling the private drawing method of each child entity to draw each child entity in the child entity list; displaying frames per second: displaying the current frame rate in real-time in the upper left corner of the canvas; animation updating: automatically calling private animation methods in the private drawing methods of child entities to update property animations or frame animation states.

[0065] In this embodiment, when the lightweight game engine receives a game object rendering request, it first determines the target game object to be rendered, and then obtains the entity composition class of the target game object. The entity composition class possesses all the transformation attributes of the target game object (such as position, rotation, scaling, etc.), and also includes attributes such as dirty flags, a list of sub-entities, an off-screen canvas in memory, and a caching strategy. Specifically, it can first traverse all game entity base classes (Entities) within the current stage base class (Stage) to determine the entity composition class corresponding to the target game object to be rendered, initialize its sub-entity list, and initialize the caching strategy according to preset values ​​or default rules.

[0066] Step S12: Determine whether the state of the dirty flag is true based on the caching strategy in the entity composition class. If the state of the dirty flag is true, clear the off-screen canvas in the entity composition class to obtain the cleared canvas.

[0067] It's important to note that when the game engine's main loop executes rendering operations, for entities of type EntityGroup, the rendering process doesn't begin immediately at the start of each frame. Instead, the engine first determines the processing path for that EntityGroup based on the caching strategy (i.e., different caching strategies correspond to different rendering methods). For caching strategies that require checking for dirty flags (such as persistent caching, intelligent adaptive caching, and static caching), the engine first checks whether the isDirty flag is in a dirty state.

[0068] In this embodiment, after obtaining the entity group class of the target game object, the state of the dirty flag can be determined based on the caching strategy in the entity group class (EntityGroup) (i.e., whether the dirty flag is in a dirty state). If the state of the dirty flag is true (i.e., the state of the dirty flag is true, and it is in a dirty state), then all the content in the off-screen canvas in the entity group class is cleared to obtain a cleared canvas.

[0069] In this embodiment, before rendering game objects, the state of the dirty flag needs to be set. Specifically, when any change is detected in any sub-entity within the sub-entity list of the entity group, the state of the dirty flag in the entity group is set to true. The dirty flag indicates whether the content in the off-screen canvas has expired. For example, when any change is detected in any sub-entity within the sub-entity list of the entity group (EntityGroup), such as when a sub-entity is added or removed, the state of the dirty flag is set to true. Similarly, when the rendering state (e.g., image source, sprite, fill color, text content, etc.) of any sub-entity within the sub-entity list of the entity group (EntityGroup) changes, the state of the dirty flag is set to true. Furthermore, when the transformation attributes (e.g., position, rotation, scaling, etc.) of any sub-entity within the sub-entity list of the entity group (EntityGroup) change, the state of the dirty flag is set to true.

[0070] In a first specific implementation, determining whether the state of the dirty flag is true based on the caching strategy in the entity composition class, and if the state of the dirty flag is true, clearing the off-screen canvas in the entity composition class to obtain a cleared canvas, specifically may include: if the caching strategy is a resident caching mode, determining whether the state of the dirty flag in the entity composition class is true; if the state of the dirty flag in the entity composition class is false, reusing the previous frame cached image in the off-screen canvas, and calling the image drawing function of the main canvas based on the transformation attribute to directly draw the previous frame cached image to the specified position of the main canvas; if the state of the dirty flag is true, clearing the off-screen canvas in the entity composition class to obtain a cleared canvas. In this embodiment, if the caching strategy in the EntityGroup class is a persistent caching mode, it is determined whether the current dirty flag status is true. If it is true, the content in the off-screen canvas is cleared; if it is false, no pre-rendering operation is required, and the cached image of the previous frame in the off-screen canvas is directly reused, thereby avoiding a large number of unnecessary redrawing operations and greatly improving the rendering performance of the engine. Then, based on the transformation attribute (such as the transformation matrix), the image drawing function of the main canvas is called, thereby drawing the cached image of the previous frame in the off-screen canvas directly to the specified position of the main canvas to complete the rendering operation of the game object.

[0071] In a second specific implementation, the step of determining whether the dirty flag is true based on the caching strategy in the entity group class, and if the dirty flag is true, then clearing the off-screen canvas in the entity group class to obtain a cleared canvas, can specifically include: if the caching strategy is a static caching mode, then determining whether the dirty flag in the entity group class is true; if the dirty flag is true, then clearing the off-screen canvas in the entity group class to obtain a cleared canvas. In this embodiment, if the caching strategy in the entity group class (EntityGroup) is a static caching mode, then determining whether the current dirty flag is true; if it is true, then clearing the content in the off-screen canvas and continuing to execute the pre-rendering operation in step S13.

[0072] In another specific implementation, after obtaining the entity group class of the target game object, the process may further include: if the caching strategy is an adaptive caching mode, monitoring whether the state of the dirty flag becomes true within a first consecutive number of frames; if the state of the dirty flag becomes true within a first consecutive number of frames, switching the current caching strategy from the adaptive caching mode to the resident caching mode, creating an off-screen canvas, and jumping to the step of determining whether the state of the dirty flag in the entity group class is true if the caching strategy is a resident caching mode. In this embodiment, if the caching strategy in the entity group class (EntityGroup) is an adaptive caching mode, monitoring whether the state of the dirty flag becomes dirty (i.e., the state of the dirty flag is true) within M consecutive frames (e.g., 3 frames); if the state of the dirty flag becomes dirty within M consecutive frames (e.g., 3 frames), dynamically upgrading the current caching strategy to the resident caching mode, creating an off-screen canvas, and then directly jumping to the pre-rendering process corresponding to the resident caching mode. For complex game objects that change frequently, the persistent caching mode and adaptive caching mode can merge multiple application interface calls into one, thereby significantly reducing the computational overhead of the central processing unit and ensuring smoothness at high frame rates.

[0073] It's important to note that caching strategies can be selected based on the actual application scenario. There are four caching strategies: resident caching, static caching, adaptive caching, and no caching. The rendering flow for resident, static, and no caching modes is fixed, while the rendering flow for adaptive caching is not fixed. It requires monitoring the state of the dirty flag and switching to a fixed caching mode (such as resident caching) based on the monitoring results. Therefore, adaptive caching differs from other caching modes in that it flexibly switches between caching modes based on the state of the dirty flag (it can switch once or multiple times) and performs the corresponding rendering operations according to the fixed caching mode of the final rendering flow. Furthermore, while adaptive caching can switch to other caching modes, other caching modes (such as resident, static, and no caching) cannot switch to adaptive caching.

[0074] In another specific implementation, after switching the current caching strategy from the adaptive caching mode to the resident caching mode and creating the off-screen canvas, the process may further include: if the caching strategy is in the resident caching mode and the state of the dirty flag has not become true within a second consecutive number of frames, then the current caching strategy is switched from the resident caching mode to the no-caching mode. In this embodiment, if the current caching strategy is already in the resident caching mode and the state of the dirty flag has not become dirty within N consecutive frames (e.g., 60 frames), then the current caching strategy is dynamically downgraded to the no-caching mode. By using the static caching mode and downgrading the adaptive caching mode, unnecessary video memory / memory can be released in a timely manner, which is particularly suitable for memory-sensitive low-power devices or large game object rendering scenarios, avoiding memory bottlenecks caused by cache overload.

[0075] In this embodiment, the method further includes: if the caching strategy is a no-caching mode, obtaining the current rendering state of the main canvas; traversing all child entities in the child entity list, drawing each child entity to a specified position on the main canvas, and restoring the state of the main canvas to the current canvas rendering state. In this embodiment, if the current caching strategy is a no-caching mode, saving the current rendering state of the main canvas (i.e., the context of the main canvas), directly traversing and drawing all child entities in its child entity list on the main canvas, and then restoring the state of the main canvas to the rendering state saved before drawing.

[0076] Through the dynamic dirty marking mechanism, the game engine's system can intelligently perceive changes and update the caching strategy only when necessary, achieving precise allocation of computing resources. This is particularly suitable for scenarios with a large number of static or infrequently updated game objects.

[0077] Step S13: Traverse all sub-entities in the sub-entity list and draw each sub-entity onto the cleared canvas to obtain the off-screen cached image, and obtain the current main canvas rendering state.

[0078] In this embodiment, after clearing the content of the off-screen canvas, the following pre-rendering operation can be performed: traverse all child entities in the entity list (entityList) and call the drawing method of each child entity to draw each child entity onto the off-screen canvas with its position relative to the local coordinate system of the entity group, thus obtaining the off-screen cached image. Through the above pre-rendering operation, a complex game object composed of multiple child entities can be pre-rendered into a complete static image in memory. Additionally, it is necessary to obtain the current rendering state of the main canvas so that the main canvas state can be restored after the rendering operation.

[0079] Furthermore, this solution supports nesting one entity group within another, forming a complex hierarchical object tree. For nested child entity groups, this process is recursive. It triggers the complete rendering process of the child entity group itself (starting from step S11), and first ensures that its caching strategy is up-to-date before drawing the cached image of the child entity group onto the off-screen canvas of the current entity group. After rendering is complete, the dirty flag is reset to false.

[0080] It's important to note that in complex rendering scenarios where one EntityGroup nests another, the inheritance relationship of transformation properties is handled systematically: when the child EntityGroup is pre-rendered on the off-screen canvas of the parent EntityGroup, its own transformation properties (such as rotation and scaling) are applied first. When the parent EntityGroup draws the merged cached image onto the main canvas, the parent's transformation properties are applied to the cached image as a whole. This "child-first, parent-later" nested transformation inheritance mechanism allows developers to construct objects with complex motion relationships (such as a rotating turret mounted on a moving tank). Furthermore, through off-screen caching, multiple renderings at each layer are merged into a single operation. The computational performance overhead is only related to the composition hierarchy, and is exponentially related to the number of child entities within the same layer.

[0081] In this embodiment, after drawing each of the sub-entities onto the cleared canvas to obtain the off-screen cached image, the method further includes resetting the state of the dirty flag in the entity composite class to false. In this embodiment, if the caching strategy is a persistent caching mode, the state of the dirty flag in the entity composite class is reset to false after the pre-rendering operation.

[0082] In this embodiment, after drawing each of the sub-entities onto the cleared canvas to obtain the off-screen cached image, the process further includes: resetting the dirty flag state in the entity composite class to false, switching the current caching strategy from the static caching mode to the no-caching mode, and destroying the cleared canvas after drawing the sub-entities. In this embodiment, if the caching strategy is static caching mode, after the pre-rendering operation, the dirty flag state in the entity composite class is reset to false, the caching strategy is immediately and automatically switched to the no-caching mode, and the off-screen canvas (i.e., the canvas that has already drawn the cached image) is destroyed to release memory.

[0083] Step S14: Based on the transformation attribute, call the image drawing function of the main canvas to draw the entire off-screen cache image directly to the specified position of the main canvas, and restore the rendering state of the main canvas to the current canvas rendering state.

[0084] In this embodiment, after pre-rendering is completed, the EntityGroup class begins to actually draw on the main canvas. Specifically, the image drawing function of the main canvas can be called based on the above transformation attributes (such as position, rotation, scaling, etc.) to draw the entire off-screen cached image to the specified position of the main canvas at once (that is, to draw the entire off-screen canvas as a single image source to the specified position of the main canvas), and then the state of the main canvas is restored using the current canvas rendering state.

[0085] Furthermore, we can return to step S11. In the next frame of the game's main loop, all entity composite classes will again undergo intelligent scheduling based on their caching strategy and dynamically updated dirty marking state. In particular, for objects in adaptive caching mode, their behavior (the frequency of changes in dirty marking state) will be continuously monitored, and their actual caching strategy will be automatically and dynamically switched between resident caching mode and no caching mode. This intelligently determines whether to update their (i.e., entity composite class) off-screen cache, thereby achieving continuous and adaptive rendering optimization.

[0086] By combining a dynamic dirty marking mechanism with nested entity composition classes, rendering performance can be maximized while ensuring rendering correctness. Furthermore, by using off-screen caching to merge multiple renderings of complex game objects into a single operation (i.e., optimizing multiple rendering operations into a single rendering), and combining this with a dynamic caching strategy to avoid unnecessary redraws, the computational overhead of the central processing unit and the frequency of application graphics rendering interface calls are significantly reduced. This addresses the core performance bottleneck of lightweight game engines when handling complex scenes.

[0087] For example, consider the process of directly rendering a complex game object (such as a digital human composed of multiple sub-parts like a torso, limbs, and weapons) onto the main canvas. The core drawback is that the main rendering loop needs to iterate through and call each rendering instruction sequentially. For example, for a digital human with N sub-parts, each frame requires N CPU calculations and N application graphics rendering interface calls. When multiple such objects exist in the game scene, the number of calls increases dramatically, with a significant amount of CPU time consumed in state switching and instruction parsing, becoming the engine's main performance bottleneck. However, the rendering process proposed in this application pre-draws all sub-parts into an off-screen cache (virtual canvas), forming a complete static cache image. Furthermore, in the main rendering loop, only one rendering instruction call is needed to render this static cache image as a whole onto the main canvas. This significantly reduces the number of calls, directly reducing the CPU's computational burden and the browser's rendering engine workload, making it possible to maintain high frame rates on low-power devices or in complex game scenes.

[0088] As can be seen, this application embodiment pre-creates corresponding entity composition classes for different game objects. These entity composition classes possess all the transformation attributes of the game objects and include attributes such as a dirty flag, a list of child entities, an off-screen canvas located in memory, and a caching strategy. In this way, when rendering game objects in real time, rendering operations can be performed directly based on the state of the dirty flag in the corresponding entity composition class. Specifically, the caching strategy determines whether the dirty flag is true; if true, the content of the off-screen canvas is cleared, and all child entities in the child entity list are drawn on the cleared off-screen canvas to obtain a pre-rendered static cached image. Then, the static cached image is drawn onto the main canvas all at once. By rendering game objects using the aforementioned entity composition class and the method of creating cached images on an off-screen canvas, the internal structure of complex game objects can be encapsulated in the pre-rendering stage of the off-screen canvas. All transformation attributes (such as rotation, scaling, and movement) only apply to the last drawing operation. This merges complex game objects that require N drawings and application graphics drawing interface calls into a single drawing call. This greatly reduces the computational overhead of the central processing unit and the frequency of application graphics drawing interface calls, and significantly improves the rendering performance of the game engine. At the same time, it ensures smoothness at high frame rates, thus solving the core performance bottleneck of lightweight game engines when handling complex scenes.

[0089] Accordingly, this application also discloses a game object rendering apparatus, applied to a game engine, see [link to relevant documentation]. Figure 3 As shown, the device includes:

[0090] Module 11 is used to determine the target game object to be rendered;

[0091] The composite class acquisition module 12 is used to acquire the entity composite class of the target game object; the entity composite class has all the transformation attributes of the target game object, and includes attributes such as dirty flag, sub-entity list, off-screen canvas in memory and caching strategy;

[0092] The judgment module 13 is used to determine whether the state of the dirty mark is true based on the caching strategy in the entity composition class;

[0093] The clearing module 14 is used to clear the off-screen canvas in the entity composition class if the state of the dirty mark is true, so as to obtain the cleared canvas.

[0094] Traversal module 15 is used to traverse all sub-entities in the sub-entity list and draw each sub-entity onto the cleared canvas to obtain an off-screen cached image.

[0095] The state acquisition module 16 is used to obtain the current rendering state of the main canvas.

[0096] Module 17 is invoked to call the image drawing function of the main canvas based on the transformation attribute, so as to draw the entire off-screen cache image directly to the specified position of the main canvas.

[0097] The state restoration module 18 is used to restore the rendering state of the main canvas to the current canvas rendering state.

[0098] The specific workflow of each of the above modules can be found in the relevant content disclosed in the foregoing embodiments, and will not be repeated here.

[0099] Furthermore, embodiments of this application also disclose an electronic device, Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.

[0100] Figure 4 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the game object rendering method disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0101] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0102] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0103] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the game object rendering method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0104] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned game object rendering method. The specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.

[0105] Furthermore, embodiments of this application also disclose a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the game object rendering method disclosed above.

[0106] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0107] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0108] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0109] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only 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.

[0110] The above provides a detailed description of a game object rendering method, apparatus, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A game object rendering method, characterized by, The application is applied to a game engine, and comprises the following steps: determining a target game object to be rendered, and obtaining an entity combination class of the target game object; the entity combination class has all transformation attributes of the target game object, and comprises a dirty flag, a child entity list, an off-screen canvas in memory and attributes of a cache strategy; the dirty flag is a Boolean flag used for dynamically selecting and switching the cache strategy, and indicating whether the content cached in the off-screen canvas of the entity combination class is expired; judging whether the dirty flag is true based on the cache strategy in the entity combination class; if the dirty flag is true, emptying the off-screen canvas in the entity combination class to obtain an emptied canvas; traversing all child entities in the child entity list, and respectively drawing each child entity into the emptied canvas to obtain an off-screen cached image, and obtaining a current main canvas rendering state to obtain a current canvas rendering state; based on the transformation attributes, calling an image drawing function of the main canvas to directly draw the entire off-screen cached image to a specified position of the main canvas, and restoring the rendering state of the main canvas to the current canvas rendering state.

2. The game object rendering method of claim 1, wherein, the cache strategy comprises a resident cache mode, a static cache mode, an adaptive cache mode and a no-cache mode; correspondingly, the step of judging whether the dirty flag is true based on the cache strategy in the entity combination class, and if the dirty flag is true, emptying the off-screen canvas in the entity combination class to obtain an emptied canvas, comprises the following steps: if the cache strategy is the resident cache mode, judging whether the dirty flag in the entity combination class is true; if the dirty flag in the entity combination class is false, reusing a last frame cached image in the off-screen canvas, and based on the transformation attributes, calling an image drawing function of the main canvas to directly draw the last frame cached image to a specified position of the main canvas; if the dirty flag is true, emptying the off-screen canvas in the entity combination class to obtain an emptied canvas; correspondingly, after the step of respectively drawing each child entity into the emptied canvas to obtain an off-screen cached image, the method further comprises the following step: resetting the dirty flag in the entity combination class to false.

3. The game object rendering method of claim 2, wherein, the step of judging whether the dirty flag is true based on the cache strategy in the entity combination class, and if the dirty flag is true, emptying the off-screen canvas in the entity combination class to obtain an emptied canvas, comprises the following steps: if the cache strategy is the static cache mode, judging whether the dirty flag in the entity combination class is true; if the dirty flag is true, emptying the off-screen canvas in the entity combination class to obtain an emptied canvas; correspondingly, after the step of respectively drawing each child entity into the emptied canvas to obtain an off-screen cached image, the method further comprises the following step: resetting the dirty flag in the entity combination class to false, switching the current cache strategy from the static cache mode to a no-cache mode, and destroying the emptied canvas after drawing the child entities.

4. The game object rendering method of claim 3, wherein, The obtaining the entity combination class of the target game object further comprises: If the cache strategy is the adaptive cache mode, monitoring whether the state of the dirty flag becomes true within a continuous first number of frames; If the state of the dirty flag becomes true within a continuous first number of frames, switching the current cache strategy from the adaptive cache mode to the resident cache mode, creating an off-screen canvas, and jumping to the step of judging whether the state of the dirty flag in the entity combination class is true if the cache strategy is the resident cache mode.

5. The game object rendering method of claim 4, wherein, The switching the current cache strategy from the adaptive cache mode to the resident cache mode, and creating the off-screen canvas further comprises: If the cache strategy is the resident cache mode, and the state of the dirty flag does not become true within a continuous second number of frames, switching the current cache strategy from the resident cache mode to the no-cache mode.

6. The game object rendering method of claim 5, wherein, Further comprising: If the cache strategy is the no-cache mode, obtaining the rendering state of the current main canvas to obtain the current canvas rendering state; Traversing all the sub-entities in the sub-entity list, and respectively drawing each of the sub-entities to a specified position of the main canvas, and restoring the state of the main canvas to the current canvas rendering state.

7. The game object rendering method according to any one of claims 1 to 6, characterized in that, Further comprising: When any sub-entity in the sub-entity list of the entity combination class is monitored to change, setting the state of the dirty flag in the entity combination class to true; The dirty flag is used to indicate whether the content in the off-screen canvas has expired.

8. A game object rendering apparatus, characterized by comprising: Applied to a game engine, comprising: A determination module for determining a target game object to be rendered; An entity combination class acquisition module for acquiring an entity combination class of the target game object; the entity combination class has all transformation attributes of the target game object, and comprises a dirty flag, a sub-entity list, an off-screen canvas in the memory, and a cache strategy attribute; the dirty flag is a Boolean flag used for dynamic cache strategy selection and switching, and indicates whether the content cached in the off-screen canvas of the entity combination class has expired; A judgment module for judging whether the state of the dirty flag is true based on the cache strategy in the entity combination class; An emptying module for emptying the off-screen canvas in the entity combination class if the state of the dirty flag is true, to obtain an emptied canvas; A traversal module for traversing all the sub-entities in the sub-entity list, and respectively drawing each of the sub-entities to the emptied canvas, to obtain an off-screen cache image; A state acquisition module for obtaining the rendering state of the current main canvas to obtain a current canvas rendering state; A calling module for calling an image drawing function of the main canvas based on the transformation attributes, to directly draw the entire off-screen cache image to a specified position of the main canvas; A state restoring module for restoring the rendering state of the main canvas to the current canvas rendering state.

9. An electronic device, comprising: Comprise a processor and a memory; wherein the processor executes the computer program saved in the memory to realize the game object rendering method in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, A computer program product for storing a computer program; wherein the computer program is executed by a processor to implement the game object rendering method according to any one of claims 1 to 7.