1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Merge branch 'settings_values_navigator' into 'master'

Use settings values for Navigator settings (#6876)

See merge request OpenMW/openmw!3468
This commit is contained in:
psi29a 2023-10-10 03:24:33 +00:00
commit 01ee448c61
15 changed files with 67 additions and 63 deletions

View file

@ -199,7 +199,7 @@ namespace NavMeshTool
Settings::game().mActorCollisionShapeType, Settings::game().mActorCollisionShapeType,
Settings::game().mDefaultActorPathfindHalfExtents, 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"); const auto dbPath = Files::pathToUnicodeString(config.getUserDataPath() / "navmesh.db");
Log(Debug::Info) << "Using navmeshdb at " << dbPath; Log(Debug::Info) << "Using navmeshdb at " << dbPath;

View file

@ -23,7 +23,7 @@ add_openmw_dir (mwrender
creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager creatureanimation effectmanager util renderinginterface pathgrid rendermode weaponanimation screenshotmanager
bulletdebugdraw globalmap characterpreview camera localmap water terrainstorage ripplesimulation bulletdebugdraw globalmap characterpreview camera localmap water terrainstorage ripplesimulation
renderbin actoranimation landmanager navmesh actorspaths recastmesh fogmanager objectpaging groundcover 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 actorutil
) )

View file

@ -55,12 +55,12 @@ namespace MWLua
api["reloadLua"] = []() { MWBase::Environment::get().getLuaManager()->reloadAllScripts(); }; api["reloadLua"] = []() { MWBase::Environment::get().getLuaManager()->reloadAllScripts(); };
api["NAV_MESH_RENDER_MODE"] api["NAV_MESH_RENDER_MODE"]
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWRender::NavMeshMode>({ = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, Settings::NavMeshRenderMode>({
{ "AreaType", MWRender::NavMeshMode::AreaType }, { "AreaType", Settings::NavMeshRenderMode::AreaType },
{ "UpdateFrequency", MWRender::NavMeshMode::UpdateFrequency }, { "UpdateFrequency", Settings::NavMeshRenderMode::UpdateFrequency },
})); }));
api["setNavMeshRenderMode"] = [context](MWRender::NavMeshMode value) { api["setNavMeshRenderMode"] = [context](Settings::NavMeshRenderMode value) {
context.mLuaManager->addAction( context.mLuaManager->addAction(
[value] { MWBase::Environment::get().getWorld()->getRenderingManager()->setNavMeshMode(value); }); [value] { MWBase::Environment::get().getWorld()->getRenderingManager()->setNavMeshMode(value); });
}; };

View file

@ -46,7 +46,7 @@ namespace MWRender
const osg::ref_ptr<osg::StateSet> mDebugDrawStateSet; const osg::ref_ptr<osg::StateSet> mDebugDrawStateSet;
const DetourNavigator::Settings mSettings; const DetourNavigator::Settings mSettings;
std::map<DetourNavigator::TilePosition, Tile> mTiles; std::map<DetourNavigator::TilePosition, Tile> mTiles;
NavMeshMode mMode; Settings::NavMeshRenderMode mMode;
std::atomic_bool mAborted{ false }; std::atomic_bool mAborted{ false };
std::mutex mMutex; std::mutex mMutex;
bool mStarted = false; bool mStarted = false;
@ -57,7 +57,7 @@ namespace MWRender
std::weak_ptr<DetourNavigator::GuardedNavMeshCacheItem> navMesh, std::weak_ptr<DetourNavigator::GuardedNavMeshCacheItem> navMesh,
const osg::ref_ptr<osg::StateSet>& groupStateSet, const osg::ref_ptr<osg::StateSet>& debugDrawStateSet, const osg::ref_ptr<osg::StateSet>& groupStateSet, const osg::ref_ptr<osg::StateSet>& debugDrawStateSet,
const DetourNavigator::Settings& settings, const std::map<DetourNavigator::TilePosition, Tile>& tiles, const DetourNavigator::Settings& settings, const std::map<DetourNavigator::TilePosition, Tile>& tiles,
NavMeshMode mode) Settings::NavMeshRenderMode mode)
: mId(id) : mId(id)
, mVersion(version) , mVersion(version)
, mNavMesh(std::move(navMesh)) , mNavMesh(std::move(navMesh))
@ -110,13 +110,13 @@ namespace MWRender
const unsigned char flags = SceneUtil::NavMeshTileDrawFlagsOffMeshConnections const unsigned char flags = SceneUtil::NavMeshTileDrawFlagsOffMeshConnections
| SceneUtil::NavMeshTileDrawFlagsClosedList | SceneUtil::NavMeshTileDrawFlagsClosedList
| (mMode == NavMeshMode::UpdateFrequency ? SceneUtil::NavMeshTileDrawFlagsHeat : 0); | (mMode == Settings::NavMeshRenderMode::UpdateFrequency ? SceneUtil::NavMeshTileDrawFlagsHeat : 0);
for (const auto& [position, version] : existingTiles) for (const auto& [position, version] : existingTiles)
{ {
const auto it = mTiles.find(position); const auto it = mTiles.find(position);
if (it != mTiles.end() && it->second.mGroup != nullptr && it->second.mVersion == version if (it != mTiles.end() && it->second.mGroup != nullptr && it->second.mVersion == version
&& mMode != NavMeshMode::UpdateFrequency) && mMode != Settings::NavMeshRenderMode::UpdateFrequency)
continue; continue;
osg::ref_ptr<osg::Group> group; osg::ref_ptr<osg::Group> group;
@ -163,7 +163,7 @@ namespace MWRender
}; };
NavMesh::NavMesh(const osg::ref_ptr<osg::Group>& root, const osg::ref_ptr<SceneUtil::WorkQueue>& workQueue, NavMesh::NavMesh(const osg::ref_ptr<osg::Group>& root, const osg::ref_ptr<SceneUtil::WorkQueue>& workQueue,
bool enabled, NavMeshMode mode) bool enabled, Settings::NavMeshRenderMode mode)
: mRootNode(root) : mRootNode(root)
, mWorkQueue(workQueue) , mWorkQueue(workQueue)
, mGroupStateSet(SceneUtil::makeNavMeshTileStateSet()) , mGroupStateSet(SceneUtil::makeNavMeshTileStateSet())
@ -310,7 +310,7 @@ namespace MWRender
mEnabled = false; mEnabled = false;
} }
void NavMesh::setMode(NavMeshMode value) void NavMesh::setMode(Settings::NavMeshRenderMode value)
{ {
if (mMode == value) if (mMode == value)
return; return;

View file

@ -1,11 +1,10 @@
#ifndef OPENMW_MWRENDER_NAVMESH_H #ifndef OPENMW_MWRENDER_NAVMESH_H
#define OPENMW_MWRENDER_NAVMESH_H #define OPENMW_MWRENDER_NAVMESH_H
#include "navmeshmode.hpp"
#include <components/detournavigator/tileposition.hpp> #include <components/detournavigator/tileposition.hpp>
#include <components/detournavigator/version.hpp> #include <components/detournavigator/version.hpp>
#include <components/misc/guarded.hpp> #include <components/misc/guarded.hpp>
#include <components/settings/navmeshrendermode.hpp>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -41,7 +40,7 @@ namespace MWRender
{ {
public: public:
explicit NavMesh(const osg::ref_ptr<osg::Group>& root, const osg::ref_ptr<SceneUtil::WorkQueue>& workQueue, explicit NavMesh(const osg::ref_ptr<osg::Group>& root, const osg::ref_ptr<SceneUtil::WorkQueue>& workQueue,
bool enabled, NavMeshMode mode); bool enabled, Settings::NavMeshRenderMode mode);
~NavMesh(); ~NavMesh();
bool toggle(); bool toggle();
@ -57,7 +56,7 @@ namespace MWRender
bool isEnabled() const { return mEnabled; } bool isEnabled() const { return mEnabled; }
void setMode(NavMeshMode value); void setMode(Settings::NavMeshRenderMode value);
private: private:
struct Tile struct Tile
@ -75,7 +74,7 @@ namespace MWRender
osg::ref_ptr<osg::StateSet> mGroupStateSet; osg::ref_ptr<osg::StateSet> mGroupStateSet;
osg::ref_ptr<osg::StateSet> mDebugDrawStateSet; osg::ref_ptr<osg::StateSet> mDebugDrawStateSet;
bool mEnabled; bool mEnabled;
NavMeshMode mMode; Settings::NavMeshRenderMode mMode;
std::size_t mId; std::size_t mId;
DetourNavigator::Version mVersion; DetourNavigator::Version mVersion;
std::map<DetourNavigator::TilePosition, Tile> mTiles; std::map<DetourNavigator::TilePosition, Tile> mTiles;

View file

@ -1,16 +0,0 @@
#include "navmeshmode.hpp"
#include <stdexcept>
#include <string>
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));
}
}

View file

@ -1,17 +0,0 @@
#ifndef OPENMW_MWRENDER_NAVMESHMODE_H
#define OPENMW_MWRENDER_NAVMESHMODE_H
#include <string_view>
namespace MWRender
{
enum class NavMeshMode
{
AreaType,
UpdateFrequency,
};
NavMeshMode parseNavMeshMode(std::string_view value);
}
#endif

View file

@ -425,13 +425,10 @@ namespace MWRender
// It is unnecessary to stop/start the viewer as no frames are being rendered yet. // It is unnecessary to stop/start the viewer as no frames are being rendered yet.
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines); mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines);
mNavMesh = std::make_unique<NavMesh>(mRootNode, mWorkQueue, mNavMesh = std::make_unique<NavMesh>(mRootNode, mWorkQueue, Settings::navigator().mEnableNavMeshRender,
Settings::Manager::getBool("enable nav mesh render", "Navigator"), Settings::navigator().mNavMeshRenderMode);
parseNavMeshMode(Settings::Manager::getString("nav mesh render mode", "Navigator"))); mActorsPaths = std::make_unique<ActorsPaths>(mRootNode, Settings::navigator().mEnableAgentsPathsRender);
mActorsPaths = std::make_unique<ActorsPaths>( mRecastMesh = std::make_unique<RecastMesh>(mRootNode, Settings::navigator().mEnableRecastMeshRender);
mRootNode, Settings::Manager::getBool("enable agents paths render", "Navigator"));
mRecastMesh = std::make_unique<RecastMesh>(
mRootNode, Settings::Manager::getBool("enable recast mesh render", "Navigator"));
mPathgrid = std::make_unique<Pathgrid>(mRootNode); mPathgrid = std::make_unique<Pathgrid>(mRootNode);
mObjects = std::make_unique<Objects>(mResourceSystem, sceneRoot, unrefQueue); mObjects = std::make_unique<Objects>(mResourceSystem, sceneRoot, unrefQueue);
@ -1666,7 +1663,7 @@ namespace MWRender
mObjectPaging->getPagedRefnums(activeGrid, out); mObjectPaging->getPagedRefnums(activeGrid, out);
} }
void RenderingManager::setNavMeshMode(NavMeshMode value) void RenderingManager::setNavMeshMode(Settings::NavMeshRenderMode value)
{ {
mNavMesh->setMode(value); mNavMesh->setMode(value);
} }

View file

@ -9,7 +9,6 @@
#include <osgUtil/IncrementalCompileOperation> #include <osgUtil/IncrementalCompileOperation>
#include "navmeshmode.hpp"
#include "objects.hpp" #include "objects.hpp"
#include "renderinginterface.hpp" #include "renderinginterface.hpp"
#include "rendermode.hpp" #include "rendermode.hpp"
@ -275,7 +274,7 @@ namespace MWRender
void setScreenRes(int width, int height); void setScreenRes(int width, int height);
void setNavMeshMode(NavMeshMode value); void setNavMeshMode(Settings::NavMeshRenderMode value);
private: private:
void updateTextureFiltering(); void updateTextureFiltering();

View file

@ -294,7 +294,7 @@ namespace MWWorld
{ {
mPhysics = std::make_unique<MWPhysics::PhysicsSystem>(mResourceSystem, rootNode); mPhysics = std::make_unique<MWPhysics::PhysicsSystem>(mResourceSystem, rootNode);
if (Settings::Manager::getBool("enable", "Navigator")) if (Settings::navigator().mEnable)
{ {
auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager(); auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager();
navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale; navigatorSettings.mRecast.mSwimHeightScale = mSwimHeightScale;

View file

@ -3,6 +3,7 @@
#include "components/settings/sanitizerimpl.hpp" #include "components/settings/sanitizerimpl.hpp"
#include "components/settings/settingvalue.hpp" #include "components/settings/settingvalue.hpp"
#include <components/settings/navmeshrendermode.hpp>
#include <osg/Math> #include <osg/Math>
#include <osg/Vec2f> #include <osg/Vec2f>
@ -52,8 +53,7 @@ namespace Settings
SettingValue<std::string> mRecastMeshPathPrefix{ mIndex, "Navigator", "recast mesh path prefix" }; SettingValue<std::string> mRecastMeshPathPrefix{ mIndex, "Navigator", "recast mesh path prefix" };
SettingValue<std::string> mNavMeshPathPrefix{ mIndex, "Navigator", "nav mesh path prefix" }; SettingValue<std::string> mNavMeshPathPrefix{ mIndex, "Navigator", "nav mesh path prefix" };
SettingValue<bool> mEnableNavMeshRender{ mIndex, "Navigator", "enable nav mesh render" }; SettingValue<bool> mEnableNavMeshRender{ mIndex, "Navigator", "enable nav mesh render" };
SettingValue<std::string> mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode", SettingValue<NavMeshRenderMode> mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode" };
makeEnumSanitizerString({ "area type", "update frequency" }) };
SettingValue<bool> mEnableAgentsPathsRender{ mIndex, "Navigator", "enable agents paths render" }; SettingValue<bool> mEnableAgentsPathsRender{ mIndex, "Navigator", "enable agents paths render" };
SettingValue<bool> mEnableRecastMeshRender{ mIndex, "Navigator", "enable recast mesh render" }; SettingValue<bool> mEnableRecastMeshRender{ mIndex, "Navigator", "enable recast mesh render" };
SettingValue<int> mMaxTilesNumber{ mIndex, "Navigator", "max tiles number", makeMaxSanitizerInt(0) }; SettingValue<int> mMaxTilesNumber{ mIndex, "Navigator", "max tiles number", makeMaxSanitizerInt(0) };

View file

@ -0,0 +1,13 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_NAVMESHRENDERMODE_H
#define OPENMW_COMPONENTS_SETTINGS_NAVMESHRENDERMODE_H
namespace Settings
{
enum class NavMeshRenderMode
{
AreaType,
UpdateFrequency,
};
}
#endif

View file

@ -481,4 +481,14 @@ namespace Settings
throw std::runtime_error("Invalid gyroscope axis: " + std::string(value)); 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));
}
} }

View file

@ -3,6 +3,7 @@
#include "categories.hpp" #include "categories.hpp"
#include "gyroscopeaxis.hpp" #include "gyroscopeaxis.hpp"
#include "navmeshrendermode.hpp"
#include "components/detournavigator/collisionshapetype.hpp" #include "components/detournavigator/collisionshapetype.hpp"
@ -206,6 +207,14 @@ namespace Settings
{ {
return parseGyroscopeAxis(getString(setting, category)); return parseGyroscopeAxis(getString(setting, category));
} }
NavMeshRenderMode parseNavMeshRenderMode(std::string_view value);
template <>
inline NavMeshRenderMode Manager::getImpl<NavMeshRenderMode>(std::string_view setting, std::string_view category)
{
return parseNavMeshRenderMode(getString(setting, category));
}
} }
#endif // COMPONENTS_SETTINGS_H #endif // COMPONENTS_SETTINGS_H

View file

@ -2,6 +2,7 @@
#define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H #define OPENMW_COMPONENTS_SETTINGS_SETTINGVALUE_H
#include "gyroscopeaxis.hpp" #include "gyroscopeaxis.hpp"
#include "navmeshrendermode.hpp"
#include "sanitizer.hpp" #include "sanitizer.hpp"
#include "settings.hpp" #include "settings.hpp"
@ -38,6 +39,7 @@ namespace Settings
StringArray, StringArray,
MyGuiColour, MyGuiColour,
GyroscopeAxis, GyroscopeAxis,
NavMeshRenderMode,
}; };
template <class T> template <class T>
@ -139,6 +141,12 @@ namespace Settings
return SettingValueType::GyroscopeAxis; return SettingValueType::GyroscopeAxis;
} }
template <>
inline constexpr SettingValueType getSettingValueType<NavMeshRenderMode>()
{
return SettingValueType::NavMeshRenderMode;
}
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type) inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{ {
switch (type) switch (type)
@ -175,6 +183,8 @@ namespace Settings
return "colour"; return "colour";
case SettingValueType::GyroscopeAxis: case SettingValueType::GyroscopeAxis:
return "gyroscope axis"; return "gyroscope axis";
case SettingValueType::NavMeshRenderMode:
return "navmesh render mode";
} }
return "unsupported"; return "unsupported";
} }