From 8592166eeb5acf5bbffb16125b0ccf5f98dc2b0b Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 7 Feb 2016 05:27:19 -0800 Subject: [PATCH] Preload surrounding cells when preloading an exterior cell destination --- apps/openmw/mwworld/cellpreloader.cpp | 2 ++ apps/openmw/mwworld/scene.cpp | 29 +++++++++++++++------------ apps/openmw/mwworld/scene.hpp | 1 + 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index f1366a8b2..429e3294d 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -66,6 +66,8 @@ namespace MWWorld /// Preload work to be called from the worker thread. virtual void doWork() { + // TODO: make CellStore::loadRefs thread safe so we can call it from here + osg::Timer preloadTimer; for (MeshList::const_iterator it = mMeshes.begin(); it != mMeshes.end(); ++it) { diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 912a39e7c..38b762018 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -334,15 +334,13 @@ namespace MWWorld std::string loadingExteriorText = "#{sLoadingMessage3}"; loadingListener->setLabel(loadingExteriorText); - const int halfGridSize = Settings::Manager::getInt("exterior cell load distance", "Cells"); - CellStoreCollection::iterator active = mActiveCells.begin(); while (active!=mActiveCells.end()) { if ((*active)->getCell()->isExterior()) { - if (std::abs (X-(*active)->getCell()->getGridX())<=halfGridSize && - std::abs (Y-(*active)->getCell()->getGridY())<=halfGridSize) + if (std::abs (X-(*active)->getCell()->getGridX())<=mHalfGridSize && + std::abs (Y-(*active)->getCell()->getGridY())<=mHalfGridSize) { // keep cells within the new grid ++active; @@ -354,9 +352,9 @@ namespace MWWorld int refsToLoad = 0; // get the number of refs to load - for (int x=X-halfGridSize; x<=X+halfGridSize; ++x) + for (int x=X-mHalfGridSize; x<=X+mHalfGridSize; ++x) { - for (int y=Y-halfGridSize; y<=Y+halfGridSize; ++y) + for (int y=Y-mHalfGridSize; y<=Y+mHalfGridSize; ++y) { CellStoreCollection::iterator iter = mActiveCells.begin(); @@ -379,9 +377,9 @@ namespace MWWorld loadingListener->setProgressRange(refsToLoad); // Load cells - for (int x=X-halfGridSize; x<=X+halfGridSize; ++x) + for (int x=X-mHalfGridSize; x<=X+mHalfGridSize; ++x) { - for (int y=Y-halfGridSize; y<=Y+halfGridSize; ++y) + for (int y=Y-mHalfGridSize; y<=Y+mHalfGridSize; ++y) { CellStoreCollection::iterator iter = mActiveCells.begin(); @@ -448,6 +446,7 @@ namespace MWWorld Scene::Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics) : mCurrentCell (0), mCellChanged (false), mPhysics(physics), mRendering(rendering) , mPreloadTimer(0.f) + , mHalfGridSize(Settings::Manager::getInt("exterior cell load distance", "Cells")) { mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager())); } @@ -640,24 +639,28 @@ namespace MWWorld if (sqrDistToPlayer < preloadDist*preloadDist) { - MWWorld::CellStore* targetCell = NULL; try { if (!door.getCellRef().getDestCell().empty()) - targetCell = MWBase::Environment::get().getWorld()->getInterior(door.getCellRef().getDestCell()); + mPreloader->preload(MWBase::Environment::get().getWorld()->getInterior(door.getCellRef().getDestCell()), mRendering.getReferenceTime()); else { int x,y; MWBase::Environment::get().getWorld()->positionToIndex (door.getCellRef().getDoorDest().pos[0], door.getCellRef().getDoorDest().pos[1], x, y); - targetCell = MWBase::Environment::get().getWorld()->getExterior(x, y); + + for (int dx = -mHalfGridSize; dx <= mHalfGridSize; ++dx) + { + for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy) + { + mPreloader->preload(MWBase::Environment::get().getWorld()->getExterior(x+dx, y+dy), mRendering.getReferenceTime()); + } + } } } catch (std::exception& e) { // ignore error for now, would spam the log too much } - if (targetCell) - mPreloader->preload(targetCell, mRendering.getReferenceTime()); } } } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 4ac0d0666..68748af85 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -59,6 +59,7 @@ namespace MWWorld MWRender::RenderingManager& mRendering; std::auto_ptr mPreloader; float mPreloadTimer; + int mHalfGridSize; void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);