Fix issues caused by loading multiple views into the same terrain View

pull/185/head
scrawl 8 years ago
parent 97ed999097
commit 42e9891504

@ -198,9 +198,7 @@ namespace MWWorld
, mMaxCacheSize(0) , mMaxCacheSize(0)
, mPreloadInstances(true) , mPreloadInstances(true)
, mLastResourceCacheUpdate(0.0) , mLastResourceCacheUpdate(0.0)
, mTerrainView(NULL)
{ {
mTerrainView = mTerrain->createView();
} }
CellPreloader::~CellPreloader() CellPreloader::~CellPreloader()
@ -210,7 +208,6 @@ namespace MWWorld
mTerrainPreloadItem->waitTillDone(); mTerrainPreloadItem->waitTillDone();
mTerrainPreloadItem = NULL; mTerrainPreloadItem = NULL;
} }
mTerrainView = NULL;
if (mUpdateCacheItem) if (mUpdateCacheItem)
{ {
@ -372,8 +369,8 @@ namespace MWWorld
class TerrainPreloadItem : public SceneUtil::WorkItem class TerrainPreloadItem : public SceneUtil::WorkItem
{ {
public: public:
TerrainPreloadItem(Terrain::View* view, Terrain::World* world, const std::vector<osg::Vec3f>& preloadPositions) TerrainPreloadItem(const std::vector<osg::ref_ptr<Terrain::View> >& views, Terrain::World* world, const std::vector<osg::Vec3f>& preloadPositions)
: mView(view) : mTerrainViews(views)
, mWorld(world) , mWorld(world)
, mPreloadPositions(preloadPositions) , mPreloadPositions(preloadPositions)
{ {
@ -381,32 +378,43 @@ namespace MWWorld
virtual void doWork() virtual void doWork()
{ {
for (std::vector<osg::Vec3f>::const_iterator it = mPreloadPositions.begin(); it != mPreloadPositions.end(); ++it) for (unsigned int i=0; i<mTerrainViews.size() && i<mPreloadPositions.size(); ++i)
mWorld->preload(mView, *it); {
mWorld->preload(mTerrainViews[i], mPreloadPositions[i]);
mView->reset(0); mTerrainViews[i]->reset(0);
}
} }
private: private:
Terrain::View* mView; std::vector<osg::ref_ptr<Terrain::View> > mTerrainViews;
Terrain::World* mWorld; Terrain::World* mWorld;
std::vector<osg::Vec3f> mPreloadPositions; std::vector<osg::Vec3f> mPreloadPositions;
}; };
void CellPreloader::setTerrainPreloadPositions(const std::vector<osg::Vec3f> &positions) void CellPreloader::setTerrainPreloadPositions(const std::vector<osg::Vec3f> &positions)
{ {
if (!mTerrainView)
return;
if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone()) if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone())
return; return;
else if (positions == mTerrainPreloadPositions) else if (positions == mTerrainPreloadPositions)
return; return;
else else
{ {
if (mTerrainViews.size() > positions.size())
{
for (unsigned int i=positions.size(); i<mTerrainViews.size(); ++i)
mUnrefQueue->push(mTerrainViews[i]);
mTerrainViews.resize(positions.size());
}
else if (mTerrainViews.size() < positions.size())
{
for (unsigned int i=mTerrainViews.size(); i<positions.size(); ++i)
mTerrainViews.push_back(mTerrain->createView());
}
// TODO: provide some way of giving the preloaded view to the main thread when we enter the cell // TODO: provide some way of giving the preloaded view to the main thread when we enter the cell
// right now, we just use it to make sure the resources are preloaded // right now, we just use it to make sure the resources are preloaded
mTerrainPreloadPositions = positions; mTerrainPreloadPositions = positions;
mTerrainPreloadItem = new TerrainPreloadItem(mTerrainView, mTerrain, positions); mTerrainPreloadItem = new TerrainPreloadItem(mTerrainViews, mTerrain, positions);
mWorkQueue->addWorkItem(mTerrainPreloadItem); mWorkQueue->addWorkItem(mTerrainPreloadItem);
} }
} }

@ -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;
osg::ref_ptr<Terrain::View> mTerrainView; std::vector<osg::ref_ptr<Terrain::View> > mTerrainViews;
std::vector<osg::Vec3f> mTerrainPreloadPositions; std::vector<osg::Vec3f> mTerrainPreloadPositions;
osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem; osg::ref_ptr<SceneUtil::WorkItem> mTerrainPreloadItem;
osg::ref_ptr<SceneUtil::WorkItem> mUpdateCacheItem; osg::ref_ptr<SceneUtil::WorkItem> mUpdateCacheItem;

Loading…
Cancel
Save