Preload surrounding cells when preloading an exterior cell destination

coverity_scan
scrawl 9 years ago
parent 023c87b215
commit 8592166eeb

@ -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)
{

@ -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());
}
}
}

@ -59,6 +59,7 @@ namespace MWWorld
MWRender::RenderingManager& mRendering;
std::auto_ptr<CellPreloader> mPreloader;
float mPreloadTimer;
int mHalfGridSize;
void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);

Loading…
Cancel
Save