External script calling method, device, equipment and medium
By converting external script files into assemblies and creating key-value pair containers, the problem of slow external script calls is solved, and the smoothness of game operation is improved.
Patent Information
- Application Number
- CN202510885035.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2045-06-30
AI Technical Summary
The existing technology has a speed defect when calling external scripts in the game, which causes the game screen to freeze and affects the user experience.
By converting external script files into assemblies, obtaining function pointers and entity indication information, and creating key-value pair containers for convenient retrieval and parallel calling, the calling speed of external scripts is improved.
Significantly improved the calling speed of external scripts, reduced latency, and improved the smoothness of game operation.
Smart Images

Figure CN120386590B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of software technology, and in particular to a method, apparatus, device and medium for calling an external script. Background Art
[0002] In games, to more easily adjust and modify in-game data or rules, they often support modules (mods). Module scripts can be written in a specific scripting language, and the game can import these modules into the game by calling external scripts.
[0003] In related technologies, in order to enable a game to support modules, a corresponding script interpreter can be set in the game. When the script is called, the script interpreter parses the external script so that the game can execute the parsed script logic, such as adding new data or rules to the game, or combining multiple game native rules to obtain new rules.
[0004] However, this approach suffers from significant speed issues when calling external scripts. When importing a mod into a game, the script's invocation can easily cause delays, leading to game freezes and other undesirable issues, significantly impacting the user experience. Summary of the Invention
[0005] In order to solve the problems in the related art, the embodiments of the present disclosure provide a method, apparatus, device and medium for calling an external script.
[0006] In a first aspect, an embodiment of the present disclosure provides a method for calling an external script, comprising:
[0007] Read the external script file and obtain the assembly according to the external script file;
[0008] Get the function pointer corresponding to any method in the assembly, and get the entity indication information of the entity acted upon by any method;
[0009] Create a first key-value pair container with entity indication information of the entity acted upon by any method as a key and a function pointer corresponding to any method as a value;
[0010] Obtain any entity type in the external script file, and determine entity indication information of at least one entity corresponding to the entity type based on the entity type;
[0011] A target function pointer is obtained from a first key-value pair container using entity indication information of at least one entity as a key, and a function indicated by the target function pointer is executed.
[0012] In one embodiment of the present disclosure, the entity indication information includes at least one of an entity name, an entity category, and an entity tag.
[0013] In one embodiment of the present disclosure, obtaining a function pointer corresponding to any method in an assembly includes:
[0014] Get the metadata of any method in the assembly. The metadata includes at least the method name and method type of any method.
[0015] Get the entry address of any method in memory based on metadata;
[0016] Get the function pointer corresponding to any method based on the entry address.
[0017] In one embodiment of the present disclosure, determining entity indication information of at least one entity corresponding to any entity type based on any entity type includes:
[0018] Obtain at least one second key-value pair container, where the second key-value pair container uses the entity indication information as a key and a query set as a value, wherein the query set is used to indicate a correspondence between an entity type and an entity corresponding to a key of the second key-value pair container;
[0019] Based on the query set in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type is determined.
[0020] In one embodiment of the present disclosure, an operation of determining entity indication information of at least one entity corresponding to an entity type based on any entity type, and / or an operation of obtaining a target function pointer from a first key-value pair container with the entity indication information of at least one entity as a key and executing a function indicated by the target function pointer is performed in an operating system.
[0021] In one embodiment of the present disclosure, before creating a first key-value pair container using entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, the method further includes:
[0022] Wrap the function pointer corresponding to any method into a delegate and convert the delegate into an unmanaged function pointer;
[0023] Creating a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, including:
[0024] A first key-value pair container is created, which takes entity indication information of an entity acted upon by any method as a key and an unmanaged function pointer as a value.
[0025] In one embodiment of the present disclosure, the entity component is constructed based on at least one type of structure, the structure is an array of fixed length, and the structure continuously stores entity attribute data corresponding to each of a plurality of entity attributes;
[0026] Executing the function indicated by the target function pointer includes: executing the function indicated by the target function pointer to modify entity attribute data of the entity acted upon by the method corresponding to the target function.
[0027] In one embodiment of the present disclosure, at least one type of structure includes at least one of an attribute parameter structure, an attribute gain structure, and an attribute identification structure;
[0028] The attribute identification structure continuously stores the attribute identifications corresponding to multiple entity attributes; the attribute parameter structure continuously stores the attribute parameters corresponding to multiple entity attributes; and the attribute gain structure continuously stores the gain parameters corresponding to multiple entity attributes.
[0029] In a second aspect, an embodiment of the present disclosure provides an external script calling device, comprising:
[0030] The assembly acquisition module is configured to read an external script file and acquire an assembly according to the external script file;
[0031] a pointer acquisition module configured to acquire a function pointer corresponding to any method in the program set and to acquire entity indication information of an entity acted upon by any method;
[0032] a key-value pair container acquisition module configured to create a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value;
[0033] An entity determination module is configured to obtain any entity type in an external script file and determine entity indication information of at least one entity corresponding to the entity type based on the entity type;
[0034] The function execution module is configured to obtain a target function pointer from a first key-value pair container with entity indication information of at least one entity as a key, and execute the function indicated by the target function pointer.
[0035] In a third aspect, an embodiment of the present disclosure provides an electronic device comprising a memory and a processor, wherein the memory is used to store one or more computer instructions, and wherein the one or more computer instructions are executed by the processor to implement a method as described in any one of the first aspects.
[0036] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the method as described in any one of the first aspects.
[0037] According to an embodiment of the present disclosure, by first converting an external script file into an assembly, obtaining the function pointer corresponding to any method in the assembly and the entity indication information of the entity acted upon by the method, creating a first key-value pair container with the entity indication information of the entity acted upon by any one of the methods as the key and the function pointer corresponding to any one of the methods as the value, the various methods in the script file are split and their program codes are saved separately in an easily searchable manner. The key-value pair container has the advantages of high retrieval efficiency and fast speed. By saving the entity indication information and the function pointer corresponding to the method in the key-value pair container in the form of a key value, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and delays can be reduced. At the same time, saving the function pointers of each method separately also facilitates subsequent parallel calls to them, further improving the speed of external script calls.
[0038] 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 disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:
[0040] Figure 1 A flowchart of a method for calling an external script according to an embodiment of the present disclosure is shown.
[0041] Figure 2 A structural block diagram of an external script calling device according to an embodiment of the present disclosure is shown.
[0042] Figure 3 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.
[0043] Figure 4 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0044] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.
[0045] In the present disclosure, it should be understood that terms such as "include" or "have" are intended to indicate the presence of features, numbers, steps, actions, components, parts, or combinations thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other features, numbers, steps, actions, components, parts, or combinations thereof exist or are added.
[0046] It should also be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0047] In this disclosure, if it involves operations of obtaining user information or user data or displaying user information or user data to others, such operations are all authorized and confirmed by the user, or actively selected by the user.
[0048] In related technologies, in order to enable a game to support modules, a corresponding script interpreter can be set in the game. When the script is called, the script interpreter parses the external script so that the game can execute the parsed script logic, such as adding new data or rules to the game, or combining multiple game native rules to obtain new rules.
[0049] However, setting up a script interpreter within the game to call external scripts presents significant speed issues. When importing a mod into the game, the script call process can easily cause delays, leading to game screen freezes and other undesirable issues, significantly impacting the user experience. This delay issue is particularly pronounced when the mod makes significant changes to the game.
[0050] In recent years, the Entity-Component-System (ECS) architecture has been widely used in game programming, allowing for the simultaneous processing of massive amounts of data. In the ECS architecture, entities are built from components, and by storing component data of the same type contiguously in memory chunks, the CPU cache line preloading feature improves access efficiency to component data. However, the existing ECS architecture still relies on a script interpreter to execute external scripts, which also suffers from the slow speed of calling external scripts.
[0051] In order to solve the above problems, the present disclosure provides a method, apparatus, device and medium for calling an external script.
[0052] According to an embodiment of the present disclosure, the external script calling method includes: reading an external script file, and obtaining an assembly according to the external script file; obtaining a function pointer corresponding to any method in the assembly, and obtaining entity indication information of the entity acted upon by any one of the methods; creating a first key-value pair container with the entity indication information of the entity acted upon by any one of the methods as a key and the function pointer corresponding to any one of the methods as a value; obtaining any one entity type in the external script file, and determining the entity indication information of at least one entity corresponding to the entity type based on the any one entity type; obtaining a target function pointer from the first key-value pair container with the entity indication information of the at least one entity as a key, and executing the function indicated by the target function pointer.
[0053] According to an embodiment of the present disclosure, by first converting an external script file into an assembly, obtaining the function pointer corresponding to any method in the assembly and the entity indication information of the entity acted upon by the method, creating a first key-value pair container with the entity indication information of the entity acted upon by any one of the methods as the key and the function pointer corresponding to any one of the methods as the value, the various methods in the script file are split and their program codes are saved separately in an easily searchable manner. The key-value pair container has the advantages of high retrieval efficiency and fast speed. By saving the entity indication information and the function pointer corresponding to the method in the key-value pair container in the form of a key value, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and delays can be reduced. At the same time, saving the function pointers of each method separately also facilitates subsequent parallel calls to them, further improving the speed of external script calls.
[0054] The solution of the embodiment of the present disclosure is not only applicable to game scenarios, but also applicable to the call of external scripts in other software scenarios. For ease of understanding, the following mainly describes the embodiment of the present disclosure with respect to the game scenario.
[0055] Figure 1 Flowchart showing the external script calling method according to an embodiment of the present disclosure. Figure 1 As shown, the external script calling method includes the following steps S101-S105:
[0056] In step S101, an external script file is read, and an assembly is obtained according to the external script file;
[0057] In step S102, a function pointer corresponding to any method in the program set is obtained, and entity indication information of the entity acted upon by any method is obtained;
[0058] In step S103, a first key-value pair container is created, with the entity indication information of the entity acted upon by any one of the methods as a key and the function pointer corresponding to any one of the methods as a value;
[0059] In step S104, any entity type in the external script file is obtained, and entity indication information of at least one entity corresponding to the entity type is determined based on the any entity type;
[0060] In step S105 , a target function pointer is obtained from a first key-value pair container using the entity indication information of the at least one entity as a key, and the function indicated by the target function pointer is executed.
[0061] According to an embodiment of the present disclosure, steps S101-S105 can be executed during the startup of the software program to reduce the load during the software operation. Alternatively, since the entity acted upon by the method in the external script may not be used during the entire software operation, steps S101-S105 can also be executed during the software operation, before the entity acted upon by the method in the external script is used, to shorten the startup process of the software program and reduce the user's waiting time. For example, during the software operation, when the system has idle resources that meet preset conditions, the execution of steps S101-S105 can be automatically triggered. Alternatively, during the software operation, steps S101-S105 can be executed in response to an input script loading instruction to allow the user to perform real-time operations on the entity through the external script, such as real-time modification of the entity component. Alternatively, the first few steps in steps S101-S105 can be executed during the software startup, while the latter few steps in steps S101-S105 can be executed during the software operation to achieve a balance between the software startup time and the resource usage during the software execution. For example, steps S101 - S103 may be executed during software startup, and steps S104 - S105 may be executed by an operating system during software execution, but the present invention is not limited thereto.
[0062] In one implementation of the present disclosure, an external script file can be understood as a script file added from outside the software to implement a module (mod) function. Reading the external script file can be implemented as reading the external script file when the software is started, or as reading the external script file in response to an input external script loading instruction during the running of the software. According to an embodiment of the present disclosure, the software can be game software or other software.
[0063] In one implementation of the present disclosure, external script files can be stored in a script directory within the software directory. Depending on the functions implemented by the external script files, the script files corresponding to different functions can be stored in different subdirectories within the script directory. For example, in a game scenario, the subdirectories within the script directory may include a buff subdirectory, a character subdirectory, a battle subdirectory, and the like.
[0064] Depending on the directory where the external script file is located, different parsing codes can be used to parse the script and deserialize it into the corresponding data objects, such as data objects supporting High Perform C# (hpc#). Categorizing external script files with different functions through directories can simplify parsing implementation. Software users and developers can write external script files according to the same specifications and place them in the corresponding directories, so that the corresponding parsing code can automatically parse the external script files.
[0065] In one implementation of the present disclosure, the external script file may be written according to a preset writing specification.
[0066] For example, taking the external script file in a game based on the ECS architecture as an example, the writing specifications may include: using curly braces to represent objects in the body of the external script file, and the elements within the curly braces are in an array-like parallel relationship rather than a key-value pair; keywords such as "AND", "OR", "XOR", and "NOR" can be added to the external script file to represent the logical relationship of the judgment condition; using symbols such as ">=", "<=", ">", and "<" in the external script file to represent conditional judgment relationships; using keywords such as "scripted_trigger" and "buff" in the external script file to identify specific objects and logical relationships.
[0067] In one implementation of the present disclosure, obtaining an assembly based on an external script file can be implemented by translating data objects parsed from the external script file into corresponding programming language code and dynamically compiling it into an assembly. For example, using an external script file for a game based on the ECS architecture as an example, a preset template can be used to translate data objects parsed from the external script file into C# code that supports HPC# and dynamically compile it into an assembly.
[0068] In one implementation of the present disclosure, a method in an assembly is an executable code block defined in the assembly that implements a specific function or operation. Different methods may correspond to different functions in an external script file. For example, using an external script file for an ECS-based game as an example, different methods in an assembly may correspond to functions acting on different entities in the external script file.
[0069] In one implementation of the present disclosure, obtaining a function pointer corresponding to any method in an assembly may include obtaining a function pointer corresponding to any method in the assembly by querying a static registry. Obtaining a function pointer corresponding to any method in an assembly may also be accomplished by obtaining metadata of any method in the assembly, obtaining an entry address of the method in memory based on the metadata, and obtaining a function pointer corresponding to the method based on the entry address, wherein the metadata includes at least the method name and method type of the method, and the method type may include the parameter type of the method, the return type of the method, etc.
[0070] In one implementation of the present disclosure, the entity indication information indicates the corresponding one or more entities. Exemplarily, the entity indication information may include at least one of an entity name, an entity classification, and an entity tag. Different entity types correspond to different component combinations. Entity tags can be used to indicate entities, and different entity tags correspond to different entities. An entity type may correspond to one or more entities. Entity classification may include categories for dividing entities according to preset classification rules. Exemplarily, taking a game based on the ECS architecture as an example, the entity classification includes three categories: soldiers, blacksmiths, and farmers; if the components of an entity are "old", "male", and "soldier", the entity classification of the entity is a soldier; if the components of an entity are "young", "female", and "farmer", the entity classification of the entity is a farmer; if the components of an entity are "old", "male", and "blacksmith", the entity classification of the entity is a blacksmith.
[0071] In one implementation of the present disclosure, creating a first key-value pair container with entity indication information of an entity acted upon by any one of the methods as a key (Key) and a function pointer corresponding to any one of the methods as a value (Value) can include storing the function pointer corresponding to any one of the methods in the first key-value pair container, wherein the first key-value pair container can establish a mapping from the entity indication information to the function pointer through a key-value pair (Key-Value Pair).
[0072] In one implementation of the present disclosure, an entity type is used to indicate a combination of components possessed by an entity, and different entity types may correspond to different behaviors and / or functions. Obtaining any entity type in an external script file may be understood as reading corresponding information in the external script file and obtaining any entity type in the external script file based on the information. Exemplarily, the external script file may be traversed to obtain the entity types in the external script file one by one.
[0073] In one implementation of the present disclosure, determining at least one entity based on any entity type can be implemented by determining an entity consisting of a component combination indicated by the entity type. For example, using an external script file in an ECS-based game as an example, a query can be performed based on the component combination indicated by the entity type, and the at least one entity can be determined based on the query result.
[0074] In one implementation of the present disclosure, obtaining entity indication information of an entity acted upon by any one of the methods can be achieved through the following steps: when obtaining a function pointer corresponding to any one of the methods in the assembly, obtaining the method name of any one of the methods, based on the method name of any one of the methods, determining a portion of code for defining any one of the methods in the code of an external script file, and extracting entity indication information from the portion of code, wherein the entity indication information is used to indicate the entity acted upon by any one of the methods.
[0075] Alternatively, obtaining the entity indication information of the entity on which any of the methods acts can also be achieved through the following steps: when obtaining the function pointer corresponding to any of the methods in the program set, obtaining the method name of any of the methods, and based on the method name of any of the methods, querying the method entity association information in the external script file to determine the entity indication information used to indicate the entity on which any of the methods acts, wherein the method entity container information is used to indicate the correspondence between the method name and the entity indication information.
[0076] The embodiment of the present disclosure provides an external script calling method that is very different from the prior art of running an external script through a script interpreter, so as to effectively solve the problem of software running jamming caused by external script calling. According to the embodiment of the present disclosure, by first converting the external script file into an assembly, obtaining the function pointer corresponding to any method in the assembly and the entity indication information of the entity acted by the method, creating a first key-value pair container with the entity indication information of the entity acted by any one of the methods as the key and the function pointer corresponding to any one of the methods as the value, the various methods in the script file are split and their program codes are saved separately in an easy-to-retrieve manner. The key-value pair container has the advantages of high retrieval efficiency and fast speed. By saving the entity indication information and the function pointer corresponding to the method in the key-value pair container in the form of key values, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and delays can be reduced. At the same time, saving the function pointers of each method separately also facilitates subsequent parallel calls to them, further improving the speed of external script calls.
[0077] In one embodiment of the present disclosure, determining entity indication information of at least one entity corresponding to the entity type based on any one entity type includes:
[0078] Obtain at least one second key-value pair container, where the second key-value pair container uses the entity indication information as a key and a query set as a value, wherein the query set is used to indicate a correspondence between an entity type and an entity corresponding to a key of the second key-value pair container;
[0079] Based on the query set in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type is determined.
[0080] According to an embodiment of the present disclosure, a query set (EntityQuery) may be used to filter out entity sets that meet the conditions by defining a combination condition of a component, wherein the combination condition includes at least the entity type of the component.
[0081] In the above embodiment, the entity indication information, entity type, and the corresponding relationship between entities are stored in a second key-value pair container with higher retrieval efficiency. This allows for rapid determination of the entity indication information corresponding to the entity type in the script. The corresponding function pointer is then retrieved from the first key-value pair container using the entity indication information, and the corresponding program code is executed. This embodiment significantly reduces the time required to retrieve and execute the program code corresponding to the method when calling an external script by searching the key-value pair container twice.
[0082] According to an embodiment of the present disclosure, the external script calling method further includes determining a designated entity domain corresponding to the external script file.
[0083] The determining, based on the query set in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type includes:
[0084] By searching the second key-value pair container for a query set corresponding to the entity type in the specified entity domain, entity indication information of at least one entity corresponding to the entity type in the specified entity domain is determined.
[0085] In one implementation of the present disclosure, an entity domain may include one or more entity types. The entity type in the external script file may be determined based on entity domain indication information preset for the external script file.
[0086] For example, taking the external script files of a game based on the ECS architecture as an example, the external script files can be stored in a script directory under the game directory. Depending on the functions implemented by the external script files, the script files corresponding to different functions in the external script files can be stored in different subdirectories under the script directory. The name of the subdirectory can include pre-set entity domain indication information, and the specified entity domain corresponding to the external script file can be determined based on the name of the subdirectory. The file name of the external script file can include the entity type in the specified entity domain involved in the script file, and one or more entity types in the specified entity domain can be determined based on the file name of the script file under the subdirectory.
[0087] According to embodiments of the present disclosure, query sets can be pre-set for different entity domains to store relationships between entities and entity types in the corresponding entity domains. When searching the second key-value pair container, only query sets corresponding to the specified entity domain can be searched, thereby further improving query efficiency.
[0088] According to an embodiment of the present disclosure, the operation of determining the entity indication information of at least one entity corresponding to the entity type based on any one of the entity types, and / or the operation of obtaining a target function pointer from a first key-value pair container with the entity indication information of the at least one entity as a key, and executing the function indicated by the target function pointer, is performed in an operating system. The operating system can be, for example, an operating system dedicated to external script calls. When software and / or external script files involve entity domains, query sets and entity indication information corresponding to different entity domains are stored in a second key-value pair container in the operating system.
[0089] Within the ECS architecture, the Job System is a multi-threaded parallel processing technology provided by the Unity engine. It optimizes game performance by assigning tasks to multiple threads for parallel execution, reducing the burden on the main thread and improving operational efficiency in complex computing scenarios. Using the Job System to perform these operations enables parallel processing when external script files involve multiple methods, effectively resolving the issue of low cache hit rates caused by dispersed data and improving the execution efficiency of external scripts.
[0090] In one embodiment of the present disclosure, before obtaining a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, the method further includes:
[0091] Wrap the function pointer corresponding to any method into a delegate and convert the delegate into an unmanaged function pointer;
[0092] Creating a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, including:
[0093] A first key-value pair container is created, which takes entity indication information of an entity acted upon by any method as a key and an unmanaged function pointer as a value.
[0094] In the above technical solution, by packaging the function pointer corresponding to any method into a delegate, converting the delegate into an unmanaged function pointer, and creating a first key-value pair container with the entity indication information of the entity acted upon by any method as the key and the unmanaged function pointer as the value, it can be ensured that the pointers stored in the first key-value pair container are easy for the operating system to use, thereby helping to improve the speed of calling external scripts.
[0095] In one embodiment of the present disclosure, the components of the entity are constructed based on at least one type of structure, the structure is an array of fixed length, and the structure continuously stores entity attribute data corresponding to each of a plurality of entity attributes.
[0096] Executing the function indicated by the target function pointer includes: executing the function indicated by the target function pointer to modify entity attribute data of the entity acted upon by the method corresponding to the target function.
[0097] In one implementation of the present disclosure, the above structure may correspond to an entity. Exemplarily, each entity in the software includes a type of component constructed based on the above structure, which is used to store all readable and writable entity attribute data of the corresponding entity.
[0098] In one implementation of the present disclosure, when constructing the aforementioned structure, corresponding indexes can be assigned to members within the structure, thereby ensuring that the members within the structure can be accessed through the indexes. For example, the address offset of the member within the structure can be determined based on the index of the member, and the address of the member can be determined based on the offset combined with the starting address of the structure, and the data of the member within the structure can be accessed based on the address of the member.
[0099] In one embodiment of the present disclosure, at least one type of structure may include at least one of an attribute parameter structure, an attribute gain structure, and an attribute identification structure, wherein:
[0100] The attribute identification structure continuously stores the attribute identifications corresponding to multiple entity attributes; the attribute parameter structure continuously stores the attribute parameters corresponding to multiple entity attributes; and the attribute gain structure continuously stores the gain parameters corresponding to multiple entity attributes.
[0101] In one implementation of the present disclosure, an attribute identifier may be used to indicate a corresponding entity attribute; an attribute parameter may be used to indicate a specific parameter of a corresponding entity attribute; and a gain parameter may be used to indicate a gain effective for the corresponding entity attribute.
[0102] According to an embodiment of the present disclosure, an entity may include one or more components constructed based on the above-mentioned structure, and a component may include one or more types of the above-mentioned structure.
[0103] For example, the attribute identification structure is defined as FixedArrayXX <ushort>id uses the short type to reduce the memory space it occupies. The attribute parameter structure includes the IDs of the entity attributes, and the IDs are stored continuously in the corresponding order.
[0104] The attribute parameter structure is defined as:
[0105] FixedArrayXX <float>value, where the data is of float type. Using float type can improve accuracy and reduce the memory space it occupies. The data in this attribute parameter structure is specifically used to indicate the attribute value of the entity with a specific numerical value. The attribute value is also stored continuously in the corresponding order. That is, the attribute parameter structure does not record the ID, but only according to the FixedArrayXX <ushort>The order of the IDs in id stores the attribute values of the corresponding entity attributes. Therefore, the storage address of the attribute value of the entity attribute can be determined based on the index of the ID of the entity attribute.
[0106] FixedArrayXX <bool>value, where the data is of Boolean type. The data in this attribute parameter structure is specifically used to indicate an entity attribute that has only two states (e.g., yes / no). Similarly, the entity attribute of this Boolean type is also stored continuously in the corresponding order, that is, the attribute parameter structure does not record the ID, but only according to the FixedArrayXX <ushort>The order of IDs in id is used to store Boolean entity attributes. Therefore, the storage address of the attribute value of the Boolean entity attribute can be determined based on the index of the entity attribute ID.
[0107] The attribute gain structure is defined as:
[0108] FixedArrayXX <float>addRateBuffs, where the data is of float type, which can improve accuracy and reduce the memory space it occupies. This data is used to indicate the addition and subtraction ratio value when modifying the entity attribute by addition and subtraction. The addition and subtraction ratio value is also stored continuously in the corresponding order, that is, FixedArrayXX <float>addRateBuffs does not record the ID, only based on FixedArrayXX <ushort>The order of the IDs in id stores the addition and subtraction ratio values of the entity attributes. Therefore, the storage address of the addition and subtraction ratio value can be determined based on the index of the entity attribute ID.
[0109] FixedArrayXX <float>The data in multiplyBuffs is of float type. Using float type can improve the accuracy and reduce the memory space it occupies. This data is used to indicate the multiplication multiple value when multiplying the entity attribute. The multiplication multiple value is also stored continuously in the corresponding order, that is, FixedArrayXX <float>The ID is not recorded in multiplyBuffs, only based on FixedArrayXX <ushort>The order of the IDs in id stores the multiplication multiples of the entity attributes. Therefore, the storage address of the multiplication multiples of the entity attributes can be determined based on the index of the ID of the entity attribute.
[0110] In the above technical solution, at least one type of structure in the external script file is limited to an array of fixed length, and the structure continuously stores entity attribute data corresponding to multiple entity attributes. In a single structure, the length of the data unit is consistent (for example, referring to the above example, in FixedArrayXX <ushort>In id, the length of each ID is the same, in FixedArrayXX <float>value, the length of each attribute value is also consistent). Based on this structure, memory alignment can be performed to effectively reduce the memory space occupied (for example, referring to the above example, after memory alignment, in FixedArrayXX <ushort>The IDs in the id are stored consecutively, so each ID only takes up 2 bytes. In contrast, when storing attributes and IDs in intervals, each attribute value takes up 4 bytes, and each ID also takes up 4 bytes. Therefore, compared with the scheme that stores attributes and IDs in intervals, this scheme can effectively reduce the memory space occupied. Furthermore, after memory alignment, data in the structure can be accessed with a single memory access. In summary, this scheme can effectively reduce memory space usage, improve cache hit rate, and enhance data access efficiency.
[0111] Figure 2 The following is a structural block diagram of an external script calling device according to an embodiment of the present disclosure, wherein the device can be implemented as part or all of an electronic device through software, hardware, or a combination of both.
[0112] like Figure 2 As shown, the external script calling device 200 includes:
[0113] The assembly acquisition module 201 is configured to read an external script file and acquire an assembly according to the external script file;
[0114] The pointer acquisition module 202 is configured to acquire a function pointer corresponding to any method in the program set and acquire entity indication information of the entity acted upon by any method;
[0115] The key-value pair container acquisition module 203 is configured to create a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value;
[0116] The entity determination module 204 is configured to obtain any entity type in the external script file, and determine entity indication information of at least one entity corresponding to the entity type based on the any entity type;
[0117] The function execution module 205 is configured to obtain a target function pointer from a first key-value pair container with entity indication information of at least one entity as a key, and execute the function indicated by the target function pointer.
[0118] According to an embodiment of the present disclosure, by first converting an external script file into an assembly, obtaining the function pointer corresponding to any method in the assembly and the entity indication information of the entity acted upon by the method, creating a first key-value pair container with the entity indication information of the entity acted upon by any one of the methods as the key and the function pointer corresponding to any one of the methods as the value, the various methods in the script file are split and their program codes are saved separately in an easily searchable manner. The key-value pair container has the advantages of high retrieval efficiency and fast speed. By saving the entity indication information and the function pointer corresponding to the method in the key-value pair container in the form of a key value, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and delays can be reduced. At the same time, saving the function pointers of each method separately also facilitates subsequent parallel calls to them, further improving the speed of external script calls.
[0119] The present disclosure also discloses an electronic device, Figure 3 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.
[0120] like Figure 3 As shown, the electronic device includes a memory and a processor, wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to an embodiment of the present disclosure.
[0121] The present disclosure provides a method for calling an external script, including:
[0122] Read the external script file and obtain the assembly according to the external script file;
[0123] Get the function pointer corresponding to any method in the assembly, and get the entity indication information of the entity acted upon by any method;
[0124] Create a first key-value pair container with entity indication information of the entity acted upon by any method as a key and a function pointer corresponding to any method as a value;
[0125] Obtain any entity type in the external script file, and determine entity indication information of at least one entity corresponding to the entity type based on the entity type;
[0126] A target function pointer is obtained from a first key-value pair container using entity indication information of at least one entity as a key, and a function indicated by the target function pointer is executed.
[0127] In one embodiment of the present disclosure, the entity indication information includes at least one of an entity name, an entity category, and an entity tag.
[0128] In one embodiment of the present disclosure, obtaining a function pointer corresponding to any method in an assembly includes:
[0129] Get the metadata of any method in the assembly. The metadata includes at least the method name and method type of any method.
[0130] Get the entry address of any method in memory based on metadata;
[0131] Get the function pointer corresponding to any method based on the entry address.
[0132] In one embodiment of the present disclosure, determining entity indication information of at least one entity corresponding to any entity type based on any entity type includes:
[0133] Obtain at least one second key-value pair container, where the second key-value pair container uses the entity indication information as a key and a query set as a value, wherein the query set is used to indicate a correspondence between an entity type and an entity corresponding to a key of the second key-value pair container;
[0134] Based on the query set in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type is determined.
[0135] In one embodiment of the present disclosure, an operation of determining entity indication information of at least one entity corresponding to an entity type based on any entity type, and / or an operation of obtaining a target function pointer from a first key-value pair container with the entity indication information of at least one entity as a key, and executing a function indicated by the target function pointer, is performed in an operating system.
[0136] In one embodiment of the present disclosure, before creating a first key-value pair container using entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, the method further includes:
[0137] Wrap the function pointer corresponding to any method into a delegate and convert the delegate into an unmanaged function pointer;
[0138] Creating a first key-value pair container with entity indication information of an entity acted upon by any method as a key and a function pointer corresponding to any method as a value, including:
[0139] A first key-value pair container is created, which takes entity indication information of an entity acted upon by any method as a key and an unmanaged function pointer as a value.
[0140] In one embodiment of the present disclosure, the entity component is constructed based on at least one type of structure, the structure is an array of fixed length, and the structure continuously stores entity attribute data corresponding to each of a plurality of entity attributes;
[0141] Executing the function indicated by the target function pointer includes executing the function indicated by the target function pointer to modify entity attribute data of the entity acted upon by the method corresponding to the target function.
[0142] In one embodiment of the present disclosure, at least one type of structure includes at least one of an attribute parameter structure, an attribute gain structure, and an attribute identification structure;
[0143] The attribute identification structure continuously stores the attribute identifications corresponding to multiple entity attributes; the attribute parameter structure continuously stores the attribute parameters corresponding to multiple entity attributes; and the attribute gain structure continuously stores the gain parameters corresponding to multiple entity attributes.
[0144] Figure 4 A schematic diagram showing the structure of a computer system suitable for implementing the method according to an embodiment of the present disclosure is shown.
[0145] like Figure 4 As shown, the computer system includes a processing unit that can execute the various methods of the above-described embodiments based on a program stored in a read-only memory (ROM) or a program loaded from a storage unit into a random access memory (RAM). The RAM also stores various programs and data required for the operation of the computer system. The processing unit, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0146] The following components are connected to the I / O interface: an input section including a keyboard, mouse, etc.; an output section including a cathode ray tube (CRT), liquid crystal display (LCD), and speakers; a storage section including a hard disk; and a communication section including a network interface card such as a LAN card and a modem. The communication section performs communication processes via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc. are installed in the drive as needed, so that computer programs read from them can be installed in the storage section as needed. The processing unit can be implemented as a CPU, GPU, TPU, FPGA, NPU, or other processing unit.
[0147] In particular, according to embodiments of the present disclosure, the methods described above can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for executing the methods described above. In such embodiments, the computer program can be downloaded and installed from a network via a communication component and / or installed from a removable medium.
[0148] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that 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 and / or flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.
[0149] The units or modules involved in the embodiments described in this disclosure may be implemented by software or programmable hardware. The units or modules described may also be provided in a processor, and the names of these units or modules do not, in certain circumstances, constitute limitations on the units or modules themselves.
[0150] As another aspect, the present disclosure further provides a computer-readable storage medium. This computer-readable storage medium may be included in the electronic device or computer system described in the above embodiments, or may be a standalone computer-readable storage medium not incorporated into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the methods described in the present disclosure.
[0151] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention herein is not limited to technical solutions formed by specific combinations of the aforementioned technical features. It also encompasses other technical solutions formed by any combination of the aforementioned technical features or their equivalents, without departing from the inventive concept. For example, a technical solution formed by replacing the aforementioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.< / ushort> < / float> < / ushort> < / ushort> < / float> < / float> < / ushort> < / float> < / float> < / ushort> < / bool> < / ushort> < / float> < / ushort>
Claims
1. A method for calling an external script, characterized in that: include: Read an external script file and obtain an assembly according to the external script file; Obtaining a function pointer corresponding to any method in the program set, and obtaining entity indication information of the entity acted upon by any method; Creating a first key-value pair container with entity indication information of an entity acted upon by any one of the methods as a key and a function pointer corresponding to any one of the methods as a value; Acquire any entity type in the external script file, and determine entity indication information of at least one entity corresponding to the entity type based on the any entity type; Obtaining a target function pointer from a first key-value pair container using the entity indication information of the at least one entity as a key, and executing a function indicated by the target function pointer; The step of obtaining an assembly according to the external script file includes: Translating the data object parsed from the external script file into programming language code, and dynamically compiling the programming language code into an assembly; The determining, based on any one entity type, entity indication information of at least one entity corresponding to the entity type includes: Obtain at least one second key-value pair container, where the second key-value pair container uses the entity indication information as a key and a query set as a value, wherein the query set is used to indicate a correspondence between an entity type and an entity corresponding to a key of the second key-value pair container; Based on the query set in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type is determined.
2. The external script calling method according to claim 1, characterized in that: The entity indication information includes at least one of an entity name, an entity category, and an entity tag.
3. The external script calling method according to claim 1, characterized in that: The obtaining of a function pointer corresponding to any method in the program includes: Obtain metadata of any method in the assembly, the metadata including at least a method name and a method type of the method; Obtaining an entry address of any one of the methods in memory based on the metadata; A function pointer corresponding to any one of the methods is obtained based on the entry address.
4. The external script calling method according to claim 1, characterized in that: The operation of determining the entity indication information of at least one entity corresponding to the entity type based on any one of the entity types, and / or obtaining the target function pointer from the first key-value pair container with the entity indication information of the at least one entity as the key, and executing the function indicated by the target function pointer, is performed in the operating system.
5. The external script calling method according to claim 1, characterized in that: Before creating a first key-value pair container with entity indication information of an entity acted upon by any one of the methods as a key and a function pointer corresponding to any one of the methods as a value, the method further includes: Wrapping the function pointer corresponding to any one of the methods into a delegate, and converting the delegate into an unmanaged function pointer; The step of creating a first key-value pair container using entity indication information of an entity acted upon by any one of the methods as a key and a function pointer corresponding to any one of the methods as a value includes: A first key-value pair container is created, with the entity indication information of the entity acted upon by any one of the methods as the key and the unmanaged function pointer as the value.
6. The external script calling method according to any one of claims 1 to 5, characterized in that: The components of the entity are constructed based on at least one type of structure, wherein the structure is an array of fixed length, and the structure continuously stores entity attribute data corresponding to each of a plurality of entity attributes; The executing the function indicated by the target function pointer includes: executing the function indicated by the target function pointer to modify entity attribute data of the entity acted upon by the method corresponding to the target function.
7. The external script calling method according to claim 6, characterized in that: The at least one type of structure includes at least one of an attribute parameter structure, an attribute gain structure, and an attribute identification structure; The attribute identification structure continuously stores the attribute identifications corresponding to the plurality of entity attributes; The attribute parameter structure continuously stores the attribute parameters corresponding to each of the multiple entity attributes; The attribute gain structure continuously stores gain parameters corresponding to the plurality of entity attributes.
8. An external script calling device, characterized in that: include: An assembly acquisition module is configured to read an external script file and acquire an assembly according to the external script file; The method of obtaining an assembly according to the external script file includes: translating a data object parsed from the external script file into programming language code, and dynamically compiling the programming language code into an assembly; a pointer acquisition module configured to obtain a function pointer corresponding to any method in the assembly, and obtain entity indication information of an entity acted upon by any method; a key-value pair container acquisition module configured to create a first key-value pair container with entity indication information of an entity acted upon by any one of the methods as a key and a function pointer corresponding to any one of the methods as a value; An entity determination module is configured to obtain any entity type in the external script file, and determine entity indication information of at least one entity corresponding to the entity type based on the any entity type; the determining the entity indication information of at least one entity corresponding to the entity type based on the any entity type includes: obtaining at least one second key-value pair container, the second key-value pair container using the entity indication information as a key and a query set as a value, and determining the entity indication information of at least one entity corresponding to the entity type based on the query set in the second key-value pair container, wherein the query set is used to indicate a correspondence between an entity type and an entity corresponding to a key of the second key-value pair container; The function execution module is configured to obtain a target function pointer from a first key-value pair container with the entity indication information of the at least one entity as a key, and execute the function indicated by the target function pointer.
9. An electronic device, characterized in that: The method comprises a memory and a processor; wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the computer instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Test task execution method, device and system, storage medium and electronic device
CN112948264A
Detection method, device, equipment, storage medium and computer program product
CN116956297A