From f175beb3047d97dffabc3caa9ffc57746760060a Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 13 Jan 2021 13:33:46 +0400 Subject: [PATCH 1/3] Define template ref classes in components --- apps/openmw/mwrender/objectpaging.cpp | 13 ++----------- components/resource/scenemanager.cpp | 18 ++++-------------- components/resource/scenemanager.hpp | 25 +++++++++++++++++++++++++ components/sceneutil/serialize.cpp | 1 + 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index a5015f377..d8e856e76 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -249,15 +249,6 @@ namespace MWRender } }; - class TemplateRef : public osg::Object - { - public: - TemplateRef() {} - TemplateRef(const TemplateRef& copy, const osg::CopyOp&) : mObjects(copy.mObjects) {} - META_Object(MWRender, TemplateRef) - std::vector> mObjects; - }; - class RefnumSet : public osg::Object { public: @@ -530,7 +521,7 @@ namespace MWRender osg::ref_ptr group = new osg::Group; osg::ref_ptr mergeGroup = new osg::Group; - osg::ref_ptr templateRefs = new TemplateRef; + osg::ref_ptr templateRefs = new Resource::TemplateMultiRef; osgUtil::StateToCompile stateToCompile(0, nullptr); CopyOp copyop; for (const auto& pair : nodes) @@ -596,7 +587,7 @@ namespace MWRender if (numinstances > 0) { // add a ref to the original template, to hint to the cache that it's still being used and should be kept in cache - templateRefs->mObjects.emplace_back(cnode); + templateRefs->addRef(cnode); if (pair.second.mNeedCompile) { diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp index 2630cd453..e75fa4f74 100644 --- a/components/resource/scenemanager.cpp +++ b/components/resource/scenemanager.cpp @@ -110,6 +110,10 @@ namespace namespace Resource { + void TemplateMultiRef::addRef(const osg::Node* node) + { + mObjects.emplace_back(node); + } class SharedStateManager : public osgDB::SharedStateManager { @@ -554,20 +558,6 @@ namespace Resource return node; } - class TemplateRef : public osg::Object - { - public: - TemplateRef(const Object* object) - : mObject(object) {} - TemplateRef() {} - TemplateRef(const TemplateRef& copy, const osg::CopyOp&) : mObject(copy.mObject) {} - - META_Object(Resource, TemplateRef) - - private: - osg::ref_ptr mObject; - }; - osg::ref_ptr SceneManager::createInstance(const std::string& name) { osg::ref_ptr scene = getTemplate(name); diff --git a/components/resource/scenemanager.hpp b/components/resource/scenemanager.hpp index fd75070a1..e897566a8 100644 --- a/components/resource/scenemanager.hpp +++ b/components/resource/scenemanager.hpp @@ -37,6 +37,31 @@ namespace Shader namespace Resource { + class TemplateRef : public osg::Object + { + public: + TemplateRef(const Object* object) : mObject(object) {} + TemplateRef() {} + TemplateRef(const TemplateRef& copy, const osg::CopyOp&) : mObject(copy.mObject) {} + + META_Object(Resource, TemplateRef) + + private: + osg::ref_ptr mObject; + }; + + class TemplateMultiRef : public osg::Object + { + public: + TemplateMultiRef() {} + TemplateMultiRef(const TemplateMultiRef& copy, const osg::CopyOp&) : mObjects(copy.mObjects) {} + void addRef(const osg::Node* node); + + META_Object(Resource, TemplateMultiRef) + + private: + std::vector> mObjects; + }; class MultiObjectCache; diff --git a/components/sceneutil/serialize.cpp b/components/sceneutil/serialize.cpp index d03612fc1..7e176be3d 100644 --- a/components/sceneutil/serialize.cpp +++ b/components/sceneutil/serialize.cpp @@ -121,6 +121,7 @@ void registerSerializers() const char* ignore[] = { "MWRender::PtrHolder", "Resource::TemplateRef", + "Resource::TemplateMultiRef", "SceneUtil::CompositeStateSetUpdater", "SceneUtil::LightListCallback", "SceneUtil::LightManagerUpdateCallback", From 0418e8e7a6eccef17a6995470d4f9ce2e95d1106 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 13 Jan 2021 13:41:02 +0400 Subject: [PATCH 2/3] Add an API to get base wind speed (which is from openmw.cfg) --- apps/openmw/mwrender/sky.cpp | 9 +++++++++ apps/openmw/mwrender/sky.hpp | 4 ++++ apps/openmw/mwworld/weather.cpp | 2 ++ 3 files changed, 15 insertions(+) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 2920e07dd..93061022c 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -1134,6 +1134,7 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana , mRainEntranceSpeed(1) , mRainMaxRaindrops(0) , mWindSpeed(0.f) + , mBaseWindSpeed(0.f) , mEnabled(true) , mSunEnabled(true) , mWeatherAlpha(0.f) @@ -1685,6 +1686,7 @@ void SkyManager::setWeather(const WeatherResult& weather) mRainMaxHeight = weather.mRainMaxHeight; mRainSpeed = weather.mRainSpeed; mWindSpeed = weather.mWindSpeed; + mBaseWindSpeed = weather.mBaseWindSpeed; if (mRainEffect != weather.mRainEffect) { @@ -1853,6 +1855,13 @@ void SkyManager::setWeather(const WeatherResult& weather) fader->setAlpha(weather.mEffectFade); } +float SkyManager::getBaseWindSpeed() const +{ + if (!mCreated) return 0.f; + + return mBaseWindSpeed; +} + void SkyManager::sunEnable() { if (!mCreated) return; diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index cf697bd44..2ec134d09 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -70,6 +70,7 @@ namespace MWRender float mDLFogOffset; float mWindSpeed; + float mBaseWindSpeed; float mCurrentWindSpeed; float mNextWindSpeed; @@ -181,6 +182,8 @@ namespace MWRender void setRainIntensityUniform(osg::Uniform *uniform); + float getBaseWindSpeed() const; + private: void create(); ///< no need to call this, automatically done on first enable() @@ -265,6 +268,7 @@ namespace MWRender float mRainEntranceSpeed; int mRainMaxRaindrops; float mWindSpeed; + float mBaseWindSpeed; bool mEnabled; bool mSunEnabled; diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 6a4a227a4..415e69d20 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -1123,6 +1123,7 @@ inline void WeatherManager::calculateResult(const int weatherID, const float gam mResult.mCloudBlendFactor = 0; mResult.mNextWindSpeed = 0; mResult.mWindSpeed = mResult.mCurrentWindSpeed = calculateWindSpeed(weatherID, mWindSpeed); + mResult.mBaseWindSpeed = mWeatherSettings[weatherID].mWindSpeed; mResult.mCloudSpeed = current.mCloudSpeed; mResult.mGlareView = current.mGlareView; @@ -1214,6 +1215,7 @@ inline void WeatherManager::calculateTransitionResult(const float factor, const mResult.mCurrentWindSpeed = calculateWindSpeed(mCurrentWeather, mCurrentWindSpeed); mResult.mNextWindSpeed = calculateWindSpeed(mNextWeather, mNextWindSpeed); + mResult.mBaseWindSpeed = lerp(current.mBaseWindSpeed, other.mBaseWindSpeed, factor); mResult.mWindSpeed = lerp(mResult.mCurrentWindSpeed, mResult.mNextWindSpeed, factor); mResult.mCloudSpeed = lerp(current.mCloudSpeed, other.mCloudSpeed, factor); From 89f3f860ed99ce1b19c4ee3ec07373ad2f4cdcf1 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 13 Jan 2021 13:57:05 +0400 Subject: [PATCH 3/3] Allow to get a rotation vector from ESM::Position --- components/esm/defs.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 0f9cefab1..9bf9b01f3 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -54,6 +54,11 @@ struct Position { return osg::Vec3f(pos[0], pos[1], pos[2]); } + + osg::Vec3f asRotationVec3() const + { + return osg::Vec3f(rot[0], rot[1], rot[2]); + } }; #pragma pack(pop)