Game scene management method
[technical field]
The present invention relates to game engine field, particularly about game scene management method.
[background technology]
Game is requisite entertainment selection in people's daily life, the almost behind of every a game now, there is a game engine matching, game engine is being controlled various resources in game, and modern game engine comprises substantially: image engine, sound engine, physical engine, control engine, artificial intelligence or game logic etc.
Described image engine is used for drawing concrete scene of game, and wherein scene of game refers to the game picture that display shows.Fig. 1 shows an easy game scene 100 of the prior art.Please refer to shown in Fig. 1, described scene of game 100 comprises LCD TV 102, TV box 104, cabinet for TV 106, desk 108, book 110, the first cup 112, the second cup 114 and room 116.Described image engine, in the time drawing scene of game, adopts scene graph to carry out the contextual data that organization and administration are relevant conventionally.Described scene graph adopts a kind of tree data structure top-down, layering to carry out organizing scenario data.The top of scene graph tree structure is a root node, extend to group node or leaf node downwards from root node, from group node extend to downwards leaf node or the group node of one deck, the group node of every layer can extend the group node of leaf node or lower one deck downwards, and described leaf node is positioned at the bottommost of scene graph tree structure, the pass of each node other nodes extended with it is set membership, each node stores contextual data, such as geometric model, rendering state, dimensional orientation etc., wherein the data message in father node can have influence on its child node.
While drawing described scene of game 100 specific to image engine, its scene graph that can adopt please refer to the scene Figure 200 shown in Fig. 2.Described scene Figure 200 comprises root node 202, home theater node 204, LCD TV node 206, cabinet for TV node 208, TV box node 210, desk node 212, this child node 214, the first cup node 216, the second cup node 218 and room node 220.Wherein home theater node 204 is group nodes, LCD TV node 206, cabinet for TV node 208 are child nodes of home theater node 204, wherein LCD TV node 206 is leaf node, cabinet for TV node 208 is group node, TV box 210 is child nodes of cabinet for TV node 208, and TV and 210 is also leaf node; Desk node 212 is group nodes, and this child node 214, the first cup node 216 and the second cup node 218 are that desk node 212 is leaf node the child node as desk node 212.A group node can have one or more leaf nodes, and leaf node is positioned at the bottommost of scene graph.The information such as the logical relation of the group node in scene graph, dimensional orientation, rendering state can affect its child node, such as desk node 212 is moved, the child node (such as this child node 214, the first cup node 216 and the second cup node 218) that it also can affect it is moved.Room node 220 in described scene Figure 200 may be also group node in practice, also has other leaf nodes such as wall.In actual scene graph, scene graph has comprised that polytype node, to carry out various user functions, forms colourful game.For example, start node can arrange its child node can with or unavailable; Level of detail node according to the observation person's distance calls different child nodes; Transform node can change the coordinate transform state of child node solid.OO scene graph provides this species diversity by the mechanism of inheriting, and all node classes have a total base class, derives separately the method that realizes specific function simultaneously.
In the time that game need to be drawn scene, adopt certain traversal mode (such as upgrading traversal, selection traversal and the traversal etc. of drawing) traversal scene graph just can draw out the scene needing.But in concrete scene, may encounter identical or similar scenario objects needs to build, and this same or similar scenario objects can be any node, and we are taking the geological information of same or similar object as example.For instance, the first cup 112 shown in Fig. 1 and the second cup 114, suppose that the first cup 112 is the same with the geological information of the second cup 114, only have dimensional orientation different with rendering state, for example in game, the first cup 112 is that a tank cola, the second cup 114 are tank Sprites, only need on identical cup solid, stick different pictures and just can realize.
Fig. 3 shows the management method that realizes identical or similar scenario objects in prior art.Please refer to Fig. 3, adopt a leaf node 302 to store the geological information of cup in scene graph, group node 304 and 306 is stored respectively dimensional orientation and the rendering state of the first cup 112 and the second cup 114, and such benefit is to have realized sharing of data.Actual while playing up scene after game running, game engine need to travel through scene graph, and the data of the each node traversing are loaded in internal memory, the geological information that comprises a cup in the data about the first cup 112 that produce in internal memory, in internal memory, produce about the geological information that also comprises a cup in the data of the second cup 114, just need to distribute more internal memory for this game so obviously.In the time that in game, identical and similar scenario objects is more, such as some big games may exist tens of even hundreds of wild strange or similar trees of the same type etc. in a scene, it is more serious that above-mentioned implementation has just greatly increased complexity and the internal memory waste of scene of game figure.In addition,, in memory management, complicated adduction relationship will cause internal memory to discharge the problems such as wrong and pointer mistake.
Therefore, be necessary to propose a kind of scheme more preferably and solve the problems referred to above.
[summary of the invention]
The object of this part is to summarize some aspects of embodiments of the invention and briefly introduces some preferred embodiments.In this part and the application's specification digest and denomination of invention, may do a little simplification or omit to avoid the making object of this part, specification digest and denomination of invention fuzzy, and this simplification or omit and can not be used for limiting the scope of the invention.
One object of the present invention is to provide a kind of game scene management method, realizes the management of identical or similar scenario objects by adding reference count mechanism.
In order to reach object of the present invention, the invention provides a kind of game scene management method, manage for the scene graph to game engine, described scene graph comprises some group node and leaf nodes with set membership, part leaf node includes reference count, and described method comprises:
In the time that described game engine travels through described scene graph and quotes for the first time a leaf node that comprises reference count, game engine is loaded into memory headroom by described leaf node and obtains an address pointer, the reference count of leaf node described in initialization; In the time that described game engine is quoted described leaf node again, described game engine is quoted described leaf node by described address pointer, and increases the reference count of described leaf node; When described game engine is complete to once quoting of described leaf node, and reduce the reference count of described leaf node; With in the time that the reference count of described leaf node is less than its initialization value, described game engine discharges the memory headroom that described leaf node occupies.
Further, described leaf node is used for storing the data that can supply multiplexing game object.
Further, the three-dimensional model that the data of described game object are object.
Further, described leaf node can be realized by vertexbuffer class.
Further, there is the group node of set membership to be used for storage space orientation and rendering state with described leaf node.
Further, described in described initialization, the reference count of leaf node refers to that the reference count of leaf node is 1 described in initialization.
Further, the reference count of the described leaf node of described increase refers to the reference count of described leaf node is added to 1.
Further, the reference count of the described leaf node of described minimizing refers to the reference count of described leaf node is subtracted to 1.
Further, when the described reference count when described leaf node is less than its initialization value, refer in the time that the reference count of described leaf node equals 0.
Compared with prior art, the game scene management method in the present invention, by for leaf node adds reference count, is realized the management of identical or similar scenario objects with this, thereby can be improved memory usage.The similar object comprising in scene of game is more, and effect of the present invention is more obvious.
[brief description of the drawings]
In conjunction with reference to accompanying drawing and ensuing detailed description, the present invention will be easier to understand, wherein structure member corresponding to same Reference numeral, wherein:
Fig. 1 shows a scene of game of the prior art;
Fig. 2 shows Fig. 1 of the prior art and illustrates the scene graph of scene of game;
Fig. 3 shows the management method that realizes identical or similar scenario objects in prior art;
Fig. 4 shows game scene management method in the present invention method flow diagram in one embodiment;
Fig. 5 shows game scene management method in the present invention application schematic diagram in one embodiment; With
Fig. 6 shows the scene of game that comprises similar scenario objects that utilizes the present invention to realize.
[embodiment]
Detailed description of the present invention is mainly carried out the running of direct or indirect simulation technical solution of the present invention by program, step, logical block, process or other symbolistic descriptions.For the thorough the present invention that understands, a lot of specific detail in ensuing description, are stated.And in the time there is no these specific detail, the present invention may still can realize.Under those of skill in the art uses these descriptions herein and states the work essence of effectively introducing them to the others skilled in the art in affiliated field.In other words, be the object of the present invention of avoiding confusion, because the method for knowing, program, composition and circuit are readily appreciated that, therefore they are not described in detail.
Alleged " embodiment " or " embodiment " refers to special characteristic, structure or the characteristic that can be contained at least one implementation of the present invention herein.Different local in this manual " in one embodiment " that occur not all refer to same embodiment, neither be independent or the embodiment mutually exclusive with other embodiment optionally.In addition, represent sequence of modules in method, process flow diagram or the functional block diagram of one or more embodiment and revocablely refer to any particular order, not also being construed as limiting the invention.
Game scene management method of the present invention can utilize computing machine to realize and become a scene graph system in conjunction with relative program, be positioned at the scene management position of whole game engine, by identical or similar scenario objects needs or other reasons causes reusable leaf node to add reference count mechanism to realizing in scene graph.Realize in data sharing, reduced the object of scene of game figure complexity, raising memory management efficiency.
In the specific implementation, in scene graph, first the relevant data of identical or similar scenario objects is designed to the leaf node with reference count.In one embodiment, described leaf node can be realized by vertexbuffer class.Fig. 4 shows a kind of game scene management method 400 of the present invention method flow diagram in one embodiment.Please refer to Fig. 4, described method 400 comprises the steps.
Step 402, in the time that described game engine travels through described scene graph and quotes for the first time a leaf node that comprises reference count, game engine is loaded into memory headroom by described leaf node and obtains an address pointer, and the reference count of leaf node is 1 described in initialization;
Step 404, in the time that described game engine is quoted described leaf node again, described game engine is quoted described leaf node by described address pointer, and the reference count of described leaf node is added to 1;
Step 406, when described game engine is complete to once quoting of described leaf node, and subtracts 1 by the reference count of described leaf node;
Step 408, in the time that the reference count of described leaf node equals 0, described game engine discharges the memory headroom that described leaf node occupies.
Fig. 5 shows the application schematic diagram in the embodiment of scene management method of a kind of game engine of the present invention.Please refer to Fig. 5, adopt implementation of the present invention to be at the first cup 112 shown in Fig. 1 and the second cup 114: scene graph adopts a leaf node 502 to store the geological information of cup, group node 504 and 506 is stored respectively dimensional orientation and the rendering state of the first cup 112 and the second cup 114, in the time building leaf node 502, just add reference count simultaneously, in the time that game engine need to show described scene 100, while traversing first cup 112 this paths, will in internal memory, create the storage space of leaf node 502, and reference count is initialized as to 1; When traversing second cup 506 this paths, will quote the leaf node 502 in internal memory by pointer, and reference count is made as to 2; When scene of game switches or when relevant cup Event triggered (such as cup is crushed etc.), the first cup 112 or the second cup 114 need to not occur in scene of game, game engine just reduces the reference count of respective numbers, in the time that reference count is 0, game engine will discharge the memory headroom of described leaf node.
Fig. 6 shows the scene of game that comprises similar scenario objects that utilizes the present invention to realize, and wherein said scene 600 comprises first cutter 622 and the second cutter 624 in the first personage 620 and first personage's 620 hands; In the second personage 640 and second personage's 640 hands the 3rd cutter 642 and the 4th cutter 644.Wherein first cutter 622 and second cutter 624 are black; The 3rd is that black and white is alternate cutter 642 and the 4th cutter 644.Due to first cutter 622, second cutter 624, the 3rd cutter 642 is all the same the geological information of cutter 644 with the 4th, so we can store the geological information of described cutter and add reference count with a leaf node, first cutter 622, second cutter 624, the 3rd are all stored respectively relevant locus and rendering state as group node cutter 642 and the 4th using cutter 644, then quote the geological information of the cutter of described leaf node storage and just can realize the shared data of the shared internal memory of four cuttves, greatly reduced internal memory occupation rate.In the time that the similar scenario objects in a game is more, make effect in this way more obvious.
Above-mentioned explanation has fully disclosed the specific embodiment of the present invention.It is pointed out that and be familiar with the scope that any change that person skilled in art does the specific embodiment of the present invention does not all depart from claims of the present invention.Correspondingly, the scope of claim of the present invention is also not limited only to described embodiment.