External script calling method and device, equipment and medium
By converting external script files into assemblies and creating key-value pair containers, the problem of slow call speed of external scripts is solved, improving the game's running efficiency and user experience.
Patent Information
- Application Number
- CN202510885035.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2045-06-30
AI Technical Summary
The prior art has speed defects when calling external scripts, which leads to stuttering of the game screen and affects the user experience.
Create key-value pair containers for easy retrieval and parallelization of calls by converting external script files into assemblies, obtaining function pointers and entity indications.
Significantly improve the speed of external script calls, reduce latency, and improve user experience.
Smart Images

Figure CN120386590A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of software technology, and in particular, to an external script calling method, apparatus, device, and medium. Background Art
[0002] In games, to more conveniently adjust and modify some data or rules in the game, the game usually provides support for mods (Modification). The scripts of the mods can be written in corresponding scripting languages, and the game can import the mods into the game by calling external scripts.
[0003] In the related art, to enable a game to support mods, a corresponding script interpreter can be set in the game. When calling a script, the script interpreter parses the external script, enabling the game to execute the script logic obtained by the parsing, such as adding new data or rules to the game, or combining multiple native rules of the game to obtain new rules, etc.
[0004] However, the above solution has obvious speed defects when calling external scripts. When importing a mod into the game, the calling process of the external script is extremely likely to cause delays, which in turn causes poor conditions such as game screen stuttering, greatly affecting the user experience. Summary of the Invention
[0005] To solve the problems in the related art, embodiments of the present disclosure provide an external script calling method, apparatus, device, and medium.
[0006] In a first aspect, an external script calling method provided in an embodiment of the present disclosure includes: Read an external script file and obtain an assembly according to the external script file; Obtain a function pointer corresponding to any method in the assembly, and obtain entity indication information of an entity to which any method applies; Create a first key-value pair container with the entity indication information of the entity to which any method applies as the key and the function pointer corresponding to any method as the value; Obtain any entity type in the external script file, and determine the entity indication information of at least one entity corresponding to the entity type based on any entity type; Obtain a target function pointer from the first key-value pair container with the entity indication information of at least one entity as the key, and execute the function indicated by the target function pointer.
[0007] In an embodiment of the present disclosure, the entity indication information includes at least one of an entity name, an entity classification, and an entity tag.
[0008] In an embodiment of the present disclosure, obtaining a function pointer corresponding to any method in the assembly includes: Obtain the metadata of any method in the assembly, where the metadata includes at least the method name and method type of any method; Based on the metadata, obtain the entry address of any method in memory; Based on the entry address, obtain the function pointer corresponding to any method.
[0009] In an implementation manner of the present disclosure, determining the entity indication information of at least one entity corresponding to the entity type based on any 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 the key and the query set as the value, and the query set is used to indicate the correspondence between the entity type and the entity corresponding to the key of the second key-value pair container; Based on the query set in the second key-value pair container, determine the entity indication information of at least one entity corresponding to the entity type.
[0010] In an implementation manner 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 entity type, and / or the operation of obtaining the target function pointer from the first key-value pair container with the entity indication information of at least one entity as the key and executing the function indicated by the target function pointer are executed in the job system.
[0011] In an implementation manner of the present disclosure, before creating the first key-value pair container with the entity indication information of the entity acted on by any method as the key and the function pointer corresponding to any method as the value, the method further includes: Wrap the function pointer corresponding to any method into a delegate and convert the delegate into an unmanaged function pointer; Creating the first key-value pair container with the entity indication information of the entity acted on by any method as the key and the function pointer corresponding to any method as the value includes: Create a first key-value pair container with the entity indication information of the entity acted on by any method as the key and the unmanaged function pointer as the value.
[0012] In an implementation manner of the present disclosure, the components of the entity are constructed based on at least one type of structure body, the structure body is a fixed-length array, and the entity attribute data corresponding to multiple entity attributes are continuously stored in the structure body; Executing the function indicated by the target function pointer includes: executing the function indicated by the target function pointer to modify the entity attribute data of the entity acted on by the method corresponding to the target function.
[0013] In an implementation manner of the present disclosure, at least one type of structure body includes at least one of an attribute parameter structure body, an attribute gain structure body, and an attribute identification structure body; The attribute identification structure stores the attribute identifications corresponding to multiple entity attributes consecutively; the attribute parameter structure stores the attribute parameters corresponding to multiple entity attributes consecutively; the attribute gain structure stores the gain parameters corresponding to multiple entity attributes consecutively.
[0014] In a second aspect, an external script calling device provided in an embodiment of the present disclosure includes: An assembly acquisition module, configured to read an external script file and obtain an assembly according to the external script file; 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 to which any method applies; A key-value pair container acquisition module, configured to create a first key-value pair container with the entity indication information of an entity to which any method applies as the key and the function pointer corresponding to any method as the value; An entity determination module, configured to obtain any entity type in the external script file and determine the entity indication information of at least one entity corresponding to the entity type based on any entity type; A function execution module, configured to obtain a target function pointer from the first key-value pair container with the entity indication information of at least one entity as the key and execute the function indicated by the target function pointer.
[0015] In a third aspect, an electronic device provided in an embodiment of the present disclosure includes 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 the method according to any one of the first aspects.
[0016] In a fourth aspect, a computer-readable storage medium provided in an embodiment of the present disclosure stores computer instructions thereon, and when the computer instructions are executed by a processor, the method according to any one of the first aspects is implemented.
[0017] According to the embodiments of the present disclosure, by first converting an external script file into an assembly, obtaining a function pointer corresponding to any method in the assembly and entity indication information of an entity to which the method applies, and creating a first key-value pair container with the entity indication information of an entity to which any method applies as the key and the function pointer corresponding to any method as the value, the 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 advantages such as high retrieval efficiency and fast speed. By storing the entity indication information and the function pointer corresponding to the method in the form of a key-value pair in the key-value pair container, the speed of obtaining the function pointer in subsequent processing can be significantly increased, and the delay can be reduced. At the same time, by storing the function pointers of each method separately, it is also convenient to perform parallel calls on them in the future, further improving the external script calling speed.
[0018] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and do not limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In conjunction with the accompanying drawings, other features, objects, and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments. In the drawings: Figure 1 A flowchart showing an external script calling method according to an embodiment of the present disclosure is shown.
[0020] Figure 2 A block diagram showing the structure of an external script calling device according to an embodiment of the present disclosure is shown.
[0021] Figure 3 A block diagram showing the structure of an electronic device according to an embodiment of the present disclosure is shown.
[0022] 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 OF THE EMBODIMENTS
[0023] 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 clarity, parts irrelevant to the description of the exemplary embodiments are omitted in the drawings.
[0024] In the present disclosure, it should be understood that terms such as "including" or "having" are intended to indicate the presence of features, numbers, steps, actions, components, parts, or combinations thereof disclosed in this specification, and do not intend to exclude the possibility of the presence or addition of one or more other features, numbers, steps, actions, components, parts, or combinations thereof.
[0025] It should be further noted that, without conflict, the embodiments in the present disclosure and the features in the embodiments can be combined with each other. The present disclosure will be described in detail below with reference to the drawings and in conjunction with the embodiments.
[0026] In the present disclosure, if it involves operations of obtaining user information or user data or operations of presenting user information or user data to others, such operations are all operations authorized, confirmed by the user, or actively selected by the user.
[0027] In the related art, in order to enable a game to support mods, a corresponding script interpreter can be set in the game. When a script is called, the script interpreter parses the external script, enabling the game to execute the parsed script logic, such as adding new materials or rules to the game, or combining multiple native game rules to obtain new rules, etc.
[0028] However, there are obvious speed defects when setting up a corresponding script interpreter in the game to call external scripts. When importing a mod into the game, the process of calling external scripts is extremely likely to cause delays, which in turn lead to poor conditions such as game screen stuttering, greatly affecting the user experience. In particular, when the mod makes a relatively large number of modifications to the game, the latency problem becomes particularly prominent.
[0029] In recent years, the Entity-Component-System (ECS) architecture has been widely used in game programming, which allows massive amounts of large-scale data to be processed simultaneously. Under the ECS architecture, entities are constructed based on components, and by continuously storing component data of the same type in a memory block (Chunk), the access efficiency of component data is improved by utilizing the CPU cache line preloading feature. However, the existing ECS architecture still relies on a script interpreter to execute external scripts, and there is also a problem of slow speed in calling external scripts.
[0030] To solve the above problems, the present disclosure provides a method, device, device and medium for calling external scripts.
[0031] The method for calling an external script according to an embodiment of the present disclosure 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 on which the any method acts; creating a first key-value pair container with the entity indication information of the entity on which the any method acts as the key and the function pointer corresponding to the any method as the value; obtaining any entity type in the external script file, and determining 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 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.
[0032] According to an embodiment of the present disclosure, by first converting the external script file into an assembly, obtaining a function pointer corresponding to any method in the assembly and entity indication information of the entity on which the method acts, creating a first key-value pair container with the entity indication information of the entity on which the any method acts as the key and the function pointer corresponding to the any method as the value, the program codes of each method in the script file are split and saved separately in an easy-to-retrieve manner. The key-value pair container has advantages such as high retrieval efficiency and fast speed. By storing the entity indication information and the function pointer corresponding to the method in the key-value pair container in a key-value form, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and the latency can be reduced. At the same time, saving the function pointers of each method separately also facilitates parallel call thereof in the future, further improving the speed of calling external scripts.
[0033] The solutions of the embodiments of the present disclosure are applicable not only to game scenarios but also to the invocation of external scripts in other software scenarios. For ease of understanding, the embodiments of the present disclosure will be mainly described below with respect to game scenarios.
[0034] Figure 1 The flowchart showing the method for invoking an external script according to an embodiment of the present disclosure is as follows. Figure 1 As shown, the method for invoking an external script includes the following steps S101 - S105: In step S101, an external script file is read, and an assembly is obtained according to the external script file; In step S102, a function pointer corresponding to any one method in the assembly is obtained, and entity indication information of the entity on which the any one method acts is obtained; In step S103, a first key - value pair container is created, with the entity indication information of the entity on which the any one method acts as the key and the function pointer corresponding to the any one method as the value; In step S104, any one 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 one entity type; In step S105, a target function pointer is obtained from the first key - value pair container with the entity indication information of the at least one entity as the key, and the function indicated by the target function pointer is executed.
[0035] According to the embodiments of the present disclosure, steps S101 - S105 can be executed during the startup of the software program to reduce the load during software operation. Alternatively, since the entities on which the methods in the external script act may not be used throughout the software operation, steps S101 - S105 can also be executed during software operation before the entities on which the methods in the external script act are used, so as to shorten the startup process of the software program and reduce the waiting time of the user. For example, during software operation, when the system has idle resources meeting preset conditions, the execution of steps S101 - S105 can be automatically triggered. Or, during software operation, in response to an input script loading instruction, steps S101 - S105 can be executed to allow the user to perform real - time operations on entities, such as real - time modification of entity components. Or, the first few steps of steps S101 - S105 can be executed during software startup, while the last few steps of S101 - S105 can be executed during software operation to achieve a balance between software startup time and resource occupancy during software execution. For example, steps S101 - S103 can be executed during software startup, and steps S104 - S105 can be executed by the operating system during software operation, but this is not limited thereto.
[0036] In an implementation of the present disclosure, an external script file can be understood as a script file added from outside the software for implementing the functions of a mod. Reading the external script file can be implemented as reading the external script file when the software starts up, or can also be implemented as, during the running process of the software, in response to an input external script loading instruction, reading the external script file. According to an embodiment of the present disclosure, the software can be a game software or other software.
[0037] In an implementation of the present disclosure, the external script file can be stored in a script directory under the software directory, and according to the different functions implemented by the external script file, the script files corresponding to different functions in the external script file are stored in different subdirectories under the script directory. For example, in a game scenario, the subdirectories under the script directory can include a buff subdirectory, a character subdirectory, a battle subdirectory, etc.
[0038] According to the different directories where the external script files are located, corresponding different parsing codes can be used to parse the scripts and deserialize them into corresponding data objects, such as data objects that support High Perform C# (hpc#). Classifying the external script files with different functions by directory can reduce the difficulty of parsing implementation. Both software users and developers can write external script files according to the same specification and place them in the corresponding directories so that the corresponding parsing codes can automatically parse the external script files.
[0039] In an implementation of the present disclosure, the external script file can be written according to a preset writing specification.
[0040] Exemplarily, taking the external script file in a game based on the ECS architecture as an example, the writing specification can include: using curly braces to represent objects in the main body of the external script file, and the elements within the curly braces are in an array-like juxtaposed relationship rather than key-value pairs; keywords such as "AND", "OR", "XOR", "NOR", etc. can be added to the external script file to represent the logical relationship of judgment conditions; symbols such as ">=", "<=", ">", "<" are used in the external script file to represent conditional judgment relationships; keywords such as "scripted_trigger", "buff", etc. are used in the external script file to identify specific objects and logical relationships.
[0041] In an implementation of the present disclosure, obtaining an assembly according to 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. Exemplarily, taking the external script file of a game based on the ECS architecture as an example, the data objects parsed from the external script file can be translated into C# code supporting HPC# through a preset template and dynamically compiled into an assembly.
[0042] In an implementation of the present disclosure, a method in an assembly is an executable code block defined in the assembly, used to implement specific functions or operations. Different methods can correspond to different functions in the external script file. Exemplarily, taking the external script file of a game based on the ECS architecture as an example for illustration, different methods in the assembly can correspond to functions acting on different entities in the external script file.
[0043] In an implementation of the present disclosure, obtaining a function pointer corresponding to any method in an assembly can 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 can also be achieved by obtaining the metadata of any method in the assembly, obtaining the entry address of the any method in memory based on the metadata, and obtaining the function pointer corresponding to the any method based on the entry address, where the metadata at least includes the method name and method type of the any method, and the method type can include the parameter type of the method, the return type of the method, etc.
[0044] In an implementation of the present disclosure, entity indication information indicates one or more corresponding entities. Exemplarily, the entity indication information can include at least one of an entity name, an entity classification, and an entity label. Different entity types correspond to different component combinations. The entity label can be used to indicate an entity, and different entity labels correspond to different entities. One entity type can correspond to one or more entities. The entity classification can include categories obtained by dividing entities according to preset classification rules. Exemplarily, taking a game based on the ECS architecture as an example for illustration, the entity classification includes three classifications: soldier, blacksmith, and farmer; if the components in a certain entity are "old", "male", and "soldier", then the entity classification of this entity is a soldier; if the components in a certain entity are "young", "female", and "farmer", then the entity classification of this entity is a farmer; if the components in a certain entity are "old", "male", and "blacksmith", then the entity classification of this entity is a blacksmith.
[0045] In one implementation of the present disclosure, a first key-value pair container is created with the entity indication information of the entity on which any of the above methods acts as the key (Key) and the function pointer corresponding to any of the above methods as the value (Value). This may include storing the function pointer corresponding to any of the above methods in the first key-value pair container, where the first key-value pair container can establish a mapping from entity indication information to function pointers through key-value pairs (Key-Value Pair).
[0046] In one implementation of the present disclosure, the entity type is used to indicate the component combination that the entity possesses. Different entity types may correspond to different behaviors and / or functions. Obtaining any one of the entity types in the external script file can be understood as reading the corresponding information in the external script file and obtaining any one of the entity types in the external script file based on this information. Exemplarily, the external script file can be traversed to obtain the entity types in the external script file one by one.
[0047] In one implementation of the present disclosure, determining at least one entity based on any one of the entity types can be implemented as determining the entity of the component combination indicated by any one of the entity types. Exemplarily, taking the external script file in a game based on the ECS architecture as an example, a query can be made based on the component combination indicated by any one of the entity types, and the at least one entity can be determined according to the query result.
[0048] In one implementation of the present disclosure, obtaining the entity indication information of the entity on which any of the above methods acts can be achieved through the following steps: when obtaining the function pointer corresponding to any of the above methods in the acquisition assembly, obtain the method name of any of the above methods, and based on the method name of any of the above methods, determine the partial code used to define any of the above methods in the code of the external script file, and extract the entity indication information from this partial code, where the entity indication information is used to indicate the entity on which any of the above methods acts.
[0049] Alternatively, obtaining the entity indication information of the entity on which any of the above methods acts can also be achieved through the following steps: when obtaining the function pointer corresponding to any of the above methods in the acquisition assembly, obtain the method name of any of the above methods, and query in the method-entity association information in the external script file based on the method name of any of the above methods, so as to determine the entity indication information used to indicate the entity on which any of the above methods acts, where the method-entity container information is used to indicate the correspondence between the method name and the entity indication information.
[0050] Embodiments of the present disclosure provide an external script calling method that is quite 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 calls. According to an embodiment of the present disclosure, by first converting an external script file into an assembly, obtaining a function pointer corresponding to any method in the assembly and entity indication information of an entity on which the method acts, creating a first key-value pair container with the entity indication information of the entity on which the any method acts as the key and the function pointer corresponding to the any method as the value, the methods in the script file are split and their program codes are respectively saved in an easily retrievable manner. The key-value pair container has advantages such as high retrieval efficiency and fast speed. By storing the entity indication information and the function pointer corresponding to the method in the form of a key-value in the key-value pair container, the speed of obtaining the function pointer in subsequent processing can be significantly increased, and the delay can be reduced. At the same time, saving the function pointers of each method separately also facilitates their parallelized calls in the future, further improving the speed of external script calls.
[0051] In an embodiment of the present disclosure, 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, where the second key-value pair container uses the entity indication information as the key and a query set as the value, and the query set is used to indicate the correspondence between the entity type and the entity corresponding to the key of the second key-value pair container; Based on the query set in the second key-value pair container, determining the entity indication information of at least one entity corresponding to the entity type.
[0052] According to an embodiment of the present disclosure, a query set (EntityQuery) can be used to screen out a set of entities that meet the conditions by defining the combination conditions of components, where the combination conditions at least include the entity types of the components.
[0053] In the above embodiment, by storing the entity indication information, entity type, and the correspondence between entities in a second key-value pair container with relatively high retrieval efficiency, the entity indication information of the entity corresponding to the entity type in the script can be quickly determined, and then the corresponding function pointer can be retrieved through the entity indication information in the first key-value pair container and the corresponding program code can be executed. This embodiment significantly shortens the time for obtaining and executing the program code corresponding to the method when calling an external script through two retrievals of the key-value pair container.
[0054] According to an embodiment of the present disclosure, the external script calling method further includes determining a specified entity domain corresponding to the external script file.
[0055] The 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 includes: By looking up a query set corresponding to the entity type in the specified entity domain in the second key-value pair container, entity indication information of at least one entity corresponding to the entity type in the specified entity domain is determined.
[0056] In an implementation manner of the present disclosure, an entity domain may include one or more entity types. The entity types in the external script file may be determined based on the entity domain indication information preset for the external script file.
[0057] Exemplarily, taking the external script file of a game based on the ECS architecture as an example, the external script file may be stored in a script directory under the game directory. According to the different functions implemented by the external script file, the script files corresponding to different functions in the external script file may be stored in different subdirectories under the script directory. The name of the subdirectory may include the preset entity domain indication information, and the specified entity domain corresponding to the external script file may be determined based on the name of the subdirectory. The file name of the external script file may include the entity types in the specified entity domain involved in the script file, and one or more entity types in the specified entity domain may be determined based on the file name of the script file under the subdirectory.
[0058] According to an embodiment of the present disclosure, query sets may be preset for different entity domains respectively, for storing the relationships between entities and entity types in the corresponding entity domains. When retrieving the second key-value pair container, only the query set corresponding to the specified entity domain may be queried, thereby further improving the query efficiency.
[0059] 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 of the entity types, and / or the operation of obtaining a 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 are executed in a job system. The job system may be, for example, a job system dedicated to external script calls. When the software and / or the external script file involve entity domains, the query sets and entity indication information corresponding to different entity domains are stored in the second key-value pair container in this job system.
[0060] In the ECS architecture, the job system is a multi-threaded parallel processing technology provided by the Unity engine, used to optimize game performance. By allocating tasks to multiple threads for parallel execution, the burden on the main thread is reduced, and the running efficiency in complex calculation scenarios is improved. By executing the above operations through the job system, parallel processing can be achieved when the external script file involves multiple methods, effectively solving the problem of low cache hit rate caused by data dispersion and improving the execution efficiency of the external script.
[0061] In one implementation of the present disclosure, before obtaining a first key-value pair container with the entity indication information of the entity acted upon by any method as the key and the function pointer corresponding to any method as the value, the method further includes: Wrap the function pointer corresponding to any method as a delegate, and convert the delegate into an unmanaged function pointer; Create a first key-value pair container with the entity indication information of the entity acted upon by any method as the key and the function pointer corresponding to any method as the value, including: Create 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.
[0062] In the above technical solution, by wrapping the function pointer corresponding to any method as 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 convenient for the operating system to use, thereby helping to improve the speed when calling external scripts.
[0063] In one implementation of the present disclosure, the components of the entity are constructed based on at least one type of structure. The structure is a fixed-length array, and the entity attribute data corresponding to multiple entity attributes are continuously stored in the structure.
[0064] Execute the function indicated by the target function pointer, including: execute the function indicated by the target function pointer to modify the entity attribute data of the entity acted upon by the method corresponding to the target function.
[0065] In one implementation of the present disclosure, the above structure can correspond to the entity. Exemplarily, each entity in the software includes a type of component constructed based on the above structure, and this type of component is used to store all the readable and writable entity attribute data of the corresponding entity.
[0066] In one implementation of the present disclosure, when constructing the above structure, corresponding index indices can be assigned to the members inside the structure, so as to ensure that the members inside the structure can be accessed through the indices. For example, the address offset of the member can be determined according to the index of the member inside the structure, and the address of the member can be determined by combining the offset with the starting address of the structure, and the data of the member in the structure can be accessed based on the address of the member.
[0067] In one implementation 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, where: The attribute identification structure stores in sequence the attribute identifications corresponding to multiple entity attributes respectively; the attribute parameter structure stores in sequence the attribute parameters corresponding to multiple entity attributes respectively; the attribute gain structure stores in sequence the gain parameters corresponding to multiple entity attributes respectively.
[0068] In an implementation manner of the present disclosure, the attribute identification can be used to indicate the corresponding entity attribute; the attribute parameter can be used to indicate the specific parameter of the corresponding entity attribute; the gain parameter can be used to indicate the gain effective for the corresponding entity attribute.
[0069] According to an embodiment of the present disclosure, an entity may include one or more components constructed based on the above structures, and the components may include one or more types of the above structures.
[0070] Exemplarily, the attribute identification structure is defined as FixedArrayXX <ushort>The id, which uses the short type, can reduce the memory space it occupies. The attribute parameter structure includes the IDs of entity attributes, and the IDs are stored continuously in the corresponding order.
[0071] The attribute parameter structure is defined as: FixedArrayXX <float>value, where the data is of float type. Using the float type can improve precision and reduce the memory space it occupies. The data in this attribute parameter structure is specifically used to indicate the attribute value with a specific numerical value in the entity's attributes. This attribute value is also stored continuously in the corresponding order, that is, the ID is not recorded in this attribute parameter structure, only according to FixedArrayXX <ushort>The order of IDs in the ID stores the attribute values corresponding to the entity attributes. Therefore, the storage address of the attribute value of the entity attribute can be determined according to the index of the ID of the entity attribute.
[0072] 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 (such as yes / no). Similarly, this boolean-type entity attribute is also stored continuously in the corresponding order, that is, the ID is not recorded in this attribute parameter structure, and only according to FixedArrayXX <ushort>The order of IDs in the ID stores entity attributes of boolean type. Therefore, the storage address of the attribute value of the entity attribute of boolean type can be determined according to the index of the ID of the entity attribute.
[0073] The attribute gain structure is defined as: FixedArrayXX <float>addRateBuffs, where the data is of float type. Using the float type can improve precision and reduce the memory space it occupies. This data is used to indicate the addition and subtraction ratio value when modifying entity attributes by addition or subtraction. The addition and subtraction ratio values are also stored continuously in the corresponding order, that is, FixedArrayXX <float>The ID is not recorded in addRateBuffs. It is only based on FixedArrayXX <ushort>The order of IDs in the ID stores the plus-minus ratio values of entity attributes. Therefore, the storage address of the plus-minus ratio value can be determined according to the index of the ID of the entity attribute.
[0074] FixedArrayXX <float>multiplyBuffs, where the data is of float type. Using float type can improve precision and reduce the memory space it occupies. This data is used to indicate the multiplication factor when modifying entity attributes by multiplication, and this multiplication factor is also stored continuously in the corresponding order, that is, FixedArrayXX <float>Do not record IDs in multiplyBuffs. Only based on FixedArrayXX <ushort>The order of IDs in the ID stores the multiplication multiple value of entity attributes. Therefore, the storage address of the multiplication multiple value of entity attributes can be determined according to the index of the IDs of entity attributes.
[0075] In the above technical solution, at least one type of structure in the external script file is defined as an array with a fixed length, and the entity attribute data corresponding to multiple entity attributes are continuously stored in the structure. Among them, since in a single structure, the length occupied by data units is the same (for example, referring to the above example, in FixedArrayXX <ushort>In the ID, the length occupied by each ID is consistent, in FixedArrayXX <float>In the value, the length occupied by each attribute value is also the same). Based on this structure, memory alignment can be performed, thus effectively reducing the occupation of memory space (for example, referring to the above example, after memory alignment, in FixedArrayXX <ushort>The IDs are stored continuously in the ID, and each ID only needs to occupy 2 bytes; while in the scheme where the attributes and IDs are stored at intervals, each attribute value needs to occupy 4 bytes, and each ID also needs to occupy 4 bytes. Therefore, compared with the scheme where the attributes and IDs are stored at intervals, the above scheme can effectively reduce the occupied memory space), and after memory alignment, the data in the structure can be accessed through a single memory access. To sum up, this scheme can effectively reduce the occupied memory space, improve the cache hit rate at the same time, and improve the data access efficiency.
[0076] Figure 2 The structural block diagram of an external script calling device according to an embodiment of the present disclosure is shown. Among them, the device can be implemented as part or all of an electronic device through software, hardware or a combination of both.
[0077] As Figure 2 shown, the external script calling device 200 includes: An assembly acquisition module 201, configured to read an external script file and obtain an assembly according to the external script file; A pointer acquisition module 202, configured to obtain a function pointer corresponding to any method in the assembly and obtain entity indication information of an entity to which any method acts; A key-value pair container acquisition module 203, configured to create a first key-value pair container with the entity indication information of an entity to which any method acts as the key and the function pointer corresponding to any method as the value; An entity determination module 204, 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; A function execution module 205, configured to obtain a target function pointer from a first key-value pair container with the entity indication information of at least one entity as the key and execute the function indicated by the target function pointer.
[0078] According to an embodiment of the present disclosure, by first converting an external script file into an assembly, obtaining a function pointer corresponding to any method in the assembly and entity indication information of an entity to which the method acts, creating a first key-value pair container with the entity indication information of an entity to which any method acts as the key and the function pointer corresponding to any method as the value, the 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 advantages such as high retrieval efficiency and fast speed. By storing the entity indication information and the function pointer corresponding to the method in the form of a key-value in the key-value pair container, the speed of obtaining the function pointer in subsequent processing can be significantly improved, and the delay can be reduced. At the same time, by storing the function pointers of each method separately, it is also convenient to perform parallel calls to them in the future, further improving the external script calling speed.
[0079] 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.
[0080] As Figure 3 shown, the electronic device includes a memory and a processor. Among them, the memory is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the method according to the embodiment of the present disclosure.
[0081] An external script calling method is provided in an embodiment of the present disclosure, including: 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 an entity on which any method acts; Creating a first key-value pair container with the entity indication information of the entity on which any method acts as the key and the function pointer corresponding to any method as the value; Obtaining any entity type in the external script file, and determining entity indication information of at least one entity corresponding to the entity type based on any entity type; Obtaining a target function pointer from the first key-value pair container with the entity indication information of at least one entity as the key, and executing the function indicated by the target function pointer.
[0082] In an embodiment of the present disclosure, the entity indication information includes at least one of an entity name, an entity classification, and an entity label.
[0083] In an embodiment of the present disclosure, obtaining a function pointer corresponding to any method in the assembly includes: Obtaining metadata of any method in the assembly, where the metadata includes at least the method name and method type of any method; Obtaining the entry address of any method in memory based on the metadata; Obtaining a function pointer corresponding to any method based on the entry address.
[0084] In an embodiment of the present disclosure, determining entity indication information of at least one entity corresponding to the entity type based on any entity type includes: Obtaining at least one second key-value pair container, where the second key-value pair container uses entity indication information as the key and a query set as the value, and the query set is used to indicate the correspondence between the entity type and the entity corresponding to the key of the second key-value pair container; Determining 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.
[0085] In one implementation of the present disclosure, the operation of determining entity indication information of at least one entity corresponding to an entity type based on any entity type, and / or the 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 the key and executing the function indicated by the target function pointer are executed in the job system. In one implementation of the present disclosure, before creating a first key-value pair container with the entity indication information of an entity acted upon by any method as the key and the function pointer corresponding to any method as the value, the method further includes: Wrapping the function pointer corresponding to any method into a delegate and converting the delegate into an unmanaged function pointer; Creating a first key-value pair container with the entity indication information of an entity acted upon by any method as the key and the function pointer corresponding to any method as the value includes: Creating a first key-value pair container with the entity indication information of an entity acted upon by any method as the key and the unmanaged function pointer as the value.
[0086] In one implementation of the present disclosure, the components of an entity are constructed based on at least one type of structure body. The structure body is a fixed-length array, and the entity attribute data corresponding to multiple entity attributes are continuously stored in the structure body; Executing the function indicated by the target function pointer includes executing the function indicated by the target function pointer to modify the entity attribute data of the entity acted upon by the method corresponding to the target function.
[0087] In one implementation of the present disclosure, at least one type of structure body includes at least one of an attribute parameter structure body, an attribute gain structure body, and an attribute identification structure body; The attribute identification structure body continuously stores the attribute identifications corresponding to multiple entity attributes; the attribute parameter structure body continuously stores the attribute parameters corresponding to multiple entity attributes; the attribute gain structure body continuously stores the gain parameters corresponding to multiple entity attributes.
[0088] Figure 4 The structural schematic diagram of a computer system suitable for implementing the method according to the embodiments of the present disclosure is shown.
[0089] As Figure 4 shown, the computer system includes a processing unit, which can execute various methods in the above embodiments according to the program stored in the read-only memory (ROM) or the program loaded from the storage part into the random access memory (RAM). In the RAM, various programs and data required for the operation of the computer system are also stored. The processing unit, ROM, and RAM are connected to each other through a bus. The input / output (I / O) interface is also connected to the bus.
[0090] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN card, a modem, etc. The communication part performs a communication process via a network such as the Internet. A drive is also connected to the I / O interface as needed. A removable medium, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive as needed so that a computer program read from it can be installed into the storage part as needed. Among them, the processing unit can be implemented as a processing unit such as a CPU, a GPU, a TPU, an FPGA, an NPU, etc.
[0091] Specifically, according to an embodiment of the present disclosure, the method described above can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program tangibly embodied on a machine-readable medium, the computer program including program code for performing the above method. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part, and / or installed from a removable medium.
[0092] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0093] The units or modules involved in the embodiments described in the present disclosure can be implemented in software or in programmable hardware. The described units or modules can also be provided in a processor, and the names of these units or modules do not, in some cases, constitute a limitation to the units or modules themselves.
[0094] As another aspect, the present disclosure also provides a computer-readable storage medium, which may be the computer-readable storage medium included in the electronic device or computer system in the above embodiments; or it may exist alone and be a computer-readable storage medium not assembled into the device. The computer-readable storage medium stores one or more programs, and the one or more programs are used by one or more processors to execute the methods described in the present disclosure.
[0095] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles applied. Those skilled in the art should understand that the scope of the invention involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the technical solutions formed by mutually replacing the above features with the technical features (but not limited to) having similar functions disclosed in the present disclosure.< / ushort> < / float> < / ushort> < / ushort> < / float> < / float> < / ushort> < / float> < / float> < / ushort> < / bool> < / ushort> < / float> < / ushort>
Claims
1. An external script calling method, characterized in that, including: reading an external script file and obtaining an assembly according to the external script file; obtaining a function pointer corresponding to any one method in the assembly, and obtaining entity indication information of an entity on which the any one method acts; creating a first key-value pair container with the entity indication information of the entity on which the any one method acts as the key and the function pointer corresponding to the any one method as the value; obtaining any one entity type in the external script file, and determining 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 a 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.
2. The external script calling method according to claim 1, wherein The entity indication information includes at least one of an entity name, an entity classification, and an entity label.
3. The external script calling method according to claim 1, wherein The obtaining a function pointer corresponding to any one method in the assembly includes: obtaining metadata of any one method in the assembly, where the metadata at least includes a method name and a method type of the any one method; obtaining an entry address in memory of the any one method based on the metadata; obtaining a function pointer corresponding to the any one method based on the entry address.
4. The external script calling method according to claim 1, wherein The determining entity indication information of at least one entity corresponding to the entity type based on the any one entity type includes: obtaining at least one second key-value pair container, where the second key-value pair container has entity indication information as the key and a query set as the value, and the query set is used to indicate a correspondence between an entity type and an entity corresponding to the key of the second key-value pair container; determining 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.
5. The external script calling method according to claim 4, wherein The operation of determining entity indication information of at least one entity corresponding to the entity type based on the any one entity type, 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 the key and executing the function indicated by the target function pointer is performed in a job system.
6. The external script call method according to claim 1, characterized in that Before creating a first key-value pair container with the entity indication information of the entity on which the any one method acts as the key and the function pointer corresponding to the any one method as the value, the method further includes: wrapping the function pointer corresponding to the any one method into a delegate, and converting the delegate into an unmanaged function pointer; The creating a first key-value pair container with the entity indication information of the entity on which the any one method acts as the key and the function pointer corresponding to the any one method as the value includes: creating a first key-value pair container with the entity indication information of the entity on which the any one method acts as the key and the unmanaged function pointer as the value.
7. The external script calling method according to any one of claims 1-6, characterized in that Components of an entity are constructed based on at least one type of structure, the structure is a fixed-length array, and entity attribute data corresponding to multiple entity attributes are continuously stored in the structure; 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 an entity on which a method corresponding to the target function acts.
8. The external script calling method according to claim 7, wherein The at least one type of structure body includes at least one of an attribute parameter structure body, an attribute gain structure body, and an attribute identification structure body; The attribute identification structure body stores in sequence the attribute identifications corresponding to the respective multiple entity attributes; The attribute parameter structure body stores in sequence the attribute parameters corresponding to the respective multiple entity attributes; The attribute gain structure body stores in sequence the gain parameters corresponding to the respective multiple entity attributes.
9. An external script calling device, characterized in that, It includes: An assembly acquisition module, configured to read an external script file and acquire an assembly according to the external script file; A pointer acquisition module, configured to acquire a function pointer corresponding to any one method in the assembly and acquire entity indication information of an entity on which the any one method acts; A key-value pair container acquisition module, configured to create a first key-value pair container with the entity indication information of the entity on which the any one method acts as the key and the function pointer corresponding to the any one method as the value; An entity determination module, configured to acquire any one 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 one entity type; A function execution module, configured to acquire a 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 execute the function indicated by the target function pointer.
10. An electronic device, characterized in that, It includes a memory and a processor; wherein, the memory is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1-8.
11. A computer-readable storage medium having computer instructions stored thereon, characterized in that, When the computer instruction is executed by the processor, it implements the method according to any one of claims 1-8.
Citation Information
Patent Citations
Script variable management method, device, equipment and computer readable storage medium
CN110362339A
Test task execution method, device and system, storage medium and electronic device
CN112948264A
Detection method, device, equipment, storage medium and computer program product
CN116956297A
Software testing method and device, equipment and storage medium
CN117632694A
METHOD, COMPUTING DEVICE, MEDIUM AND PROGRAM PRODUCT FOR DETERMINING Matching OPERATORS
CN118502847A
