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

Revision 3226, 2.7 KB checked in by mattausch, 16 years ago (diff)

worked on submission

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 model
35        */
36        bool Load(const std::string &filename, SceneEntityContainer &geometry);
37        /** Returns number of scene entities loaded with this manager.
38        */
39        int GetNumEntities() const { return (int)mSceneEntities.size(); }
40        /** Returns pointer to shape container.
41        */
42        const ShapeContainer * const GetShapes() const { return &mShapes; }
43        /** Returns pointer to scene entity container.
44        */
45        const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; }
46        /** Returns the resource manager as a singleton.
47        */
48        inline static ResourceManager *GetSingleton();
49        /** We also want full control over the delete.
50        */
51        static void DelSingleton();
52        /** Adds a scene entity to the resource mananger, which from now on is handled by the manager.
53        */
54        void AddSceneEntity(SceneEntity *ent);
55        /** Creates a new transform.
56        */
57        Transform3 *CreateTransform(const Matrix4x4 &m);
58        /** Creates a new default material that is handled by the manager.
59        */
60        Material *CreateMaterial();
61
62        /// giant hack: set this to true if the geometry to load has tangent data for normal mapping
63        bool mUseNormalMapping;
64        bool mUseSpecialColors;
65
66
67protected:
68       
69        /** Default constructor. The constructor is protected
70                to have control over instantiation using the
71                singleton pattern.
72        */
73        ResourceManager();
74
75        ~ResourceManager();
76
77        void LoadTextures(igzstream &str);
78        void LoadShapes(igzstream &str);
79        void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities);
80
81        SceneEntity *LoadSceneEntity(igzstream &str);
82        Material *LoadMaterial(igzstream &str);
83        Geometry *LoadGeometry(igzstream &str);
84
85
86        std::map<int, Texture *> mTextureTable;
87        std::map<int, Material *> mMaterialTable;
88        std::map<int, Geometry *> mGeometryTable;
89        //std::map<int, Shape *> mShapesTable;
90
91
92        /////////////
93        //-- these are kept to be able to delete these resources afterwards
94
95        TextureContainer mTextures;
96        MaterialContainer mMaterials;
97        GeometryContainer mGeometry;
98        TransformContainer mTrafos;
99        ShapeContainer mShapes;
100       
101        /// the scene entities
102        SceneEntityContainer mSceneEntities;
103
104private:
105
106        static ResourceManager *sResourceManager;
107};
108
109
110ResourceManager *ResourceManager::GetSingleton()
111{
112        if (!sResourceManager)
113                sResourceManager = new ResourceManager();
114       
115        return sResourceManager;
116}
117
118
119}
120#endif
Note: See TracBrowser for help on using the repository browser.