70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#ifndef RESOURCEBASE_H
|
|
#define RESOURCEBASE_H
|
|
|
|
class Texture;
|
|
class Mesh;
|
|
class Material;
|
|
class Shader;
|
|
class Entity;
|
|
class Lights;
|
|
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <stdio.h>
|
|
|
|
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 <typename T>
|
|
class DataBase
|
|
{
|
|
public:
|
|
std::vector<std::string> names;
|
|
std::unordered_map<std::string, T*> 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<Texture> textures;
|
|
static DataBase<Mesh> meshes;
|
|
static DataBase<Material> materials;
|
|
static DataBase<Shader> shaders;
|
|
static DataBase<Entity> entities;
|
|
static DataBase<Lights> lights;
|
|
};
|
|
|
|
#endif // RESOURCEBASE_H
|