@ -21,6 +21,29 @@
# include "cellstore.hpp"
# include "class.hpp"
namespace
{
template < class Contained >
bool contains ( const std : : vector < MWWorld : : CellPreloader : : PositionCellGrid > & container ,
const Contained & contained , float tolerance = 1.f )
{
for ( const auto & pos : contained )
{
bool found = false ;
for ( const auto & pos2 : container )
{
if ( ( pos . first - pos2 . first ) . length2 ( ) < tolerance * tolerance & & pos . second = = pos2 . second )
{
found = true ;
break ;
}
}
if ( ! found ) return false ;
}
return true ;
}
}
namespace MWWorld
{
@ -224,6 +247,7 @@ namespace MWWorld
, mPreloadInstances ( true )
, mLastResourceCacheUpdate ( 0.0 )
, mStoreViewsFailCount ( 0 )
, mLoadedTerrainTimestamp ( 0.0 )
{
}
@ -369,7 +393,11 @@ namespace MWWorld
setTerrainPreloadPositions ( std : : vector < PositionCellGrid > ( ) ) ;
}
else
{
mStoreViewsFailCount = 0 ;
mLoadedTerrainPositions = mTerrainPreloadPositions ;
mLoadedTerrainTimestamp = timestamp ;
}
mTerrainPreloadItem = nullptr ;
}
}
@ -436,10 +464,8 @@ namespace MWWorld
void CellPreloader : : abortTerrainPreloadExcept ( const CellPreloader : : PositionCellGrid * exceptPos )
{
const float resetThreshold = ESM : : Land : : REAL_SIZE ;
for ( const auto & pos : mTerrainPreloadPositions )
if ( exceptPos & & ( pos . first - exceptPos - > first ) . length2 ( ) < resetThreshold * resetThreshold & & pos . second = = exceptPos - > second )
return ;
if ( exceptPos & & contains ( mTerrainPreloadPositions , std : : array { * exceptPos } , ESM : : Land : : REAL_SIZE ) )
return ;
if ( mTerrainPreloadItem & & ! mTerrainPreloadItem - > isDone ( ) )
{
mTerrainPreloadItem - > abort ( ) ;
@ -448,28 +474,13 @@ namespace MWWorld
setTerrainPreloadPositions ( std : : vector < CellPreloader : : PositionCellGrid > ( ) ) ;
}
bool contains ( const std : : vector < CellPreloader : : PositionCellGrid > & container , const std : : vector < CellPreloader : : PositionCellGrid > & contained )
{
for ( const auto & pos : contained )
{
bool found = false ;
for ( const auto & pos2 : container )
{
if ( ( pos . first - pos2 . first ) . length2 ( ) < 1 & & pos . second = = pos2 . second )
{
found = true ;
break ;
}
}
if ( ! found ) return false ;
}
return true ;
}
void CellPreloader : : setTerrainPreloadPositions ( const std : : vector < CellPreloader : : PositionCellGrid > & positions )
{
if ( positions . empty ( ) )
{
mTerrainPreloadPositions . clear ( ) ;
mLoadedTerrainPositions . clear ( ) ;
}
else if ( contains ( mTerrainPreloadPositions , positions ) )
return ;
if ( mTerrainPreloadItem & & ! mTerrainPreloadItem - > isDone ( ) )
@ -496,5 +507,10 @@ namespace MWWorld
}
}
}
bool CellPreloader : : isTerrainLoaded ( const CellPreloader : : PositionCellGrid & position , double referenceTime ) const
{
return mLoadedTerrainTimestamp + mResourceSystem - > getSceneManager ( ) - > getExpiryDelay ( ) > referenceTime & & contains ( mLoadedTerrainPositions , std : : array { position } , ESM : : Land : : REAL_SIZE ) ;
}
}