mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Store object tiles position as sorted vector instead of set
This commit is contained in:
parent
f4f9fa4701
commit
22c2f106b7
2 changed files with 23 additions and 17 deletions
|
@ -3,6 +3,9 @@
|
|||
#include "gettilespositions.hpp"
|
||||
#include "settingsutils.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
TileCachedRecastMeshManager::TileCachedRecastMeshManager(const Settings& settings)
|
||||
|
@ -12,23 +15,22 @@ namespace DetourNavigator
|
|||
bool TileCachedRecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape,
|
||||
const btTransform& transform, const AreaType areaType)
|
||||
{
|
||||
bool result = false;
|
||||
auto& tilesPositions = mObjectsTilesPositions[id];
|
||||
std::vector<TilePosition> tilesPositions;
|
||||
const auto border = getBorderSize(mSettings);
|
||||
{
|
||||
auto tiles = mTiles.lock();
|
||||
getTilesPositions(shape, transform, mSettings, [&] (const TilePosition& tilePosition)
|
||||
{
|
||||
if (addTile(id, shape, transform, areaType, tilePosition, border, tiles.get()))
|
||||
{
|
||||
tilesPositions.insert(tilePosition);
|
||||
result = true;
|
||||
}
|
||||
tilesPositions.push_back(tilePosition);
|
||||
});
|
||||
}
|
||||
if (result)
|
||||
++mRevision;
|
||||
return result;
|
||||
if (tilesPositions.empty())
|
||||
return false;
|
||||
std::sort(tilesPositions.begin(), tilesPositions.end());
|
||||
mObjectsTilesPositions.insert_or_assign(id, std::move(tilesPositions));
|
||||
++mRevision;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeObject(const ObjectId id)
|
||||
|
|
|
@ -9,9 +9,10 @@
|
|||
|
||||
#include <components/misc/guarded.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
|
@ -33,14 +34,14 @@ namespace DetourNavigator
|
|||
auto& currentTiles = object->second;
|
||||
const auto border = getBorderSize(mSettings);
|
||||
bool changed = false;
|
||||
std::set<TilePosition> newTiles;
|
||||
std::vector<TilePosition> newTiles;
|
||||
{
|
||||
auto tiles = mTiles.lock();
|
||||
const auto onTilePosition = [&] (const TilePosition& tilePosition)
|
||||
{
|
||||
if (currentTiles.count(tilePosition))
|
||||
if (std::binary_search(currentTiles.begin(), currentTiles.end(), tilePosition))
|
||||
{
|
||||
newTiles.insert(tilePosition);
|
||||
newTiles.push_back(tilePosition);
|
||||
if (updateTile(id, transform, areaType, tilePosition, tiles.get()))
|
||||
{
|
||||
onChangedTile(tilePosition);
|
||||
|
@ -49,24 +50,27 @@ namespace DetourNavigator
|
|||
}
|
||||
else if (addTile(id, shape, transform, areaType, tilePosition, border, tiles.get()))
|
||||
{
|
||||
newTiles.insert(tilePosition);
|
||||
newTiles.push_back(tilePosition);
|
||||
onChangedTile(tilePosition);
|
||||
changed = true;
|
||||
}
|
||||
};
|
||||
getTilesPositions(shape, transform, mSettings, onTilePosition);
|
||||
std::sort(newTiles.begin(), newTiles.end());
|
||||
for (const auto& tile : currentTiles)
|
||||
{
|
||||
if (!newTiles.count(tile) && removeTile(id, tile, tiles.get()))
|
||||
if (!std::binary_search(newTiles.begin(), newTiles.end(), tile) && removeTile(id, tile, tiles.get()))
|
||||
{
|
||||
onChangedTile(tile);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::swap(currentTiles, newTiles);
|
||||
if (changed)
|
||||
{
|
||||
currentTiles = std::move(newTiles);
|
||||
++mRevision;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
@ -94,7 +98,7 @@ namespace DetourNavigator
|
|||
private:
|
||||
const Settings& mSettings;
|
||||
Misc::ScopeGuarded<std::map<TilePosition, CachedRecastMeshManager>> mTiles;
|
||||
std::unordered_map<ObjectId, std::set<TilePosition>> mObjectsTilesPositions;
|
||||
std::unordered_map<ObjectId, std::vector<TilePosition>> mObjectsTilesPositions;
|
||||
std::map<osg::Vec2i, std::vector<TilePosition>> mWaterTilesPositions;
|
||||
std::size_t mRevision = 0;
|
||||
std::size_t mTilesGeneration = 0;
|
||||
|
|
Loading…
Reference in a new issue