2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// ResourceManager.h
|
|
|
|
//
|
|
|
|
// Handles the application resources (fonts, graphics, sounds etc.).
|
|
|
|
// Loading and unloading of these files are done here.
|
|
|
|
//
|
|
|
|
|
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
|
|
|
|
2013-07-09 05:57:28 +00:00
|
|
|
#include <list>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <memory>
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +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
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
struct ResourceData {
|
|
|
|
const std::shared_ptr<unsigned char> ptr;
|
|
|
|
const size_t length;
|
2013-07-09 05:44:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourceManager;
|
|
|
|
|
|
|
|
class IReloadable
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +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:
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::shared_ptr<ResourceManager>& getInstance();
|
2013-10-04 23:09:54 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void addReloadable(std::weak_ptr<IReloadable> reloadable);
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void unloadAll();
|
|
|
|
void reloadAll();
|
2013-06-21 16:49:29 +00:00
|
|
|
|
2020-10-19 15:28:20 +00:00
|
|
|
std::string getResourcePath(const std::string& path, bool terminateOnFailure = true) const;
|
2020-06-21 12:25:28 +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:
|
2020-06-21 12:25:28 +00:00
|
|
|
ResourceManager();
|
2013-10-04 23:09:54 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::shared_ptr<ResourceManager> sInstance;
|
|
|
|
std::list< std::weak_ptr<IReloadable> > mReloadables;
|
2013-07-03 07:54:55 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
ResourceData loadFile(const std::string& path) const;
|
2013-06-21 16:49:29 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|