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