Changes to land creation, add ability to specifically clear terrain cache

new-script-api
Kyle Cooley 7 years ago
parent ab607f3028
commit 2eacc2f093

@ -77,27 +77,55 @@ bool CSVRender::Cell::addObjects (int start, int end)
void CSVRender::Cell::createLand()
{
// Cell is deleted
if (mDeleted)
{
mTerrain.reset();
unloadLand();
return;
}
// Setup land if available
const CSMWorld::IdCollection<CSMWorld::Land>& land = mData.getLand();
int landIndex = land.searchId(mId);
if (landIndex != -1)
if (landIndex != -1 && !land.getRecord(mId).isDeleted())
{
const ESM::Land& esmLand = land.getRecord(mId).get();
if (esmLand.getLandData (ESM::Land::DATA_VHGT))
{
mTerrain.reset(new Terrain::TerrainGrid(mCellNode, mCellNode, mData.getResourceSystem().get(), new TerrainStorage(mData), Mask_Terrain));
if (mTerrain)
{
mTerrain->unloadCell(mCoordinates.getX(), mCoordinates.getY());
mTerrain->clearAssociatedCaches();
}
else
{
mTerrain.reset(new Terrain::TerrainGrid(mCellNode, mCellNode,
mData.getResourceSystem().get(), new TerrainStorage(mData), Mask_Terrain));
}
mTerrain->loadCell(esmLand.mX, esmLand.mY);
if (!mCellBorder)
mCellBorder.reset(new CellBorder(mCellNode, mCoordinates));
mCellBorder->buildShape(esmLand);
return;
}
}
// No land data
unloadLand();
}
void CSVRender::Cell::unloadLand()
{
if (mTerrain)
mTerrain->unloadCell(mCoordinates.getX(), mCoordinates.getY());
if (mCellBorder)
mCellBorder.reset();
}
CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::string& id,

@ -73,6 +73,7 @@ namespace CSVRender
bool addObjects (int start, int end);
void createLand();
void unloadLand();
public:

@ -400,18 +400,21 @@ void CSVRender::PagedWorldspaceWidget::landTextureDataChanged (const QModelIndex
{
for (auto cellIt : mCells)
cellIt.second->landTextureChanged(topLeft, bottomRight);
flagAsModified();
}
void CSVRender::PagedWorldspaceWidget::landTextureAboutToBeRemoved (const QModelIndex& parent, int start, int end)
{
for (auto cellIt : mCells)
cellIt.second->landTextureAboutToBeRemoved(parent, start, end);
flagAsModified();
}
void CSVRender::PagedWorldspaceWidget::landTextureAdded (const QModelIndex& parent, int start, int end)
{
for (auto cellIt : mCells)
cellIt.second->landTextureAdded(parent, start, end);
flagAsModified();
}

@ -75,4 +75,10 @@ void World::updateTextureFiltering()
mTextureManager->updateTextureFiltering();
}
void World::clearAssociatedCaches()
{
mTextureManager->clearCache();
mChunkManager->clearCache();
}
}

@ -63,6 +63,10 @@ namespace Terrain
float getHeightAt (const osg::Vec3f& worldPos);
/// Clears the cached land and landtexture data.
/// @note Thread safe.
virtual void clearAssociatedCaches();
/// Load a terrain cell at maximum LOD and store it in the View for later use.
/// @note Thread safe.
virtual void cacheCell(View* view, int x, int y) {}

Loading…
Cancel
Save