2013-06-21 16:49:29 +00:00
|
|
|
#pragma once
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|
|
|
|
#define ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|
2013-06-21 16:49:29 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
2013-07-09 05:57:28 +00:00
|
|
|
#include <list>
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
//The ResourceManager exists to...
|
|
|
|
//Allow loading resources embedded into the executable like an actual file.
|
|
|
|
//Allow embedded resources to be optionally remapped to actual files for further customization.
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
struct ResourceData
|
|
|
|
{
|
|
|
|
const std::shared_ptr<unsigned char> ptr;
|
|
|
|
const size_t length;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceManager;
|
|
|
|
|
|
|
|
class IReloadable
|
|
|
|
{
|
|
|
|
public:
|
2013-10-04 23:09:54 +00:00
|
|
|
virtual void unload(std::shared_ptr<ResourceManager>& rm) = 0;
|
|
|
|
virtual void reload(std::shared_ptr<ResourceManager>& rm) = 0;
|
2013-07-09 05:44:24 +00:00
|
|
|
};
|
2013-06-21 16:49:29 +00:00
|
|
|
|
|
|
|
class ResourceManager
|
|
|
|
{
|
|
|
|
public:
|
2013-10-04 23:09:54 +00:00
|
|
|
static std::shared_ptr<ResourceManager>& getInstance();
|
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
void addReloadable(std::weak_ptr<IReloadable> reloadable);
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
void unloadAll();
|
|
|
|
void reloadAll();
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
const ResourceData getFileData(const std::string& path) const;
|
|
|
|
bool fileExists(const std::string& path) const;
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
private:
|
2013-10-04 23:09:54 +00:00
|
|
|
ResourceManager();
|
|
|
|
|
|
|
|
static std::shared_ptr<ResourceManager> sInstance;
|
|
|
|
|
2013-07-09 05:44:24 +00:00
|
|
|
ResourceData loadFile(const std::string& path) const;
|
2013-07-03 07:54:55 +00:00
|
|
|
|
2013-07-09 05:57:28 +00:00
|
|
|
std::list< std::weak_ptr<IReloadable> > mReloadables;
|
2013-06-21 16:49:29 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|