openmw/components/detournavigator/recastcontext.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.7 KiB
C++
Raw Permalink Normal View History

#include "recastcontext.hpp"
#include "debug.hpp"
#include <components/debug/debuglog.hpp>
#include <sstream>
namespace DetourNavigator
{
namespace
{
Debug::Level getLogLevel(rcLogCategory category)
{
switch (category)
{
case RC_LOG_PROGRESS:
return Debug::Verbose;
case RC_LOG_WARNING:
return Debug::Warning;
case RC_LOG_ERROR:
return Debug::Error;
}
return Debug::Debug;
}
2025-03-22 02:49:48 +01:00
std::string formatPrefix(ESM::RefId worldspace, const TilePosition& tilePosition,
const AgentBounds& agentBounds, const Version& version)
{
std::ostringstream stream;
2023-06-10 13:23:47 +02:00
stream << "Worldspace: " << worldspace << "; tile position: " << tilePosition.x() << ", "
2025-03-22 02:49:48 +01:00
<< tilePosition.y() << "; agent bounds: " << agentBounds << "; version: " << version << "; ";
return stream.str();
}
}
RecastContext::RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition,
2025-03-22 02:49:48 +01:00
const AgentBounds& agentBounds, const Version& version, Debug::Level maxLogLevel)
: mMaxLogLevel(maxLogLevel)
2025-03-22 02:49:48 +01:00
, mPrefix(formatPrefix(worldspace, tilePosition, agentBounds, version))
{
}
void RecastContext::doLog(const rcLogCategory category, const char* msg, const int len)
{
if (msg == nullptr || len <= 0)
return;
const Debug::Level level = getLogLevel(category);
if (level > mMaxLogLevel)
return;
Log(level) << mPrefix << std::string_view(msg, static_cast<std::size_t>(len));
}
}