mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-15 05:36:44 +00:00
Use single map to store last updates
This commit is contained in:
parent
bfcc430822
commit
a97b2ced27
2 changed files with 12 additions and 15 deletions
|
@ -65,6 +65,11 @@ namespace
|
||||||
const auto it = std::upper_bound(queue.begin(), queue.end(), job, LessByJobPriority {});
|
const auto it = std::upper_bound(queue.begin(), queue.end(), job, LessByJobPriority {});
|
||||||
queue.insert(it, job);
|
queue.insert(it, job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto getAgentAndTile(const Job& job) noexcept
|
||||||
|
{
|
||||||
|
return std::make_tuple(job.mAgentHalfExtents, job.mChangedTile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DetourNavigator
|
namespace DetourNavigator
|
||||||
|
@ -127,7 +132,7 @@ namespace DetourNavigator
|
||||||
job.mDistanceToPlayer = getManhattanDistance(changedTile.first, playerTile);
|
job.mDistanceToPlayer = getManhattanDistance(changedTile.first, playerTile);
|
||||||
job.mDistanceToOrigin = getManhattanDistance(changedTile.first, TilePosition {0, 0});
|
job.mDistanceToOrigin = getManhattanDistance(changedTile.first, TilePosition {0, 0});
|
||||||
job.mProcessTime = job.mChangeType == ChangeType::update
|
job.mProcessTime = job.mChangeType == ChangeType::update
|
||||||
? mLastUpdates[job.mAgentHalfExtents][job.mChangedTile] + mSettings.get().mMinUpdateInterval
|
? mLastUpdates[getAgentAndTile(job)] + mSettings.get().mMinUpdateInterval
|
||||||
: std::chrono::steady_clock::time_point();
|
: std::chrono::steady_clock::time_point();
|
||||||
|
|
||||||
const JobIt it = mJobs.insert(mJobs.end(), std::move(job));
|
const JobIt it = mJobs.insert(mJobs.end(), std::move(job));
|
||||||
|
@ -387,7 +392,7 @@ namespace DetourNavigator
|
||||||
jobs.pop_front();
|
jobs.pop_front();
|
||||||
|
|
||||||
if (changeLastUpdate && job->mChangeType == ChangeType::update)
|
if (changeLastUpdate && job->mChangeType == ChangeType::update)
|
||||||
mLastUpdates[job->mAgentHalfExtents][job->mChangedTile] = now;
|
mLastUpdates[getAgentAndTile(*job)] = now;
|
||||||
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
@ -477,20 +482,12 @@ namespace DetourNavigator
|
||||||
|
|
||||||
const std::lock_guard<std::mutex> lock(mMutex);
|
const std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
|
||||||
for (auto agent = mLastUpdates.begin(); agent != mLastUpdates.end();)
|
for (auto it = mLastUpdates.begin(); it != mLastUpdates.end();)
|
||||||
{
|
{
|
||||||
for (auto tile = agent->second.begin(); tile != agent->second.end();)
|
if (now - it->second > mSettings.get().mMinUpdateInterval)
|
||||||
{
|
it = mLastUpdates.erase(it);
|
||||||
if (now - tile->second > mSettings.get().mMinUpdateInterval)
|
|
||||||
tile = agent->second.erase(tile);
|
|
||||||
else
|
else
|
||||||
++tile;
|
++it;
|
||||||
}
|
|
||||||
|
|
||||||
if (agent->second.empty())
|
|
||||||
agent = mLastUpdates.erase(agent);
|
|
||||||
else
|
|
||||||
++agent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace DetourNavigator
|
||||||
Misc::ScopeGuarded<TilePosition> mPlayerTile;
|
Misc::ScopeGuarded<TilePosition> mPlayerTile;
|
||||||
NavMeshTilesCache mNavMeshTilesCache;
|
NavMeshTilesCache mNavMeshTilesCache;
|
||||||
Misc::ScopeGuarded<std::map<std::tuple<osg::Vec3f, TilePosition>, std::thread::id>> mProcessingTiles;
|
Misc::ScopeGuarded<std::map<std::tuple<osg::Vec3f, TilePosition>, std::thread::id>> mProcessingTiles;
|
||||||
std::map<osg::Vec3f, std::map<TilePosition, std::chrono::steady_clock::time_point>> mLastUpdates;
|
std::map<std::tuple<osg::Vec3f, TilePosition>, std::chrono::steady_clock::time_point> mLastUpdates;
|
||||||
std::set<std::tuple<osg::Vec3f, TilePosition>> mPresentTiles;
|
std::set<std::tuple<osg::Vec3f, TilePosition>> mPresentTiles;
|
||||||
std::map<std::thread::id, std::deque<JobIt>> mThreadsQueues;
|
std::map<std::thread::id, std::deque<JobIt>> mThreadsQueues;
|
||||||
std::vector<std::thread> mThreads;
|
std::vector<std::thread> mThreads;
|
||||||
|
|
Loading…
Reference in a new issue