OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cellpreloader.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWWORLD_CELLPRELOADER_H
2 #define OPENMW_MWWORLD_CELLPRELOADER_H
3 
4 #include <map>
5 #include <osg/ref_ptr>
6 #include <osg/Vec3f>
8 
9 namespace Resource
10 {
11  class ResourceSystem;
12  class BulletShapeManager;
13 }
14 
15 namespace Terrain
16 {
17  class World;
18  class View;
19 }
20 
21 namespace SceneUtil
22 {
23  class UnrefQueue;
24 }
25 
26 namespace MWRender
27 {
28  class LandManager;
29 }
30 
31 namespace MWWorld
32 {
33  class CellStore;
34 
36  {
37  public:
38  CellPreloader(Resource::ResourceSystem* resourceSystem, Resource::BulletShapeManager* bulletShapeManager, Terrain::World* terrain, MWRender::LandManager* landManager);
40 
43  void preload(MWWorld::CellStore* cell, double timestamp);
44 
45  void notifyLoaded(MWWorld::CellStore* cell);
46 
47  void clear();
48 
50  void updateCache(double timestamp);
51 
53  void setExpiryDelay(double expiryDelay);
54 
56  void setMinCacheSize(unsigned int num);
57 
59  void setMaxCacheSize(unsigned int num);
60 
62  void setPreloadInstances(bool preload);
63 
64  unsigned int getMaxCacheSize() const;
65 
66  void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
67 
68  void setUnrefQueue(SceneUtil::UnrefQueue* unrefQueue);
69 
70  void setTerrainPreloadPositions(const std::vector<osg::Vec3f>& positions);
71 
72  private:
77  osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
78  osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
79  double mExpiryDelay;
80  unsigned int mMinCacheSize;
81  unsigned int mMaxCacheSize;
83 
85 
86  struct PreloadEntry
87  {
88  PreloadEntry(double timestamp, osg::ref_ptr<SceneUtil::WorkItem> workItem)
89  : mTimeStamp(timestamp)
90  , mWorkItem(workItem)
91  {
92  }
94  : mTimeStamp(0.0)
95  {
96  }
97 
98  double mTimeStamp;
99  osg::ref_ptr<SceneUtil::WorkItem> mWorkItem;
100  };
101  typedef std::map<const MWWorld::CellStore*, PreloadEntry> PreloadMap;
102 
103  // Cells that are currently being preloaded, or have already finished preloading
105 
106  std::vector<osg::ref_ptr<Terrain::View> > mTerrainViews;
107  std::vector<osg::Vec3f> mTerrainPreloadPositions;
108  osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem;
109  osg::ref_ptr<SceneUtil::WorkItem> mUpdateCacheItem;
110  };
111 
112 }
113 
114 #endif
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:30
void setExpiryDelay(double expiryDelay)
How long to keep a preloaded cell in cache after it's no longer requested.
Definition: cellpreloader.cpp:334
osg::ref_ptr< SceneUtil::WorkItem > mTerrainPreloadItem
Definition: cellpreloader.hpp:108
The basic interface for a terrain world. How the terrain chunks are paged and displayed is up to the ...
Definition: world.hpp:52
void setPreloadInstances(bool preload)
Enables the creation of instances in the preloading thread.
Definition: cellpreloader.cpp:349
osg::ref_ptr< SceneUtil::WorkItem > mUpdateCacheItem
Definition: cellpreloader.hpp:109
unsigned int mMaxCacheSize
Definition: cellpreloader.hpp:81
void num(char i, bool last)
Definition: gen_iconv.cpp:12
std::vector< osg::ref_ptr< Terrain::View > > mTerrainViews
Definition: cellpreloader.hpp:106
osg::ref_ptr< SceneUtil::UnrefQueue > mUnrefQueue
Definition: cellpreloader.hpp:78
Resource::ResourceSystem * mResourceSystem
Definition: cellpreloader.hpp:73
void clear()
Definition: cellpreloader.cpp:294
Resource::BulletShapeManager * mBulletShapeManager
Definition: cellpreloader.hpp:74
Definition: cellpreloader.hpp:86
Definition: landmanager.hpp:17
CellPreloader(Resource::ResourceSystem *resourceSystem, Resource::BulletShapeManager *bulletShapeManager, Terrain::World *terrain, MWRender::LandManager *landManager)
Definition: cellpreloader.cpp:190
void preload(MWWorld::CellStore *cell, double timestamp)
Definition: cellpreloader.cpp:227
void setMinCacheSize(unsigned int num)
The minimum number of preloaded cells before unused cells get thrown out.
Definition: cellpreloader.cpp:339
PreloadEntry(double timestamp, osg::ref_ptr< SceneUtil::WorkItem > workItem)
Definition: cellpreloader.hpp:88
bool mPreloadInstances
Definition: cellpreloader.hpp:82
~CellPreloader()
Definition: cellpreloader.cpp:203
std::vector< osg::Vec3f > mTerrainPreloadPositions
Definition: cellpreloader.hpp:107
osg::ref_ptr< SceneUtil::WorkQueue > mWorkQueue
Definition: cellpreloader.hpp:77
std::map< const MWWorld::CellStore *, PreloadEntry > PreloadMap
Definition: cellpreloader.hpp:101
Mutable state of a cell.
Definition: cellstore.hpp:51
void setUnrefQueue(SceneUtil::UnrefQueue *unrefQueue)
Definition: cellpreloader.cpp:364
double mLastResourceCacheUpdate
Definition: cellpreloader.hpp:84
PreloadMap mPreloadCells
Definition: cellpreloader.hpp:104
void setMaxCacheSize(unsigned int num)
The maximum number of preloaded cells.
Definition: cellpreloader.cpp:344
unsigned int mMinCacheSize
Definition: cellpreloader.hpp:80
void setWorkQueue(osg::ref_ptr< SceneUtil::WorkQueue > workQueue)
Definition: cellpreloader.cpp:359
Terrain::World * mTerrain
Definition: cellpreloader.hpp:75
double mExpiryDelay
Definition: cellpreloader.hpp:79
Handles unreferencing of objects through the WorkQueue. Typical use scenario would be the main thread...
Definition: unrefqueue.hpp:24
double mTimeStamp
Definition: cellpreloader.hpp:98
void notifyLoaded(MWWorld::CellStore *cell)
Definition: cellpreloader.cpp:278
void setTerrainPreloadPositions(const std::vector< osg::Vec3f > &positions)
Definition: cellpreloader.cpp:401
unsigned int getMaxCacheSize() const
Definition: cellpreloader.cpp:354
MWRender::LandManager * mLandManager
Definition: cellpreloader.hpp:76
Definition: bulletshapemanager.hpp:25
void updateCache(double timestamp)
Removes preloaded cells that have not had a preload request for a while.
Definition: cellpreloader.cpp:308
osg::ref_ptr< SceneUtil::WorkItem > mWorkItem
Definition: cellpreloader.hpp:99
PreloadEntry()
Definition: cellpreloader.hpp:93
Definition: cellpreloader.hpp:35