Method and related device for realizing loading game resources of mini game
Through the file system bridging between mini-games and application clients, the problem of excessive engine heap memory consumption when mini-games load game resources is solved, achieving the effect of reducing the risk of memory corruption and enhancing compatibility.
Patent Information
- Application Number
- CN202410758498.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-06-13
AI Technical Summary
When existing mini-games load game resources, the engine heap memory consumption is too large, causing the mini-game memory to crash.
Through the file system bridge associated with the mini-game and the application client it depends on, it provides disk read and write capabilities, stores the game resource package in the disk space, and loads specific game resources from the disk space when needed, without the need to The entire game resource bundle is read into the engine heap.
It reduces the memory consumption of the engine heap and avoids the memory crash problem of mini-games, while maintaining the click-to-play advantage of mini-games.
Smart Images

Figure CN118312245B
Abstract
Description
Technical Field
[0001] The present application relates to the field of game development technology, and in particular to a method and related device for implementing loading of game resources for a mini-game. Background Art
[0002] Mini Programs are applications that use application clients (APPs) as their operating medium and can be used without downloading or installing. Mini Games are a category of Mini Programs that are click-and-play and offer a lightweight experience.
[0003] In the existing technical implementation, the game resource package downloaded by the mini-game through the network will be completely read into the engine stack, resulting in a large memory consumption of the engine stack, and the memory consumption of the engine stack is the primary culprit causing the memory crash of the mini-game.
[0004] Therefore, how to reduce the memory consumption of the engine stack to avoid the memory crash of the mini-game is a technical problem that needs to be solved urgently by technicians in this field. Summary of the invention
[0005] To solve the above technical problems, the embodiments of the present application provide a method and device for implementing mini-games loading game resources, an electronic device, a computer-readable storage medium, and a computer program product, so as to reduce the memory consumption of the engine stack and avoid memory crashes of mini-games.
[0006] One aspect of an embodiment of the present application provides a method for implementing a mini-game loading game resources, wherein the mini-game is exported through a game engine and runs based on an application client, and the application client runs on a terminal operating system. The method comprises: detecting whether the mini-game is bridged with a file system associated with the application client, the file system being used to manage a disk space corresponding to the application client, the disk space being used to store a game resource package corresponding to the mini-game; if so, loading target game resources from the disk space through the file system.
[0007] On the other hand, an apparatus for implementing loading of game resources for a mini-game is provided. The mini-game is exported through a game engine and runs based on an application client, and the application client runs on a terminal operating system. The apparatus includes: a first detection module, configured to detect whether the mini-game is bridged with a file system associated with the application client, the file system being used to manage a disk space corresponding to the application client, the disk space being used to store a game resource package corresponding to the mini-game; and a first loading module, configured to load target game resources from the disk space through the file system when the first detection module detects that the mini-game is bridged with a file system associated with the application client.
[0008] Another aspect of an embodiment of the present application provides an electronic device, including: one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the electronic device implements the method for loading game resources for a mini-game as described above.
[0009] Another aspect of an embodiment of the present application provides a computer-readable storage medium having computer-readable instructions stored thereon. When the computer-readable instructions are executed by a processor of a computer, the computer executes the method for implementing loading game resources for a mini-game as described above.
[0010] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method for loading game resources for a mini-game as described above.
[0011] In the technical solution provided in the embodiments of the present application, disk reading and writing capabilities are provided to the mini-game by means of a file system bridge associated with the mini-game and the application client on which it depends. Specifically, the game resource package of the mini-game is stored in the disk space corresponding to the application client, and the mini-game loads the target game resources from the disk space through the file system without reading the entire game resource package corresponding to the target game resources into the engine stack, thereby reducing the memory consumption of the engine stack and avoiding memory crashes in the mini-game.
[0012] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 It is a schematic diagram of the memory generated when a mini-game loads game resources in the existing technology implementation;
[0014] Figure 2 This is a memory diagram generated by a WebGL game when loading game resources in a web page environment;
[0015] Figure 3 This is a memory diagram generated by the APP game when loading game resources;
[0016] Figure 4 This is a schematic diagram of the memory generated when the mini-game proposed in the embodiment of the present application loads game resources;
[0017] Figure 5 is a flowchart of a method for implementing a mini-game loading game resources shown in an exemplary embodiment of the present application;
[0018] Figure 6This is another memory diagram generated when the mini-game proposed in the embodiment of the present application loads game resources;
[0019] Figure 7 is based on Figure 5 A flowchart of another exemplary method for implementing a method of loading game resources for a mini-game proposed in the illustrated embodiment;
[0020] Figure 8 is based on Figure 5 A flowchart of another exemplary method for implementing a mini-game loading game resources proposed in the illustrated embodiment;
[0021] Fig. 9 This is a flowchart of how a WeChat mini-game loads game resources from a developer's perspective;
[0022] Fig.10 This is a flowchart of how to uninstall game resources from a WeChat mini-game from a developer's perspective;
[0023] Fig.11 is a block diagram of a device for implementing loading game resources for a mini-game, shown in an exemplary embodiment of the present application;
[0024] Fig.12 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0025] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0026] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0027] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0028] The term "multiple" as used in this application refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0029] The terms "first", "second", "third" and "fourth" etc. in the specification and claims of the present application and the drawings are used to distinguish different objects, rather than to describe a specific order. The terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.
[0030] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0031] First of all, as mentioned above, mini programs refer to applications that use application clients as operating carriers and can be used without downloading and installing. Mini games are a category of mini programs, which have the characteristics of being click-to-play, no need to download and install, and a lightweight experience.
[0032] Mini games are classified by programming method, and can generally be divided into JS (Java Script, an interpreted or just-in-time compiled programming language) mini games and WASM (Web Assembly, a binary instruction format that can be run in a web browser) mini games. JS mini games use the JS programming language to describe their execution logic. The game engine and game business code are both JS codes, and their main user is the Cocos game engine. WASM mini games are also called heavy mini games. They use the WASM instruction format to describe their execution logic. The game engine and game business code are both WASM codes, and their main user is the Unity game engine. It should be understood that WASM mini games will be attached with some JS codes, and WASM is not a programming language, but an "executable file".
[0033] Emscripten is a tool that compiles C / C++ code into JS code or WASM code. For example, the game engine uses the Emscripten tool to export WebGL (Web Graphics Library, a technology for drawing and rendering three-dimensional graphics on web pages, allowing users to interact with them) game packages that can be run in browsers. Therefore, mini games can also be understood as a type of WebGL game that runs on an application client, and WebGL games are usually run on web pages.
[0034] Asset Bundle is a resource packaging technology in the Unity game engine. It allows developers to package game or application resources (such as textures, models, scenes, audio, etc.) into one file for dynamic loading at runtime. It can be simply understood as a compressed package of game resources.
[0035] The technical solution proposed in this application can be applied to small games exported through the Unity game engine and relying on the application client to run, or small games of the same type. The application scope of the technical solution proposed in this application is not limited here.
[0036] This type of mini-game uses resource packaging technology to load game resources. It can be understood that the download and storage of game resources are implemented in the form of compressed packages of game resources. This type of mini-game usually provides file caching capabilities, such as XHR (XML Http Request, a browser-built-in way of processing Http requests and responses) automatic caching. Based on this file caching capability, the mini-game can download game resources on demand instead of downloading all game resources when the game is started. The memory generated by this type of mini-game when loading game resources is as follows: Figure 1 shown.
[0037] It is important to understand that Figure 1 The JS memory shown is used to run the execution logic corresponding to the JS glue layer, and the WASM memory is used to run the execution logic corresponding to the game engine and the game business. In the embodiment of the present application, the JS memory is referred to as the running memory and the WASM is referred to as the virtual memory.
[0038] The JS glue layer refers to the interface layer between JS and WebGL, which allows JS code to call the interface of WASM code, or provides JS code interface for WASM code. Since WASM code does not support direct interaction with external components (such as network transmission components, disks and file systems, rendering and display, etc.), the JS glue layer is required to complete the interaction between the game execution logic and external components.
[0039] like Figure 1As shown in the figure, since network downloads need to be executed through the JS glue layer, the game resource package downloaded through the network will first be saved in the JS memory (file A), then copied to the WASM memory (file B), and the game resource package will be read directly from the WASM memory into the engine heap (Unity Heap) through the LoadFromMemory method. However, since what really needs to be loaded may only be part of the game resources contained in the game resource package, the memory consumption of the engine heap is relatively large, and the memory consumption of the engine heap is the primary culprit for the memory crash of the mini game.
[0040] Figure 2 This is a memory diagram of a WebGL game when loading game resources in a web page environment. In a web page environment, the disk is simulated in JS memory by the file system of the Emscripten tool, so all files need to be maintained in JS memory, and files that need to be persistently stored will be asynchronously written to indexDB (a non-relational database running in the browser) periodically. Figure 2 As shown, the game resource package downloaded through the network is first saved in the JS memory (file A), then copied to the WASM memory (file B), and then saved to the virtual disk simulated in the JS memory (file C). In this way, the game resources to be loaded can be read from the virtual disk to the engine stack (game resource D) through the LoadFromFile method, without the need to read the entire game resource package into the engine stack.
[0041] However, there are still memory issues that need to be optimized. For example, an extra copy of the game resource package (i.e., file C) will be generated in the JS memory to occupy memory, and a copy of the game resource package (i.e., file B) will also exist in the WASM memory to occupy memory. Although this copy of the game resource package will be released after the simulated disk successfully saves file C, due to the poor memory recycling and reuse performance of WASM, it will still have a negative impact on WASM memory.
[0042] Figure 3 This is a memory diagram generated when an APP game loads game resources. Usually, the game resources of an APP game are checked for updates when the game is started. All game resources are first downloaded from the network (file B), then saved to disk (file C), and then the actual game resources to be loaded are read from the disk through the LoadFromFile method (game resource D). It can be seen that since APP games have disk capabilities, the game resource package is saved on the disk, and unlike WebGL games, the game resource package is not saved in the disk simulated by JS memory to occupy memory.
[0043] based on Figure 1-3As shown in the figure, the memory generated when loading game resources by different types of games, the inventor of the present application thinks that: although the browser environment has no disk capability, the application client that the mini-game relies on has disk reading and writing capabilities. Therefore, by bridging the mini-game with the file system of the application client, specifically, the file system interface of the game engine can be modified to bridge to the file system of the application client. The mini-game can read only the game resources that need to be loaded into the engine stack like a WebGL game, instead of reading in the complete game resource package, and store the game resource package on the disk like an APP game, without occupying JS memory; combined with the file caching capability of the mini-game, it is possible to avoid downloading the game resource package in full when the game starts like an APP game, but download it when it is used, and then write it to the cache asynchronously, thereby retaining the advantage of the mini-game of being able to play as soon as it is clicked.
[0044] Therefore, an embodiment of the present application proposes to provide disk read and write capabilities for the mini-game by bridging the file system associated with the mini-game and the application client on which it depends, thereby optimizing the memory problem of the mini-game.
[0045] Figure 4 This is a memory diagram generated by the mini-game proposed in the embodiment of the present application when loading game resources. It can be seen that the game resource package downloaded from the network by the mini-game is first saved in the JS memory, and then asynchronously written to the disk space corresponding to the application client. Therefore, unlike WebGL games, an extra game resource package will not be generated in the virtual disk simulated by the JS memory to occupy memory. In addition, when the mini-game loads specific game resources, the specific game resources are read from the disk space to the engine heap of the WASM memory, without the need to load the entire game resource package into the engine heap, thereby reducing the memory consumption of the engine heap and avoiding memory crashes in the mini-game. At the same time, compared to WebGL games, WASM memory will not save complete game resource packages, which can also reflect the optimization of the mini-game memory by the embodiment of the present application.
[0046] The embodiments of the present application will be described in detail below.
[0047] See first Figure 5 , Figure 5 This is a flowchart of a method for implementing a method of loading game resources for a mini-game, as shown in an exemplary embodiment of the present application. It should be noted that the mini-game is exported through a game engine, so the game package of the mini-game contains a game engine code and a game service code. In addition, the mini-game runs based on an application client, which runs on a terminal operating system, so the application client has disk read and write capabilities.
[0048] like Figure 5As shown, in an exemplary embodiment, the method for implementing a mini-game to load game resources includes S510-S530, which are described in detail as follows:
[0049] S510, detecting whether the mini game is bridged with the file system associated with the application client.
[0050] First of all, it should be noted that the file system associated with the application client is used to manage the disk space corresponding to the application client, for example, to provide the ability to add, delete, and modify the disk.
[0051] The disk space corresponding to the application client is used to store the game resource package corresponding to the mini-game. Specifically, this embodiment bridges the file system associated with the mini-game and the application client, so that the mini-game also has disk reading and writing capabilities, saves the game resource package downloaded from the network to the disk, and reads the specific required game resources from the disk into the engine stack through the LoadFromFile method, without the need to read the entire game resource package into the engine stack.
[0052] The way to bridge the file system associated with the mini-game and the application client is to modify the file system interface of the game engine during the development stage of the mini-game to bridge it to the file system interface of the application client. Taking WeChat mini-games as an example, the application client it relies on to run is WeChat, represented by WX. Then the UnityWebRequestAssetBundle.GetAssetBundle interface of the game engine can be transformed into WXAssetBundle.GetAssetBundle, the DownloadHandlerAssetBundle interface can be transformed into DownloadHandlerWXAssetBundle, and the Unload interface can be transformed into WXUnload. It can be understood that the file system interface of the modified game engine is also some methods that can use the WeChat file system.
[0053] This embodiment detects whether the mini-game is bridged with the file system associated with the application client, and selects a specific method for loading game resources according to the detection result. If the detection result is that the mini-game is bridged with the file system associated with the application client, S520 is executed, and the game resources to be loaded are read from the disk space corresponding to the application client through the file system associated with the application client, without the need to load the entire game resource package where the game resources to be loaded are located into the engine stack, thereby reducing the memory consumption of the engine stack and avoiding the problem of memory crash in the mini-game. If the detection result is that the mini-game is not bridged with the file system associated with the application client, S530 is executed, and the game resource package is loaded from the virtual memory (i.e., WASM memory) as implemented in the prior art, thereby enabling the mini-game to run in a normal browser environment, thereby increasing the compatibility of the mini-game.
[0054] In some exemplary embodiments, it is possible to determine whether the mini-game is connected to the file system bridge associated with the application client by detecting whether the preset identifier is a target value. During the initialization process, the mini-game will detect the file system associated with the application client. If detected, the preset identifier will be set to the target value, and the target value is, for example, true. Therefore, when the preset identifier is detected as the target value, it can be determined that the mini-game is connected to the file system bridge associated with the application client. Otherwise, it is determined that the mini-game is not connected to the file system bridge associated with the application client.
[0055] S520, loading target game resources from the disk space through the file system associated with the application client.
[0056] When the file system associated with the mini-game and the application client is confirmed to be bridged, since the disk space corresponding to the application client is used to store game resource packages, the mini-game loads specific game resources, namely, target game resources, from the disk space corresponding to the application client through the file system associated with the application client. The target game resources can also be understood as the game resources required by the mini-game during operation.
[0057] The game resource package stored in the disk space is obtained by downloading the game resource package from the network. Since the network download is implemented through the glue layer code of the mini-game, the downloaded game resource package will be saved in the running memory of the mini-game and then stored in the disk space.
[0058] This embodiment does not need to load the game resource package where the target game resource is located into the engine stack, but loads the resource index information corresponding to the game resource package into the engine stack, and loads specific game resources according to the resource index information. For example, the game resource to be loaded is read from the disk into the engine stack through the LoadFromFile method, without reading the entire game resource package into the engine stack, thereby realizing the loading of the game resource. The resource index information is, for example, a resource index table or other formats, which are not limited here.
[0059] As an exemplary implementation, when the target game resource needs to be loaded, the game engine determines the location of the target game resource in the game resource package based on the resource index information, and then reads the content of the corresponding location in the game resource package through the file system to read the specific target game resource. It should be understood that since the glue layer logic runs in the running memory, the process of reading the target game resource from the disk space specifically occurs in the running memory, so the following can be obtained: Figure 6 The following is a diagram of the memory usage of the mini-game when loading game resources.
[0060] As another exemplary implementation, the game resource package may be read from the disk space into the running memory, and then the specific target game resource may be read from the running memory according to the resource index information loaded in the virtual memory. The memory diagram may also be represented as follows: Figure 6 shown.
[0061] It can be understood that the running memory of the mini-game is used to run the glue layer logic of the mini-game, and the running memory is also the JS memory; the virtual memory of the mini-game is used to run the game logic of the mini-game, which includes the execution logic corresponding to the game engine and the execution logic corresponding to the game business, and the virtual memory is also the WASM memory.
[0062] S530: Load the corresponding game resource package from the virtual memory included in the running memory of the mini-game.
[0063] If it is detected that the mini-game is not bridged with the file system associated with the application client, the corresponding game resource package is loaded from the virtual memory contained in the running memory of the mini-game. Exemplarily, the game resource package is filled into the DownloadHandler of UnityWebRequest and then loaded into the engine heap through the LoadFromMemory method, thereby realizing the loading of the corresponding game resource package from the virtual memory.
[0064] It should also be noted that since the network download is implemented through the glue layer code of the mini-game, the game resource package obtained by the mini-game through network download of the game resource package is saved in the running memory of the mini-game and then copied from the running memory to the virtual memory.
[0065] Therefore, in the technical solution provided in this embodiment, on the one hand, disk reading and writing capabilities are provided to the mini-game by means of a file system bridge that associates the mini-game with the application client on which it depends for running. The mini-game loads specific game resources from the disk space through the file system without having to read the entire game resource package into the engine stack, thereby reducing the memory consumption of the engine stack and avoiding memory crashes in the mini-game. On the other hand, the mini-game can also run in a normal browser environment, which increases the compatibility of the mini-game.
[0066] like Figure 7 As shown, in another exemplary embodiment, in Figure 5 Based on the embodiment shown, the method for implementing the loading of game resources for a mini-game further includes S710-S730, which are described in detail as follows:
[0067] S710, query whether a game resource package containing target game resources is cached in the running memory.
[0068] This embodiment takes into account that in some high-performance operating system environments, mini-games run in independent processes, such as the WebContent (web page content) process. The interaction between mini-games and application clients requires cross-process communication. If the disk space corresponding to the application client is read each time the game resources are loaded, it will cause high resource consumption.
[0069] To solve this problem, this application maintains a cache of game resource packages in the glue layer to ensure that only one cross-process communication is required when a large number of game resources in a game resource package are read in a short period of time.
[0070] The glue layer caches the game resource package, that is, caches the game resource package in the JS memory. Therefore, this embodiment queries whether the game resource package corresponding to the game resource to be loaded is cached in the running memory. If yes, it means that the game resource package containing the game resource to be loaded has been previously read into the running memory for caching, so S720 is executed to directly load the target game resource from the running memory according to the resource index information loaded in the virtual memory.
[0071] If the answer is no, it means that the corresponding game resource package is not cached in the running memory. Therefore, execute S730, read the game resource package from the disk space to the running memory through the file system associated with the application client, and then continue to execute S710, and the game resource package containing the target game resources can be queried from the running memory.
[0072] S720, load the target game resource from the running memory according to the resource index information loaded in the virtual memory.
[0073] Since the corresponding game resource package is cached in the running memory, the target game resource can be loaded from the running memory according to the resource index information loaded in the virtual memory, thereby avoiding loading the game resource through the disk space every time.
[0074] S730, read the game resource package from the disk space to the running memory through the file system.
[0075] Since the corresponding game resource package has not been cached in the running memory, the game resource package needs to be read from the disk space to the running memory for caching. Then, the game resource package containing the target game resources can be queried from the running memory, and then the target game resources can be loaded from the running memory according to the resource index information loaded in the virtual memory.
[0076] The technical solution provided in this embodiment, when determining that the mini-game has been bridged with the file system associated with the application client, will first query whether the corresponding game resource package is cached in the running memory when loading game resources. If so, the target game resource is read from the running memory according to the resource index information loaded in the virtual memory, so as to load the specific game resource. If not, the corresponding game resource package is read from the disk space to the running memory through the file system for caching. Therefore, it is not necessary to read from the disk space every time the game resource is loaded. When the mini-game reads the game resources contained in a game resource package, only one cross-process communication is performed, which can reduce resource consumption.
[0077] In another exemplary embodiment, the storage status of the game resource packages cached in the running memory may be periodically detected, and the game resource packages in the target status may be cleared, where the target status indicates that the game resource packages have not been read within a specified time period.
[0078] The target state game resource package is a game resource package that has not been read within a specified time period. This embodiment can reduce the memory consumption in the running memory by regularly cleaning up the game resource packages that have not been read within a specified time period, thereby optimizing the memory consumed by the mini-game to load game resources to a certain extent.
[0079] like Figure 8 As shown, in another exemplary embodiment, in Figure 5 Based on the embodiment shown, the method for implementing the loading of game resources for a mini-game further includes S810-S820, which are described in detail as follows:
[0080] S810, in response to a game resource loading request, registering a network address in a game engine, where the network address is used to indicate a source of the game resource to be loaded.
[0081] It can be understood that the game resource loading request is generated when the game resource needs to be loaded, and is used to indicate the network address of the source of the game resource to be loaded, that is, the URL for downloading the game resource package. In response to the game loading request, the mini game registers the corresponding network address in the game engine.
[0082] S820, registers the network address and disk path in the glue layer.
[0083] After registering the network address in the game engine, the glue layer is notified to register the network address and the corresponding disk path, wherein the disk path is used to indicate the storage location of the game resource package in the disk space. The file system associated with the application client also registers the disk path accordingly, so the glue layer can obtain the disk path through the file system associated with the application client. This embodiment is equivalent to realizing the initialization of game resource loading by performing the above registration process. After the initialization is completed, the specific game resource loading process, that is, the process shown in S510-S530, can be executed, thereby ensuring the logical perfection of the game resource loading process. It should also be noted that, illustratively, the game resource loading process provided by the embodiment of the present application can be provided to the mini-game developer in the form of a software development kit (SDK). That is, the mini-game developer can directly use the software development kit in the process of exporting the game package of the mini-game, so that the mini-game executes the process recorded in the above embodiment during operation.
[0084] During the running of the mini-game, when a request for instructing to call the resource loading interface provided by the software development kit is received, the request is determined as a game resource loading request, and the process of loading game resources is started.
[0085] In some exemplary embodiments, the mini-game also detects whether the glue layer has registered the corresponding network address and disk path during the process of loading game resources.
[0086] If it is detected that the glue layer has registered the network address and disk path, and the file system bridge associated with the mini-game and the application client is detected, it means that the target resource needs to be loaded from the disk space corresponding to the application client, so the step content corresponding to S520 is executed.
[0087] If it is detected that the glue layer has not registered the network address and disk path, but the file system bridge associated with the mini-game and the application client is detected, it means that the mini-game has target files that are not loaded using the SDK. Therefore, the target files are loaded from the simulated disk contained in the running memory, so that the mini-game is compatible with loading ordinary files while having the game resource package loaded using the SDK.
[0088] If it is detected that the glue layer has registered the network address and disk path, but the file system bridge associated with the mini-game and the application client is not detected, it means that the mini-game is running in an environment such as a browser. For example, the mini-game is debugged or tested in a browser on a PC (Personal Computer). Therefore, it is also necessary to ensure that the mini-game can run in a browser environment even if the SDK is used. Therefore, execute the corresponding steps of S530.
[0089] When a request for instructing to call the resource uninstallation interface provided by the software development kit is received, the game resource packages related to the mini-games stored in the disk space are cleaned up through the file system, thereby optimizing the disk space. It should be noted that the game resource packages related to the mini-games stored in the disk space cannot be cleaned up before the resources are uninstalled.
[0090] See also Fig. 9 and Fig.10 , Fig. 9 This is a flowchart of how WeChat Mini Games load game resources from a developer's perspective. Fig.10 This is a flowchart of how to uninstall game resources from a WeChat mini-game, taken from a developer's perspective.
[0091] Still taking WeChat Mini Games as an example, the software development kit provided in the embodiment of the present application is called WXAssetBundle, the resource loading interface is GetAssetBundle, and the resource unloading interface is WXUnload. When the GetAssetBundle interface is called, a game resource loading request is received, so the specific game resource loading process is executed. When the WXUnload interface is called, a game resource unloading request is received, so the specific game resource unloading process is executed.
[0092] See also Fig. 9From the example of the game resource loading process, it can be seen that the embodiment of the present application does not construct a new AssetBundle and Request type, but outsources a layer of registration logic in the original UnityWebRequest to implement the easy-to-migrate WXAssetBundle SDK. In this way, developers only need to use the WXAssetBundle SDK when loading the AssetBundle (game resource package), without having to modify the asynchronous handle type, game resource loading method, etc., which can minimize the developer's development costs. And in the specific loading process, the actual operation logic is determined by checking whether the WeChat file system is available. If there is no WeChat file system environment, it is determined that the file content callback needs to be filled, and the complete AssetBundle content is filled into the DownloadHandler of UnityWebRequest, and then loaded into the UnityHeap memory through the LoadFromMemory method, so that the exported small game package is still compatible with the browser WebGL environment. If there is a WeChat file system environment, it is determined not to fill the file content, and the target game resources are loaded into the UnityHeap memory through the LoadFromFile method.
[0093] See also Fig.10 In the example of the game resource uninstallation process, when the WXUnload interface is called, the specific game resource uninstallation process is executed to clean up the game resource package cached in the JS memory and the disk path corresponding to the mini-game in the WeChat disk. In this way, the game resource package uninstallation capability is realized without using new data types.
[0094] Fig.11 This is a block diagram of an apparatus for implementing loading game resources for a mini-game, shown in an exemplary embodiment of the present application. The mini-game is exported through a game engine and runs based on an application client, which runs on a terminal operating system. The apparatus includes:
[0095] A first detection module 1110 is configured to detect whether the mini-game is bridged with a file system associated with the application client, the file system is used to manage the disk space corresponding to the application client, and the disk space is used to store the game resource package corresponding to the mini-game;
[0096] The first loading module 1120 is configured to load target game resources from the disk space through the file system when the first detection module 1110 detects that the file system bridge associated with the mini-game and the application client is connected.
[0097] In another exemplary embodiment, the apparatus further comprises:
[0098] The first download module is configured to download the game resource package from the network and save the downloaded game resource package in the running memory, the running memory is used to run the glue layer logic of the mini-game, and the downloaded game resource package is stored in the disk space.
[0099] In another exemplary embodiment, the first loading module 1120 is further configured to perform the following steps:
[0100] Read the game resource package from the disk space to the running memory, which is used to run the glue layer logic of the mini-game;
[0101] According to the resource index information corresponding to the game resource package loaded in the virtual memory, the target game resources are read from the running memory. The virtual memory is used to run the game logic of the mini-game.
[0102] In another exemplary embodiment, the first loading module 1120 is further configured to perform the following steps:
[0103] Check whether there is a game resource package containing the target game resources cached in the running memory;
[0104] If not, execute the step of reading the game resource package from the disk space to the running memory through the file system;
[0105] If yes, the target game resource is loaded from the running memory according to the resource index information loaded in the virtual memory.
[0106] In another exemplary embodiment, the first loading module 1120 is further configured to perform the following steps:
[0107] Regularly check the storage status of the game resource packages cached in the running memory;
[0108] Clear the game resource package in the target state, where the target state indicates that the game resource package has not been read within the specified time period.
[0109] In another exemplary embodiment, the apparatus further comprises:
[0110] The second loading module is configured to load a game resource package containing target game resources from a virtual memory contained in a running memory of the mini-game when it is detected that the mini-game is not bridged with the file system.
[0111] In another exemplary embodiment, the apparatus further comprises:
[0112] The second download module is configured to download the game resources from the network, save the downloaded game resource package in the running memory, and copy the downloaded game resource package to the virtual memory.
[0113] In another exemplary embodiment, the first detection module 1110 is further configured to perform the following steps:
[0114] Detect whether the preset identifier is the target value; during the initialization process of the mini-game, if the file system associated with the application client is detected, the preset identifier is set to the target value;
[0115] If yes, make sure the mini game is bridged to the file system associated with the application client.
[0116] In another exemplary embodiment, the apparatus further includes a registration module, and the registration module is configured to perform the following steps:
[0117] In response to a game resource loading request, registering a network address in the game engine, the network address being used to indicate a source of the game resource to be loaded;
[0118] Register the network address and disk path in the glue layer. The disk path is used to indicate the storage location of the game resource package in the disk space. The glue layer obtains the disk path through the file system.
[0119] In another exemplary embodiment, the apparatus further comprises:
[0120] The second detection module is configured to detect whether the glue layer has registered the corresponding network address and disk path; if yes, execute the step of loading the target game resource from the disk space through the file system; if not, load the target file from the simulated disk contained in the running memory.
[0121] In another exemplary embodiment, when a request for instructing to call a resource loading interface provided by a software development kit is received, the request is determined to be a game resource loading request.
[0122] In another exemplary embodiment, the device further includes an uninstall module, which is configured to clean up the game resource package corresponding to the mini-game in the disk space through the file system when receiving a request for instructing to call a resource uninstall interface provided by the software development kit.
[0123] It should be noted that the device for implementing the loading of game resources for a mini-game provided in the above embodiment and the method for implementing the loading of game resources for a mini-game provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In actual applications, the device for implementing the loading of game resources for a mini-game provided in the above embodiment can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0124] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device implements the method for loading game resources for a mini-game provided in the above-mentioned embodiments.
[0125] Fig.12 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Fig.12 The computer system 1200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0126] like Fig.12 As shown, the computer system 1200 includes a central processing unit (CPU) 1201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1202 or the program loaded from the storage part 1208 to the random access memory (RAM) 1203, such as executing the method described in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1203. The CPU 1201, the ROM 1202 and the RAM 1203 are connected to each other through the bus 1204. The input / output (I / O) interface 1205 is also connected to the bus 1204.
[0127] The following components are connected to the I / O interface 1205: an input section 1206 including a keyboard, a mouse, etc.; an output section 1207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1208 including a hard disk, etc.; and a communication section 1209 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the I / O interface 1205 as needed. A removable medium 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1210 as needed so that a computer program read therefrom is installed into the storage section 1208 as needed.
[0128] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 1209, and / or installed from a removable medium 1211. When the computer program is executed by the central processing unit (CPU) 1201, various functions defined in the system of the present application are executed.
[0129] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. The computer program contained in the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0130] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0131] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0132] Another aspect of the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the method for implementing the aforementioned method of loading game resources for a mini-game is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0133] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method for implementing the loading of game resources for a mini-game provided in each of the above embodiments.
[0134] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
[0135] It can be understood that in the specific implementation of this application, data related to the file system, game resources, game resource packages, memory, etc. are involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
Claims
1. A method for realizing loading game resources of a mini-game, characterized in that: The mini-game is exported through a game engine and runs based on an application client, and the application client runs on a terminal operating system. The method includes: Detecting whether the game engine of the mini-game is bridged with the file system associated with the application client, the file system is used to manage the disk space corresponding to the application client, and the disk space is used to store the game resource package corresponding to the mini-game; If yes, read the game resource package from the disk space to the running memory, and the running memory is used to run the glue layer logic of the mini game; According to the resource index information corresponding to the game resource package loaded in the virtual memory, the target game resources are read from the running memory, and the virtual memory is used to run the game logic of the mini-game, and the game logic includes the execution logic corresponding to the game engine.
2. The method according to claim 1, characterized in that The method further comprises: Downloading a game resource package from the Internet, and saving the downloaded game resource package in the running memory; The downloaded game resource package is stored in the disk space.
3. The method according to claim 1, characterized in that The method further comprises: Querying whether a game resource package containing the target game resource is cached in the running memory; If not, executing the step of reading the game resource package from the disk space to the running memory through the file system; If yes, the target game resource is loaded from the running memory according to the resource index information loaded in the virtual memory.
4. The method according to claim 3, characterized in that: The method further comprises: Regularly checking the storage status of the game resource packages cached in the running memory; The game resource package of the target state is cleared, where the target state indicates that the game resource package has not been read within a specified time period.
5. The method according to claim 1, characterized in that The method further comprises: If it is detected that the game engine of the mini-game is not bridged with the file system, a game resource package including the target game resources is loaded from the virtual memory included in the running memory of the mini-game.
6. The method according to claim 5, characterized in that The method further comprises: Download the game resources from the network, and save the downloaded game resource package in the running memory; The downloaded game resource package is copied to the virtual memory.
7. The method according to claim 1, characterized in that The detecting whether the game engine of the mini-game is bridged with the file system associated with the application client includes: Detecting whether the preset identifier is a target value; during the initialization process of the mini-game, if the file system associated with the application client is detected, setting the preset identifier to the target value; If yes, it is determined that the game engine of the mini-game has been bridged with the file system associated with the application client.
8. The method according to claim 1, characterized in that: The method further comprises: In response to a game resource loading request, registering a network address in the game engine, the network address being used to indicate a source of the game resource to be loaded; The network address and disk path are registered in the glue layer, the disk path is used to indicate the storage location of the game resource package in the disk space, and the glue layer obtains the disk path through the file system.
9. The method according to claim 8, characterized in that The method further comprises: Detect whether the glue layer has registered the corresponding network address and disk path; If yes, execute the step of loading the target game resource from the disk space through the file system; If No, load the target file from the simulated disk contained in the running memory.
10. The method according to claim 8, characterized in that The method further comprises: When a request for instructing to call a resource loading interface provided by a software development kit is received, the request is determined to be a game resource loading request.
11. The method according to claim 1 or 10, characterized in that: The method further comprises: When a request for instructing to call a resource uninstallation interface provided by a software development kit is received, the game resource package corresponding to the mini-game in the disk space is cleaned up through the file system.
12. A device for realizing loading game resources of a mini-game, characterized in that: The mini-game is exported through a game engine and runs based on an application client, and the application client runs on a terminal operating system. The device includes: A first detection module is configured to detect whether the file system interface of the game engine of the mini-game is bridged with the file system associated with the application client, the file system is used to manage the disk space corresponding to the application client, and the disk space is used to store the game resource package corresponding to the mini-game; The first loading module is configured to read the game resource package from the disk space to the running memory when the first detection module detects the file system bridge associated with the mini-game and the application client, the running memory is used to run the glue layer logic of the mini-game, and read the target game resources from the running memory according to the resource index information corresponding to the game resource package loaded in the virtual memory, the virtual memory is used to run the game logic of the mini-game, and the game logic includes the execution logic corresponding to the game engine.
13. An electronic device, characterized in that: include: one or more processors; The memory is used to store one or more programs. When the one or more programs are executed by the one or more processors, the electronic device implements the method for loading game resources for a mini-game as described in any one of claims 1-11.
14. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method for implementing loading game resources for a mini-game as described in any one of claims 1-11.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for realizing loading game resources for a mini-game as described in any one of claims 1-11 is implemented.
