1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 05:39:42 +00:00

Use single set to store pushed tiles

This commit is contained in:
elsid 2021-08-06 19:55:34 +02:00
parent a97b2ced27
commit 8bca9eec80
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 8 additions and 15 deletions

View file

@ -29,14 +29,13 @@ namespace
}
int getMinDistanceTo(const TilePosition& position, int maxDistance,
const std::map<osg::Vec3f, std::set<TilePosition>>& tilesPerHalfExtents,
const std::set<std::tuple<osg::Vec3f, TilePosition>>& pushedTiles,
const std::set<std::tuple<osg::Vec3f, TilePosition>>& presentTiles)
{
int result = maxDistance;
for (const auto& [halfExtents, tiles] : tilesPerHalfExtents)
for (const TilePosition& tile : tiles)
if (presentTiles.find(std::make_tuple(halfExtents, tile)) == presentTiles.end())
result = std::min(result, getManhattanDistance(position, tile));
for (const auto& [halfExtents, tile] : pushedTiles)
if (presentTiles.find(std::tie(halfExtents, tile)) == presentTiles.end())
result = std::min(result, getManhattanDistance(position, tile));
return result;
}
@ -120,7 +119,7 @@ namespace DetourNavigator
for (const auto& changedTile : changedTiles)
{
if (mPushed[agentHalfExtents].insert(changedTile.first).second)
if (mPushed.emplace(agentHalfExtents, changedTile.first).second)
{
Job job;
@ -367,13 +366,7 @@ namespace DetourNavigator
if (owner == threadId)
{
const auto it = mPushed.find(job->mAgentHalfExtents);
if (it != mPushed.end())
{
it->second.erase(job->mChangedTile);
if (it->second.empty())
mPushed.erase(it);
}
mPushed.erase(getAgentAndTile(*job));
return job;
}
@ -427,7 +420,7 @@ namespace DetourNavigator
const std::lock_guard<std::mutex> lock(mMutex);
if (mPushed[job->mAgentHalfExtents].insert(job->mChangedTile).second)
if (mPushed.emplace(job->mAgentHalfExtents, job->mChangedTile).second)
{
++job->mTryNumber;
mWaiting.push_back(job);

View file

@ -92,7 +92,7 @@ namespace DetourNavigator
std::condition_variable mProcessed;
std::list<Job> mJobs;
std::deque<JobIt> mWaiting;
std::map<osg::Vec3f, std::set<TilePosition>> mPushed;
std::set<std::tuple<osg::Vec3f, TilePosition>> mPushed;
Misc::ScopeGuarded<TilePosition> mPlayerTile;
NavMeshTilesCache mNavMeshTilesCache;
Misc::ScopeGuarded<std::map<std::tuple<osg::Vec3f, TilePosition>, std::thread::id>> mProcessingTiles;