diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index 27f84104ac..a05babfbe8 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -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(); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2736f339e4..bfdf58ce06 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -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); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 39056af560..69fdd3869c 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -172,6 +173,7 @@ namespace OMW bool mGrab; unsigned int mRandomSeed; + Debug::Level mMaxRecastLogLevel = Debug::Error; Compiler::Extensions mExtensions; std::unique_ptr 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; } }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 5b89bca960..7ed3292b55 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -220,6 +220,8 @@ int runApplication(int argc, char* argv[]) Files::ConfigurationManager cfgMgr; std::unique_ptr engine = std::make_unique(cfgMgr); + engine->setRecastMaxLogLevel(Debug::getRecastMaxLogLevel()); + if (parseOptions(argc, argv, *engine, cfgMgr)) { if (!Misc::checkRequiredOSGPluginsArePresent()) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7b2f178343..57d794c535 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -290,14 +290,14 @@ namespace MWWorld mSwimHeightScale = mStore.get().find("fSwimHeightScale")->mValue.getFloat(); } - void World::init(osgViewer::Viewer* viewer, osg::ref_ptr rootNode, SceneUtil::WorkQueue* workQueue, - SceneUtil::UnrefQueue& unrefQueue) + void World::init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr rootNode, + SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue) { mPhysics = std::make_unique(mResourceSystem, rootNode); if (Settings::navigator().mEnable) { - auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(); + auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(maxRecastLogLevel); navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale; mNavigator = DetourNavigator::makeNavigator(navigatorSettings, mUserDataPath); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 6f06812e20..983682a98f 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -201,8 +202,8 @@ namespace MWWorld Loading::Listener* listener); // Must be called after `loadData`. - void init(osgViewer::Viewer* viewer, osg::ref_ptr rootNode, SceneUtil::WorkQueue* workQueue, - SceneUtil::UnrefQueue& unrefQueue); + void init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr rootNode, + SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue); virtual ~World(); diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index 32aec8f0fc..6006e1abe5 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -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(); diff --git a/components/debug/debugging.hpp b/components/debug/debugging.hpp index 68cdec93a2..2f9d7aa2d7 100644 --- a/components/debug/debugging.hpp +++ b/components/debug/debugging.hpp @@ -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); diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index f037da69f8..11751e631c 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -523,7 +523,7 @@ namespace DetourNavigator std::unique_ptr 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); diff --git a/components/detournavigator/recastcontext.cpp b/components/detournavigator/recastcontext.cpp index 225f251f4d..89bb268b16 100644 --- a/components/detournavigator/recastcontext.cpp +++ b/components/detournavigator/recastcontext.cpp @@ -1,7 +1,7 @@ #include "recastcontext.hpp" #include "debug.hpp" -#include "components/debug/debuglog.hpp" +#include #include @@ -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(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(len)); } } diff --git a/components/detournavigator/recastcontext.hpp b/components/detournavigator/recastcontext.hpp index 8e75f50b34..7c9d50951b 100644 --- a/components/detournavigator/recastcontext.hpp +++ b/components/detournavigator/recastcontext.hpp @@ -3,6 +3,7 @@ #include "tileposition.hpp" +#include #include #include @@ -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; diff --git a/components/detournavigator/settings.cpp b/components/detournavigator/settings.cpp index 5e555050f7..d71b3d12bc 100644 --- a/components/detournavigator/settings.cpp +++ b/components/detournavigator/settings.cpp @@ -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); diff --git a/components/detournavigator/settings.hpp b/components/detournavigator/settings.hpp index 1d1f6f5847..ecd9cf073b 100644 --- a/components/detournavigator/settings.hpp +++ b/components/detournavigator/settings.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H +#include + #include #include @@ -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