From 04d439485b44336e5e6eb81516b035ee61af186d Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 13 May 2023 14:55:20 +0200 Subject: [PATCH] Log more info about navmesh shapes and jobs --- apps/bulletobjecttool/main.cpp | 18 ++--------- apps/navmeshtool/worldspacedata.cpp | 1 + .../detournavigator/asyncnavmeshupdater.cpp | 9 +++--- .../detournavigator/asyncnavmeshupdater.cpp | 30 ++++++++++++++++--- .../detournavigator/dbrefgeometryobject.hpp | 5 ++-- components/detournavigator/navmeshdbutils.cpp | 6 ++-- components/misc/strings/conversion.hpp | 15 ++++++++++ 7 files changed, 56 insertions(+), 28 deletions(-) diff --git a/apps/bulletobjecttool/main.cpp b/apps/bulletobjecttool/main.cpp index 28c5df452e..ee86203bd9 100644 --- a/apps/bulletobjecttool/main.cpp +++ b/apps/bulletobjecttool/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -112,21 +113,6 @@ namespace } }; - std::string toHex(std::string_view value) - { - std::string buffer(value.size() * 2, '0'); - char* out = buffer.data(); - for (const char v : value) - { - const std::ptrdiff_t space = static_cast(static_cast(v) <= 0xf); - const auto [ptr, ec] = std::to_chars(out + space, out + space + 2, static_cast(v), 16); - if (ec != std::errc()) - throw std::system_error(std::make_error_code(ec)); - out += 2; - } - return buffer; - } - int runBulletObjectTool(int argc, char* argv[]) { Platform::init(); @@ -204,7 +190,7 @@ namespace Log(Debug::Verbose) << "Found bullet object in " << (cell.isExterior() ? "exterior" : "interior") << " cell \"" << cell.getDescription() << "\":" << " fileName=\"" << object.mShape->mFileName << '"' - << " fileHash=" << toHex(object.mShape->mFileHash) + << " fileHash=" << Misc::StringUtils::toHex(object.mShape->mFileHash) << " collisionShape=" << std::boolalpha << (object.mShape->mCollisionShape == nullptr) << " avoidCollisionShape=" << std::boolalpha diff --git a/apps/navmeshtool/worldspacedata.cpp b/apps/navmeshtool/worldspacedata.cpp index e6f1dca6b0..19a85d60c6 100644 --- a/apps/navmeshtool/worldspacedata.cpp +++ b/apps/navmeshtool/worldspacedata.cpp @@ -37,6 +37,7 @@ #include #include #include + namespace NavMeshTool { namespace diff --git a/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp index f51c118a8a..9d8a5d85de 100644 --- a/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp +++ b/apps/openmw_test_suite/detournavigator/asyncnavmeshupdater.cpp @@ -197,7 +197,7 @@ namespace ASSERT_NE(recastMesh, nullptr); const auto objects = makeDbRefGeometryObjects( recastMesh->getMeshSources(), [&](const MeshSource& v) { return resolveMeshSource(*dbPtr, v); }); - EXPECT_FALSE(objects.has_value()); + EXPECT_TRUE(std::holds_alternative(objects)); } TEST_F(DetourNavigatorAsyncNavMeshUpdaterTest, post_should_read_from_db_on_cache_miss) @@ -285,13 +285,14 @@ namespace const TilePosition tilePosition(x, y); const auto recastMesh = mRecastMeshManager.getMesh(mWorldspace, tilePosition); ASSERT_NE(recastMesh, nullptr); - const std::optional> objects = makeDbRefGeometryObjects( + const auto objects = makeDbRefGeometryObjects( recastMesh->getMeshSources(), [&](const MeshSource& v) { return resolveMeshSource(*dbPtr, v); }); - if (!objects.has_value()) + if (std::holds_alternative(objects)) continue; EXPECT_EQ(dbPtr ->findTile(mWorldspace, tilePosition, - serialize(mSettings.mRecast, mAgentBounds, *recastMesh, *objects)) + serialize(mSettings.mRecast, mAgentBounds, *recastMesh, + std::get>(objects))) .has_value(), present.find(tilePosition) != present.end()) << tilePosition.x() << " " << tilePosition.y() diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 85a953b261..0ba7906b6a 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -199,7 +200,8 @@ namespace DetourNavigator changeType, getManhattanDistance(changedTile, playerTile), processTime); Log(Debug::Debug) << "Post job " << it->mId << " for agent=(" << it->mAgentBounds << ")" - << " changedTile=(" << it->mChangedTile << ")"; + << " changedTile=(" << it->mChangedTile << ") " + << " changeType=" << it->mChangeType; if (playerTileChanged) mWaiting.push_back(it); @@ -834,11 +836,31 @@ namespace DetourNavigator } else { - const auto objects = makeDbRefGeometryObjects(job->mRecastMesh->getMeshSources(), + struct HandleResult + { + const RecastSettings& mRecastSettings; + Job& mJob; + + bool operator()(const std::vector& objects) const + { + mJob.mInput = serialize(mRecastSettings, mJob.mAgentBounds, *mJob.mRecastMesh, objects); + return true; + } + + bool operator()(const MeshSource& meshSource) const + { + Log(Debug::Debug) << "No object for mesh source (fileName=\"" << meshSource.mShape->mFileName + << "\", areaType=" << meshSource.mAreaType + << ", fileHash=" << Misc::StringUtils::toHex(meshSource.mShape->mFileHash) + << ") for job " << mJob.mId; + return false; + } + }; + + const auto result = makeDbRefGeometryObjects(job->mRecastMesh->getMeshSources(), [&](const MeshSource& v) { return resolveMeshSource(*mDb, v); }); - if (!objects.has_value()) + if (!std::visit(HandleResult{ mRecastSettings, *job }, result)) return; - job->mInput = serialize(mRecastSettings, job->mAgentBounds, *job->mRecastMesh, *objects); } } diff --git a/components/detournavigator/dbrefgeometryobject.hpp b/components/detournavigator/dbrefgeometryobject.hpp index 0eb217a9ff..dbbafe7e18 100644 --- a/components/detournavigator/dbrefgeometryobject.hpp +++ b/components/detournavigator/dbrefgeometryobject.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace DetourNavigator @@ -32,7 +33,7 @@ namespace DetourNavigator inline auto makeDbRefGeometryObjects( const std::vector& meshSources, ResolveMeshSource&& resolveMeshSource) -> std::conditional_t>, - std::optional>, std::vector> + std::variant, MeshSource>, std::vector> { std::vector result; result.reserve(meshSources.size()); @@ -42,7 +43,7 @@ namespace DetourNavigator if constexpr (Misc::isOptional>) { if (!shapeId.has_value()) - return std::nullopt; + return meshSource; result.push_back(DbRefGeometryObject{ *shapeId, meshSource.mObjectTransform }); } else diff --git a/components/detournavigator/navmeshdbutils.cpp b/components/detournavigator/navmeshdbutils.cpp index 001259b6ff..6453ac7118 100644 --- a/components/detournavigator/navmeshdbutils.cpp +++ b/components/detournavigator/navmeshdbutils.cpp @@ -2,7 +2,8 @@ #include "navmeshdb.hpp" #include "recastmesh.hpp" -#include +#include "components/debug/debuglog.hpp" +#include "components/misc/strings/conversion.hpp" #include #include @@ -27,7 +28,8 @@ namespace DetourNavigator return *existingShapeId; const ShapeId newShapeId = nextShapeId; db.insertShape(newShapeId, name, type, hashData); - Log(Debug::Verbose) << "Added " << name << " " << type << " shape to navmeshdb with id " << newShapeId; + Log(Debug::Verbose) << "Added " << name << " " << Misc::StringUtils::toHex(hash) << " " << type + << " shape to navmeshdb with id " << newShapeId; ++nextShapeId; return newShapeId; } diff --git a/components/misc/strings/conversion.hpp b/components/misc/strings/conversion.hpp index bac4ab49b7..ae5535f39b 100644 --- a/components/misc/strings/conversion.hpp +++ b/components/misc/strings/conversion.hpp @@ -129,6 +129,21 @@ namespace Misc::StringUtils return std::nullopt; } #endif + + inline std::string toHex(std::string_view value) + { + std::string buffer(value.size() * 2, '0'); + char* out = buffer.data(); + for (const char v : value) + { + const std::ptrdiff_t space = static_cast(static_cast(v) <= 0xf); + const auto [ptr, ec] = std::to_chars(out + space, out + space + 2, static_cast(v), 16); + if (ec != std::errc()) + throw std::system_error(std::make_error_code(ec)); + out += 2; + } + return buffer; + } } #endif // COMPONENTS_MISC_STRINGS_CONVERSION_H