diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 7d9f9559d1..f9c2019a98 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/soundmanager.hpp" @@ -183,6 +184,7 @@ namespace MWWorld navigatorSettings.mMaxPolygonPathSize = static_cast(Settings::Manager::getInt("max polygon path size", "Navigator")); navigatorSettings.mMaxSmoothPathSize = static_cast(Settings::Manager::getInt("max smooth path size", "Navigator")); navigatorSettings.mTrianglesPerChunk = static_cast(Settings::Manager::getInt("triangles per chunk", "Navigator")); + DetourNavigator::Log::instance().setEnabled(Settings::Manager::getBool("enable log", "Navigator")); mNavigator.reset(new DetourNavigator::Navigator(navigatorSettings)); mRendering->preloadCommonAssets(); diff --git a/components/detournavigator/debug.hpp b/components/detournavigator/debug.hpp index c9f25ca496..59bfb73d44 100644 --- a/components/detournavigator/debug.hpp +++ b/components/detournavigator/debug.hpp @@ -39,6 +39,37 @@ namespace DetourNavigator void writeToFile(const dtNavMesh& navMesh, const std::string& revision); #endif + class Log + { + public: + Log() : mEnabled(false) {} + + void setEnabled(bool value) + { + mEnabled = value; + } + + bool isEnabled() const + { + return mEnabled; + } + + void write(const std::string& text) + { + if (mEnabled) + std::cout << text; + } + + static Log& instance() + { + static Log value; + return value; + } + + private: + bool mEnabled; + }; + inline void write(std::ostream& stream) { stream << '\n'; @@ -54,9 +85,12 @@ namespace DetourNavigator template void log(Ts&& ... values) { + auto& log = Log::instance(); + if (!log.isEnabled()) + return; std::ostringstream stream; write(stream, std::forward(values) ...); - std::cout << stream.str(); + log.write(stream.str()); } } diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index cac6d0952b..eb9cd6c5a3 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -1,5 +1,6 @@ #include "makenavmesh.hpp" #include "chunkytrimesh.hpp" +#include "debug.hpp" #include "dtstatus.hpp" #include "exceptions.hpp" #include "recastmesh.hpp" @@ -12,10 +13,6 @@ #include #include -#include -#include -#include - namespace { using namespace DetourNavigator; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 008d34ee07..7bc9ac6c06 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -590,3 +590,6 @@ max smooth path size = 1024 # Maximum number of triangles in each node of mesh AABB tree (value > 0) triangles per chunk = 256 + +# Enable debug log (true, false) +enable log = false