mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 10:36:39 +00:00
Use algorithms to check if PositionCellGrid(s) is/are contained in a range
This commit is contained in:
parent
d71b422615
commit
ac891a5eb1
1 changed files with 24 additions and 27 deletions
|
@ -1,8 +1,9 @@
|
||||||
#include "cellpreloader.hpp"
|
#include "cellpreloader.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
#include <osg/Stats>
|
#include <osg/Stats>
|
||||||
|
|
||||||
|
@ -26,32 +27,28 @@
|
||||||
#include "cellstore.hpp"
|
#include "cellstore.hpp"
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
template <class Contained>
|
|
||||||
bool contains(const std::vector<MWWorld::PositionCellGrid>& container, const Contained& contained, float tolerance)
|
|
||||||
{
|
|
||||||
for (const auto& pos : contained)
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
for (const auto& pos2 : container)
|
|
||||||
{
|
|
||||||
if ((pos.mPosition - pos2.mPosition).length2() < tolerance * tolerance
|
|
||||||
&& pos.mCellBounds == pos2.mCellBounds)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool contains(std::span<const PositionCellGrid> positions, const PositionCellGrid& contained, float tolerance)
|
||||||
|
{
|
||||||
|
const float squaredTolerance = tolerance * tolerance;
|
||||||
|
const auto predicate = [&](const PositionCellGrid& v) {
|
||||||
|
return (contained.mPosition - v.mPosition).length2() < squaredTolerance
|
||||||
|
&& contained.mCellBounds == v.mCellBounds;
|
||||||
|
};
|
||||||
|
return std::ranges::any_of(positions, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(
|
||||||
|
std::span<const PositionCellGrid> container, std::span<const PositionCellGrid> contained, float tolerance)
|
||||||
|
{
|
||||||
|
const auto predicate = [&](const PositionCellGrid& v) { return contains(container, v, tolerance); };
|
||||||
|
return std::ranges::all_of(contained, predicate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ListModelsVisitor
|
struct ListModelsVisitor
|
||||||
{
|
{
|
||||||
bool operator()(const MWWorld::ConstPtr& ptr)
|
bool operator()(const MWWorld::ConstPtr& ptr)
|
||||||
|
@ -376,7 +373,7 @@ namespace MWWorld
|
||||||
|
|
||||||
void CellPreloader::abortTerrainPreloadExcept(const PositionCellGrid* exceptPos)
|
void CellPreloader::abortTerrainPreloadExcept(const PositionCellGrid* exceptPos)
|
||||||
{
|
{
|
||||||
if (exceptPos && contains(mTerrainPreloadPositions, std::array{ *exceptPos }, Constants::CellSizeInUnits))
|
if (exceptPos != nullptr && contains(mTerrainPreloadPositions, *exceptPos, Constants::CellSizeInUnits))
|
||||||
return;
|
return;
|
||||||
if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone())
|
if (mTerrainPreloadItem && !mTerrainPreloadItem->isDone())
|
||||||
{
|
{
|
||||||
|
@ -419,7 +416,7 @@ namespace MWWorld
|
||||||
bool CellPreloader::isTerrainLoaded(const PositionCellGrid& position, double referenceTime) const
|
bool CellPreloader::isTerrainLoaded(const PositionCellGrid& position, double referenceTime) const
|
||||||
{
|
{
|
||||||
return mLoadedTerrainTimestamp + mResourceSystem->getSceneManager()->getExpiryDelay() > referenceTime
|
return mLoadedTerrainTimestamp + mResourceSystem->getSceneManager()->getExpiryDelay() > referenceTime
|
||||||
&& contains(mLoadedTerrainPositions, std::array{ position }, Constants::CellSizeInUnits);
|
&& contains(mLoadedTerrainPositions, position, Constants::CellSizeInUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CellPreloader::setTerrain(Terrain::World* terrain)
|
void CellPreloader::setTerrain(Terrain::World* terrain)
|
||||||
|
|
Loading…
Reference in a new issue