Skip to content

Commit 57fb334

Browse files
committed
Merge branch 'recast_log_level' into 'master'
Support max log level for Recast via env variable See merge request OpenMW/openmw!4596
2 parents 88c673d + 5125866 commit 57fb334

File tree

13 files changed

+68
-35
lines changed

13 files changed

+68
-35
lines changed

apps/navmeshtool/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ namespace NavMeshTool
225225
Resource::SceneManager sceneManager(&vfs, &imageManager, &nifFileManager, &bgsmFileManager, expiryDelay);
226226
Resource::BulletShapeManager bulletShapeManager(&vfs, &sceneManager, &nifFileManager, expiryDelay);
227227
DetourNavigator::RecastGlobalAllocator::init();
228-
DetourNavigator::Settings navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
228+
DetourNavigator::Settings navigatorSettings
229+
= DetourNavigator::makeSettingsFromSettingsManager(Debug::getRecastMaxLogLevel());
229230
navigatorSettings.mRecast.mSwimHeightScale
230231
= EsmLoader::getGameSetting(esmData.mGameSettings, "fSwimHeightScale").getFloat();
231232

apps/openmw/engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ void OMW::Engine::prepareEngine()
847847
}
848848
listener->loadingOff();
849849

850-
mWorld->init(mViewer, std::move(rootNode), mWorkQueue.get(), *mUnrefQueue);
850+
mWorld->init(mMaxRecastLogLevel, mViewer, std::move(rootNode), mWorkQueue.get(), *mUnrefQueue);
851851
mEnvironment.setWorldScene(mWorld->getWorldScene());
852852
mWorld->setupPlayer();
853853
mWorld->setRandomSeed(mRandomSeed);

apps/openmw/engine.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <filesystem>
55

66
#include <components/compiler/extensions.hpp>
7+
#include <components/debug/debuglog.hpp>
78
#include <components/esm/refid.hpp>
89
#include <components/files/collections.hpp>
910
#include <components/settings/settings.hpp>
@@ -172,6 +173,7 @@ namespace OMW
172173
bool mGrab;
173174

174175
unsigned int mRandomSeed;
176+
Debug::Level mMaxRecastLogLevel = Debug::Error;
175177

176178
Compiler::Extensions mExtensions;
177179
std::unique_ptr<Compiler::Context> mScriptContext;
@@ -180,6 +182,9 @@ namespace OMW
180182
Translation::Storage mTranslationDataStorage;
181183
bool mNewGame;
182184

185+
Files::ConfigurationManager& mCfgMgr;
186+
int mGlMaxTextureImageUnits;
187+
183188
// not implemented
184189
Engine(const Engine&);
185190
Engine& operator=(const Engine&);
@@ -256,9 +261,7 @@ namespace OMW
256261

257262
void setRandomSeed(unsigned int seed);
258263

259-
private:
260-
Files::ConfigurationManager& mCfgMgr;
261-
int mGlMaxTextureImageUnits;
264+
void setRecastMaxLogLevel(Debug::Level value) { mMaxRecastLogLevel = value; }
262265
};
263266
}
264267

apps/openmw/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ int runApplication(int argc, char* argv[])
220220
Files::ConfigurationManager cfgMgr;
221221
std::unique_ptr<OMW::Engine> engine = std::make_unique<OMW::Engine>(cfgMgr);
222222

223+
engine->setRecastMaxLogLevel(Debug::getRecastMaxLogLevel());
224+
223225
if (parseOptions(argc, argv, *engine, cfgMgr))
224226
{
225227
if (!Misc::checkRequiredOSGPluginsArePresent())

apps/openmw/mwworld/worldimp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ namespace MWWorld
290290
mSwimHeightScale = mStore.get<ESM::GameSetting>().find("fSwimHeightScale")->mValue.getFloat();
291291
}
292292

293-
void World::init(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, SceneUtil::WorkQueue* workQueue,
294-
SceneUtil::UnrefQueue& unrefQueue)
293+
void World::init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode,
294+
SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue)
295295
{
296296
mPhysics = std::make_unique<MWPhysics::PhysicsSystem>(mResourceSystem, rootNode);
297297

298298
if (Settings::navigator().mEnable)
299299
{
300-
auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
300+
auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(maxRecastLogLevel);
301301
navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale;
302302
mNavigator = DetourNavigator::makeNavigator(navigatorSettings, mUserDataPath);
303303
}

apps/openmw/mwworld/worldimp.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <osg/Timer>
55
#include <osg/ref_ptr>
66

7+
#include <components/debug/debuglog.hpp>
78
#include <components/esm3/readerscache.hpp>
89
#include <components/misc/rng.hpp>
910
#include <components/settings/settings.hpp>
@@ -201,8 +202,8 @@ namespace MWWorld
201202
Loading::Listener* listener);
202203

203204
// Must be called after `loadData`.
204-
void init(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, SceneUtil::WorkQueue* workQueue,
205-
SceneUtil::UnrefQueue& unrefQueue);
205+
void init(Debug::Level maxRecastLogLevel, osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode,
206+
SceneUtil::WorkQueue* workQueue, SceneUtil::UnrefQueue& unrefQueue);
206207

207208
virtual ~World();
208209

components/debug/debugging.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ namespace Debug
324324
First mFirst;
325325
Second mSecond;
326326
};
327+
328+
Level toLevel(std::string_view value)
329+
{
330+
if (value == "ERROR")
331+
return Error;
332+
if (value == "WARNING")
333+
return Warning;
334+
if (value == "INFO")
335+
return Info;
336+
if (value == "VERBOSE")
337+
return Verbose;
338+
if (value == "DEBUG")
339+
return Debug;
340+
341+
return Verbose;
342+
}
327343
}
328344
#endif
329345

@@ -359,23 +375,19 @@ namespace Debug
359375
Level getDebugLevel()
360376
{
361377
if (const char* env = getenv("OPENMW_DEBUG_LEVEL"))
362-
{
363-
const std::string_view value(env);
364-
if (value == "ERROR")
365-
return Error;
366-
if (value == "WARNING")
367-
return Warning;
368-
if (value == "INFO")
369-
return Info;
370-
if (value == "VERBOSE")
371-
return Verbose;
372-
if (value == "DEBUG")
373-
return Debug;
374-
}
378+
return toLevel(env);
375379

376380
return Verbose;
377381
}
378382

383+
Level getRecastMaxLogLevel()
384+
{
385+
if (const char* env = getenv("OPENMW_RECAST_MAX_LOG_LEVEL"))
386+
return toLevel(env);
387+
388+
return Error;
389+
}
390+
379391
void setupLogging(const std::filesystem::path& logDir, std::string_view appName)
380392
{
381393
Log::sMinDebugLevel = getDebugLevel();

components/debug/debugging.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace Debug
3636

3737
Level getDebugLevel();
3838

39+
Level getRecastMaxLogLevel();
40+
3941
// Redirect cout and cerr to the log file
4042
void setupLogging(const std::filesystem::path& logDir, std::string_view appName);
4143

components/detournavigator/makenavmesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ namespace DetourNavigator
523523
std::unique_ptr<PreparedNavMeshData> prepareNavMeshTileData(const RecastMesh& recastMesh, ESM::RefId worldspace,
524524
const TilePosition& tilePosition, const AgentBounds& agentBounds, const RecastSettings& settings)
525525
{
526-
RecastContext context(worldspace, tilePosition, agentBounds);
526+
RecastContext context(worldspace, tilePosition, agentBounds, settings.mMaxLogLevel);
527527

528528
const auto [minZ, maxZ] = getBoundsByZ(recastMesh, agentBounds.mHalfExtents.z(), settings);
529529

components/detournavigator/recastcontext.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "recastcontext.hpp"
22
#include "debug.hpp"
33

4-
#include "components/debug/debuglog.hpp"
4+
#include <components/debug/debuglog.hpp>
55

66
#include <sstream>
77

@@ -33,15 +33,20 @@ namespace DetourNavigator
3333
}
3434
}
3535

36-
RecastContext::RecastContext(
37-
ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds)
38-
: mPrefix(formatPrefix(worldspace, tilePosition, agentBounds))
36+
RecastContext::RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition,
37+
const AgentBounds& agentBounds, Debug::Level maxLogLevel)
38+
: mMaxLogLevel(maxLogLevel)
39+
, mPrefix(formatPrefix(worldspace, tilePosition, agentBounds))
3940
{
4041
}
4142

4243
void RecastContext::doLog(const rcLogCategory category, const char* msg, const int len)
4344
{
44-
if (len > 0)
45-
Log(getLogLevel(category)) << mPrefix << std::string_view(msg, static_cast<std::size_t>(len));
45+
if (msg == nullptr || len <= 0)
46+
return;
47+
const Debug::Level level = getLogLevel(category);
48+
if (level > mMaxLogLevel)
49+
return;
50+
Log(level) << mPrefix << std::string_view(msg, static_cast<std::size_t>(len));
4651
}
4752
}

0 commit comments

Comments
 (0)