From b3c8a15af1c6d48f052d031b1da268ed88a79377 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 1 Oct 2023 10:36:18 +0200 Subject: [PATCH 1/2] Parse navmesh render mode on reading settings --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwlua/debugbindings.cpp | 8 ++++---- apps/openmw/mwrender/navmesh.cpp | 12 ++++++------ apps/openmw/mwrender/navmesh.hpp | 9 ++++----- apps/openmw/mwrender/navmeshmode.cpp | 16 ---------------- apps/openmw/mwrender/navmeshmode.hpp | 17 ----------------- apps/openmw/mwrender/renderingmanager.cpp | 4 ++-- apps/openmw/mwrender/renderingmanager.hpp | 3 +-- components/settings/categories/navigator.hpp | 4 ++-- components/settings/navmeshrendermode.hpp | 13 +++++++++++++ components/settings/settings.cpp | 10 ++++++++++ components/settings/settings.hpp | 9 +++++++++ components/settings/settingvalue.hpp | 10 ++++++++++ 13 files changed, 62 insertions(+), 55 deletions(-) delete mode 100644 apps/openmw/mwrender/navmeshmode.cpp delete mode 100644 apps/openmw/mwrender/navmeshmode.hpp create mode 100644 components/settings/navmeshrendermode.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 535d854239..b54d3bac92 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -23,7 +23,7 @@ add_openmw_dir (mwrender creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager bulletdebugdraw globalmap characterpreview camera localmap water terrainstorage ripplesimulation renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover - postprocessor pingpongcull luminancecalculator pingpongcanvas transparentpass navmeshmode precipitationocclusion ripples + postprocessor pingpongcull luminancecalculator pingpongcanvas transparentpass precipitationocclusion ripples actorutil ) diff --git a/apps/openmw/mwlua/debugbindings.cpp b/apps/openmw/mwlua/debugbindings.cpp index 1c9854df5e..0aa1f4ace5 100644 --- a/apps/openmw/mwlua/debugbindings.cpp +++ b/apps/openmw/mwlua/debugbindings.cpp @@ -55,12 +55,12 @@ namespace MWLua api["reloadLua"] = []() { MWBase::Environment::get().getLuaManager()->reloadAllScripts(); }; api["NAV_MESH_RENDER_MODE"] - = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs({ - { "AreaType", MWRender::NavMeshMode::AreaType }, - { "UpdateFrequency", MWRender::NavMeshMode::UpdateFrequency }, + = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs({ + { "AreaType", Settings::NavMeshRenderMode::AreaType }, + { "UpdateFrequency", Settings::NavMeshRenderMode::UpdateFrequency }, })); - api["setNavMeshRenderMode"] = [context](MWRender::NavMeshMode value) { + api["setNavMeshRenderMode"] = [context](Settings::NavMeshRenderMode value) { context.mLuaManager->addAction( [value] { MWBase::Environment::get().getWorld()->getRenderingManager()->setNavMeshMode(value); }); }; diff --git a/apps/openmw/mwrender/navmesh.cpp b/apps/openmw/mwrender/navmesh.cpp index 8d638c918b..df3cd22699 100644 --- a/apps/openmw/mwrender/navmesh.cpp +++ b/apps/openmw/mwrender/navmesh.cpp @@ -46,7 +46,7 @@ namespace MWRender const osg::ref_ptr mDebugDrawStateSet; const DetourNavigator::Settings mSettings; std::map mTiles; - NavMeshMode mMode; + Settings::NavMeshRenderMode mMode; std::atomic_bool mAborted{ false }; std::mutex mMutex; bool mStarted = false; @@ -57,7 +57,7 @@ namespace MWRender std::weak_ptr navMesh, const osg::ref_ptr& groupStateSet, const osg::ref_ptr& debugDrawStateSet, const DetourNavigator::Settings& settings, const std::map& tiles, - NavMeshMode mode) + Settings::NavMeshRenderMode mode) : mId(id) , mVersion(version) , mNavMesh(std::move(navMesh)) @@ -110,13 +110,13 @@ namespace MWRender const unsigned char flags = SceneUtil::NavMeshTileDrawFlagsOffMeshConnections | SceneUtil::NavMeshTileDrawFlagsClosedList - | (mMode == NavMeshMode::UpdateFrequency ? SceneUtil::NavMeshTileDrawFlagsHeat : 0); + | (mMode == Settings::NavMeshRenderMode::UpdateFrequency ? SceneUtil::NavMeshTileDrawFlagsHeat : 0); for (const auto& [position, version] : existingTiles) { const auto it = mTiles.find(position); if (it != mTiles.end() && it->second.mGroup != nullptr && it->second.mVersion == version - && mMode != NavMeshMode::UpdateFrequency) + && mMode != Settings::NavMeshRenderMode::UpdateFrequency) continue; osg::ref_ptr group; @@ -163,7 +163,7 @@ namespace MWRender }; NavMesh::NavMesh(const osg::ref_ptr& root, const osg::ref_ptr& workQueue, - bool enabled, NavMeshMode mode) + bool enabled, Settings::NavMeshRenderMode mode) : mRootNode(root) , mWorkQueue(workQueue) , mGroupStateSet(SceneUtil::makeNavMeshTileStateSet()) @@ -310,7 +310,7 @@ namespace MWRender mEnabled = false; } - void NavMesh::setMode(NavMeshMode value) + void NavMesh::setMode(Settings::NavMeshRenderMode value) { if (mMode == value) return; diff --git a/apps/openmw/mwrender/navmesh.hpp b/apps/openmw/mwrender/navmesh.hpp index 4b4e50f791..193a474ec4 100644 --- a/apps/openmw/mwrender/navmesh.hpp +++ b/apps/openmw/mwrender/navmesh.hpp @@ -1,11 +1,10 @@ #ifndef OPENMW_MWRENDER_NAVMESH_H #define OPENMW_MWRENDER_NAVMESH_H -#include "navmeshmode.hpp" - #include #include #include +#include #include @@ -41,7 +40,7 @@ namespace MWRender { public: explicit NavMesh(const osg::ref_ptr& root, const osg::ref_ptr& workQueue, - bool enabled, NavMeshMode mode); + bool enabled, Settings::NavMeshRenderMode mode); ~NavMesh(); bool toggle(); @@ -57,7 +56,7 @@ namespace MWRender bool isEnabled() const { return mEnabled; } - void setMode(NavMeshMode value); + void setMode(Settings::NavMeshRenderMode value); private: struct Tile @@ -75,7 +74,7 @@ namespace MWRender osg::ref_ptr mGroupStateSet; osg::ref_ptr mDebugDrawStateSet; bool mEnabled; - NavMeshMode mMode; + Settings::NavMeshRenderMode mMode; std::size_t mId; DetourNavigator::Version mVersion; std::map mTiles; diff --git a/apps/openmw/mwrender/navmeshmode.cpp b/apps/openmw/mwrender/navmeshmode.cpp deleted file mode 100644 index d08e7cf693..0000000000 --- a/apps/openmw/mwrender/navmeshmode.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "navmeshmode.hpp" - -#include -#include - -namespace MWRender -{ - NavMeshMode parseNavMeshMode(std::string_view value) - { - if (value == "area type") - return NavMeshMode::AreaType; - if (value == "update frequency") - return NavMeshMode::UpdateFrequency; - throw std::logic_error("Unsupported navigation mesh rendering mode: " + std::string(value)); - } -} diff --git a/apps/openmw/mwrender/navmeshmode.hpp b/apps/openmw/mwrender/navmeshmode.hpp deleted file mode 100644 index 9401479e21..0000000000 --- a/apps/openmw/mwrender/navmeshmode.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef OPENMW_MWRENDER_NAVMESHMODE_H -#define OPENMW_MWRENDER_NAVMESHMODE_H - -#include - -namespace MWRender -{ - enum class NavMeshMode - { - AreaType, - UpdateFrequency, - }; - - NavMeshMode parseNavMeshMode(std::string_view value); -} - -#endif diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 6155325410..70724cd08c 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -427,7 +427,7 @@ namespace MWRender mNavMesh = std::make_unique(mRootNode, mWorkQueue, Settings::Manager::getBool("enable nav mesh render", "Navigator"), - parseNavMeshMode(Settings::Manager::getString("nav mesh render mode", "Navigator"))); + Settings::navigator().mNavMeshRenderMode); mActorsPaths = std::make_unique( mRootNode, Settings::Manager::getBool("enable agents paths render", "Navigator")); mRecastMesh = std::make_unique( @@ -1666,7 +1666,7 @@ namespace MWRender mObjectPaging->getPagedRefnums(activeGrid, out); } - void RenderingManager::setNavMeshMode(NavMeshMode value) + void RenderingManager::setNavMeshMode(Settings::NavMeshRenderMode value) { mNavMesh->setMode(value); } diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0e2ece7de9..f1760d3960 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -9,7 +9,6 @@ #include -#include "navmeshmode.hpp" #include "objects.hpp" #include "renderinginterface.hpp" #include "rendermode.hpp" @@ -275,7 +274,7 @@ namespace MWRender void setScreenRes(int width, int height); - void setNavMeshMode(NavMeshMode value); + void setNavMeshMode(Settings::NavMeshRenderMode value); private: void updateTextureFiltering(); diff --git a/components/settings/categories/navigator.hpp b/components/settings/categories/navigator.hpp index 9dcf08d299..b820b2c950 100644 --- a/components/settings/categories/navigator.hpp +++ b/components/settings/categories/navigator.hpp @@ -3,6 +3,7 @@ #include "components/settings/sanitizerimpl.hpp" #include "components/settings/settingvalue.hpp" +#include #include #include @@ -52,8 +53,7 @@ namespace Settings SettingValue mRecastMeshPathPrefix{ mIndex, "Navigator", "recast mesh path prefix" }; SettingValue mNavMeshPathPrefix{ mIndex, "Navigator", "nav mesh path prefix" }; SettingValue mEnableNavMeshRender{ mIndex, "Navigator", "enable nav mesh render" }; - SettingValue mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode", - makeEnumSanitizerString({ "area type", "update frequency" }) }; + SettingValue mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode" }; SettingValue mEnableAgentsPathsRender{ mIndex, "Navigator", "enable agents paths render" }; SettingValue mEnableRecastMeshRender{ mIndex, "Navigator", "enable recast mesh render" }; SettingValue mMaxTilesNumber{ mIndex, "Navigator", "max tiles number", makeMaxSanitizerInt(0) }; diff --git a/components/settings/navmeshrendermode.hpp b/components/settings/navmeshrendermode.hpp new file mode 100644 index 0000000000..416e2afab1 --- /dev/null +++ b/components/settings/navmeshrendermode.hpp @@ -0,0 +1,13 @@ +#ifndef OPENMW_COMPONENTS_SETTINGS_NAVMESHRENDERMODE_H +#define OPENMW_COMPONENTS_SETTINGS_NAVMESHRENDERMODE_H + +namespace Settings +{ + enum class NavMeshRenderMode + { + AreaType, + UpdateFrequency, + }; +} + +#endif diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 0b5260fb8e..305d4edc88 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -481,4 +481,14 @@ namespace Settings throw std::runtime_error("Invalid gyroscope axis: " + std::string(value)); } + + NavMeshRenderMode parseNavMeshRenderMode(std::string_view value) + { + if (value == "area type") + return NavMeshRenderMode::AreaType; + if (value == "update frequency") + return NavMeshRenderMode::UpdateFrequency; + + throw std::invalid_argument("Invalid navigation mesh rendering mode: " + std::string(value)); + } } diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index c9a5dbc6ea..784c7c613c 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -3,6 +3,7 @@ #include "categories.hpp" #include "gyroscopeaxis.hpp" +#include "navmeshrendermode.hpp" #include "components/detournavigator/collisionshapetype.hpp" @@ -206,6 +207,14 @@ namespace Settings { return parseGyroscopeAxis(getString(setting, category)); } + + NavMeshRenderMode parseNavMeshRenderMode(std::string_view value); + + template <> + inline NavMeshRenderMode Manager::getImpl(std::string_view setting, std::string_view category) + { + return parseNavMeshRenderMode(getString(setting, category)); + } } #endif // COMPONENTS_SETTINGS_H diff --git a/components/settings/settingvalue.hpp b/components/settings/settingvalue.hpp index 540ef1fe0b..407fd15baf 100644 --- a/components/settings/settingvalue.hpp +++ b/components/settings/settingvalue.hpp @@ -2,6 +2,7 @@ #define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H #include "gyroscopeaxis.hpp" +#include "navmeshrendermode.hpp" #include "sanitizer.hpp" #include "settings.hpp" @@ -38,6 +39,7 @@ namespace Settings StringArray, MyGuiColour, GyroscopeAxis, + NavMeshRenderMode, }; template @@ -139,6 +141,12 @@ namespace Settings return SettingValueType::GyroscopeAxis; } + template <> + inline constexpr SettingValueType getSettingValueType() + { + return SettingValueType::NavMeshRenderMode; + } + inline constexpr std::string_view getSettingValueTypeName(SettingValueType type) { switch (type) @@ -175,6 +183,8 @@ namespace Settings return "colour"; case SettingValueType::GyroscopeAxis: return "gyroscope axis"; + case SettingValueType::NavMeshRenderMode: + return "navmesh render mode"; } return "unsupported"; } From 68de5690ef047d44141018fed70f005dd59aa172 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 1 Oct 2023 10:36:55 +0200 Subject: [PATCH 2/2] Use settings values for Navigator settings --- apps/navmeshtool/main.cpp | 2 +- apps/openmw/mwrender/renderingmanager.cpp | 9 +++------ apps/openmw/mwworld/worldimp.cpp | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/navmeshtool/main.cpp b/apps/navmeshtool/main.cpp index f82bd09f9e..793a08ba2c 100644 --- a/apps/navmeshtool/main.cpp +++ b/apps/navmeshtool/main.cpp @@ -199,7 +199,7 @@ namespace NavMeshTool Settings::game().mActorCollisionShapeType, Settings::game().mDefaultActorPathfindHalfExtents, }; - const std::uint64_t maxDbFileSize = Settings::Manager::getUInt64("max navmeshdb file size", "Navigator"); + const std::uint64_t maxDbFileSize = Settings::navigator().mMaxNavmeshdbFileSize; const auto dbPath = Files::pathToUnicodeString(config.getUserDataPath() / "navmesh.db"); Log(Debug::Info) << "Using navmeshdb at " << dbPath; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 70724cd08c..8b370c73b6 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -425,13 +425,10 @@ namespace MWRender // It is unnecessary to stop/start the viewer as no frames are being rendered yet. mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines); - mNavMesh = std::make_unique(mRootNode, mWorkQueue, - Settings::Manager::getBool("enable nav mesh render", "Navigator"), + mNavMesh = std::make_unique(mRootNode, mWorkQueue, Settings::navigator().mEnableNavMeshRender, Settings::navigator().mNavMeshRenderMode); - mActorsPaths = std::make_unique( - mRootNode, Settings::Manager::getBool("enable agents paths render", "Navigator")); - mRecastMesh = std::make_unique( - mRootNode, Settings::Manager::getBool("enable recast mesh render", "Navigator")); + mActorsPaths = std::make_unique(mRootNode, Settings::navigator().mEnableAgentsPathsRender); + mRecastMesh = std::make_unique(mRootNode, Settings::navigator().mEnableRecastMeshRender); mPathgrid = std::make_unique(mRootNode); mObjects = std::make_unique(mResourceSystem, sceneRoot, unrefQueue); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 02e4d066bc..b9bf454895 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -294,7 +294,7 @@ namespace MWWorld { mPhysics = std::make_unique(mResourceSystem, rootNode); - if (Settings::Manager::getBool("enable", "Navigator")) + if (Settings::navigator().mEnable) { auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(); navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale;