2013-06-21 16:49:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#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:
|
|
|
|
virtual void unload(const ResourceManager& rm) = 0;
|
|
|
|
virtual void reload(const ResourceManager& rm) = 0;
|
|
|
|
};
|
2013-06-21 16:49:29 +00:00
|
|
|
|
|
|
|
class ResourceManager
|
|
|
|
{
|
|
|
|
public:
|
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:
|
|
|
|
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
|
|
|
};
|