A snapshot history record operation method and device based on terrain editor
Undo and redo operations are implemented in Unity's terrain editor through difference set operations, which solves the problem of low performance when the amount of data is large in the existing technology and improves processing efficiency.
Patent Information
- Application Number
- CN202010622041.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-06-30
AI Technical Summary
In the existing technology, Unity's terrain map editor needs to traverse all elements when restoring data in a snapshot, resulting in huge performance consumption and long processing time when the amount of data is large.
By obtaining the difference between the current terrain data and the previous terrain data, the difference operation is performed to implement undo or redo operations, avoiding traversing all elements and only processing the difference result.
It improves the processing efficiency of the system, reduces system consumption, and realizes efficient snapshot history operations.
Smart Images

Figure CN112001984B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a snapshot history record operation method and device based on a terrain editor. Background Art
[0002] All editors have history undo and redo functions, and the Unity-based terrain map editor is no exception. Generally, history records are divided into "command type" and "snapshot type".
[0003] The "imperative" history record implements undo and redo. What is saved in the history record is the operation command (or method), and two commands are saved each time. For each operation of the user, a forward operation method and a reverse operation method are written and submitted to a command executor. The command executor will save such a pair of methods and immediately execute the forward operation method. When you need to undo this operation, execute the corresponding reverse operation method to return to the state before the operation; when redoing, execute the forward operation method again.
[0004] "Snapshot" Undo and redo are implemented in snapshot mode. What is saved in the history record is a snapshot of the application data. After each operation of the user, the part of the application data that needs to be saved is saved in the history record (using deep copy or immutable data). When undoing or redoing, directly take out the corresponding snapshot and restore it to the application. According to this idea, as long as the corresponding data snapshot is taken out, it can be restored to any state.
[0005] When restoring data in snapshot style, the usual practice is to save a snapshot of all elements in the scene each time a modification is made. All elements are directly overwritten when undoing or redoing. All elements need to be traversed each time. When the amount of data is large, the performance consumption is huge and the processing time is long.
[0006] An example of undo and redo in the prior art is as follows: perform the following operations in order:
[0007] Original data: {1, 2, 3, 4};
[0008] Operation 1: {1, 2, 3, 4, 5};
[0009] Operation 2: {1, 2, 4, 5};
[0010] withdraw: {1, 2, 3, 4, 5};
[0011] Redo: {1, 2, 4, 5};
[0012] Full data withdrawal and redo
[0013] Undo directly overwrites the previous operation {1, 2, 3, 4, 5};
[0014] Redo directly overwrites the previous operation {1, 2, 4, 5}.
[0015] Therefore, the prior art still needs to be improved and developed. Summary of the invention
[0016] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a snapshot history record operation method and device based on a terrain editor, aiming to solve the problem that when restoring data in a snapshot manner in the terrain map editor of Unity in the prior art, all elements need to be traversed each time, which results in huge performance consumption and long processing time when the data volume is large.
[0017] The technical solution of the present invention is as follows:
[0018] A snapshot history operation method based on a terrain editor, the method comprising:
[0019] Get the user's modification operation on the terrain editor and save all the data after the modification operation;
[0020] A control operation is detected, and a difference set between the terrain data of the previous step and the current terrain data is obtained, wherein the control operation includes an undo operation or a redo operation;
[0021] Perform corresponding response operations according to the difference set.
[0022] Optionally, the acquiring of the user's modification operation on the terrain editor and saving all data after the modification operation include:
[0023] Get the user's modification operation on the terrain data in the terrain editor, and save all the terrain data after the modification operation in the history queue.
[0024] Optionally, the acquiring of the modification operation of the user on the terrain data in the terrain editor and saving all the terrain data after the modification operation in the history queue includes:
[0025] Traverse all elements in the map, save the historical record data set, write the data set to a file, and save it locally.
[0026] Optionally, when the control operation is an undo operation, obtaining a difference set between the previous terrain data and the current terrain data includes:
[0027] Get the data in the current scene and the data in the previous scene, perform a set difference operation on the data in the previous scene and the data in the current scene, and use the result of the set difference operation as the set to be deleted.
[0028] Optionally, performing a corresponding response operation according to the difference set includes:
[0029] Traverse the collection that needs to be deleted to delete the terrain elements.
[0030] Optionally, when the control operation is a redo operation, obtaining a difference set between the previous terrain data and the current terrain data includes:
[0031] Get the data in the current scene and the data in the previous scene, perform a set difference operation on the data in the current scene and the data in the previous scene, and use the result of the set difference operation as the set to be added.
[0032] Optionally, performing a corresponding response operation according to the difference set includes:
[0033] Traverse the collection that needs to be added to add terrain elements.
[0034] Another embodiment of the present invention provides a snapshot history record operation device based on a terrain editor, the device comprising at least one processor; and
[0035] a memory communicatively connected to the at least one processor; wherein,
[0036] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the above-mentioned snapshot history operation method based on the terrain editor.
[0037] Another embodiment of the present invention further provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors can execute the above-mentioned snapshot history operation method based on the terrain editor.
[0038] Another embodiment of the present invention provides a computer program product, which includes a computer program stored on a non-volatile computer-readable storage medium, and the computer program includes program instructions, which, when executed by a processor, cause the processor to execute the above-mentioned snapshot history operation method based on the terrain editor.
[0039] Beneficial effect: The present invention discloses a snapshot history record operation method and device based on a terrain editor. Compared with the prior art, the embodiment of the present invention obtains the difference between the current terrain data and the previous terrain data, and performs undo or redo operations according to the difference, without traversing all elements, with low system consumption and high processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0041] Figure 1 It is a flow chart of a preferred embodiment of a snapshot history record operation method based on a terrain editor of the present invention;
[0042] Figure 2 The figure is a hardware structure diagram of a preferred embodiment of a snapshot history record operation device based on a terrain editor of the present invention. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0044] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0045] The embodiment of the present invention provides a snapshot history operation method based on a terrain editor. Figure 1 , Figure 1 FIG. 1 is a flowchart of a preferred embodiment of a snapshot history record operation method based on a terrain editor of the present invention. Figure 1 As shown, it includes the steps of:
[0046] Step S100: obtaining the modification operation of the user on the terrain editor, and saving all data after the modification operation;
[0047] Step S200: Detecting a control operation, obtaining a difference set between the terrain data of the previous step and the terrain data of the current step, wherein the control operation includes an undo operation or a redo operation;
[0048] Step S300: Execute corresponding response operations according to the difference set.
[0049] During specific implementation, the snapshot history record operation method based on the terrain editor of the embodiment of the present invention is applied to the Unity terrain editor. Unity has a fully functional terrain editor that supports real-time carving of mountains, canyons, plains, highlands and other terrains in a brush-drawing manner. The Unity terrain editor also provides functions such as real-time drawing of surface material textures, tree planting, and large-area grassland layout. It is worth mentioning that the terrain editor in Unity supports the LOD (Level of Detail) function, which can adjust the density of the terrain block (Patch) grid according to the distance between the camera and the terrain and the degree of terrain undulation. Use sparse grids for distant or flat terrain blocks, and dense grids for nearby or steep terrain blocks. This will make the game scene both realistic and detailed, while also not affecting performance.
[0050] The embodiment of the present invention saves a snapshot of all information in the scene each time a modification operation such as adding or deleting an element in the scene is performed. When historical data needs to be restored, the following operations are performed on the data in the current scene and the data in the previous scene:
[0051] Perform a difference operation on the data in the previous scene and the data in the current scene as the data set to be deleted;
[0052] Perform a difference operation on the data in the current scene and the data in the previous scene as the data set to be added;
[0053] Get the data sets that need to be deleted and added, and perform deletion and addition operations to implement the undo and redo operations of historical records.
[0054] In a further embodiment, a modification operation of a user on a terrain editor is obtained, and all data after the modification operation is saved, including:
[0055] Get the user's modification operation on the terrain data in the terrain editor, and save all the terrain data after the modification operation in the history queue.
[0056] In specific implementation, modification operation refers to adding or deleting elements of Unity Terrain Editor. When users add or delete terrain data in Unity Terrain Editor, the added or deleted data will only be in the history queue.
[0057] Furthermore, obtaining the user's modification operation on the terrain data in the terrain editor, and saving all the terrain data after the modification operation in the history queue, includes:
[0058] Traverse all elements in the map, save the historical record data set, write the data set to a file, and save it locally.
[0059] In the specific implementation, all terrain data is saved in the history queue; all elements in the map are traversed; the data set is saved; and the file is written. For example, the file name can be recorded as a local history record set and stored locally. The historical operation data is sorted from the most recent to the most recent in time. The earliest historical operation is recorded as historical operation 1, and so on. The arrangement in the historical operation data is historical operation 1, historical operation 2...historical operation n, where n is an integer greater than or equal to 1, and historical operation n refers to the most recent operation.
[0060] Furthermore, when the control operation is a cancel operation, the step of obtaining the difference between the terrain data of the previous step and the current terrain data includes:
[0061] Get the data in the current scene and the data in the previous scene, perform a set difference operation on the data in the previous scene and the data in the current scene, and use the result of the set difference operation as the set to be deleted.
[0062] In specific implementation, when an undo operation is performed on the Unity terrain editor, the last record n is taken out from the local historical data set, that is, historical operation n is called, and the historical operation record n is subtracted from the current data set, that is, the result of historical operation n-current operation data set is the set to be deleted.
[0063] Furthermore, a corresponding response operation is performed according to the difference set, including:
[0064] Traverse the collection that needs to be deleted to delete the terrain elements.
[0065] During specific implementation, the collection to be deleted is traversed to delete the terrain elements.
[0066] In a further embodiment, when the control operation is a redo operation, the step of obtaining a difference set between the previous terrain data and the current terrain data includes:
[0067] Get the data in the current scene and the data in the previous scene, perform a set difference operation on the data in the current scene and the data in the previous scene, and use the result of the set difference operation as the set to be added.
[0068] In specific implementation, when a redo operation is performed on the Unity terrain editor, the last record n is taken out from the local historical data set, that is, historical operation n is called, and the current data set is subtracted from the historical operation record n, that is, the result of the current operation data set - historical operation n is the set to be added.
[0069] Further, a corresponding response operation is performed according to the difference set, including:
[0070] Traverse the collection that needs to be added to add terrain elements.
[0071] During the specific implementation, all elements in the map are traversed, and the collection that needs to be added is traversed to add terrain elements.
[0072] The present invention also provides a specific embodiment of a snapshot history record operation method based on a terrain editor, which is as follows:
[0073] Original data: {1, 2, 3, 4};
[0074] Operation 1: {1, 2, 3, 4, 5};
[0075] Operation 2: {1, 2, 4, 5};
[0076] withdraw: {1, 2, 3, 4, 5};
[0077] The specific implementation method of the withdrawal operation is: the current data and the previous step data are subtracted to obtain the set to be deleted;
[0078] {1, 2, 4, 5}-{1, 2, 3, 4, 5} = empty set
[0079] Perform a set difference operation on the previous data and the current data to obtain the set to be added;
[0080] {1, 2, 3, 4, 5}-{1, 2, 4, 5}={3}
[0081] If the set to be deleted is an empty set, no operation is required;
[0082] If the set to be added is {3}, then directly add {3} to {1, 2, 4, 5};
[0083] The specific implementation of the redo is:
[0084] Perform a set difference operation on the current data and the data in the previous step to obtain the set that needs to be deleted;
[0085] {1, 2, 3, 4, 5}-{1, 2, 3, 5}={3}
[0086] Perform a set difference operation on the previous data and the current data to obtain the set to be added;
[0087] {1, 2, 4, 5}-{1, 2, 3, 4, 5} = empty set
[0088] The set to be deleted is {3}, then directly delete {3} from {1, 2, 3, 4, 5};
[0089] If the set to be added is an empty set, no operation is required.
[0090] The embodiment of the present invention also provides a code example of a snapshot history record operation method based on a terrain editor, which implements the undo and redo functions in a unity map editor, as follows:
[0091] List <int>past=new List <int>{1,2,3}; / / Previous step record
[0092] List <int>present=new List <int>{2,3,3}; / / Current record
[0093] List <int>needRemove = past.Except(present).ToList(); / / need to delete data
[0094] List <int>needAdd = present.Except(past).ToList(); / / need to add data
[0095] remove(needRemove); / / delete
[0096] add(needAdd); / / Add.
[0097] It should be noted that, in each of the above embodiments, there is not necessarily a certain order between the above steps. A person skilled in the art can understand, based on the description of the embodiments of the present invention, that in different embodiments, the above steps may have different execution orders, that is, they may be executed in parallel, may be executed interchangeably, and so on.
[0098] Another embodiment of the present invention provides a snapshot history record operation device based on a terrain editor, such as Figure 2 As shown, the device 10 comprises:
[0099] One or more processors 110 and memory 120, Figure 2 A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a bus or other means. Figure 2 The example of connecting through bus is taken in the following.
[0100] The processor 110 is used to complete various control logics of the device 10, and it can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISCMachine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP core, or any other such configuration.
[0101] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions corresponding to the snapshot history recording operation method based on the terrain editor in the embodiment of the present invention. The processor 110 executes various functional applications and data processing of the device 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, the snapshot history recording operation method based on the terrain editor in the above method embodiment is implemented.
[0102] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store applications required for operating the device and at least one function; the data storage area may store data created according to the use of the device 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0103] One or more units are stored in the memory 120, and when executed by one or more processors 110, execute the snapshot history operation method based on the terrain editor in any of the above method embodiments, for example, execute the above described Figure 1 The method comprises steps S100 to S300.
[0104] An embodiment of the present invention provides a non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, for example, to execute the above-described Figure 1 The method comprises steps S100 to S300.
[0105] As an example, the non-volatile storage medium can include a read-only memory (ROM), a programmable ROM (PROM), an electrically programmable ROM (EPROM), an electrically erasable ROM (EEPROM), or a flash memory. Volatile memory can include a random access memory (RAM) as an external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0106] Another embodiment of the present invention provides a computer program product, the computer program product includes a computer program stored on a non-volatile computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a processor, the processor executes the snapshot history operation method based on the terrain editor of the above method embodiment. For example, the above described Figure 1 The method comprises steps S100 to S300.
[0107] The embodiments described above are merely illustrative, in which the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0108] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can exist in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0109] Conditional language such as "can," "can," "might," or "may," among other things, unless specifically stated otherwise or otherwise understood within the context as used, is generally intended to convey that particular embodiments can include (while other embodiments do not) particular features, elements, and / or operations. Thus, such conditional language is also generally intended to imply that features, elements, and / or operations are anyway required for one or more embodiments or that one or more embodiments must include logic for determining, with or without input or prompting, whether such features, elements, and / or operations are included or will be performed in any particular embodiment.
[0110] What has been described herein in this specification and the accompanying drawings includes examples of snapshot-style history operation methods and devices that can provide terrain editors. Of course, it is not possible to describe every conceivable combination of elements and / or methods for the purpose of describing the various features of the present disclosure, but it can be recognized that many other combinations and permutations of the disclosed features are possible. Therefore, it is obvious that various modifications can be made to the present disclosure without departing from the scope or spirit of the present disclosure. In addition, or in an alternative, other embodiments of the present disclosure may be apparent from consideration of this specification and the accompanying drawings and from the practice of the present disclosure as presented herein. It is intended that the examples proposed in this specification and the accompanying drawings are considered to be illustrative and not restrictive in all respects. Although specific terms are employed herein, they are used in a general and descriptive sense and are not used for limiting purposes.< / int> < / int> < / int> < / int> < / int> < / int>
Claims
1. A snapshot history record operation method based on a terrain editor, characterized in that: The method comprises: Get the user's modification operation on the terrain editor and save all the data after the modification operation; A control operation is detected, and a difference set between the terrain data of the previous step and the terrain data of the current step is obtained, wherein the control operation includes an undo operation or a redo operation; Execute corresponding response operations according to the difference set; When the control operation is a cancel operation, the step of obtaining a difference set between the previous terrain data and the current terrain data includes: Get the data in the current scene and the data in the previous scene, perform a difference operation on the data in the previous scene and the data in the current scene, and use the result of the difference operation as the set to be deleted; When the control operation is a redo operation, obtaining the difference between the previous terrain data and the current terrain data includes: Get the data in the current scene and the data in the previous scene, perform a set difference operation on the data in the current scene and the data in the previous scene, and use the result of the set difference operation as the set to be added.
2. The snapshot history record operation method based on the terrain editor according to claim 1, characterized in that: The obtaining of the modification operation of the terrain editor by the user and saving all the data after the modification operation include: Get the user's modification operation on the terrain data in the terrain editor, and save all the terrain data after the modification operation in the history queue.
3. The snapshot history record operation method based on the terrain editor according to claim 2, characterized in that: The method of obtaining the modification operation of the user on the terrain data in the terrain editor and saving all the terrain data after the modification operation in the history queue includes: Traverse all elements in the map, save the historical record data set, write the data set to a file, and save it locally.
4. The snapshot history record operation method based on terrain editor according to claim 1, characterized in that: The performing a corresponding response operation according to the difference set includes: Traverse the collection that needs to be deleted to delete the terrain elements.
5. The snapshot history record operation method based on terrain editor according to claim 1, characterized in that: The performing corresponding response operations according to the difference set includes: Traverse the collection that needs to be added to add terrain elements.
6. A snapshot history record operation device based on a terrain editor, characterized in that: The apparatus comprises at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the snapshot history operation method based on the terrain editor as described in any one of claims 1-5.
7. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions, which, when executed by one or more processors, enable the one or more processors to execute the snapshot history record operation method based on the terrain editor as described in any one of claims 1-5.
8. A computer program product, characterized in that The computer program product includes a computer program stored on a non-volatile computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the snapshot history operation method based on the terrain editor as described in any one of claims 1-5.
Citation Information
Patent Citations
Online content management system with undo and REDO operations
US20140244713A1
