1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-23 18:11:34 +00:00

Revert "Use ESM::RefId for worldspace in detournavigator"

This reverts commit b4ab153418.

# Conflicts:
#	apps/navmeshtool/worldspacedata.cpp
This commit is contained in:
florent.teppe 2023-01-21 14:54:46 +01:00
parent 3780033837
commit 150e2ba885
23 changed files with 133 additions and 154 deletions

View file

@ -8,7 +8,6 @@
#include <components/detournavigator/navmeshdb.hpp> #include <components/detournavigator/navmeshdb.hpp>
#include <components/detournavigator/recastglobalallocator.hpp> #include <components/detournavigator/recastglobalallocator.hpp>
#include <components/detournavigator/settings.hpp> #include <components/detournavigator/settings.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/readerscache.hpp> #include <components/esm3/readerscache.hpp>
#include <components/esm3/variant.hpp> #include <components/esm3/variant.hpp>
#include <components/esmloader/esmdata.hpp> #include <components/esmloader/esmdata.hpp>

View file

@ -106,7 +106,7 @@ namespace NavMeshTool
return DetourNavigator::resolveMeshSource(mDb, source, mNextShapeId); return DetourNavigator::resolveMeshSource(mDb, source, mNextShapeId);
} }
std::optional<NavMeshTileInfo> find(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::optional<NavMeshTileInfo> find(std::string_view worldspace, const TilePosition& tilePosition,
const std::vector<std::byte>& input) override const std::vector<std::byte>& input) override
{ {
std::optional<NavMeshTileInfo> result; std::optional<NavMeshTileInfo> result;
@ -121,7 +121,7 @@ namespace NavMeshTool
return result; return result;
} }
void ignore(const ESM::RefId& worldspace, const TilePosition& tilePosition) override void ignore(std::string_view worldspace, const TilePosition& tilePosition) override
{ {
if (mRemoveUnusedTiles) if (mRemoveUnusedTiles)
{ {
@ -131,7 +131,7 @@ namespace NavMeshTool
report(); report();
} }
void identity(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t tileId) override void identity(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId) override
{ {
if (mRemoveUnusedTiles) if (mRemoveUnusedTiles)
{ {
@ -142,7 +142,7 @@ namespace NavMeshTool
report(); report();
} }
void insert(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t version, void insert(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t version,
const std::vector<std::byte>& input, PreparedNavMeshData& data) override const std::vector<std::byte>& input, PreparedNavMeshData& data) override
{ {
{ {
@ -158,7 +158,7 @@ namespace NavMeshTool
report(); report();
} }
void update(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t tileId, void update(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId,
std::int64_t version, PreparedNavMeshData& data) override std::int64_t version, PreparedNavMeshData& data) override
{ {
data.mUserId = static_cast<unsigned>(tileId); data.mUserId = static_cast<unsigned>(tileId);
@ -217,7 +217,7 @@ namespace NavMeshTool
mDb.vacuum(); mDb.vacuum();
} }
void removeTilesOutsideRange(const ESM::RefId& worldspace, const TilesPositionsRange& range) void removeTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range)
{ {
const std::lock_guard lock(mMutex); const std::lock_guard lock(mMutex);
mTransaction.commit(); mTransaction.commit();

View file

@ -8,7 +8,6 @@
#include <components/detournavigator/recastmesh.hpp> #include <components/detournavigator/recastmesh.hpp>
#include <components/detournavigator/settings.hpp> #include <components/detournavigator/settings.hpp>
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp> #include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/cellref.hpp> #include <components/esm3/cellref.hpp>
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/loadcell.hpp> #include <components/esm3/loadcell.hpp>
@ -30,6 +29,7 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <algorithm> #include <algorithm>
#include <components/esm/refid.hpp>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -37,7 +37,6 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include <vector> #include <vector>
namespace NavMeshTool namespace NavMeshTool
{ {
namespace namespace
@ -222,7 +221,7 @@ namespace NavMeshTool
} }
WorldspaceNavMeshInput::WorldspaceNavMeshInput( WorldspaceNavMeshInput::WorldspaceNavMeshInput(
ESM::RefId worldspace, const DetourNavigator::RecastSettings& settings) std::string worldspace, const DetourNavigator::RecastSettings& settings)
: mWorldspace(std::move(worldspace)) : mWorldspace(std::move(worldspace))
, mTileCachedRecastMeshManager(settings) , mTileCachedRecastMeshManager(settings)
{ {
@ -236,7 +235,7 @@ namespace NavMeshTool
{ {
Log(Debug::Info) << "Processing " << esmData.mCells.size() << " cells..."; Log(Debug::Info) << "Processing " << esmData.mCells.size() << " cells...";
std::map<ESM::RefId, std::unique_ptr<WorldspaceNavMeshInput>> navMeshInputs; std::map<std::string_view, std::unique_ptr<WorldspaceNavMeshInput>> navMeshInputs;
WorldspaceData data; WorldspaceData data;
std::size_t objectsCounter = 0; std::size_t objectsCounter = 0;
@ -264,17 +263,16 @@ namespace NavMeshTool
const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY); const osg::Vec2i cellPosition(cell.mData.mX, cell.mData.mY);
const std::size_t cellObjectsBegin = data.mObjects.size(); const std::size_t cellObjectsBegin = data.mObjects.size();
const auto cellNameLowerCase = Misc::StringUtils::lowerCase(cell.mCellId.mWorldspace);
WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& { WorldspaceNavMeshInput& navMeshInput = [&]() -> WorldspaceNavMeshInput& {
auto it = navMeshInputs.find(ESM::RefId::stringRefId(cell.mCellId.mWorldspace)); auto it = navMeshInputs.find(cellNameLowerCase);
if (it == navMeshInputs.end()) if (it == navMeshInputs.end())
{ {
it = navMeshInputs it = navMeshInputs
.emplace(ESM::RefId::stringRefId(cell.mCellId.mWorldspace), .emplace(cellNameLowerCase,
std::make_unique<WorldspaceNavMeshInput>( std::make_unique<WorldspaceNavMeshInput>(cellNameLowerCase, settings.mRecast))
ESM::RefId::stringRefId(cell.mCellId.mWorldspace), settings.mRecast))
.first; .first;
it->second->mTileCachedRecastMeshManager.setWorldspace( it->second->mTileCachedRecastMeshManager.setWorldspace(cellNameLowerCase, nullptr);
ESM::RefId::stringRefId(cell.mCellId.mWorldspace), nullptr);
} }
return *it->second; return *it->second;
}(); }();

View file

@ -3,7 +3,6 @@
#include <components/bullethelpers/collisionobject.hpp> #include <components/bullethelpers/collisionobject.hpp>
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp> #include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/loadland.hpp> #include <components/esm3/loadland.hpp>
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
#include <components/resource/bulletshape.hpp> #include <components/resource/bulletshape.hpp>
@ -49,12 +48,12 @@ namespace NavMeshTool
struct WorldspaceNavMeshInput struct WorldspaceNavMeshInput
{ {
ESM::RefId mWorldspace; std::string mWorldspace;
TileCachedRecastMeshManager mTileCachedRecastMeshManager; TileCachedRecastMeshManager mTileCachedRecastMeshManager;
btAABB mAabb; btAABB mAabb;
bool mAabbInitialized = false; bool mAabbInitialized = false;
explicit WorldspaceNavMeshInput(ESM::RefId worldspace, const DetourNavigator::RecastSettings& settings); explicit WorldspaceNavMeshInput(std::string worldspace, const DetourNavigator::RecastSettings& settings);
}; };
class BulletObject class BulletObject

View file

@ -5,7 +5,6 @@
#include <components/detournavigator/makenavmesh.hpp> #include <components/detournavigator/makenavmesh.hpp>
#include <components/detournavigator/navmeshdbutils.hpp> #include <components/detournavigator/navmeshdbutils.hpp>
#include <components/detournavigator/serialization.hpp> #include <components/detournavigator/serialization.hpp>
#include <components/esm/refid.hpp>
#include <components/loadinglistener/loadinglistener.hpp> #include <components/loadinglistener/loadinglistener.hpp>
#include <BulletCollision/CollisionShapes/btBoxShape.h> #include <BulletCollision/CollisionShapes/btBoxShape.h>
@ -53,7 +52,7 @@ namespace
OffMeshConnectionsManager mOffMeshConnectionsManager{ mSettings.mRecast }; OffMeshConnectionsManager mOffMeshConnectionsManager{ mSettings.mRecast };
const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } }; const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } };
const TilePosition mPlayerTile{ 0, 0 }; const TilePosition mPlayerTile{ 0, 0 };
const ESM::RefId mWorldspace = ESM::RefId::stringRefId("sys::default"); const std::string mWorldspace = "sys::default";
const btBoxShape mBox{ btVector3(100, 100, 20) }; const btBoxShape mBox{ btVector3(100, 100, 20) };
Loading::Listener mListener; Loading::Listener mListener;
}; };

View file

@ -44,6 +44,7 @@ namespace
Settings mSettings = makeSettings(); Settings mSettings = makeSettings();
std::unique_ptr<Navigator> mNavigator; std::unique_ptr<Navigator> mNavigator;
const osg::Vec3f mPlayerPosition; const osg::Vec3f mPlayerPosition;
const std::string mWorldspace;
const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } }; const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } };
osg::Vec3f mStart; osg::Vec3f mStart;
osg::Vec3f mEnd; osg::Vec3f mEnd;
@ -60,6 +61,7 @@ namespace
DetourNavigatorNavigatorTest() DetourNavigatorNavigatorTest()
: mPlayerPosition(256, 256, 0) : mPlayerPosition(256, 256, 0)
, mWorldspace("sys::default")
, mStart(52, 460, 1) , mStart(52, 460, 1)
, mEnd(460, 52, 1) , mEnd(460, 52, 1)
, mOut(mPath) , mOut(mPath)

View file

@ -1,7 +1,6 @@
#include "generate.hpp" #include "generate.hpp"
#include <components/detournavigator/navmeshdb.hpp> #include <components/detournavigator/navmeshdb.hpp>
#include <components/esm/refid.hpp>
#include <DetourAlloc.h> #include <DetourAlloc.h>
@ -20,7 +19,7 @@ namespace
struct Tile struct Tile
{ {
ESM::RefId mWorldspace; std::string mWorldspace;
TilePosition mTilePosition; TilePosition mTilePosition;
std::vector<std::byte> mInput; std::vector<std::byte> mInput;
std::vector<std::byte> mData; std::vector<std::byte> mData;
@ -40,7 +39,7 @@ namespace
Tile insertTile(TileId tileId, TileVersion version) Tile insertTile(TileId tileId, TileVersion version)
{ {
ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); std::string worldspace = "sys::default";
const TilePosition tilePosition{ 3, 4 }; const TilePosition tilePosition{ 3, 4 };
std::vector<std::byte> input = generateData(); std::vector<std::byte> input = generateData();
std::vector<std::byte> data = generateData(); std::vector<std::byte> data = generateData();
@ -90,7 +89,7 @@ namespace
{ {
const TileId tileId{ 53 }; const TileId tileId{ 53 };
const TileVersion version{ 1 }; const TileVersion version{ 1 };
const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::string worldspace = "sys::default";
const TilePosition tilePosition{ 3, 4 }; const TilePosition tilePosition{ 3, 4 };
const std::vector<std::byte> input = generateData(); const std::vector<std::byte> input = generateData();
const std::vector<std::byte> data = generateData(); const std::vector<std::byte> data = generateData();
@ -102,7 +101,7 @@ namespace
{ {
const TileId tileId{ 53 }; const TileId tileId{ 53 };
const TileVersion version{ 1 }; const TileVersion version{ 1 };
const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::string worldspace = "sys::default";
const TilePosition tilePosition{ 3, 4 }; const TilePosition tilePosition{ 3, 4 };
const std::vector<std::byte> input = generateData(); const std::vector<std::byte> input = generateData();
const std::vector<std::byte> data = generateData(); const std::vector<std::byte> data = generateData();
@ -114,7 +113,7 @@ namespace
TEST_F(DetourNavigatorNavMeshDbTest, delete_tiles_at_should_remove_all_tiles_with_given_worldspace_and_position) TEST_F(DetourNavigatorNavMeshDbTest, delete_tiles_at_should_remove_all_tiles_with_given_worldspace_and_position)
{ {
const TileVersion version{ 1 }; const TileVersion version{ 1 };
const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::string worldspace = "sys::default";
const TilePosition tilePosition{ 3, 4 }; const TilePosition tilePosition{ 3, 4 };
const std::vector<std::byte> input1 = generateData(); const std::vector<std::byte> input1 = generateData();
const std::vector<std::byte> input2 = generateData(); const std::vector<std::byte> input2 = generateData();
@ -131,7 +130,7 @@ namespace
const TileId leftTileId{ 53 }; const TileId leftTileId{ 53 };
const TileId removedTileId{ 54 }; const TileId removedTileId{ 54 };
const TileVersion version{ 1 }; const TileVersion version{ 1 };
const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::string worldspace = "sys::default";
const TilePosition tilePosition{ 3, 4 }; const TilePosition tilePosition{ 3, 4 };
const std::vector<std::byte> leftInput = generateData(); const std::vector<std::byte> leftInput = generateData();
const std::vector<std::byte> removedInput = generateData(); const std::vector<std::byte> removedInput = generateData();
@ -149,7 +148,7 @@ namespace
{ {
TileId tileId{ 1 }; TileId tileId{ 1 };
const TileVersion version{ 1 }; const TileVersion version{ 1 };
const ESM::RefId worldspace = ESM::RefId::stringRefId("sys::default"); const std::string worldspace = "sys::default";
const std::vector<std::byte> input = generateData(); const std::vector<std::byte> input = generateData();
const std::vector<std::byte> data = generateData(); const std::vector<std::byte> data = generateData();
for (int x = -2; x <= 2; ++x) for (int x = -2; x <= 2; ++x)

View file

@ -2,7 +2,6 @@
#include <components/detournavigator/debug.hpp> #include <components/detournavigator/debug.hpp>
#include <components/detournavigator/settingsutils.hpp> #include <components/detournavigator/settingsutils.hpp>
#include <components/detournavigator/tilecachedrecastmeshmanager.hpp> #include <components/detournavigator/tilecachedrecastmeshmanager.hpp>
#include <components/esm/refid.hpp>
#include <BulletCollision/CollisionShapes/btBoxShape.h> #include <BulletCollision/CollisionShapes/btBoxShape.h>
@ -22,8 +21,6 @@ namespace
const ObjectTransform mObjectTransform{ ESM::Position{ { 0, 0, 0 }, { 0, 0, 0 } }, 0.0f }; const ObjectTransform mObjectTransform{ ESM::Position{ { 0, 0, 0 }, { 0, 0, 0 } }, 0.0f };
const osg::ref_ptr<const Resource::BulletShape> mShape = new Resource::BulletShape; const osg::ref_ptr<const Resource::BulletShape> mShape = new Resource::BulletShape;
const osg::ref_ptr<const Resource::BulletShapeInstance> mInstance = new Resource::BulletShapeInstance(mShape); const osg::ref_ptr<const Resource::BulletShapeInstance> mInstance = new Resource::BulletShapeInstance(mShape);
const ESM::RefId mWorldspace = ESM::RefId::stringRefId("worldspace");
const ESM::RefId mOtherWorldspace = ESM::RefId::stringRefId("other");
DetourNavigatorTileCachedRecastMeshManagerTest() DetourNavigatorTileCachedRecastMeshManagerTest()
{ {
@ -37,7 +34,7 @@ namespace
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_empty_should_return_nullptr) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_empty_should_return_nullptr)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_for_empty_should_return_zero) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, get_revision_for_empty_should_return_zero)
@ -68,14 +65,14 @@ namespace
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_add_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_add_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
ASSERT_TRUE(manager.addObject( ASSERT_TRUE(manager.addObject(
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr)); ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
for (int x = -1; x < 1; ++x) for (int x = -1; x < 1; ++x)
for (int y = -1; y < 1; ++y) for (int y = -1; y < 1; ++y)
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_add_changed_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_object_should_return_add_changed_tiles)
@ -148,25 +145,25 @@ namespace
get_mesh_after_add_object_should_return_recast_mesh_for_each_used_tile) get_mesh_after_add_object_should_return_recast_mesh_for_each_used_tile)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
} }
TEST_F( TEST_F(
DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_after_add_object_should_return_nullptr_for_unused_tile) DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_after_add_object_should_return_nullptr_for_unused_tile)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
@ -186,23 +183,23 @@ namespace
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(1, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(1, -1)), nullptr);
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
} }
TEST_F( TEST_F(
DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_moved_object_should_return_nullptr_for_unused_tile) DetourNavigatorTileCachedRecastMeshManagerTest, get_mesh_for_moved_object_should_return_nullptr_for_unused_tile)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const btTransform transform( const btTransform transform(
@ -210,48 +207,48 @@ namespace
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, transform, AreaType::AreaType_ground, nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, 0)), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(1, -1)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(1, -1)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
get_mesh_for_removed_object_should_return_nullptr_for_all_previously_used_tiles) get_mesh_for_removed_object_should_return_nullptr_for_all_previously_used_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
manager.removeObject(ObjectId(&boxShape), nullptr); manager.removeObject(ObjectId(&boxShape), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_EQ(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_EQ(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
get_mesh_for_not_changed_object_after_update_should_return_recast_mesh_for_same_tiles) get_mesh_for_not_changed_object_after_update_should_return_recast_mesh_for_same_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.updateObject(ObjectId(&boxShape), btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(-1, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(-1, 0)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, -1)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, -1)), nullptr);
EXPECT_NE(manager.getMesh(mWorldspace, TilePosition(0, 0)), nullptr); EXPECT_NE(manager.getMesh("worldspace", TilePosition(0, 0)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest,
@ -296,7 +293,7 @@ namespace
get_revision_after_update_not_changed_object_should_return_same_value) get_revision_after_update_not_changed_object_should_return_same_value)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr); manager.addObject(ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr);
@ -342,19 +339,19 @@ namespace
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; const int cellSize = 8192;
manager.addWater(cellPosition, cellSize, 0.0f, nullptr); manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
for (int x = -1; x < 12; ++x) for (int x = -1; x < 12; ++x)
for (int y = -1; y < 12; ++y) for (int y = -1; y < 12; ++y)
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_max_int_should_not_add_new_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_max_int_should_not_add_new_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
ASSERT_TRUE(manager.addObject( ASSERT_TRUE(manager.addObject(
@ -364,7 +361,7 @@ namespace
manager.addWater(cellPosition, cellSize, 0.0f, nullptr); manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
for (int x = -6; x < 6; ++x) for (int x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr, ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr,
-1 <= x && x <= 0 && -1 <= y && y <= 0); -1 <= x && x <= 0 && -1 <= y && y <= 0);
} }
@ -393,20 +390,20 @@ namespace
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_remove_empty_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; const int cellSize = 8192;
manager.addWater(cellPosition, cellSize, 0.0f, nullptr); manager.addWater(cellPosition, cellSize, 0.0f, nullptr);
manager.removeWater(cellPosition, nullptr); manager.removeWater(cellPosition, nullptr);
for (int x = -6; x < 6; ++x) for (int x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_leave_not_empty_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_water_for_existing_cell_should_leave_not_empty_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(mInstance, boxShape, mObjectTransform); const CollisionShape shape(mInstance, boxShape, mObjectTransform);
ASSERT_TRUE(manager.addObject( ASSERT_TRUE(manager.addObject(
@ -417,14 +414,14 @@ namespace
manager.removeWater(cellPosition, nullptr); manager.removeWater(cellPosition, nullptr);
for (int x = -6; x < 6; ++x) for (int x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
ASSERT_EQ(manager.getMesh(mWorldspace, TilePosition(x, y)) != nullptr, ASSERT_EQ(manager.getMesh("worldspace", TilePosition(x, y)) != nullptr,
-1 <= x && x <= 0 && -1 <= y && y <= 0); -1 <= x && x <= 0 && -1 <= y && y <= 0);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_not_remove_tile_with_water) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, remove_object_should_not_remove_tile_with_water)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; const int cellSize = 8192;
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
@ -435,21 +432,21 @@ namespace
manager.removeObject(ObjectId(&boxShape), nullptr); manager.removeObject(ObjectId(&boxShape), nullptr);
for (int x = -1; x < 12; ++x) for (int x = -1; x < 12; ++x)
for (int y = -1; y < 12; ++y) for (int y = -1; y < 12; ++y)
ASSERT_NE(manager.getMesh(mWorldspace, TilePosition(x, y)), nullptr); ASSERT_NE(manager.getMesh("worldspace", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_new_worldspace_should_remove_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_new_worldspace_should_remove_tiles)
{ {
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
manager.setWorldspace(mWorldspace, nullptr); manager.setWorldspace("worldspace", nullptr);
const btBoxShape boxShape(btVector3(20, 20, 100)); const btBoxShape boxShape(btVector3(20, 20, 100));
const CollisionShape shape(nullptr, boxShape, mObjectTransform); const CollisionShape shape(nullptr, boxShape, mObjectTransform);
ASSERT_TRUE(manager.addObject( ASSERT_TRUE(manager.addObject(
ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr)); ObjectId(&boxShape), shape, btTransform::getIdentity(), AreaType::AreaType_ground, nullptr));
manager.setWorldspace(mOtherWorldspace, nullptr); manager.setWorldspace("other", nullptr);
for (int x = -1; x < 1; ++x) for (int x = -1; x < 1; ++x)
for (int y = -1; y < 1; ++y) for (int y = -1; y < 1; ++y)
ASSERT_EQ(manager.getMesh(mOtherWorldspace, TilePosition(x, y)), nullptr); ASSERT_EQ(manager.getMesh("other", TilePosition(x, y)), nullptr);
} }
TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_add_changed_tiles) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, set_bounds_should_add_changed_tiles)

View file

@ -8,7 +8,6 @@
#include "version.hpp" #include "version.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <components/loadinglistener/loadinglistener.hpp> #include <components/loadinglistener/loadinglistener.hpp>
#include <components/misc/thread.hpp> #include <components/misc/thread.hpp>
@ -136,7 +135,7 @@ namespace DetourNavigator
} }
Job::Job(const AgentBounds& agentBounds, std::weak_ptr<GuardedNavMeshCacheItem> navMeshCacheItem, Job::Job(const AgentBounds& agentBounds, std::weak_ptr<GuardedNavMeshCacheItem> navMeshCacheItem,
const ESM::RefId& worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer,
std::chrono::steady_clock::time_point processTime) std::chrono::steady_clock::time_point processTime)
: mId(getNextJobId()) : mId(getNextJobId())
, mAgentBounds(agentBounds) , mAgentBounds(agentBounds)
@ -169,7 +168,7 @@ namespace DetourNavigator
} }
void AsyncNavMeshUpdater::post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, void AsyncNavMeshUpdater::post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem,
const TilePosition& playerTile, const ESM::RefId& worldspace, const TilePosition& playerTile, std::string_view worldspace,
const std::map<TilePosition, ChangeType>& changedTiles) const std::map<TilePosition, ChangeType>& changedTiles)
{ {
bool playerTileChanged = false; bool playerTileChanged = false;

View file

@ -14,8 +14,6 @@
#include "tileposition.hpp" #include "tileposition.hpp"
#include "waitconditiontype.hpp" #include "waitconditiontype.hpp"
#include <components/esm/refid.hpp>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <atomic> #include <atomic>
@ -51,7 +49,7 @@ namespace DetourNavigator
const std::size_t mId; const std::size_t mId;
const AgentBounds mAgentBounds; const AgentBounds mAgentBounds;
const std::weak_ptr<GuardedNavMeshCacheItem> mNavMeshCacheItem; const std::weak_ptr<GuardedNavMeshCacheItem> mNavMeshCacheItem;
const ESM::RefId mWorldspace; const std::string mWorldspace;
const TilePosition mChangedTile; const TilePosition mChangedTile;
const std::chrono::steady_clock::time_point mProcessTime; const std::chrono::steady_clock::time_point mProcessTime;
unsigned mTryNumber = 0; unsigned mTryNumber = 0;
@ -65,7 +63,7 @@ namespace DetourNavigator
std::unique_ptr<PreparedNavMeshData> mGeneratedNavMeshData; std::unique_ptr<PreparedNavMeshData> mGeneratedNavMeshData;
Job(const AgentBounds& agentBounds, std::weak_ptr<GuardedNavMeshCacheItem> navMeshCacheItem, Job(const AgentBounds& agentBounds, std::weak_ptr<GuardedNavMeshCacheItem> navMeshCacheItem,
const ESM::RefId& worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer, std::string_view worldspace, const TilePosition& changedTile, ChangeType changeType, int distanceToPlayer,
std::chrono::steady_clock::time_point processTime); std::chrono::steady_clock::time_point processTime);
}; };
@ -150,7 +148,7 @@ namespace DetourNavigator
~AsyncNavMeshUpdater(); ~AsyncNavMeshUpdater();
void post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem, void post(const AgentBounds& agentBounds, const SharedNavMeshCacheItem& navMeshCacheItem,
const TilePosition& playerTile, const ESM::RefId& worldspace, const TilePosition& playerTile, std::string_view worldspace,
const std::map<TilePosition, ChangeType>& changedTiles); const std::map<TilePosition, ChangeType>& changedTiles);
void wait(WaitConditionType waitConditionType, Loading::Listener* listener); void wait(WaitConditionType waitConditionType, Loading::Listener* listener);

View file

@ -7,7 +7,6 @@
#include "settings.hpp" #include "settings.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <osg/io_utils> #include <osg/io_utils>
@ -24,7 +23,7 @@ namespace DetourNavigator
{ {
struct Ignore struct Ignore
{ {
const ESM::RefId& mWorldspace; std::string_view mWorldspace;
const TilePosition& mTilePosition; const TilePosition& mTilePosition;
std::shared_ptr<NavMeshTileConsumer> mConsumer; std::shared_ptr<NavMeshTileConsumer> mConsumer;
@ -36,7 +35,7 @@ namespace DetourNavigator
}; };
} }
GenerateNavMeshTile::GenerateNavMeshTile(ESM::RefId worldspace, const TilePosition& tilePosition, GenerateNavMeshTile::GenerateNavMeshTile(std::string worldspace, const TilePosition& tilePosition,
RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds, RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds,
const DetourNavigator::Settings& settings, std::weak_ptr<NavMeshTileConsumer> consumer) const DetourNavigator::Settings& settings, std::weak_ptr<NavMeshTileConsumer> consumer)
: mWorldspace(std::move(worldspace)) : mWorldspace(std::move(worldspace))

View file

@ -5,7 +5,6 @@
#include "recastmeshprovider.hpp" #include "recastmeshprovider.hpp"
#include "tileposition.hpp" #include "tileposition.hpp"
#include <components/esm/refid.hpp>
#include <components/sceneutil/workqueue.hpp> #include <components/sceneutil/workqueue.hpp>
#include <osg/Vec3f> #include <osg/Vec3f>
@ -39,18 +38,18 @@ namespace DetourNavigator
virtual std::int64_t resolveMeshSource(const MeshSource& source) = 0; virtual std::int64_t resolveMeshSource(const MeshSource& source) = 0;
virtual std::optional<NavMeshTileInfo> find( virtual std::optional<NavMeshTileInfo> find(
const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input) std::string_view worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input)
= 0; = 0;
virtual void ignore(const ESM::RefId& worldspace, const TilePosition& tilePosition) = 0; virtual void ignore(std::string_view worldspace, const TilePosition& tilePosition) = 0;
virtual void identity(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t tileId) = 0; virtual void identity(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId) = 0;
virtual void insert(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t version, virtual void insert(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t version,
const std::vector<std::byte>& input, PreparedNavMeshData& data) const std::vector<std::byte>& input, PreparedNavMeshData& data)
= 0; = 0;
virtual void update(const ESM::RefId& worldspace, const TilePosition& tilePosition, std::int64_t tileId, virtual void update(std::string_view worldspace, const TilePosition& tilePosition, std::int64_t tileId,
std::int64_t version, PreparedNavMeshData& data) std::int64_t version, PreparedNavMeshData& data)
= 0; = 0;
@ -60,14 +59,14 @@ namespace DetourNavigator
class GenerateNavMeshTile final : public SceneUtil::WorkItem class GenerateNavMeshTile final : public SceneUtil::WorkItem
{ {
public: public:
GenerateNavMeshTile(ESM::RefId worldspace, const TilePosition& tilePosition, GenerateNavMeshTile(std::string worldspace, const TilePosition& tilePosition,
RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds, const Settings& settings, RecastMeshProvider recastMeshProvider, const AgentBounds& agentBounds, const Settings& settings,
std::weak_ptr<NavMeshTileConsumer> consumer); std::weak_ptr<NavMeshTileConsumer> consumer);
void doWork() final; void doWork() final;
private: private:
const ESM::RefId mWorldspace; const std::string mWorldspace;
const TilePosition mTilePosition; const TilePosition mTilePosition;
const RecastMeshProvider mRecastMeshProvider; const RecastMeshProvider mRecastMeshProvider;
const AgentBounds mAgentBounds; const AgentBounds mAgentBounds;

View file

@ -91,6 +91,8 @@ namespace DetourNavigator
* @brief setWorldspace should be called before adding object from new worldspace * @brief setWorldspace should be called before adding object from new worldspace
* @param worldspace * @param worldspace
*/ */
virtual void setWorldspace(std::string_view worldspace, const UpdateGuard* guard) = 0;
virtual void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) = 0; virtual void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) = 0;
/** /**

View file

@ -34,11 +34,16 @@ namespace DetourNavigator
--it->second; --it->second;
} }
void NavigatorImpl::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) void NavigatorImpl::setWorldspace(std::string_view worldspace, const UpdateGuard* guard)
{ {
mNavMeshManager.setWorldspace(worldspace, getImpl(guard)); mNavMeshManager.setWorldspace(worldspace, getImpl(guard));
} }
void NavigatorImpl::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard)
{
setWorldspace(Misc::StringUtils::lowerCase(worldspace.getRefIdString()), guard);
}
void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
{ {
mNavMeshManager.updateBounds(playerPosition, getImpl(guard)); mNavMeshManager.updateBounds(playerPosition, getImpl(guard));

View file

@ -27,6 +27,8 @@ namespace DetourNavigator
void removeAgent(const AgentBounds& agentBounds) override; void removeAgent(const AgentBounds& agentBounds) override;
void setWorldspace(std::string_view worldspace, const UpdateGuard* guard) override;
void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) override; void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) override;
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override; void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override;

View file

@ -23,6 +23,7 @@ namespace DetourNavigator
void removeAgent(const AgentBounds& /*agentBounds*/) override {} void removeAgent(const AgentBounds& /*agentBounds*/) override {}
void setWorldspace(std::string_view /*worldspace*/, const UpdateGuard* /*guard*/) override {}
void setWorldspace(const ESM::RefId& /*worldspace*/, const UpdateGuard* /*guard*/) override {} void setWorldspace(const ESM::RefId& /*worldspace*/, const UpdateGuard* /*guard*/) override {}
void addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/, void addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/,

View file

@ -1,10 +1,8 @@
#include "navmeshdb.hpp" #include "navmeshdb.hpp"
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <components/misc/compression.hpp> #include <components/misc/compression.hpp>
#include <components/misc/strings/format.hpp> #include <components/misc/strings/format.hpp>
#include <components/misc/strings/lower.hpp>
#include <components/sqlite3/db.hpp> #include <components/sqlite3/db.hpp>
#include <components/sqlite3/request.hpp> #include <components/sqlite3/request.hpp>
@ -154,11 +152,6 @@ namespace DetourNavigator
if (const int ec = sqlite3_exec(&db, query.c_str(), nullptr, nullptr, nullptr); ec != SQLITE_OK) if (const int ec = sqlite3_exec(&db, query.c_str(), nullptr, nullptr, nullptr); ec != SQLITE_OK)
throw std::runtime_error("Failed set max page count: " + std::string(sqlite3_errmsg(&db))); throw std::runtime_error("Failed set max page count: " + std::string(sqlite3_errmsg(&db)));
} }
std::string toLowerCaseString(const ESM::RefId& refId)
{
return Misc::StringUtils::lowerCase(refId.getRefIdString());
}
} }
std::ostream& operator<<(std::ostream& stream, ShapeType value) std::ostream& operator<<(std::ostream& stream, ShapeType value)
@ -207,35 +200,34 @@ namespace DetourNavigator
} }
std::optional<Tile> NavMeshDb::findTile( std::optional<Tile> NavMeshDb::findTile(
const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input) std::string_view worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input)
{ {
Tile result; Tile result;
auto row = std::tie(result.mTileId, result.mVersion); auto row = std::tie(result.mTileId, result.mVersion);
const std::vector<std::byte> compressedInput = Misc::compress(input); const std::vector<std::byte> compressedInput = Misc::compress(input);
if (&row == request(*mDb, mFindTile, &row, 1, toLowerCaseString(worldspace), tilePosition, compressedInput)) if (&row == request(*mDb, mFindTile, &row, 1, worldspace, tilePosition, compressedInput))
return {}; return {};
return result; return result;
} }
std::optional<TileData> NavMeshDb::getTileData( std::optional<TileData> NavMeshDb::getTileData(
const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input) std::string_view worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input)
{ {
TileData result; TileData result;
auto row = std::tie(result.mTileId, result.mVersion, result.mData); auto row = std::tie(result.mTileId, result.mVersion, result.mData);
const std::vector<std::byte> compressedInput = Misc::compress(input); const std::vector<std::byte> compressedInput = Misc::compress(input);
if (&row == request(*mDb, mGetTileData, &row, 1, toLowerCaseString(worldspace), tilePosition, compressedInput)) if (&row == request(*mDb, mGetTileData, &row, 1, worldspace, tilePosition, compressedInput))
return {}; return {};
result.mData = Misc::decompress(result.mData); result.mData = Misc::decompress(result.mData);
return result; return result;
} }
int NavMeshDb::insertTile(TileId tileId, const ESM::RefId& worldspace, const TilePosition& tilePosition, int NavMeshDb::insertTile(TileId tileId, std::string_view worldspace, const TilePosition& tilePosition,
TileVersion version, const std::vector<std::byte>& input, const std::vector<std::byte>& data) TileVersion version, const std::vector<std::byte>& input, const std::vector<std::byte>& data)
{ {
const std::vector<std::byte> compressedInput = Misc::compress(input); const std::vector<std::byte> compressedInput = Misc::compress(input);
const std::vector<std::byte> compressedData = Misc::compress(data); const std::vector<std::byte> compressedData = Misc::compress(data);
return execute(*mDb, mInsertTile, tileId, toLowerCaseString(worldspace), tilePosition, version, compressedInput, return execute(*mDb, mInsertTile, tileId, worldspace, tilePosition, version, compressedInput, compressedData);
compressedData);
} }
int NavMeshDb::updateTile(TileId tileId, TileVersion version, const std::vector<std::byte>& data) int NavMeshDb::updateTile(TileId tileId, TileVersion version, const std::vector<std::byte>& data)
@ -244,20 +236,20 @@ namespace DetourNavigator
return execute(*mDb, mUpdateTile, tileId, version, compressedData); return execute(*mDb, mUpdateTile, tileId, version, compressedData);
} }
int NavMeshDb::deleteTilesAt(const ESM::RefId& worldspace, const TilePosition& tilePosition) int NavMeshDb::deleteTilesAt(std::string_view worldspace, const TilePosition& tilePosition)
{ {
return execute(*mDb, mDeleteTilesAt, toLowerCaseString(worldspace), tilePosition); return execute(*mDb, mDeleteTilesAt, worldspace, tilePosition);
} }
int NavMeshDb::deleteTilesAtExcept( int NavMeshDb::deleteTilesAtExcept(
const ESM::RefId& worldspace, const TilePosition& tilePosition, TileId excludeTileId) std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId)
{ {
return execute(*mDb, mDeleteTilesAtExcept, toLowerCaseString(worldspace), tilePosition, excludeTileId); return execute(*mDb, mDeleteTilesAtExcept, worldspace, tilePosition, excludeTileId);
} }
int NavMeshDb::deleteTilesOutsideRange(const ESM::RefId& worldspace, const TilesPositionsRange& range) int NavMeshDb::deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range)
{ {
return execute(*mDb, mDeleteTilesOutsideRange, toLowerCaseString(worldspace), range); return execute(*mDb, mDeleteTilesOutsideRange, worldspace, range);
} }
ShapeId NavMeshDb::getMaxShapeId() ShapeId NavMeshDb::getMaxShapeId()

View file

@ -25,11 +25,6 @@
struct sqlite3; struct sqlite3;
struct sqlite3_stmt; struct sqlite3_stmt;
namespace ESM
{
struct RefId;
}
namespace DetourNavigator namespace DetourNavigator
{ {
using TileId = Misc::StrongTypedef<std::int64_t, struct TiledIdTag>; using TileId = Misc::StrongTypedef<std::int64_t, struct TiledIdTag>;
@ -153,21 +148,21 @@ namespace DetourNavigator
TileId getMaxTileId(); TileId getMaxTileId();
std::optional<Tile> findTile( std::optional<Tile> findTile(
const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input); std::string_view worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input);
std::optional<TileData> getTileData( std::optional<TileData> getTileData(
const ESM::RefId& worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input); std::string_view worldspace, const TilePosition& tilePosition, const std::vector<std::byte>& input);
int insertTile(TileId tileId, const ESM::RefId& worldspace, const TilePosition& tilePosition, int insertTile(TileId tileId, std::string_view worldspace, const TilePosition& tilePosition,
TileVersion version, const std::vector<std::byte>& input, const std::vector<std::byte>& data); TileVersion version, const std::vector<std::byte>& input, const std::vector<std::byte>& data);
int updateTile(TileId tileId, TileVersion version, const std::vector<std::byte>& data); int updateTile(TileId tileId, TileVersion version, const std::vector<std::byte>& data);
int deleteTilesAt(const ESM::RefId& worldspace, const TilePosition& tilePosition); int deleteTilesAt(std::string_view worldspace, const TilePosition& tilePosition);
int deleteTilesAtExcept(const ESM::RefId& worldspace, const TilePosition& tilePosition, TileId excludeTileId); int deleteTilesAtExcept(std::string_view worldspace, const TilePosition& tilePosition, TileId excludeTileId);
int deleteTilesOutsideRange(const ESM::RefId& worldspace, const TilesPositionsRange& range); int deleteTilesOutsideRange(std::string_view worldspace, const TilesPositionsRange& range);
ShapeId getMaxShapeId(); ShapeId getMaxShapeId();

View file

@ -10,7 +10,6 @@
#include <components/bullethelpers/heightfield.hpp> #include <components/bullethelpers/heightfield.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
#include <osg/io_utils> #include <osg/io_utils>
@ -64,7 +63,7 @@ namespace DetourNavigator
{ {
} }
void NavMeshManager::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) void NavMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard)
{ {
if (worldspace == mWorldspace) if (worldspace == mWorldspace)
return; return;

View file

@ -8,8 +8,6 @@
#include "recastmeshtiles.hpp" #include "recastmeshtiles.hpp"
#include "waitconditiontype.hpp" #include "waitconditiontype.hpp"
#include <components/esm/refid.hpp>
#include <osg/Vec3f> #include <osg/Vec3f>
#include <map> #include <map>
@ -41,7 +39,7 @@ namespace DetourNavigator
explicit NavMeshManager(const Settings& settings, std::unique_ptr<NavMeshDb>&& db); explicit NavMeshManager(const Settings& settings, std::unique_ptr<NavMeshDb>&& db);
void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard); void setWorldspace(std::string_view worldspace, const UpdateGuard* guard);
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard); void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard);
@ -84,7 +82,7 @@ namespace DetourNavigator
private: private:
const Settings& mSettings; const Settings& mSettings;
ESM::RefId mWorldspace; std::string mWorldspace;
TileCachedRecastMeshManager mRecastMeshManager; TileCachedRecastMeshManager mRecastMeshManager;
OffMeshConnectionsManager mOffMeshConnectionsManager; OffMeshConnectionsManager mOffMeshConnectionsManager;
AsyncNavMeshUpdater mAsyncNavMeshUpdater; AsyncNavMeshUpdater mAsyncNavMeshUpdater;

View file

@ -20,7 +20,7 @@ namespace DetourNavigator
{ {
} }
std::shared_ptr<RecastMesh> getMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition) const std::shared_ptr<RecastMesh> getMesh(std::string_view worldspace, const TilePosition& tilePosition) const
{ {
return mImpl.get().getNewMesh(worldspace, tilePosition); return mImpl.get().getNewMesh(worldspace, tilePosition);
} }

View file

@ -5,7 +5,6 @@
#include "settingsutils.hpp" #include "settingsutils.hpp"
#include <components/bullethelpers/aabb.hpp> #include <components/bullethelpers/aabb.hpp>
#include <components/esm/refid.hpp>
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
#include <boost/geometry/geometry.hpp> #include <boost/geometry/geometry.hpp>
@ -114,7 +113,7 @@ namespace DetourNavigator
return getIntersection(mRange, objectsRange); return getIntersection(mRange, objectsRange);
} }
void TileCachedRecastMeshManager::setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard) void TileCachedRecastMeshManager::setWorldspace(std::string_view worldspace, const UpdateGuard* guard)
{ {
const MaybeLockGuard lock(mMutex, guard); const MaybeLockGuard lock(mMutex, guard);
if (mWorldspace == worldspace) if (mWorldspace == worldspace)
@ -323,7 +322,7 @@ namespace DetourNavigator
} }
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getMesh( std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getMesh(
const ESM::RefId& worldspace, const TilePosition& tilePosition) std::string_view worldspace, const TilePosition& tilePosition)
{ {
{ {
const std::lock_guard lock(mMutex); const std::lock_guard lock(mMutex);
@ -347,7 +346,7 @@ namespace DetourNavigator
} }
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getCachedMesh( std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getCachedMesh(
const ESM::RefId& worldspace, const TilePosition& tilePosition) const std::string_view worldspace, const TilePosition& tilePosition) const
{ {
const std::lock_guard lock(mMutex); const std::lock_guard lock(mMutex);
if (mWorldspace != worldspace) if (mWorldspace != worldspace)
@ -359,7 +358,7 @@ namespace DetourNavigator
} }
std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getNewMesh( std::shared_ptr<RecastMesh> TileCachedRecastMeshManager::getNewMesh(
const ESM::RefId& worldspace, const TilePosition& tilePosition) const std::string_view worldspace, const TilePosition& tilePosition) const
{ {
{ {
const std::lock_guard lock(mMutex); const std::lock_guard lock(mMutex);

View file

@ -12,8 +12,6 @@
#include "tileposition.hpp" #include "tileposition.hpp"
#include "version.hpp" #include "version.hpp"
#include <components/esm/refid.hpp>
#include <boost/geometry/geometries/box.hpp> #include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/point.hpp> #include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/index/rtree.hpp> #include <boost/geometry/index/rtree.hpp>
@ -48,7 +46,7 @@ namespace DetourNavigator
TilesPositionsRange getLimitedObjectsRange() const; TilesPositionsRange getLimitedObjectsRange() const;
void setWorldspace(const ESM::RefId& worldspace, const UpdateGuard* guard); void setWorldspace(std::string_view worldspace, const UpdateGuard* guard);
bool addObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType, bool addObject(ObjectId id, const CollisionShape& shape, const btTransform& transform, AreaType areaType,
const UpdateGuard* guard); const UpdateGuard* guard);
@ -66,11 +64,11 @@ namespace DetourNavigator
void removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard); void removeHeightfield(const osg::Vec2i& cellPosition, const UpdateGuard* guard);
std::shared_ptr<RecastMesh> getMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition); std::shared_ptr<RecastMesh> getMesh(std::string_view worldspace, const TilePosition& tilePosition);
std::shared_ptr<RecastMesh> getCachedMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition) const; std::shared_ptr<RecastMesh> getCachedMesh(std::string_view worldspace, const TilePosition& tilePosition) const;
std::shared_ptr<RecastMesh> getNewMesh(const ESM::RefId& worldspace, const TilePosition& tilePosition) const; std::shared_ptr<RecastMesh> getNewMesh(std::string_view worldspace, const TilePosition& tilePosition) const;
std::size_t getRevision() const { return mRevision; } std::size_t getRevision() const { return mRevision; }
@ -127,7 +125,7 @@ namespace DetourNavigator
const RecastSettings& mSettings; const RecastSettings& mSettings;
TilesPositionsRange mRange; TilesPositionsRange mRange;
ESM::RefId mWorldspace; std::string mWorldspace;
std::unordered_map<ObjectId, std::unique_ptr<ObjectData>> mObjects; std::unordered_map<ObjectId, std::unique_ptr<ObjectData>> mObjects;
boost::geometry::index::rtree<ObjectIndexValue, boost::geometry::index::quadratic<16>> mObjectIndex; boost::geometry::index::rtree<ObjectIndexValue, boost::geometry::index::quadratic<16>> mObjectIndex;
std::map<osg::Vec2i, WaterData> mWater; std::map<osg::Vec2i, WaterData> mWater;