mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-28 14:53:58 +00:00
Preload surrounding cells when preloading an exterior cell destination
This commit is contained in:
parent
023c87b215
commit
8592166eeb
@ -66,6 +66,8 @@ namespace MWWorld
|
|||||||
/// Preload work to be called from the worker thread.
|
/// Preload work to be called from the worker thread.
|
||||||
virtual void doWork()
|
virtual void doWork()
|
||||||
{
|
{
|
||||||
|
// TODO: make CellStore::loadRefs thread safe so we can call it from here
|
||||||
|
|
||||||
osg::Timer preloadTimer;
|
osg::Timer preloadTimer;
|
||||||
for (MeshList::const_iterator it = mMeshes.begin(); it != mMeshes.end(); ++it)
|
for (MeshList::const_iterator it = mMeshes.begin(); it != mMeshes.end(); ++it)
|
||||||
{
|
{
|
||||||
|
@ -334,15 +334,13 @@ namespace MWWorld
|
|||||||
std::string loadingExteriorText = "#{sLoadingMessage3}";
|
std::string loadingExteriorText = "#{sLoadingMessage3}";
|
||||||
loadingListener->setLabel(loadingExteriorText);
|
loadingListener->setLabel(loadingExteriorText);
|
||||||
|
|
||||||
const int halfGridSize = Settings::Manager::getInt("exterior cell load distance", "Cells");
|
|
||||||
|
|
||||||
CellStoreCollection::iterator active = mActiveCells.begin();
|
CellStoreCollection::iterator active = mActiveCells.begin();
|
||||||
while (active!=mActiveCells.end())
|
while (active!=mActiveCells.end())
|
||||||
{
|
{
|
||||||
if ((*active)->getCell()->isExterior())
|
if ((*active)->getCell()->isExterior())
|
||||||
{
|
{
|
||||||
if (std::abs (X-(*active)->getCell()->getGridX())<=halfGridSize &&
|
if (std::abs (X-(*active)->getCell()->getGridX())<=mHalfGridSize &&
|
||||||
std::abs (Y-(*active)->getCell()->getGridY())<=halfGridSize)
|
std::abs (Y-(*active)->getCell()->getGridY())<=mHalfGridSize)
|
||||||
{
|
{
|
||||||
// keep cells within the new grid
|
// keep cells within the new grid
|
||||||
++active;
|
++active;
|
||||||
@ -354,9 +352,9 @@ namespace MWWorld
|
|||||||
|
|
||||||
int refsToLoad = 0;
|
int refsToLoad = 0;
|
||||||
// get the number of refs to load
|
// 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();
|
CellStoreCollection::iterator iter = mActiveCells.begin();
|
||||||
|
|
||||||
@ -379,9 +377,9 @@ namespace MWWorld
|
|||||||
loadingListener->setProgressRange(refsToLoad);
|
loadingListener->setProgressRange(refsToLoad);
|
||||||
|
|
||||||
// Load cells
|
// 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();
|
CellStoreCollection::iterator iter = mActiveCells.begin();
|
||||||
|
|
||||||
@ -448,6 +446,7 @@ namespace MWWorld
|
|||||||
Scene::Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics)
|
Scene::Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics)
|
||||||
: mCurrentCell (0), mCellChanged (false), mPhysics(physics), mRendering(rendering)
|
: mCurrentCell (0), mCellChanged (false), mPhysics(physics), mRendering(rendering)
|
||||||
, mPreloadTimer(0.f)
|
, mPreloadTimer(0.f)
|
||||||
|
, mHalfGridSize(Settings::Manager::getInt("exterior cell load distance", "Cells"))
|
||||||
{
|
{
|
||||||
mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager()));
|
mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager()));
|
||||||
}
|
}
|
||||||
@ -640,24 +639,28 @@ namespace MWWorld
|
|||||||
|
|
||||||
if (sqrDistToPlayer < preloadDist*preloadDist)
|
if (sqrDistToPlayer < preloadDist*preloadDist)
|
||||||
{
|
{
|
||||||
MWWorld::CellStore* targetCell = NULL;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!door.getCellRef().getDestCell().empty())
|
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
|
else
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
MWBase::Environment::get().getWorld()->positionToIndex (door.getCellRef().getDoorDest().pos[0], door.getCellRef().getDoorDest().pos[1], 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)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
// ignore error for now, would spam the log too much
|
// 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;
|
MWRender::RenderingManager& mRendering;
|
||||||
std::auto_ptr<CellPreloader> mPreloader;
|
std::auto_ptr<CellPreloader> mPreloader;
|
||||||
float mPreloadTimer;
|
float mPreloadTimer;
|
||||||
|
int mHalfGridSize;
|
||||||
|
|
||||||
void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);
|
void insertCell (CellStore &cell, bool rescale, Loading::Listener* loadingListener);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user