1 #ifndef OPENMW_COMPONENTS_BULLETSHAPEMANAGER_H 2 #define OPENMW_COMPONENTS_BULLETSHAPEMANAGER_H 3 4 #include <map> 5 #include <string> 6 7 #include <osg/ref_ptr> 8 9 #include "bulletshape.hpp" 10 #include "resourcemanager.hpp" 11 12 namespace Resource 13 { 14 class SceneManager; 15 class NifFileManager; 16 17 class BulletShape; 18 class BulletShapeInstance; 19 20 class MultiObjectCache; 21 22 /// Handles loading, caching and "instancing" of bullet shapes. 23 /// A shape 'instance' is a clone of another shape, with the goal of setting a different scale on this instance. 24 /// @note May be used from any thread. 25 class BulletShapeManager : public ResourceManager 26 { 27 public: 28 BulletShapeManager(const VFS::Manager* vfs, SceneManager* sceneMgr, NifFileManager* nifFileManager); 29 ~BulletShapeManager(); 30 31 /// @note May return a null pointer if the object has no shape. 32 osg::ref_ptr<const BulletShape> getShape(const std::string& name); 33 34 /// Create an instance of the given shape and cache it for later use, so that future calls to getInstance() can simply return 35 /// the cached instance instead of having to create a new one. 36 /// @note The returned ref_ptr may be kept by the caller to ensure that the instance stays in cache for as long as needed. 37 osg::ref_ptr<BulletShapeInstance> cacheInstance(const std::string& name); 38 39 /// @note May return a null pointer if the object has no shape. 40 osg::ref_ptr<BulletShapeInstance> getInstance(const std::string& name); 41 42 /// @see ResourceManager::updateCache 43 void updateCache(double referenceTime) override; 44 45 void clearCache() override; 46 47 void reportStats(unsigned int frameNumber, osg::Stats *stats) const override; 48 49 private: 50 osg::ref_ptr<BulletShapeInstance> createInstance(const std::string& name); 51 52 osg::ref_ptr<MultiObjectCache> mInstanceCache; 53 SceneManager* mSceneManager; 54 NifFileManager* mNifFileManager; 55 }; 56 57 } 58 59 #endif 60