mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-06 00:40:04 +00:00
Log more info about navmesh shapes and jobs
This commit is contained in:
parent
3fe621d55f
commit
04d439485b
@ -10,6 +10,7 @@
|
||||
#include <components/files/collections.hpp>
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/files/multidircollection.hpp>
|
||||
#include <components/misc/strings/conversion.hpp>
|
||||
#include <components/platform/platform.hpp>
|
||||
#include <components/resource/bulletshape.hpp>
|
||||
#include <components/resource/bulletshapemanager.hpp>
|
||||
@ -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<std::ptrdiff_t>(static_cast<std::uint8_t>(v) <= 0xf);
|
||||
const auto [ptr, ec] = std::to_chars(out + space, out + space + 2, static_cast<std::uint8_t>(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
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace NavMeshTool
|
||||
{
|
||||
namespace
|
||||
|
@ -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<MeshSource>(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<std::vector<DbRefGeometryObject>> objects = makeDbRefGeometryObjects(
|
||||
const auto objects = makeDbRefGeometryObjects(
|
||||
recastMesh->getMeshSources(), [&](const MeshSource& v) { return resolveMeshSource(*dbPtr, v); });
|
||||
if (!objects.has_value())
|
||||
if (std::holds_alternative<MeshSource>(objects))
|
||||
continue;
|
||||
EXPECT_EQ(dbPtr
|
||||
->findTile(mWorldspace, tilePosition,
|
||||
serialize(mSettings.mRecast, mAgentBounds, *recastMesh, *objects))
|
||||
serialize(mSettings.mRecast, mAgentBounds, *recastMesh,
|
||||
std::get<std::vector<DbRefGeometryObject>>(objects)))
|
||||
.has_value(),
|
||||
present.find(tilePosition) != present.end())
|
||||
<< tilePosition.x() << " " << tilePosition.y()
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/loadinglistener/loadinglistener.hpp>
|
||||
#include <components/misc/strings/conversion.hpp>
|
||||
#include <components/misc/thread.hpp>
|
||||
|
||||
#include <DetourNavMesh.h>
|
||||
@ -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<DbRefGeometryObject>& 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace DetourNavigator
|
||||
@ -32,7 +33,7 @@ namespace DetourNavigator
|
||||
inline auto makeDbRefGeometryObjects(
|
||||
const std::vector<MeshSource>& meshSources, ResolveMeshSource&& resolveMeshSource)
|
||||
-> std::conditional_t<Misc::isOptional<std::decay_t<decltype(resolveMeshSource(meshSources.front()))>>,
|
||||
std::optional<std::vector<DbRefGeometryObject>>, std::vector<DbRefGeometryObject>>
|
||||
std::variant<std::vector<DbRefGeometryObject>, MeshSource>, std::vector<DbRefGeometryObject>>
|
||||
{
|
||||
std::vector<DbRefGeometryObject> result;
|
||||
result.reserve(meshSources.size());
|
||||
@ -42,7 +43,7 @@ namespace DetourNavigator
|
||||
if constexpr (Misc::isOptional<std::decay_t<decltype(shapeId)>>)
|
||||
{
|
||||
if (!shapeId.has_value())
|
||||
return std::nullopt;
|
||||
return meshSource;
|
||||
result.push_back(DbRefGeometryObject{ *shapeId, meshSource.mObjectTransform });
|
||||
}
|
||||
else
|
||||
|
@ -2,7 +2,8 @@
|
||||
#include "navmeshdb.hpp"
|
||||
#include "recastmesh.hpp"
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include "components/debug/debuglog.hpp"
|
||||
#include "components/misc/strings/conversion.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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<std::ptrdiff_t>(static_cast<std::uint8_t>(v) <= 0xf);
|
||||
const auto [ptr, ec] = std::to_chars(out + space, out + space + 2, static_cast<std::uint8_t>(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
|
||||
|
Loading…
x
Reference in New Issue
Block a user