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

Parse navmesh render mode on reading settings

This commit is contained in:
elsid 2023-10-01 10:36:18 +02:00
parent 08ff69f199
commit b3c8a15af1
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
13 changed files with 62 additions and 55 deletions

View file

@ -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
)

View file

@ -55,12 +55,12 @@ namespace MWLua
api["reloadLua"] = []() { MWBase::Environment::get().getLuaManager()->reloadAllScripts(); };
api["NAV_MESH_RENDER_MODE"]
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWRender::NavMeshMode>({
{ "AreaType", MWRender::NavMeshMode::AreaType },
{ "UpdateFrequency", MWRender::NavMeshMode::UpdateFrequency },
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, Settings::NavMeshRenderMode>({
{ "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); });
};

View file

@ -46,7 +46,7 @@ namespace MWRender
const osg::ref_ptr<osg::StateSet> mDebugDrawStateSet;
const DetourNavigator::Settings mSettings;
std::map<DetourNavigator::TilePosition, Tile> 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<DetourNavigator::GuardedNavMeshCacheItem> navMesh,
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,
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<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,
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;

View file

@ -1,11 +1,10 @@
#ifndef OPENMW_MWRENDER_NAVMESH_H
#define OPENMW_MWRENDER_NAVMESH_H
#include "navmeshmode.hpp"
#include <components/detournavigator/tileposition.hpp>
#include <components/detournavigator/version.hpp>
#include <components/misc/guarded.hpp>
#include <components/settings/navmeshrendermode.hpp>
#include <osg/ref_ptr>
@ -41,7 +40,7 @@ namespace MWRender
{
public:
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();
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<osg::StateSet> mGroupStateSet;
osg::ref_ptr<osg::StateSet> mDebugDrawStateSet;
bool mEnabled;
NavMeshMode mMode;
Settings::NavMeshRenderMode mMode;
std::size_t mId;
DetourNavigator::Version mVersion;
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

@ -427,7 +427,7 @@ namespace MWRender
mNavMesh = std::make_unique<NavMesh>(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<ActorsPaths>(
mRootNode, Settings::Manager::getBool("enable agents paths render", "Navigator"));
mRecastMesh = std::make_unique<RecastMesh>(
@ -1666,7 +1666,7 @@ namespace MWRender
mObjectPaging->getPagedRefnums(activeGrid, out);
}
void RenderingManager::setNavMeshMode(NavMeshMode value)
void RenderingManager::setNavMeshMode(Settings::NavMeshRenderMode value)
{
mNavMesh->setMode(value);
}

View file

@ -9,7 +9,6 @@
#include <osgUtil/IncrementalCompileOperation>
#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();

View file

@ -3,6 +3,7 @@
#include "components/settings/sanitizerimpl.hpp"
#include "components/settings/settingvalue.hpp"
#include <components/settings/navmeshrendermode.hpp>
#include <osg/Math>
#include <osg/Vec2f>
@ -52,8 +53,7 @@ namespace Settings
SettingValue<std::string> mRecastMeshPathPrefix{ mIndex, "Navigator", "recast mesh path prefix" };
SettingValue<std::string> mNavMeshPathPrefix{ mIndex, "Navigator", "nav mesh path prefix" };
SettingValue<bool> mEnableNavMeshRender{ mIndex, "Navigator", "enable nav mesh render" };
SettingValue<std::string> mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode",
makeEnumSanitizerString({ "area type", "update frequency" }) };
SettingValue<NavMeshRenderMode> mNavMeshRenderMode{ mIndex, "Navigator", "nav mesh render mode" };
SettingValue<bool> mEnableAgentsPathsRender{ mIndex, "Navigator", "enable agents paths render" };
SettingValue<bool> mEnableRecastMeshRender{ mIndex, "Navigator", "enable recast mesh render" };
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));
}
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 "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<NavMeshRenderMode>(std::string_view setting, std::string_view category)
{
return parseNavMeshRenderMode(getString(setting, category));
}
}
#endif // COMPONENTS_SETTINGS_H

View file

@ -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 <class T>
@ -139,6 +141,12 @@ namespace Settings
return SettingValueType::GyroscopeAxis;
}
template <>
inline constexpr SettingValueType getSettingValueType<NavMeshRenderMode>()
{
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";
}