forked from teamnwah/openmw-tes3coop
Use the View-based preloading for TerrainGrid as well
This commit is contained in:
parent
3c29e2dbeb
commit
6ccb6009ee
5 changed files with 25 additions and 16 deletions
|
@ -60,6 +60,8 @@ namespace MWWorld
|
||||||
, mPreloadInstances(preloadInstances)
|
, mPreloadInstances(preloadInstances)
|
||||||
, mAbort(false)
|
, mAbort(false)
|
||||||
{
|
{
|
||||||
|
mTerrainView = mTerrain->createView();
|
||||||
|
|
||||||
ListModelsVisitor visitor (mMeshes);
|
ListModelsVisitor visitor (mMeshes);
|
||||||
if (cell->getState() == MWWorld::CellStore::State_Loaded)
|
if (cell->getState() == MWWorld::CellStore::State_Loaded)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +94,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mPreloadedObjects.push_back(mTerrain->cacheCell(mX, mY));
|
mTerrain->cacheCell(mTerrainView.get(), mX, mY);
|
||||||
mPreloadedObjects.push_back(mLandManager->getLand(mX, mY));
|
mPreloadedObjects.push_back(mLandManager->getLand(mX, mY));
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
|
@ -160,6 +162,8 @@ namespace MWWorld
|
||||||
|
|
||||||
volatile bool mAbort;
|
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
|
// 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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,14 @@
|
||||||
namespace Terrain
|
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)
|
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)
|
: Terrain::World(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask)
|
||||||
, mNumSplits(4)
|
, 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);
|
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)
|
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);
|
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(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask=~0);
|
||||||
~TerrainGrid();
|
~TerrainGrid();
|
||||||
|
|
||||||
/// Load a terrain cell and store it in cache for later use.
|
virtual void cacheCell(View* view, int x, int y);
|
||||||
/// @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);
|
|
||||||
|
|
||||||
/// @note Not thread safe.
|
/// @note Not thread safe.
|
||||||
virtual void loadCell(int x, int y);
|
virtual void loadCell(int x, int y);
|
||||||
|
@ -28,6 +25,8 @@ namespace Terrain
|
||||||
/// @note Not thread safe.
|
/// @note Not thread safe.
|
||||||
virtual void unloadCell(int x, int y);
|
virtual void unloadCell(int x, int y);
|
||||||
|
|
||||||
|
View* createView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<osg::Node> buildTerrain (osg::Group* parent, float chunkSize, const osg::Vec2f& chunkCenter);
|
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);
|
return mStorage->getHeightAt(worldPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> World::cacheCell(int x, int y)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::updateTextureFiltering()
|
void World::updateTextureFiltering()
|
||||||
{
|
{
|
||||||
mTextureManager->updateTextureFiltering();
|
mTextureManager->updateTextureFiltering();
|
||||||
|
|
|
@ -62,11 +62,9 @@ namespace Terrain
|
||||||
|
|
||||||
float getHeightAt (const osg::Vec3f& worldPos);
|
float getHeightAt (const osg::Vec3f& worldPos);
|
||||||
|
|
||||||
/// Load a terrain cell and store it in cache for later use.
|
/// Load a terrain cell at maximum LOD and store it in the View 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.
|
/// @note Thread safe.
|
||||||
/// @note May be ignored by derived implementations that don't organize the terrain into cells.
|
virtual void cacheCell(View* view, int x, int y) {}
|
||||||
virtual osg::ref_ptr<osg::Node> cacheCell(int x, int y);
|
|
||||||
|
|
||||||
/// Load the cell into the scene graph.
|
/// Load the cell into the scene graph.
|
||||||
/// @note Not thread safe.
|
/// @note Not thread safe.
|
||||||
|
|
Loading…
Reference in a new issue