1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 10:53:53 +00:00
openmw/components/resource/multiobjectcache.hpp

52 lines
1.2 KiB
C++
Raw Normal View History

2016-02-09 17:33:02 +00:00
#ifndef OPENMW_COMPONENTS_MULTIOBJECTCACHE_H
#define OPENMW_COMPONENTS_MULTIOBJECTCACHE_H
#include <map>
2020-06-25 19:46:07 +00:00
#include <mutex>
2022-09-22 18:26:05 +00:00
#include <string>
2016-02-09 17:33:02 +00:00
#include <osg/Referenced>
2022-09-22 18:26:05 +00:00
#include <osg/ref_ptr>
2016-02-09 17:33:02 +00:00
namespace osg
{
class Object;
class State;
}
namespace Resource
{
/// @brief Cache for "non reusable" objects.
class MultiObjectCache : public osg::Referenced
{
public:
MultiObjectCache();
~MultiObjectCache();
void removeUnreferencedObjectsInCache();
2017-08-21 22:58:38 +00:00
/** Remove all objects from the cache. */
void clear();
2016-02-09 17:33:02 +00:00
void addEntryToObjectCache(const std::string& filename, osg::Object* object);
2018-10-09 06:21:12 +00:00
/** Take an Object from cache. Return nullptr if no object found. */
2016-02-09 17:33:02 +00:00
osg::ref_ptr<osg::Object> takeFromObjectCache(const std::string& fileName);
/** call releaseGLObjects on all objects attached to the object cache.*/
void releaseGLObjects(osg::State* state);
unsigned int getCacheSize() const;
2016-02-09 17:33:02 +00:00
protected:
2022-09-22 18:26:05 +00:00
typedef std::multimap<std::string, osg::ref_ptr<osg::Object>> ObjectCacheMap;
2016-02-09 17:33:02 +00:00
2022-09-22 18:26:05 +00:00
ObjectCacheMap _objectCache;
mutable std::mutex _objectCacheMutex;
2016-02-09 17:33:02 +00:00
};
}
#endif