1
0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-12 16:34:52 +00:00

Merge branch 'recast_log_level' into 'master'

Support max log level for Recast via env variable

See merge request 
This commit is contained in:
Evil Eye 2025-03-23 14:50:11 +00:00
commit 57fb334a6e
13 changed files with 68 additions and 35 deletions

@ -225,7 +225,8 @@ namespace NavMeshTool
Resource::SceneManager sceneManager(&vfs, &imageManager, &nifFileManager, &bgsmFileManager, expiryDelay);
Resource::BulletShapeManager bulletShapeManager(&vfs, &sceneManager, &nifFileManager, expiryDelay);
DetourNavigator::RecastGlobalAllocator::init();
DetourNavigator::Settings navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
DetourNavigator::Settings navigatorSettings
= DetourNavigator::makeSettingsFromSettingsManager(Debug::getRecastMaxLogLevel());
navigatorSettings.mRecast.mSwimHeightScale
= EsmLoader::getGameSetting(esmData.mGameSettings, "fSwimHeightScale").getFloat();

@ -847,7 +847,7 @@ void OMW::Engine::prepareEngine()
}
listener->loadingOff();
mWorld->init(mViewer, std::move(rootNode), mWorkQueue.get(), *mUnrefQueue);
mWorld->init(mMaxRecastLogLevel, mViewer, std::move(rootNode), mWorkQueue.get(), *mUnrefQueue);
mEnvironment.setWorldScene(mWorld->getWorldScene());
mWorld->setupPlayer();
mWorld->setRandomSeed(mRandomSeed);

@ -4,6 +4,7 @@
#include <filesystem>
#include <components/compiler/extensions.hpp>
#include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <components/files/collections.hpp>
#include <components/settings/settings.hpp>
@ -172,6 +173,7 @@ namespace OMW
bool mGrab;
unsigned int mRandomSeed;
Debug::Level mMaxRecastLogLevel = Debug::Error;
Compiler::Extensions mExtensions;
std::unique_ptr<Compiler::Context> mScriptContext;
@ -180,6 +182,9 @@ namespace OMW
Translation::Storage mTranslationDataStorage;
bool mNewGame;
Files::ConfigurationManager& mCfgMgr;
int mGlMaxTextureImageUnits;
// not implemented
Engine(const Engine&);
Engine& operator=(const Engine&);
@ -256,9 +261,7 @@ namespace OMW
void setRandomSeed(unsigned int seed);
private:
Files::ConfigurationManager& mCfgMgr;
int mGlMaxTextureImageUnits;
void setRecastMaxLogLevel(Debug::Level value) { mMaxRecastLogLevel = value; }
};
}

@ -220,6 +220,8 @@ int runApplication(int argc, char* argv[])
Files::ConfigurationManager cfgMgr;
std::unique_ptr<OMW::Engine> engine = std::make_unique<OMW::Engine>(cfgMgr);
engine->setRecastMaxLogLevel(Debug::getRecastMaxLogLevel());
if (parseOptions(argc, argv, *engine, cfgMgr))
{
if (!Misc::checkRequiredOSGPluginsArePresent())

@ -290,14 +290,14 @@ namespace MWWorld
mSwimHeightScale = mStore.get<ESM::GameSetting>().find("fSwimHeightScale")->mValue.getFloat();
}
void World::init(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, SceneUtil::WorkQueue* workQueue,
SceneUtil::UnrefQueue& unrefQueue)
void World::init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode,
SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue)
{
mPhysics = std::make_unique<MWPhysics::PhysicsSystem>(mResourceSystem, rootNode);
if (Settings::navigator().mEnable)
{
auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(maxRecastLogLevel);
navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale;
mNavigator = DetourNavigator::makeNavigator(navigatorSettings, mUserDataPath);
}

@ -4,6 +4,7 @@
#include <osg/Timer>
#include <osg/ref_ptr>
#include <components/debug/debuglog.hpp>
#include <components/esm3/readerscache.hpp>
#include <components/misc/rng.hpp>
#include <components/settings/settings.hpp>
@ -201,8 +202,8 @@ namespace MWWorld
Loading::Listener* listener);
// Must be called after `loadData`.
void init(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, SceneUtil::WorkQueue* workQueue,
SceneUtil::UnrefQueue& unrefQueue);
void init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode,
SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue);
virtual ~World();

@ -324,6 +324,22 @@ namespace Debug
First mFirst;
Second mSecond;
};
Level toLevel(std::string_view value)
{
if (value == "ERROR")
return Error;
if (value == "WARNING")
return Warning;
if (value == "INFO")
return Info;
if (value == "VERBOSE")
return Verbose;
if (value == "DEBUG")
return Debug;
return Verbose;
}
}
#endif
@ -359,23 +375,19 @@ namespace Debug
Level getDebugLevel()
{
if (const char* env = getenv("OPENMW_DEBUG_LEVEL"))
{
const std::string_view value(env);
if (value == "ERROR")
return Error;
if (value == "WARNING")
return Warning;
if (value == "INFO")
return Info;
if (value == "VERBOSE")
return Verbose;
if (value == "DEBUG")
return Debug;
}
return toLevel(env);
return Verbose;
}
Level getRecastMaxLogLevel()
{
if (const char* env = getenv("OPENMW_RECAST_MAX_LOG_LEVEL"))
return toLevel(env);
return Error;
}
void setupLogging(const std::filesystem::path& logDir, std::string_view appName)
{
Log::sMinDebugLevel = getDebugLevel();

@ -36,6 +36,8 @@ namespace Debug
Level getDebugLevel();
Level getRecastMaxLogLevel();
// Redirect cout and cerr to the log file
void setupLogging(const std::filesystem::path& logDir, std::string_view appName);

@ -523,7 +523,7 @@ namespace DetourNavigator
std::unique_ptr<PreparedNavMeshData> prepareNavMeshTileData(const RecastMesh& recastMesh, ESM::RefId worldspace,
const TilePosition& tilePosition, const AgentBounds& agentBounds, const RecastSettings& settings)
{
RecastContext context(worldspace, tilePosition, agentBounds);
RecastContext context(worldspace, tilePosition, agentBounds, settings.mMaxLogLevel);
const auto [minZ, maxZ] = getBoundsByZ(recastMesh, agentBounds.mHalfExtents.z(), settings);

@ -1,7 +1,7 @@
#include "recastcontext.hpp"
#include "debug.hpp"
#include "components/debug/debuglog.hpp"
#include <components/debug/debuglog.hpp>
#include <sstream>
@ -33,15 +33,20 @@ namespace DetourNavigator
}
}
RecastContext::RecastContext(
ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds)
: mPrefix(formatPrefix(worldspace, tilePosition, agentBounds))
RecastContext::RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition,
const AgentBounds& agentBounds, Debug::Level maxLogLevel)
: mMaxLogLevel(maxLogLevel)
, mPrefix(formatPrefix(worldspace, tilePosition, agentBounds))
{
}
void RecastContext::doLog(const rcLogCategory category, const char* msg, const int len)
{
if (len > 0)
Log(getLogLevel(category)) << mPrefix << std::string_view(msg, static_cast<std::size_t>(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));
}
}

@ -3,6 +3,7 @@
#include "tileposition.hpp"
#include <components/debug/debuglog.hpp>
#include <components/esm/refid.hpp>
#include <string>
@ -16,11 +17,13 @@ namespace DetourNavigator
class RecastContext final : public rcContext
{
public:
explicit RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds);
explicit RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds,
Debug::Level maxLogLevel);
const std::string& getPrefix() const { return mPrefix; }
private:
Debug::Level mMaxLogLevel;
std::string mPrefix;
void doLog(rcLogCategory category, const char* msg, int len) override;

@ -44,7 +44,7 @@ namespace DetourNavigator
};
}
RecastSettings makeRecastSettingsFromSettingsManager()
RecastSettings makeRecastSettingsFromSettingsManager(Debug::Level maxLogLevel)
{
RecastSettings result;
@ -63,6 +63,7 @@ namespace DetourNavigator
result.mRegionMergeArea = ::Settings::navigator().mRegionMergeArea;
result.mRegionMinArea = ::Settings::navigator().mRegionMinArea;
result.mTileSize = ::Settings::navigator().mTileSize;
result.mMaxLogLevel = maxLogLevel;
return result;
}
@ -80,11 +81,11 @@ namespace DetourNavigator
}
}
Settings makeSettingsFromSettingsManager()
Settings makeSettingsFromSettingsManager(Debug::Level maxLogLevel)
{
Settings result;
result.mRecast = makeRecastSettingsFromSettingsManager();
result.mRecast = makeRecastSettingsFromSettingsManager(maxLogLevel);
result.mDetour = makeDetourSettingsFromSettingsManager();
const NavMeshLimits limits = getNavMeshTileLimits(result.mDetour);

@ -1,6 +1,8 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
#include <components/debug/debuglog.hpp>
#include <chrono>
#include <string>
@ -23,6 +25,7 @@ namespace DetourNavigator
int mRegionMergeArea = 0;
int mRegionMinArea = 0;
int mTileSize = 0;
Debug::Level mMaxLogLevel = Debug::Error;
};
struct DetourSettings
@ -55,7 +58,7 @@ namespace DetourNavigator
inline constexpr std::int64_t navMeshFormatVersion = 2;
Settings makeSettingsFromSettingsManager();
Settings makeSettingsFromSettingsManager(Debug::Level maxLogLevel);
}
#endif