2016-02-09 18:33:02 +01:00
|
|
|
#ifndef OPENMW_COMPONENTS_MULTIOBJECTCACHE_H
|
|
|
|
#define OPENMW_COMPONENTS_MULTIOBJECTCACHE_H
|
|
|
|
|
|
|
|
#include <map>
|
2020-06-25 21:46:07 +02:00
|
|
|
#include <mutex>
|
2016-02-09 18:33:02 +01:00
|
|
|
|
|
|
|
#include <osg/Referenced>
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
2024-09-24 00:14:18 +02:00
|
|
|
#include <components/vfs/pathutil.hpp>
|
|
|
|
|
2023-12-22 00:23:49 +01:00
|
|
|
#include "cachestats.hpp"
|
|
|
|
|
2016-02-09 18:33:02 +01:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Object;
|
|
|
|
class State;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
|
|
|
|
/// @brief Cache for "non reusable" objects.
|
|
|
|
class MultiObjectCache : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void removeUnreferencedObjectsInCache();
|
|
|
|
|
2017-08-21 18:58:38 -04:00
|
|
|
/** Remove all objects from the cache. */
|
|
|
|
void clear();
|
|
|
|
|
2024-09-24 00:14:18 +02:00
|
|
|
void addEntryToObjectCache(VFS::Path::NormalizedView filename, osg::Object* object);
|
2016-02-09 18:33:02 +01:00
|
|
|
|
2018-10-09 10:21:12 +04:00
|
|
|
/** Take an Object from cache. Return nullptr if no object found. */
|
2024-09-24 00:14:18 +02:00
|
|
|
osg::ref_ptr<osg::Object> takeFromObjectCache(VFS::Path::NormalizedView fileName);
|
2016-02-09 18:33:02 +01:00
|
|
|
|
|
|
|
/** call releaseGLObjects on all objects attached to the object cache.*/
|
|
|
|
void releaseGLObjects(osg::State* state);
|
|
|
|
|
2023-12-22 00:23:49 +01:00
|
|
|
CacheStats getStats() const;
|
2017-02-22 02:18:18 +01:00
|
|
|
|
2016-02-09 18:33:02 +01:00
|
|
|
protected:
|
2024-09-24 00:14:18 +02:00
|
|
|
typedef std::multimap<VFS::Path::Normalized, osg::ref_ptr<osg::Object>, std::less<>> ObjectCacheMap;
|
2016-02-09 18:33:02 +01:00
|
|
|
|
|
|
|
ObjectCacheMap _objectCache;
|
2020-06-25 21:46:07 +02:00
|
|
|
mutable std::mutex _objectCacheMutex;
|
2023-12-22 00:23:49 +01:00
|
|
|
std::size_t mGet = 0;
|
|
|
|
std::size_t mHit = 0;
|
|
|
|
std::size_t mExpired = 0;
|
2016-02-09 18:33:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|