mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
preload tweak
Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
parent
89ec6cfea2
commit
6fa12a6eb8
@ -8,6 +8,7 @@
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
#include <components/resource/bulletshapemanager.hpp>
|
||||
#include <components/resource/keyframemanager.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/terrain/world.hpp>
|
||||
@ -65,23 +66,7 @@ namespace MWWorld
|
||||
mTerrainView = mTerrain->createView();
|
||||
|
||||
ListModelsVisitor visitor (mMeshes);
|
||||
if (cell->getState() == MWWorld::CellStore::State_Loaded)
|
||||
{
|
||||
cell->forEach(visitor);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::vector<std::string>& objectIds = cell->getPreloadedIds();
|
||||
|
||||
// could possibly build the model list in the worker thread if we manage to make the Store thread safe
|
||||
for (const std::string& id : objectIds)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id);
|
||||
std::string model = ref.getPtr().getClass().getModel(ref.getPtr());
|
||||
if (!model.empty())
|
||||
mMeshes.push_back(model);
|
||||
}
|
||||
}
|
||||
cell->forEach(visitor);
|
||||
}
|
||||
|
||||
virtual void abort()
|
||||
@ -97,7 +82,7 @@ namespace MWWorld
|
||||
try
|
||||
{
|
||||
mTerrain->cacheCell(mTerrainView.get(), mX, mY);
|
||||
mPreloadedObjects.push_back(mLandManager->getLand(mX, mY));
|
||||
mPreloadedObjects.insert(mLandManager->getLand(mX, mY));
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@ -113,17 +98,7 @@ namespace MWWorld
|
||||
{
|
||||
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
bool animated = false;
|
||||
size_t slashpos = mesh.find_last_of("/\\");
|
||||
if (slashpos != std::string::npos && slashpos != mesh.size()-1)
|
||||
{
|
||||
@ -134,11 +109,23 @@ namespace MWWorld
|
||||
if(kfname.size() > 4 && kfname.compare(kfname.size()-4, 4, ".nif") == 0)
|
||||
{
|
||||
kfname.replace(kfname.size()-4, 4, ".kf");
|
||||
mPreloadedObjects.push_back(mKeyframeManager->get(kfname));
|
||||
if (mSceneManager->getVFS()->exists(kfname))
|
||||
{
|
||||
mPreloadedObjects.insert(mKeyframeManager->get(kfname));
|
||||
animated = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (mPreloadInstances && animated)
|
||||
mPreloadedObjects.insert(mSceneManager->cacheInstance(mesh));
|
||||
else
|
||||
mPreloadedObjects.insert(mSceneManager->getTemplate(mesh));
|
||||
if (mPreloadInstances)
|
||||
mPreloadedObjects.insert(mBulletShapeManager->cacheInstance(mesh));
|
||||
else
|
||||
mPreloadedObjects.insert(mBulletShapeManager->getShape(mesh));
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@ -166,7 +153,7 @@ namespace MWWorld
|
||||
osg::ref_ptr<Terrain::View> mTerrainView;
|
||||
|
||||
// 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::set<osg::ref_ptr<const osg::Object> > mPreloadedObjects;
|
||||
};
|
||||
|
||||
class TerrainPreloadItem : public SceneUtil::WorkItem
|
||||
|
@ -305,12 +305,7 @@ namespace MWWorld
|
||||
|
||||
void Scene::update (float duration, bool paused)
|
||||
{
|
||||
mPreloadTimer -= duration;
|
||||
if (mPreloadTimer <= 0.f)
|
||||
{
|
||||
preloadCells(0.1f);
|
||||
mPreloadTimer = 0.1f;
|
||||
}
|
||||
preloadCells(duration);
|
||||
|
||||
mRendering.update (duration, paused);
|
||||
|
||||
@ -760,13 +755,12 @@ namespace MWWorld
|
||||
|
||||
MWBase::Environment::get().getWorld()->adjustSky();
|
||||
|
||||
mLastPlayerPos = pos.asVec3();
|
||||
mLastPlayerPos = player.getRefData().getPosition().asVec3();
|
||||
}
|
||||
|
||||
Scene::Scene (MWRender::RenderingManager& rendering, MWPhysics::PhysicsSystem *physics,
|
||||
DetourNavigator::Navigator& navigator)
|
||||
: mCurrentCell (0), mCellChanged (false), mPhysics(physics), mRendering(rendering), mNavigator(navigator)
|
||||
, mPreloadTimer(0.f)
|
||||
, mHalfGridSize(Settings::Manager::getInt("exterior cell load distance", "Cells"))
|
||||
, mCellLoadingThreshold(1024.f)
|
||||
, mPreloadDistance(Settings::Manager::getInt("preload distance", "Cells"))
|
||||
@ -1025,6 +1019,7 @@ namespace MWWorld
|
||||
|
||||
void Scene::preloadCells(float dt)
|
||||
{
|
||||
if (dt<=1e-06) return;
|
||||
std::vector<PositionCellGrid> exteriorPositions;
|
||||
|
||||
const MWWorld::ConstPtr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
@ -1160,7 +1155,6 @@ namespace MWWorld
|
||||
|
||||
void Scene::reloadTerrain()
|
||||
{
|
||||
mPreloadTimer = 0;
|
||||
mPreloader->setTerrainPreloadPositions(std::vector<PositionCellGrid>());
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,6 @@ namespace MWWorld
|
||||
MWRender::RenderingManager& mRendering;
|
||||
DetourNavigator::Navigator& mNavigator;
|
||||
std::unique_ptr<CellPreloader> mPreloader;
|
||||
float mPreloadTimer;
|
||||
int mHalfGridSize;
|
||||
float mCellLoadingThreshold;
|
||||
float mPreloadDistance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user