Skip to content

Commit

Permalink
Add "preload instances" setting, disabling this may help if you are l…
Browse files Browse the repository at this point in the history
…ow on memory.
  • Loading branch information
scrawl committed Mar 29, 2016
1 parent 2162d9e commit e1dda96
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
24 changes: 20 additions & 4 deletions apps/openmw/mwworld/cellpreloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ namespace MWWorld
{
public:
/// Constructor to be called from the main thread.
PreloadItem(MWWorld::CellStore* cell, Resource::SceneManager* sceneManager, Resource::BulletShapeManager* bulletShapeManager, Resource::KeyframeManager* keyframeManager, Terrain::World* terrain)
PreloadItem(MWWorld::CellStore* cell, Resource::SceneManager* sceneManager, Resource::BulletShapeManager* bulletShapeManager, Resource::KeyframeManager* keyframeManager, Terrain::World* terrain, bool preloadInstances)
: mIsExterior(cell->getCell()->isExterior())
, mX(cell->getCell()->getGridX())
, mY(cell->getCell()->getGridY())
, mSceneManager(sceneManager)
, mBulletShapeManager(bulletShapeManager)
, mKeyframeManager(keyframeManager)
, mTerrain(terrain)
, mPreloadInstances(preloadInstances)
{
ListModelsVisitor visitor (mMeshes);
if (cell->getState() == MWWorld::CellStore::State_Loaded)
Expand Down Expand Up @@ -84,8 +85,16 @@ namespace MWWorld
std::string mesh = *it;
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());

mPreloadedObjects.push_back(mSceneManager->cacheInstance(mesh));
mPreloadedObjects.push_back(mBulletShapeManager->cacheInstance(mesh));
if (mPreloadInstances)
{
mPreloadedObjects.push_back(mSceneManager->cacheInstance(mesh));
mPreloadedObjects.push_back(mBulletShapeManager->cacheInstance(mesh));
}
else
{
mPreloadedObjects.push_back(mSceneManager->getTemplate(mesh));
mPreloadedObjects.push_back(mBulletShapeManager->getShape(mesh));
}

size_t slashpos = mesh.find_last_of("/\\");
if (slashpos != std::string::npos && slashpos != mesh.size()-1)
Expand Down Expand Up @@ -132,6 +141,7 @@ namespace MWWorld
Resource::BulletShapeManager* mBulletShapeManager;
Resource::KeyframeManager* mKeyframeManager;
Terrain::World* mTerrain;
bool mPreloadInstances;

// keep a ref to the loaded objects to make sure it stays loaded as long as this cell is in the preloaded state
std::vector<osg::ref_ptr<const osg::Object> > mPreloadedObjects;
Expand Down Expand Up @@ -168,6 +178,7 @@ namespace MWWorld
, mExpiryDelay(0.0)
, mMinCacheSize(0)
, mMaxCacheSize(0)
, mPreloadInstances(true)
{
}

Expand Down Expand Up @@ -220,7 +231,7 @@ namespace MWWorld
return;
}

osg::ref_ptr<PreloadItem> item (new PreloadItem(cell, mResourceSystem->getSceneManager(), mBulletShapeManager, mResourceSystem->getKeyframeManager(), mTerrain));
osg::ref_ptr<PreloadItem> item (new PreloadItem(cell, mResourceSystem->getSceneManager(), mBulletShapeManager, mResourceSystem->getKeyframeManager(), mTerrain, mPreloadInstances));
mWorkQueue->addWorkItem(item);

mPreloadCells[cell] = PreloadEntry(timestamp, item);
Expand Down Expand Up @@ -260,6 +271,11 @@ namespace MWWorld
mMaxCacheSize = num;
}

void CellPreloader::setPreloadInstances(bool preload)
{
mPreloadInstances = preload;
}

unsigned int CellPreloader::getMaxCacheSize() const
{
return mMaxCacheSize;
Expand Down
4 changes: 4 additions & 0 deletions apps/openmw/mwworld/cellpreloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace MWWorld
/// The maximum number of preloaded cells.
void setMaxCacheSize(unsigned int num);

/// Enables the creation of instances in the preloading thread.
void setPreloadInstances(bool preload);

unsigned int getMaxCacheSize() const;

void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
Expand All @@ -56,6 +59,7 @@ namespace MWWorld
double mExpiryDelay;
unsigned int mMinCacheSize;
unsigned int mMaxCacheSize;
bool mPreloadInstances;

struct PreloadEntry
{
Expand Down
1 change: 1 addition & 0 deletions apps/openmw/mwworld/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ namespace MWWorld
mPreloader->setExpiryDelay(Settings::Manager::getFloat("preload cell expiry delay", "Cells"));
mPreloader->setMinCacheSize(Settings::Manager::getInt("preload cell cache min", "Cells"));
mPreloader->setMaxCacheSize(Settings::Manager::getInt("preload cell cache max", "Cells"));
mPreloader->setPreloadInstances(Settings::Manager::getBool("preload instances", "Cells"));
}

Scene::~Scene()
Expand Down
5 changes: 5 additions & 0 deletions files/settings-default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ preload doors = true
# Preloading distance threshold
preload distance = 1000

# Controls whether or not the nodes/collision shapes are pre-"instanced" (i.e. cloned) when a cell is preloaded.
# Enabling this option slightly reduces the time it takes to transition into a preloaded cell, but also results in higher memory usage
# proportional to the number of cells that are preloaded.
preload instances = true

# The minimum amount of cells in the preload cache before unused cells start to get thrown out (see "preload cell expiry delay").
# This value should be lower or equal to 'preload cell cache max'.
preload cell cache min = 12
Expand Down

0 comments on commit e1dda96

Please sign in to comment.