Refactor ownership of terrain views

0.6.1
scrawl 8 years ago
parent 28fd492711
commit 3c29e2dbeb

@ -207,7 +207,6 @@ namespace MWWorld
mTerrainPreloadItem = NULL;
}
mTerrain->removeView(mTerrainView);
mTerrainView = NULL;
for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();++it)

@ -103,7 +103,7 @@ namespace MWWorld
// Cells that are currently being preloaded, or have already finished preloading
PreloadMap mPreloadCells;
Terrain::View* mTerrainView;
osg::ref_ptr<Terrain::View> mTerrainView;
std::vector<osg::Vec3f> mTerrainPreloadPositions;
osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem;
};

@ -386,14 +386,7 @@ void QuadTreeWorld::enable(bool enabled)
View* QuadTreeWorld::createView()
{
ViewData* vd = mViewDataMap->createOrReuseView();
vd->setPersistent(true);
return vd;
}
void QuadTreeWorld::removeView(View *view)
{
mViewDataMap->removeView(static_cast<ViewData*>(view));
return new ViewData;
}
void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint)

@ -29,7 +29,6 @@ namespace Terrain
virtual void enable(bool enabled);
View* createView();
void removeView(View* view);
void preload(View* view, const osg::Vec3f& eyePoint);
void reportStats(unsigned int frameNumber, osg::Stats* stats);

@ -7,7 +7,6 @@ ViewData::ViewData()
: mNumEntries(0)
, mFrameLastUsed(0)
, mChanged(false)
, mPersistent(false)
{
}
@ -126,20 +125,12 @@ ViewData *ViewDataMap::createOrReuseView()
}
}
void ViewDataMap::removeView(ViewData* vd)
{
vd->setPersistent(false);
vd->clear();
mUnusedViews.push_back(vd);
}
void ViewDataMap::clearUnusedViews(unsigned int frame)
{
for (Map::iterator it = mViews.begin(); it != mViews.end(); )
{
ViewData* vd = it->second;
if (!vd->getPersistent() &&
(!vd->getViewer() // if no ref was held, always need to clear to avoid holding a dangling ref.
if ((!vd->getViewer() // if no ref was held, always need to clear to avoid holding a dangling ref.
|| vd->getFrameLastUsed() + 2 < frame))
{
vd->setViewer(NULL);

@ -44,9 +44,6 @@ namespace Terrain
Entry& getEntry(unsigned int i);
bool getPersistent() const { return mPersistent; }
void setPersistent(bool persistent) { mPersistent = persistent; }
osg::Object* getViewer() const { return mViewer.get(); }
void setViewer(osg::Object* viewer) { mViewer = viewer; }
@ -60,7 +57,6 @@ namespace Terrain
unsigned int mNumEntries;
unsigned int mFrameLastUsed;
bool mChanged;
bool mPersistent;
osg::ref_ptr<osg::Object> mViewer;
};
@ -70,7 +66,6 @@ namespace Terrain
ViewData* getViewData(osg::Object* viewer, bool ref);
ViewData* createOrReuseView();
void removeView(ViewData* view);
void clearUnusedViews(unsigned int frame);

@ -2,6 +2,7 @@
#define COMPONENTS_TERRAIN_WORLD_H
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/Vec3f>
#include <memory>
@ -32,7 +33,7 @@ namespace Terrain
* @brief A View is a collection of rendering objects that are visible from a given camera/intersection.
* The base View class is part of the interface for usage in conjunction with preload feature.
*/
class View
class View : public osg::Referenced
{
public:
virtual ~View() {}
@ -79,14 +80,10 @@ namespace Terrain
virtual void enable(bool enabled) {}
/// Create a View to use with preload feature. If a View is returned, it will remain valid until the user calls 'removeView' or the World is destroyed.
/// @note Not thread safe.
/// Create a View to use with preload feature. The caller is responsible for deleting the view.
/// @note Thread safe.
virtual View* createView() { return NULL; }
/// Remove a View that was previously created with 'createView'.
/// @note Not thread safe.
virtual void removeView(View* view) {}
/// @note Thread safe, as long as you do not attempt to load into the same view from multiple threads.
virtual void preload(View* view, const osg::Vec3f& eyePoint) {}

Loading…
Cancel
Save