source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.h @ 3237

Revision 3237, 2.9 KB checked in by mattausch, 15 years ago (diff)

debug version

Line 
1#ifndef __RESOURCEMANAGER_H__
2#define __RESOURCEMANAGER_H__
3
4
5#include <string>
6#include <iostream>
7#include <fstream>
8#include <map>
9#include "common.h"
10
11
12
13class igzstream;
14
15
16namespace CHCDemoEngine
17{
18
19class SceneEntity;
20class Material;
21class Geometry;
22class Texture;
23class Matrix4x4;
24class Transform3;
25class ShaderProgram;
26
27
28/** Loads a scene and also handles the cleanup
29*/
30class ResourceManager
31{
32public:
33
34        /** Loads a scene containing of several scene entities. the entities are added to
35                the previously loaded entities. Returns the number of entities in the
36                scene.
37        */
38        int Load(const std::string &filename, SceneEntityContainer &geometry);
39        /** Returns number of scene entities loaded with this manager.
40        */
41        int GetNumEntities() const { return (int)mSceneEntities.size(); }
42        /** Returns pointer to shape container.
43        */
44        const ShapeContainer * const GetShapes() const { return &mShapes; }
45        /** Returns pointer to scene entity container.
46        */
47        const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; }
48        /** Returns the resource manager as a singleton.
49        */
50        inline static ResourceManager *GetSingleton();
51        /** We also want full control over the delete.
52        */
53        static void DelSingleton();
54        /** Adds a scene entity to the resource mananger, which from now on is handled by the manager.
55        */
56        void AddSceneEntity(SceneEntity *ent);
57        /** Creates a new transform.
58        */
59        Transform3 *CreateTransform(const Matrix4x4 &m);
60        /** Creates a new default material that is handled by the manager.
61        */
62        Material *CreateMaterial();
63
64        /////////////////
65
66        /// giant hack: set this to true if the geometry to load has tangent data for normal mapping
67        bool mUseNormalMapping;
68        bool mUseSpecialColors;
69
70
71protected:
72       
73        /** Default constructor. The constructor is protected
74                to have control over instantiation using the
75                singleton pattern.
76        */
77        ResourceManager();
78
79        ~ResourceManager();
80
81        int LoadTextures(igzstream &str);
82        int LoadShapes(igzstream &str);
83        int LoadSceneEntities(igzstream &str, SceneEntityContainer &entities);
84
85        SceneEntity *LoadSceneEntity(igzstream &str);
86        Material *LoadMaterial(igzstream &str);
87        Geometry *LoadGeometry(igzstream &str);
88
89
90        std::map<int, Texture *> mTextureTable;
91        std::map<int, Material *> mMaterialTable;
92        std::map<int, Geometry *> mGeometryTable;
93        //std::map<int, Shape *> mShapesTable;
94
95
96        /////////////
97        //-- these are kept to be able to delete these resources afterwards
98
99        TextureContainer mTextures;
100        MaterialContainer mMaterials;
101        GeometryContainer mGeometry;
102        TransformContainer mTrafos;
103        ShapeContainer mShapes;
104       
105        /// the scene entities
106        SceneEntityContainer mSceneEntities;
107
108private:
109
110        static ResourceManager *sResourceManager;
111};
112
113
114ResourceManager *ResourceManager::GetSingleton()
115{
116        if (!sResourceManager)
117                sResourceManager = new ResourceManager();
118       
119        return sResourceManager;
120}
121
122
123}
124#endif
Note: See TracBrowser for help on using the repository browser.