1. Foreword
Say that there is a period of time has not been updated, this period of time to play a bit, but also to write a point of the program, the octree scene management wrote, but also optimized a little resources loaded some content. It's not clear how much of DirectX has been done before, and there's at least a lot more to know about these places. Send out today's finished octree scene management, inside the model with the DirectX sample Tiger, here is not very clear--;
Today I'm going to talk about the models, effects, and textures of my engine, at least make the most of the meaning. If there is no understanding of where to contact me.
2. Model, special effects, mapping of resource reuse
We can also see that the above picture of the tiger more than one, when the number of the same model to a certain extent (for example, 10,000), it is necessary to consider a certain optimization, if every time innocently from the file to read out the model, save for a ID3DXMesh, That is not only slow loading time is unbearable, but also the memory consumption is huge. In Wuguiengine, I used a simpler way to solve this problem.
The central idea of design mode is to modify the closed, open to expand, central idea is "change", but very embarrassed to say, I d3d, in many times not even clear "change" will appear in where, so I use the method, very simple, now use it very clear, However, if the subsequent extension support is not good or there is a better architectural approach is also looking for guidance. The purpose of this series of articles is to initiate a novel.
I used a simple map to do these things. The definition of Resource Manager (ResourceManager) is given below
1:class graphicsdevice
2:
3://resource type
4:enum resourcetype
5: {
6:rttexture = 0,
7: Rtmesh = 1,
8:rteffect = 2,
9:};
Ten:
11://Description of a resource
12://PreSource by pointer of type resourcetype,void*, reference us Ecount consists of
13:typedef struct Structres
: {
15:public:
16:structres (void* pRes, resourcetype type)
{
18:presource = pRes
19:usecount = 1;
20:resourcetype = type;
:}
22:re SourceType ResourceType;
23:void* PreSource;
24:int Usecount;
25:} Structres;
:
27://Resource Manager
28:class ResourceManager
: {
30:public:
31:static resourcemanager* Getinst Ance ();
:
33://Get resource file based on filename
34:void* getd3dresource (string filename,
35:graphicsdevice* pdevice,
36:resourcetype type);
38://Uninstall resource file based on filename
39:void disposed3dresource (string filename);
40:protected:
41:resource Manager ();
42:
43:map<string, structres*> resourcetable
44:static resourcemanager* pinstance;
:};