From 5d5e6844d18dccb18f49e042c534a8a4609ae31c Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 20 May 2023 22:23:09 +0200 Subject: [PATCH] Use settings values for Camera settings --- apps/openmw/mwgui/mapwindow.cpp | 3 +-- apps/openmw/mwlua/camerabindings.cpp | 10 +++------- apps/openmw/mwrender/renderingmanager.cpp | 20 +++++++++----------- apps/openmw/mwrender/screenshotmanager.cpp | 7 +++---- components/sceneutil/depth.cpp | 4 ++-- components/stereo/stereomanager.cpp | 9 +++------ 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwgui/mapwindow.cpp b/apps/openmw/mwgui/mapwindow.cpp index f3d3b346e4..1e3028f319 100644 --- a/apps/openmw/mwgui/mapwindow.cpp +++ b/apps/openmw/mwgui/mapwindow.cpp @@ -93,8 +93,7 @@ namespace return Constants::CellGridRadius; const int maxLocalViewingDistance = std::max(Settings::Manager::getInt("max local viewing distance", "Map"), Constants::CellGridRadius); - const int viewingDistanceInCells - = Settings::Manager::getFloat("viewing distance", "Camera") / Constants::CellSizeInUnits; + const int viewingDistanceInCells = Settings::camera().mViewingDistance / Constants::CellSizeInUnits; return std::clamp(viewingDistanceInCells, Constants::CellGridRadius, maxLocalViewingDistance); } } diff --git a/apps/openmw/mwlua/camerabindings.cpp b/apps/openmw/mwlua/camerabindings.cpp index a62f743b5d..4d27ce317c 100644 --- a/apps/openmw/mwlua/camerabindings.cpp +++ b/apps/openmw/mwlua/camerabindings.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -82,17 +82,13 @@ namespace MWLua api["getCollisionType"] = [camera]() { return camera->getCollisionType(); }; api["setCollisionType"] = [camera](int collisionType) { camera->setCollisionType(collisionType); }; - api["getBaseFieldOfView"] = []() { - return osg::DegreesToRadians( - std::clamp(Settings::Manager::getFloat("field of view", "Camera"), 1.f, 179.f)); - }; + api["getBaseFieldOfView"] = [] { return osg::DegreesToRadians(Settings::camera().mFieldOfView); }; api["getFieldOfView"] = [renderingManager]() { return osg::DegreesToRadians(renderingManager->getFieldOfView()); }; api["setFieldOfView"] = [renderingManager](float v) { renderingManager->setFieldOfView(osg::RadiansToDegrees(v)); }; - api["getBaseViewDistance"] - = []() { return std::max(0.f, Settings::Manager::getFloat("viewing distance", "Camera")); }; + api["getBaseViewDistance"] = [] { return Settings::camera().mViewingDistance.get(); }; api["getViewDistance"] = [renderingManager]() { return renderingManager->getViewDistance(); }; api["setViewDistance"] = [renderingManager](float d) { renderingManager->setViewDistance(d, true); }; diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 3987ee587d..b114ed92bc 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -315,13 +315,12 @@ namespace MWRender , mNightEyeFactor(0.f) // TODO: Near clip should not need to be bounded like this, but too small values break OSG shadow calculations // CPU-side. See issue: #6072 - , mNearClip(std::max(0.005f, Settings::Manager::getFloat("near clip", "Camera"))) - , mViewDistance(Settings::Manager::getFloat("viewing distance", "Camera")) + , mNearClip(Settings::camera().mNearClip) + , mViewDistance(Settings::camera().mViewingDistance) , mFieldOfViewOverridden(false) , mFieldOfViewOverride(0.f) - , mFieldOfView(std::clamp(Settings::Manager::getFloat("field of view", "Camera"), 1.f, 179.f)) - , mFirstPersonFieldOfView( - std::clamp(Settings::Manager::getFloat("first person field of view", "Camera"), 1.f, 179.f)) + , mFieldOfView(Settings::camera().mFieldOfView) + , mFirstPersonFieldOfView(Settings::camera().mFirstPersonFieldOfView) { bool reverseZ = SceneUtil::AutoDepth::isReversed(); auto lightingMethod = SceneUtil::LightManager::getLightingMethodFromString( @@ -565,12 +564,11 @@ namespace MWRender osg::Camera::CullingMode cullingMode = osg::Camera::DEFAULT_CULLING | osg::Camera::FAR_PLANE_CULLING; - if (!Settings::Manager::getBool("small feature culling", "Camera")) + if (!Settings::camera().mSmallFeatureCulling) cullingMode &= ~(osg::CullStack::SMALL_FEATURE_CULLING); else { - mViewer->getCamera()->setSmallFeatureCullingPixelSize( - Settings::Manager::getFloat("small feature culling pixel size", "Camera")); + mViewer->getCamera()->setSmallFeatureCullingPixelSize(Settings::camera().mSmallFeatureCullingPixelSize); cullingMode |= osg::CullStack::SMALL_FEATURE_CULLING; } @@ -1365,7 +1363,7 @@ namespace MWRender { if (it->first == "Camera" && it->second == "field of view") { - mFieldOfView = Settings::Manager::getFloat("field of view", "Camera"); + mFieldOfView = Settings::camera().mFieldOfView; updateProjection = true; } else if (it->first == "Video" && (it->second == "resolution x" || it->second == "resolution y")) @@ -1374,7 +1372,7 @@ namespace MWRender } else if (it->first == "Camera" && it->second == "viewing distance") { - setViewDistance(Settings::Manager::getFloat("viewing distance", "Camera")); + setViewDistance(Settings::camera().mViewingDistance); } else if (it->first == "General" && (it->second == "texture filter" || it->second == "texture mipmap" || it->second == "anisotropy")) diff --git a/apps/openmw/mwrender/screenshotmanager.cpp b/apps/openmw/mwrender/screenshotmanager.cpp index 87fb705187..80248907ca 100644 --- a/apps/openmw/mwrender/screenshotmanager.cpp +++ b/apps/openmw/mwrender/screenshotmanager.cpp @@ -13,12 +13,11 @@ #include #include #include +#include #include #include #include -#include - #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwgui/loadingscreen.hpp" @@ -341,8 +340,8 @@ namespace MWRender void ScreenshotManager::makeCubemapScreenshot(osg::Image* image, int w, int h, const osg::Matrixd& cameraTransform) { osg::ref_ptr rttCamera(new osg::Camera); - float nearClip = Settings::Manager::getFloat("near clip", "Camera"); - float viewDistance = Settings::Manager::getFloat("viewing distance", "Camera"); + const float nearClip = Settings::camera().mNearClip; + const float viewDistance = Settings::camera().mViewingDistance; // each cubemap side sees 90 degrees if (SceneUtil::AutoDepth::isReversed()) rttCamera->setProjectionMatrix( diff --git a/components/sceneutil/depth.cpp b/components/sceneutil/depth.cpp index d6fc0172cb..ff623f3786 100644 --- a/components/sceneutil/depth.cpp +++ b/components/sceneutil/depth.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include namespace SceneUtil { @@ -113,7 +113,7 @@ namespace SceneUtil { bool enableReverseZ = false; - if (Settings::Manager::getBool("reverse z", "Camera")) + if (Settings::camera().mReverseZ) { osg::ref_ptr exts = osg::GLExtensions::Get(0, false); if (exts && exts->isClipControlSupported) diff --git a/components/stereo/stereomanager.cpp b/components/stereo/stereomanager.cpp index 348e287d8e..e1973d2b18 100644 --- a/components/stereo/stereomanager.cpp +++ b/components/stereo/stereomanager.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace Stereo { @@ -309,11 +309,8 @@ namespace Stereo void Manager::update() { - double near_ = 1.f; - double far_ = 10000.f; - - near_ = Settings::Manager::getFloat("near clip", "Camera"); - far_ = Settings::Manager::getFloat("viewing distance", "Camera"); + const double near_ = Settings::camera().mNearClip; + const double far_ = Settings::camera().mViewingDistance; if (mUpdateViewCallback) {