1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/components/resource/multiobjectcache.hpp

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

57 lines
1.3 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>
2016-02-09 17:33:02 +00:00
#include <string>
#include <osg/Referenced>
#include <osg/ref_ptr>
2023-12-21 23:23:49 +00:00
#include "cachestats.hpp"
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);
2023-12-21 23:23:49 +00:00
CacheStats getStats() const;
2016-02-09 17:33:02 +00:00
protected:
typedef std::multimap<std::string, osg::ref_ptr<osg::Object>> ObjectCacheMap;
ObjectCacheMap _objectCache;
2020-06-25 19:46:07 +00:00
mutable std::mutex _objectCacheMutex;
2023-12-21 23:23:49 +00:00
std::size_t mGet = 0;
std::size_t mHit = 0;
std::size_t mExpired = 0;
2016-02-09 17:33:02 +00:00
};
}
#endif