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

13 files changed

+68
-35
lines changed

apps/navmeshtool/main.cpp

+2-1
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

+1-1
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

+6-3
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

+2
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

+3-3
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

+3-2
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

+25-13
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

+2
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

+1-1
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

+11-6
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
}

components/detournavigator/recastcontext.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "tileposition.hpp"
55

6+
#include <components/debug/debuglog.hpp>
67
#include <components/esm/refid.hpp>
78

89
#include <string>
@@ -16,11 +17,13 @@ namespace DetourNavigator
1617
class RecastContext final : public rcContext
1718
{
1819
public:
19-
explicit RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds);
20+
explicit RecastContext(ESM::RefId worldspace, const TilePosition& tilePosition, const AgentBounds& agentBounds,
21+
Debug::Level maxLogLevel);
2022

2123
const std::string& getPrefix() const { return mPrefix; }
2224

2325
private:
26+
Debug::Level mMaxLogLevel;
2427
std::string mPrefix;
2528

2629
void doLog(rcLogCategory category, const char* msg, int len) override;

components/detournavigator/settings.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace DetourNavigator
4444
};
4545
}
4646

47-
RecastSettings makeRecastSettingsFromSettingsManager()
47+
RecastSettings makeRecastSettingsFromSettingsManager(Debug::Level maxLogLevel)
4848
{
4949
RecastSettings result;
5050

@@ -63,6 +63,7 @@ namespace DetourNavigator
6363
result.mRegionMergeArea = ::Settings::navigator().mRegionMergeArea;
6464
result.mRegionMinArea = ::Settings::navigator().mRegionMinArea;
6565
result.mTileSize = ::Settings::navigator().mTileSize;
66+
result.mMaxLogLevel = maxLogLevel;
6667

6768
return result;
6869
}
@@ -80,11 +81,11 @@ namespace DetourNavigator
8081
}
8182
}
8283

83-
Settings makeSettingsFromSettingsManager()
84+
Settings makeSettingsFromSettingsManager(Debug::Level maxLogLevel)
8485
{
8586
Settings result;
8687

87-
result.mRecast = makeRecastSettingsFromSettingsManager();
88+
result.mRecast = makeRecastSettingsFromSettingsManager(maxLogLevel);
8889
result.mDetour = makeDetourSettingsFromSettingsManager();
8990

9091
const NavMeshLimits limits = getNavMeshTileLimits(result.mDetour);

components/detournavigator/settings.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
22
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_SETTINGS_H
33

4+
#include <components/debug/debuglog.hpp>
5+
46
#include <chrono>
57
#include <string>
68

@@ -23,6 +25,7 @@ namespace DetourNavigator
2325
int mRegionMergeArea = 0;
2426
int mRegionMinArea = 0;
2527
int mTileSize = 0;
28+
Debug::Level mMaxLogLevel = Debug::Error;
2629
};
2730

2831
struct DetourSettings
@@ -55,7 +58,7 @@ namespace DetourNavigator
5558

5659
inline constexpr std::int64_t navMeshFormatVersion = 2;
5760

58-
Settings makeSettingsFromSettingsManager();
61+
Settings makeSettingsFromSettingsManager(Debug::Level maxLogLevel);
5962
}
6063

6164
#endif

0 commit comments

Comments
 (0)