mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-26 17:41:33 +00:00
Add "preload instances" setting, disabling this may help if you are low on memory.
This commit is contained in:
parent
2162d9ed02
commit
e1dda9675d
4 changed files with 30 additions and 4 deletions
|
@ -45,7 +45,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Constructor to be called from the main thread.
|
/// 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())
|
: mIsExterior(cell->getCell()->isExterior())
|
||||||
, mX(cell->getCell()->getGridX())
|
, mX(cell->getCell()->getGridX())
|
||||||
, mY(cell->getCell()->getGridY())
|
, mY(cell->getCell()->getGridY())
|
||||||
|
@ -53,6 +53,7 @@ namespace MWWorld
|
||||||
, mBulletShapeManager(bulletShapeManager)
|
, mBulletShapeManager(bulletShapeManager)
|
||||||
, mKeyframeManager(keyframeManager)
|
, mKeyframeManager(keyframeManager)
|
||||||
, mTerrain(terrain)
|
, mTerrain(terrain)
|
||||||
|
, mPreloadInstances(preloadInstances)
|
||||||
{
|
{
|
||||||
ListModelsVisitor visitor (mMeshes);
|
ListModelsVisitor visitor (mMeshes);
|
||||||
if (cell->getState() == MWWorld::CellStore::State_Loaded)
|
if (cell->getState() == MWWorld::CellStore::State_Loaded)
|
||||||
|
@ -84,8 +85,16 @@ namespace MWWorld
|
||||||
std::string mesh = *it;
|
std::string mesh = *it;
|
||||||
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());
|
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());
|
||||||
|
|
||||||
|
if (mPreloadInstances)
|
||||||
|
{
|
||||||
mPreloadedObjects.push_back(mSceneManager->cacheInstance(mesh));
|
mPreloadedObjects.push_back(mSceneManager->cacheInstance(mesh));
|
||||||
mPreloadedObjects.push_back(mBulletShapeManager->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("/\\");
|
size_t slashpos = mesh.find_last_of("/\\");
|
||||||
if (slashpos != std::string::npos && slashpos != mesh.size()-1)
|
if (slashpos != std::string::npos && slashpos != mesh.size()-1)
|
||||||
|
@ -132,6 +141,7 @@ namespace MWWorld
|
||||||
Resource::BulletShapeManager* mBulletShapeManager;
|
Resource::BulletShapeManager* mBulletShapeManager;
|
||||||
Resource::KeyframeManager* mKeyframeManager;
|
Resource::KeyframeManager* mKeyframeManager;
|
||||||
Terrain::World* mTerrain;
|
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
|
// 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;
|
std::vector<osg::ref_ptr<const osg::Object> > mPreloadedObjects;
|
||||||
|
@ -168,6 +178,7 @@ namespace MWWorld
|
||||||
, mExpiryDelay(0.0)
|
, mExpiryDelay(0.0)
|
||||||
, mMinCacheSize(0)
|
, mMinCacheSize(0)
|
||||||
, mMaxCacheSize(0)
|
, mMaxCacheSize(0)
|
||||||
|
, mPreloadInstances(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +231,7 @@ namespace MWWorld
|
||||||
return;
|
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);
|
mWorkQueue->addWorkItem(item);
|
||||||
|
|
||||||
mPreloadCells[cell] = PreloadEntry(timestamp, item);
|
mPreloadCells[cell] = PreloadEntry(timestamp, item);
|
||||||
|
@ -260,6 +271,11 @@ namespace MWWorld
|
||||||
mMaxCacheSize = num;
|
mMaxCacheSize = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CellPreloader::setPreloadInstances(bool preload)
|
||||||
|
{
|
||||||
|
mPreloadInstances = preload;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int CellPreloader::getMaxCacheSize() const
|
unsigned int CellPreloader::getMaxCacheSize() const
|
||||||
{
|
{
|
||||||
return mMaxCacheSize;
|
return mMaxCacheSize;
|
||||||
|
|
|
@ -44,6 +44,9 @@ namespace MWWorld
|
||||||
/// The maximum number of preloaded cells.
|
/// The maximum number of preloaded cells.
|
||||||
void setMaxCacheSize(unsigned int num);
|
void setMaxCacheSize(unsigned int num);
|
||||||
|
|
||||||
|
/// Enables the creation of instances in the preloading thread.
|
||||||
|
void setPreloadInstances(bool preload);
|
||||||
|
|
||||||
unsigned int getMaxCacheSize() const;
|
unsigned int getMaxCacheSize() const;
|
||||||
|
|
||||||
void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
|
void setWorkQueue(osg::ref_ptr<SceneUtil::WorkQueue> workQueue);
|
||||||
|
@ -56,6 +59,7 @@ namespace MWWorld
|
||||||
double mExpiryDelay;
|
double mExpiryDelay;
|
||||||
unsigned int mMinCacheSize;
|
unsigned int mMinCacheSize;
|
||||||
unsigned int mMaxCacheSize;
|
unsigned int mMaxCacheSize;
|
||||||
|
bool mPreloadInstances;
|
||||||
|
|
||||||
struct PreloadEntry
|
struct PreloadEntry
|
||||||
{
|
{
|
||||||
|
|
|
@ -478,6 +478,7 @@ namespace MWWorld
|
||||||
mPreloader->setExpiryDelay(Settings::Manager::getFloat("preload cell expiry delay", "Cells"));
|
mPreloader->setExpiryDelay(Settings::Manager::getFloat("preload cell expiry delay", "Cells"));
|
||||||
mPreloader->setMinCacheSize(Settings::Manager::getInt("preload cell cache min", "Cells"));
|
mPreloader->setMinCacheSize(Settings::Manager::getInt("preload cell cache min", "Cells"));
|
||||||
mPreloader->setMaxCacheSize(Settings::Manager::getInt("preload cell cache max", "Cells"));
|
mPreloader->setMaxCacheSize(Settings::Manager::getInt("preload cell cache max", "Cells"));
|
||||||
|
mPreloader->setPreloadInstances(Settings::Manager::getBool("preload instances", "Cells"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene::~Scene()
|
Scene::~Scene()
|
||||||
|
|
|
@ -52,6 +52,11 @@ preload doors = true
|
||||||
# Preloading distance threshold
|
# Preloading distance threshold
|
||||||
preload distance = 1000
|
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").
|
# 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'.
|
# This value should be lower or equal to 'preload cell cache max'.
|
||||||
preload cell cache min = 12
|
preload cell cache min = 12
|
||||||
|
|
Loading…
Reference in a new issue