#ifndef RESOURCEBASE_H #define RESOURCEBASE_H class Texture; class Mesh; class Material; class Shader; class Entity; class Lights; #include #include #include #include class ResourceBase { public: enum {TEXTURES, MESHES, MATERIALS, SHADERS, ENTITIES}; static void setTexture(const std::string &textureName, Texture* myTexture); static void setMesh(const std::string &meshName, Mesh* myMesh); static void setMaterial(const std::string &materialName, Material* myMaterial); static void setShader(const std::string &shaderName, Shader* myShader); static void setEntity(const std::string &entityName, Entity* myEntity); static void setLights(const std::string &lightsName, Lights* myLights); static Texture* getTexture(const std::string &textureName); static Mesh* getMesh(const std::string &meshName); static Material* getMaterial(const std::string &materialName); static Shader* getShader(const std::string &shaderName); static Entity* getEntity(const std::string &entityName); static Lights* getLights(const std::string &lightsName); protected: template class DataBase { public: std::vector names; std::unordered_map data; void add(const std::string &name, T* t) { data[name] = t; names.push_back(name); } T* get(const std::string &name) { if(data.count(name)) return data[name]; else { fprintf(stderr, "Requesting unloaded resource : %s\n", name.c_str()); return NULL; } } }; static DataBase textures; static DataBase meshes; static DataBase materials; static DataBase shaders; static DataBase entities; static DataBase lights; }; #endif // RESOURCEBASE_H