forked from teamnwah/openmw-tes3coop
Refactor ownership of terrain views
This commit is contained in:
parent
28fd492711
commit
3c29e2dbeb
7 changed files with 7 additions and 33 deletions
|
@ -207,7 +207,6 @@ namespace MWWorld
|
||||||
mTerrainPreloadItem = NULL;
|
mTerrainPreloadItem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTerrain->removeView(mTerrainView);
|
|
||||||
mTerrainView = NULL;
|
mTerrainView = NULL;
|
||||||
|
|
||||||
for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();++it)
|
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
|
// Cells that are currently being preloaded, or have already finished preloading
|
||||||
PreloadMap mPreloadCells;
|
PreloadMap mPreloadCells;
|
||||||
|
|
||||||
Terrain::View* mTerrainView;
|
osg::ref_ptr<Terrain::View> mTerrainView;
|
||||||
std::vector<osg::Vec3f> mTerrainPreloadPositions;
|
std::vector<osg::Vec3f> mTerrainPreloadPositions;
|
||||||
osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem;
|
osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem;
|
||||||
};
|
};
|
||||||
|
|
|
@ -386,14 +386,7 @@ void QuadTreeWorld::enable(bool enabled)
|
||||||
|
|
||||||
View* QuadTreeWorld::createView()
|
View* QuadTreeWorld::createView()
|
||||||
{
|
{
|
||||||
ViewData* vd = mViewDataMap->createOrReuseView();
|
return new ViewData;
|
||||||
vd->setPersistent(true);
|
|
||||||
return vd;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QuadTreeWorld::removeView(View *view)
|
|
||||||
{
|
|
||||||
mViewDataMap->removeView(static_cast<ViewData*>(view));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint)
|
void QuadTreeWorld::preload(View *view, const osg::Vec3f &eyePoint)
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace Terrain
|
||||||
virtual void enable(bool enabled);
|
virtual void enable(bool enabled);
|
||||||
|
|
||||||
View* createView();
|
View* createView();
|
||||||
void removeView(View* view);
|
|
||||||
void preload(View* view, const osg::Vec3f& eyePoint);
|
void preload(View* view, const osg::Vec3f& eyePoint);
|
||||||
|
|
||||||
void reportStats(unsigned int frameNumber, osg::Stats* stats);
|
void reportStats(unsigned int frameNumber, osg::Stats* stats);
|
||||||
|
|
|
@ -7,7 +7,6 @@ ViewData::ViewData()
|
||||||
: mNumEntries(0)
|
: mNumEntries(0)
|
||||||
, mFrameLastUsed(0)
|
, mFrameLastUsed(0)
|
||||||
, mChanged(false)
|
, 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)
|
void ViewDataMap::clearUnusedViews(unsigned int frame)
|
||||||
{
|
{
|
||||||
for (Map::iterator it = mViews.begin(); it != mViews.end(); )
|
for (Map::iterator it = mViews.begin(); it != mViews.end(); )
|
||||||
{
|
{
|
||||||
ViewData* vd = it->second;
|
ViewData* vd = it->second;
|
||||||
if (!vd->getPersistent() &&
|
if ((!vd->getViewer() // if no ref was held, always need to clear to avoid holding a dangling ref.
|
||||||
(!vd->getViewer() // if no ref was held, always need to clear to avoid holding a dangling ref.
|
|
||||||
|| vd->getFrameLastUsed() + 2 < frame))
|
|| vd->getFrameLastUsed() + 2 < frame))
|
||||||
{
|
{
|
||||||
vd->setViewer(NULL);
|
vd->setViewer(NULL);
|
||||||
|
|
|
@ -44,9 +44,6 @@ namespace Terrain
|
||||||
|
|
||||||
Entry& getEntry(unsigned int i);
|
Entry& getEntry(unsigned int i);
|
||||||
|
|
||||||
bool getPersistent() const { return mPersistent; }
|
|
||||||
void setPersistent(bool persistent) { mPersistent = persistent; }
|
|
||||||
|
|
||||||
osg::Object* getViewer() const { return mViewer.get(); }
|
osg::Object* getViewer() const { return mViewer.get(); }
|
||||||
void setViewer(osg::Object* viewer) { mViewer = viewer; }
|
void setViewer(osg::Object* viewer) { mViewer = viewer; }
|
||||||
|
|
||||||
|
@ -60,7 +57,6 @@ namespace Terrain
|
||||||
unsigned int mNumEntries;
|
unsigned int mNumEntries;
|
||||||
unsigned int mFrameLastUsed;
|
unsigned int mFrameLastUsed;
|
||||||
bool mChanged;
|
bool mChanged;
|
||||||
bool mPersistent;
|
|
||||||
osg::ref_ptr<osg::Object> mViewer;
|
osg::ref_ptr<osg::Object> mViewer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,7 +66,6 @@ namespace Terrain
|
||||||
ViewData* getViewData(osg::Object* viewer, bool ref);
|
ViewData* getViewData(osg::Object* viewer, bool ref);
|
||||||
|
|
||||||
ViewData* createOrReuseView();
|
ViewData* createOrReuseView();
|
||||||
void removeView(ViewData* view);
|
|
||||||
|
|
||||||
void clearUnusedViews(unsigned int frame);
|
void clearUnusedViews(unsigned int frame);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define COMPONENTS_TERRAIN_WORLD_H
|
#define COMPONENTS_TERRAIN_WORLD_H
|
||||||
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
#include <osg/Referenced>
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
#include <memory>
|
#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.
|
* @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.
|
* The base View class is part of the interface for usage in conjunction with preload feature.
|
||||||
*/
|
*/
|
||||||
class View
|
class View : public osg::Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~View() {}
|
virtual ~View() {}
|
||||||
|
@ -79,14 +80,10 @@ namespace Terrain
|
||||||
|
|
||||||
virtual void enable(bool enabled) {}
|
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.
|
/// Create a View to use with preload feature. The caller is responsible for deleting the view.
|
||||||
/// @note Not thread safe.
|
/// @note Thread safe.
|
||||||
virtual View* createView() { return NULL; }
|
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.
|
/// @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) {}
|
virtual void preload(View* view, const osg::Vec3f& eyePoint) {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue