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

Revision 3216, 2.7 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[3057]1#ifndef __RESOURCEMANAGER_H__
2#define __RESOURCEMANAGER_H__
[2747]3
[2795]4
[2747]5#include <string>
[2755]6#include <iostream>
7#include <fstream>
[2757]8#include <map>
[2755]9#include "common.h"
[2747]10
[2840]11
[3019]12
[2795]13class igzstream;
[2747]14
[2795]15
[2776]16namespace CHCDemoEngine
[2755]17{
18
19class SceneEntity;
20class Material;
[2747]21class Geometry;
[2757]22class Texture;
[2795]23class Matrix4x4;
[2840]24class Transform3;
[3036]25class ShaderProgram;
[2747]26
[2840]27
[2795]28/** Loads a scene and also handles the cleanup
29*/
30class ResourceManager
[2747]31{
32public:
33
[2795]34        /** Loads a model
35        */
[2755]36        bool Load(const std::string &filename, SceneEntityContainer &geometry);
[3052]37        /** Returns number of scene entities loaded with this manager.
38        */
[2948]39        int GetNumEntities() const { return (int)mSceneEntities.size(); }
[3054]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; }
[3052]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();
[3215]52        /** Adds a scene entity to the resource mananger, which from now on is handled by the manager.
[3070]53        */
54        void AddSceneEntity(SceneEntity *ent);
[3215]55        /** Creates a new transform.
[3070]56        */
57        Transform3 *CreateTransform(const Matrix4x4 &m);
[3215]58        /** Creates a new default material that is handled by the manager.
59        */
60        Material *CreateMaterial();
[3038]61
[3215]62        /// giant hack: set this to true if the geometry to load has tangent data for normal mapping
[3127]63        bool mUseNormalMapping;
64
[3216]65
[2747]66protected:
[2755]67       
[3037]68        /** Default constructor. The constructor is protected
69                to have control over instantiation using the
70                singleton pattern.
71        */
[3038]72        ResourceManager();
[3037]73
74        ~ResourceManager();
75
[2795]76        void LoadTextures(igzstream &str);
77        void LoadShapes(igzstream &str);
78        void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities);
[2757]79
[2795]80        SceneEntity *LoadSceneEntity(igzstream &str);
81        Material *LoadMaterial(igzstream &str);
82        Geometry *LoadGeometry(igzstream &str);
[2747]83
[3127]84
[2757]85        std::map<int, Texture *> mTextureTable;
[2764]86        std::map<int, Material *> mMaterialTable;
87        std::map<int, Geometry *> mGeometryTable;
[2842]88        //std::map<int, Shape *> mShapesTable;
[2795]89
[3038]90
91        /////////////
92        //-- these are kept to be able to delete these resources afterwards
93
[3036]94        TextureContainer mTextures;
95        MaterialContainer mMaterials;
96        GeometryContainer mGeometry;
97        TransformContainer mTrafos;
[2842]98        ShapeContainer mShapes;
[3127]99       
[2948]100        /// the scene entities
[2946]101        SceneEntityContainer mSceneEntities;
[3037]102
103private:
104
105        static ResourceManager *sResourceManager;
[2747]106};
107
[3037]108
[3052]109ResourceManager *ResourceManager::GetSingleton()
110{
111        if (!sResourceManager)
112                sResourceManager = new ResourceManager();
113       
114        return sResourceManager;
[2755]115}
[3052]116
117
118}
[2747]119#endif
Note: See TracBrowser for help on using the repository browser.