1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 12:59:55 +00:00
openmw/components/resource/resourcesystem.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
3.2 KiB
C++
Raw Normal View History

2015-03-26 17:02:51 +00:00
#ifndef OPENMW_COMPONENTS_RESOURCE_RESOURCESYSTEM_H
#define OPENMW_COMPONENTS_RESOURCE_RESOURCESYSTEM_H
#include <memory>
#include <vector>
2015-03-26 17:02:51 +00:00
namespace VFS
{
class Manager;
}
namespace osg
{
class Stats;
class State;
}
2024-01-16 19:56:58 +00:00
namespace ToUTF8
{
2024-01-17 17:10:42 +00:00
class StatelessUtf8Encoder;
2024-01-16 19:56:58 +00:00
}
2015-03-26 17:02:51 +00:00
namespace Resource
{
class SceneManager;
2016-02-05 22:03:53 +00:00
class ImageManager;
class BgsmFileManager;
class NifFileManager;
class KeyframeManager;
2019-03-13 07:15:58 +00:00
class BaseResourceManager;
class AnimBlendRulesManager;
2015-03-26 17:02:51 +00:00
/// @brief Wrapper class that constructs and provides access to the most commonly used resource subsystems.
/// @par Resource subsystems can be used with multiple OpenGL contexts, just like the OSG equivalents, but
/// are built around the use of a single virtual file system.
2015-03-26 17:02:51 +00:00
class ResourceSystem
{
public:
2024-01-17 17:10:42 +00:00
explicit ResourceSystem(
const VFS::Manager* vfs, double expiryDelay, const ToUTF8::StatelessUtf8Encoder* encoder);
2015-05-08 15:52:35 +00:00
~ResourceSystem();
2015-03-26 17:02:51 +00:00
SceneManager* getSceneManager();
ImageManager* getImageManager();
BgsmFileManager* getBgsmFileManager();
NifFileManager* getNifFileManager();
KeyframeManager* getKeyframeManager();
AnimBlendRulesManager* getAnimBlendRulesManager();
/// Indicates to each resource manager to clear the cache, i.e. to drop cached objects that are no longer
/// referenced.
/// @note May be called from any thread if you do not add or remove resource managers at that point.
void updateCache(double referenceTime);
2015-03-26 17:02:51 +00:00
2017-08-19 19:26:46 +00:00
/// Indicates to each resource manager to clear the entire cache.
2017-08-21 22:58:38 +00:00
/// @note May be called from any thread if you do not add or remove resource managers at that point.
2017-08-19 19:26:46 +00:00
void clearCache();
/// Add this ResourceManager to be handled by the ResourceSystem.
/// @note Does not transfer ownership.
2019-03-13 07:15:58 +00:00
void addResourceManager(BaseResourceManager* resourceMgr);
/// @note Do nothing if resourceMgr does not exist.
/// @note Does not delete resourceMgr.
2019-03-13 07:15:58 +00:00
void removeResourceManager(BaseResourceManager* resourceMgr);
/// How long to keep objects in cache after no longer being referenced.
void setExpiryDelay(double expiryDelay);
/// @note May be called from any thread.
2015-03-26 17:02:51 +00:00
const VFS::Manager* getVFS() const;
2017-03-07 03:02:06 +00:00
void reportStats(unsigned int frameNumber, osg::Stats* stats) const;
/// Call releaseGLObjects for each resource manager.
void releaseGLObjects(osg::State* state);
2015-03-26 17:02:51 +00:00
private:
std::unique_ptr<SceneManager> mSceneManager;
std::unique_ptr<ImageManager> mImageManager;
std::unique_ptr<BgsmFileManager> mBgsmFileManager;
std::unique_ptr<NifFileManager> mNifFileManager;
std::unique_ptr<KeyframeManager> mKeyframeManager;
std::unique_ptr<AnimBlendRulesManager> mAnimBlendRulesManager;
2015-03-26 17:02:51 +00:00
// Store the base classes separately to get convenient access to the common interface
// Here users can register their own resourcemanager as well
2019-03-13 07:15:58 +00:00
std::vector<BaseResourceManager*> mResourceManagers;
2015-03-26 17:02:51 +00:00
const VFS::Manager* mVFS;
2015-05-08 15:52:35 +00:00
ResourceSystem(const ResourceSystem&);
void operator=(const ResourceSystem&);
2015-03-26 17:02:51 +00:00
};
}
#endif