#ifndef __RESOURCEMANAGER_H__ #define __RESOURCEMANAGER_H__ #include #include #include #include #include "common.h" class igzstream; namespace CHCDemoEngine { class SceneEntity; class Material; class Geometry; class Texture; class Matrix4x4; class Transform3; class ShaderProgram; /** Loads a scene and also handles the cleanup */ class ResourceManager { public: /** Loads a model */ bool Load(const std::string &filename, SceneEntityContainer &geometry); /** Returns number of scene entities loaded with this manager. */ int GetNumEntities() const { return (int)mSceneEntities.size(); } /** Returns pointer to shape container. */ const ShapeContainer * const GetShapes() const { return &mShapes; } /** Returns pointer to scene entity container. */ const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; } /** Returns the resource manager as a singleton. */ inline static ResourceManager *GetSingleton(); /** We also want full control over the delete. */ static void DelSingleton(); /** Adds a scene entity to the resource mananger, which from now on is handled by the manager. */ void AddSceneEntity(SceneEntity *ent); /** Creates a new transform. */ Transform3 *CreateTransform(const Matrix4x4 &m); /** Creates a new default material that is handled by the manager. */ Material *CreateMaterial(); /// giant hack: set this to true if the geometry to load has tangent data for normal mapping bool mUseNormalMapping; bool mUseSpecialColors; protected: /** Default constructor. The constructor is protected to have control over instantiation using the singleton pattern. */ ResourceManager(); ~ResourceManager(); void LoadTextures(igzstream &str); void LoadShapes(igzstream &str); void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities); SceneEntity *LoadSceneEntity(igzstream &str); Material *LoadMaterial(igzstream &str); Geometry *LoadGeometry(igzstream &str); std::map mTextureTable; std::map mMaterialTable; std::map mGeometryTable; //std::map mShapesTable; ///////////// //-- these are kept to be able to delete these resources afterwards TextureContainer mTextures; MaterialContainer mMaterials; GeometryContainer mGeometry; TransformContainer mTrafos; ShapeContainer mShapes; /// the scene entities SceneEntityContainer mSceneEntities; private: static ResourceManager *sResourceManager; }; ResourceManager *ResourceManager::GetSingleton() { if (!sResourceManager) sResourceManager = new ResourceManager(); return sResourceManager; } } #endif