Use the View-based preloading for TerrainGrid as well

0.6.1
scrawl 8 years ago
parent 3c29e2dbeb
commit 6ccb6009ee

@ -60,6 +60,8 @@ namespace MWWorld
, mPreloadInstances(preloadInstances)
, mAbort(false)
{
mTerrainView = mTerrain->createView();
ListModelsVisitor visitor (mMeshes);
if (cell->getState() == MWWorld::CellStore::State_Loaded)
{
@ -92,7 +94,7 @@ namespace MWWorld
{
try
{
mPreloadedObjects.push_back(mTerrain->cacheCell(mX, mY));
mTerrain->cacheCell(mTerrainView.get(), mX, mY);
mPreloadedObjects.push_back(mLandManager->getLand(mX, mY));
}
catch(std::exception& e)
@ -160,6 +162,8 @@ namespace MWWorld
volatile bool mAbort;
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;
};

@ -9,6 +9,14 @@
namespace Terrain
{
class MyView : public View
{
public:
osg::ref_ptr<osg::Node> mLoaded;
virtual void reset(unsigned int frame) {}
};
TerrainGrid::TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask)
: Terrain::World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask)
, mNumSplits(4)
@ -23,10 +31,10 @@ TerrainGrid::~TerrainGrid()
}
}
osg::ref_ptr<osg::Node> TerrainGrid::cacheCell(int x, int y)
void TerrainGrid::cacheCell(View* view, int x, int y)
{
osg::Vec2f center(x+0.5f, y+0.5f);
return buildTerrain(NULL, 1.f, center);
static_cast<MyView*>(view)->mLoaded = buildTerrain(NULL, 1.f, center);
}
osg::ref_ptr<osg::Node> TerrainGrid::buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter)
@ -84,4 +92,9 @@ void TerrainGrid::unloadCell(int x, int y)
mGrid.erase(it);
}
View *TerrainGrid::createView()
{
return new MyView;
}
}

@ -17,10 +17,7 @@ namespace Terrain
TerrainGrid(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask=~0);
~TerrainGrid();
/// Load a terrain cell and store it in cache for later use.
/// @note The returned ref_ptr should be kept by the caller to ensure that the terrain stays in cache for as long as needed.
/// @note Thread safe.
virtual osg::ref_ptr<osg::Node> cacheCell(int x, int y);
virtual void cacheCell(View* view, int x, int y);
/// @note Not thread safe.
virtual void loadCell(int x, int y);
@ -28,6 +25,8 @@ namespace Terrain
/// @note Not thread safe.
virtual void unloadCell(int x, int y);
View* createView();
private:
osg::ref_ptr<osg::Node> buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter);

@ -70,11 +70,6 @@ float World::getHeightAt(const osg::Vec3f &worldPos)
return mStorage->getHeightAt(worldPos);
}
osg::ref_ptr<osg::Node> World::cacheCell(int x, int y)
{
return NULL;
}
void World::updateTextureFiltering()
{
mTextureManager->updateTextureFiltering();

@ -62,11 +62,9 @@ namespace Terrain
float getHeightAt (const osg::Vec3f& worldPos);
/// Load a terrain cell and store it in cache for later use.
/// @note The returned ref_ptr should be kept by the caller to ensure that the terrain stays in cache for as long as needed.
/// Load a terrain cell at maximum LOD and store it in the View for later use.
/// @note Thread safe.
/// @note May be ignored by derived implementations that don't organize the terrain into cells.
virtual osg::ref_ptr<osg::Node> cacheCell(int x, int y);
virtual void cacheCell(View* view, int x, int y) {}
/// Load the cell into the scene graph.
/// @note Not thread safe.

Loading…
Cancel
Save