diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 649d17334..9e9c85320 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -198,9 +198,7 @@ namespace MWWorld , mMaxCacheSize(0) , mPreloadInstances(true) , mLastResourceCacheUpdate(0.0) - , mTerrainView(NULL) { - mTerrainView = mTerrain->createView(); } CellPreloader::~CellPreloader() @@ -210,7 +208,6 @@ namespace MWWorld mTerrainPreloadItem->waitTillDone(); mTerrainPreloadItem = NULL; } - mTerrainView = NULL; if (mUpdateCacheItem) { @@ -372,8 +369,8 @@ namespace MWWorld class TerrainPreloadItem : public SceneUtil::WorkItem { public: - TerrainPreloadItem(Terrain::View* view, Terrain::World* world, const std::vector& preloadPositions) - : mView(view) + TerrainPreloadItem(const std::vector >& views, Terrain::World* world, const std::vector& preloadPositions) + : mTerrainViews(views) , mWorld(world) , mPreloadPositions(preloadPositions) { @@ -381,32 +378,43 @@ namespace MWWorld virtual void doWork() { - for (std::vector::const_iterator it = mPreloadPositions.begin(); it != mPreloadPositions.end(); ++it) - mWorld->preload(mView, *it); - - mView->reset(0); + for (unsigned int i=0; ipreload(mTerrainViews[i], mPreloadPositions[i]); + mTerrainViews[i]->reset(0); + } } private: - Terrain::View* mView; + std::vector > mTerrainViews; Terrain::World* mWorld; std::vector mPreloadPositions; }; void CellPreloader::setTerrainPreloadPositions(const std::vector &positions) { - if (!mTerrainView) - return; if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone()) return; else if (positions == mTerrainPreloadPositions) return; else { + if (mTerrainViews.size() > positions.size()) + { + for (unsigned int i=positions.size(); ipush(mTerrainViews[i]); + mTerrainViews.resize(positions.size()); + } + else if (mTerrainViews.size() < positions.size()) + { + for (unsigned int i=mTerrainViews.size(); icreateView()); + } + // 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 mTerrainPreloadPositions = positions; - mTerrainPreloadItem = new TerrainPreloadItem(mTerrainView, mTerrain, positions); + mTerrainPreloadItem = new TerrainPreloadItem(mTerrainViews, mTerrain, positions); mWorkQueue->addWorkItem(mTerrainPreloadItem); } } diff --git a/apps/openmw/mwworld/cellpreloader.hpp b/apps/openmw/mwworld/cellpreloader.hpp index e188f21ee..df878a55d 100644 --- a/apps/openmw/mwworld/cellpreloader.hpp +++ b/apps/openmw/mwworld/cellpreloader.hpp @@ -103,7 +103,7 @@ namespace MWWorld // Cells that are currently being preloaded, or have already finished preloading PreloadMap mPreloadCells; - osg::ref_ptr mTerrainView; + std::vector > mTerrainViews; std::vector mTerrainPreloadPositions; osg::ref_ptr mTerrainPreloadItem; osg::ref_ptr mUpdateCacheItem;