From 486d15b19eb30c5e58f10c9d6f57eef540856fbf Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Tue, 7 Feb 2023 11:30:57 +0100 Subject: [PATCH] moved light common to its own file moved esm4light to it's own file --- apps/opencs/view/render/object.cpp | 3 +- apps/openmw/CMakeLists.txt | 1 + apps/openmw/mwclass/classes.cpp | 1 + apps/openmw/mwclass/light.cpp | 48 ------------------- apps/openmw/mwclass/light.hpp | 26 ----------- apps/openmw/mwclass/light4.cpp | 61 +++++++++++++++++++++++++ apps/openmw/mwclass/light4.hpp | 34 ++++++++++++++ apps/openmw/mwrender/actoranimation.cpp | 3 +- apps/openmw/mwrender/animation.cpp | 7 +-- apps/openmw/mwrender/animation.hpp | 3 +- apps/openmw/mwrender/npcanimation.cpp | 6 +-- components/CMakeLists.txt | 2 +- components/esm/esmbridge.cpp | 28 ------------ components/esm/esmbridge.hpp | 20 -------- components/sceneutil/lightcommon.cpp | 33 +++++++++++++ components/sceneutil/lightcommon.hpp | 38 +++++++++++++++ components/sceneutil/lightutil.cpp | 6 +-- components/sceneutil/lightutil.hpp | 6 +-- 18 files changed, 188 insertions(+), 138 deletions(-) create mode 100644 apps/openmw/mwclass/light4.cpp create mode 100644 apps/openmw/mwclass/light4.hpp create mode 100644 components/sceneutil/lightcommon.cpp create mode 100644 components/sceneutil/lightcommon.hpp diff --git a/apps/opencs/view/render/object.cpp b/apps/opencs/view/render/object.cpp index a933aed12b..4887d0ef3d 100644 --- a/apps/opencs/view/render/object.cpp +++ b/apps/opencs/view/render/object.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -168,7 +169,7 @@ void CSVRender::Object::update() if (light) { bool isExterior = false; // FIXME - SceneUtil::addLight(mBaseNode, ESM::LightCommon(*light), Mask_Lighting, isExterior); + SceneUtil::addLight(mBaseNode, SceneUtil::LightCommon(*light), Mask_Lighting, isExterior); } } diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index cf9d76be4e..294dc9e7b6 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -90,6 +90,7 @@ add_openmw_dir (mwphysics add_openmw_dir (mwclass classes activator creature npc weapon armor potion apparatus book clothing container door ingredient creaturelevlist itemlevlist light lockpick misc probe repair static actor bodypart + light4 ) add_openmw_dir (mwmechanics diff --git a/apps/openmw/mwclass/classes.cpp b/apps/openmw/mwclass/classes.cpp index 076e9670b7..ca4bbee5db 100644 --- a/apps/openmw/mwclass/classes.cpp +++ b/apps/openmw/mwclass/classes.cpp @@ -13,6 +13,7 @@ #include "ingredient.hpp" #include "itemlevlist.hpp" #include "light.hpp" +#include "light4.hpp" #include "lockpick.hpp" #include "misc.hpp" #include "npc.hpp" diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 4fc03c7a76..0465240a65 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -244,52 +244,4 @@ namespace MWClass return ptr.get()->mBase->mSound; } - ESM4Light::ESM4Light() - : MWWorld::RegisteredClass(ESM4::Light::sRecordId) - { - } - - void ESM4Light ::insertObjectRendering( - const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const - { - MWWorld::LiveCellRef* ref = ptr.get(); - - // Insert even if model is empty, so that the light is added - renderingInterface.getObjects().insertModel(ptr, model, !(ref->mBase->mData.flags & ESM4::Light::OffDefault)); - } - - void ESM4Light::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const - { - insertObjectPhysics(ptr, model, rotation, physics); - } - - void ESM4Light::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const - { - physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); - } - - std::string ESM4Light::getModel(const MWWorld::ConstPtr& ptr) const - { - return getClassModel(ptr); - } - - std::string_view ESM4Light ::getName(const MWWorld::ConstPtr& ptr) const - { - return {}; - } - - bool ESM4Light::hasToolTip(const MWWorld::ConstPtr& ptr) const - { - return false; - } - - MWWorld::Ptr ESM4Light::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const - { - const MWWorld::LiveCellRef* ref = ptr.get(); - - return MWWorld::Ptr(cell.insert(ref), &cell); - } - } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index b76b72735f..d2e80a945a 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -79,32 +79,6 @@ namespace MWClass const ESM::RefId& getSound(const MWWorld::ConstPtr& ptr) const override; }; - class ESM4Light : public MWWorld::RegisteredClass - { - friend MWWorld::RegisteredClass; - - ESM4Light(); - - MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override; - - public: - void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model, - MWRender::RenderingInterface& renderingInterface) const override; - ///< Add reference into a cell for rendering - - void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const override; - void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, - MWPhysics::PhysicsSystem& physics) const override; - - std::string_view getName(const MWWorld::ConstPtr& ptr) const override; - ///< \return name or ID; can return an empty string. - - bool hasToolTip(const MWWorld::ConstPtr& ptr) const override; - ///< @return true if this object has a tooltip when focused (default implementation: true) - - std::string getModel(const MWWorld::ConstPtr& ptr) const override; - }; } #endif diff --git a/apps/openmw/mwclass/light4.cpp b/apps/openmw/mwclass/light4.cpp new file mode 100644 index 0000000000..8e3341fbb1 --- /dev/null +++ b/apps/openmw/mwclass/light4.cpp @@ -0,0 +1,61 @@ +#include "light4.hpp" +#include "classmodel.hpp" + +#include "../mwphysics/physicssystem.hpp" +#include "../mwrender/objects.hpp" +#include "../mwrender/renderinginterface.hpp" +#include "../mwworld/cellstore.hpp" +#include "../mwworld/ptr.hpp" + +#include + +namespace MWClass +{ + ESM4Light::ESM4Light() + : MWWorld::RegisteredClass(ESM4::Light::sRecordId) + { + } + + void ESM4Light ::insertObjectRendering( + const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const + { + MWWorld::LiveCellRef* ref = ptr.get(); + + // Insert even if model is empty, so that the light is added + renderingInterface.getObjects().insertModel(ptr, model, !(ref->mBase->mData.flags & ESM4::Light::OffDefault)); + } + + void ESM4Light::insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, + MWPhysics::PhysicsSystem& physics) const + { + insertObjectPhysics(ptr, model, rotation, physics); + } + + void ESM4Light::insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, + MWPhysics::PhysicsSystem& physics) const + { + physics.addObject(ptr, model, rotation, MWPhysics::CollisionType_World); + } + + std::string ESM4Light::getModel(const MWWorld::ConstPtr& ptr) const + { + return getClassModel(ptr); + } + + std::string_view ESM4Light ::getName(const MWWorld::ConstPtr& ptr) const + { + return {}; + } + + bool ESM4Light::hasToolTip(const MWWorld::ConstPtr& ptr) const + { + return false; + } + + MWWorld::Ptr ESM4Light::copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const + { + const MWWorld::LiveCellRef* ref = ptr.get(); + + return MWWorld::Ptr(cell.insert(ref), &cell); + } +} diff --git a/apps/openmw/mwclass/light4.hpp b/apps/openmw/mwclass/light4.hpp new file mode 100644 index 0000000000..6145281298 --- /dev/null +++ b/apps/openmw/mwclass/light4.hpp @@ -0,0 +1,34 @@ +#ifndef OPENW_MWCLASS_LIGHT4 +#define OPENW_MWCLASS_LIGHT4 +#include "../mwworld/registeredclass.hpp" + +namespace MWClass +{ + class ESM4Light : public MWWorld::RegisteredClass + { + friend MWWorld::RegisteredClass; + + ESM4Light(); + + MWWorld::Ptr copyToCellImpl(const MWWorld::ConstPtr& ptr, MWWorld::CellStore& cell) const override; + + public: + void insertObjectRendering(const MWWorld::Ptr& ptr, const std::string& model, + MWRender::RenderingInterface& renderingInterface) const override; + ///< Add reference into a cell for rendering + + void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, + MWPhysics::PhysicsSystem& physics) const override; + void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, + MWPhysics::PhysicsSystem& physics) const override; + + std::string_view getName(const MWWorld::ConstPtr& ptr) const override; + ///< \return name or ID; can return an empty string. + + bool hasToolTip(const MWWorld::ConstPtr& ptr) const override; + ///< @return true if this object has a tooltip when focused (default implementation: true) + + std::string getModel(const MWWorld::ConstPtr& ptr) const override; + }; +} +#endif diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index 5317082b1a..c71e4f0afd 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -557,7 +558,7 @@ namespace MWRender osg::Vec4f ambient(1, 1, 1, 1); osg::ref_ptr lightSource - = SceneUtil::createLightSource(ESM::LightCommon(*esmLight), Mask_Lighting, exterior, ambient); + = SceneUtil::createLightSource(SceneUtil::LightCommon(*esmLight), Mask_Lighting, exterior, ambient); mInsert->addChild(lightSource); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 0d49d1d973..9813c68a06 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -1511,7 +1512,7 @@ namespace MWRender } } - void Animation::addExtraLight(osg::ref_ptr parent, const ESM::LightCommon& esmLight) + void Animation::addExtraLight(osg::ref_ptr parent, const SceneUtil::LightCommon& esmLight) { bool exterior = mPtr.isInCell() && mPtr.getCell()->getCell()->isExterior(); @@ -1855,9 +1856,9 @@ namespace MWRender mObjectRoot, mResourceSystem, ptr.getClass().getEnchantmentColor(ptr)); } if (ptr.getType() == ESM::Light::sRecordId && allowLight) - addExtraLight(getOrCreateObjectRoot(), ESM::LightCommon(*ptr.get()->mBase)); + addExtraLight(getOrCreateObjectRoot(), SceneUtil::LightCommon(*ptr.get()->mBase)); if (ptr.getType() == ESM4::Light::sRecordId && allowLight) - addExtraLight(getOrCreateObjectRoot(), ESM::LightCommon(*ptr.get()->mBase)); + addExtraLight(getOrCreateObjectRoot(), SceneUtil::LightCommon(*ptr.get()->mBase)); if (!allowLight && mObjectRoot) { diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 6c7fb964dd..ac5376fb22 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -30,6 +30,7 @@ namespace SceneUtil class LightSource; class LightListCallback; class Skeleton; + struct LightCommon; } namespace MWRender @@ -333,7 +334,7 @@ namespace MWRender void addSingleAnimSource(const std::string& model, const std::string& baseModel); /** Adds an additional light to the given node using the specified ESM record. */ - void addExtraLight(osg::ref_ptr parent, const ESM::LightCommon& light); + void addExtraLight(osg::ref_ptr parent, const SceneUtil::LightCommon& light); void clearAnimSources(); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 6d59d397ba..7d2a9ec0a4 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -13,7 +13,6 @@ #include -#include #include #include #include @@ -22,6 +21,7 @@ #include #include #include +#include #include #include @@ -665,7 +665,7 @@ namespace MWRender addOrReplaceIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1, Misc::ResourceHelpers::correctMeshPath(light->mModel, vfs), false, nullptr, true); if (mObjectParts[ESM::PRT_Shield]) - addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), ESM::LightCommon(*light)); + addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), SceneUtil::LightCommon(*light)); } } @@ -1043,7 +1043,7 @@ namespace MWRender reserveIndividualPart(ESM::PRT_Shield, MWWorld::InventoryStore::Slot_CarriedLeft, 1); if (iter->getType() == ESM::Light::sRecordId && mObjectParts[ESM::PRT_Shield]) addExtraLight(mObjectParts[ESM::PRT_Shield]->getNode()->asGroup(), - ESM::LightCommon(*iter->get()->mBase)); + SceneUtil::LightCommon(*iter->get()->mBase)); } } else diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 22305abd05..b926ec4b86 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -61,7 +61,7 @@ add_component_dir (sceneutil clone attach visitor util statesetupdater controller skeleton riggeometry morphgeometry lightcontroller lightmanager lightutil positionattitudetransform workqueue pathgridutil waterutil writescene serialize optimizer actorutil detourdebugdraw navmesh agentpath shadow mwshadowtechnique recastmesh shadowsbin osgacontroller rtt - screencapture depth color riggeometryosgaextension extradata unrefqueue + screencapture depth color riggeometryosgaextension extradata unrefqueue lightcommon ) add_component_dir (nif diff --git a/components/esm/esmbridge.cpp b/components/esm/esmbridge.cpp index 2d90530233..2470a837b0 100644 --- a/components/esm/esmbridge.cpp +++ b/components/esm/esmbridge.cpp @@ -1,9 +1,6 @@ #include #include -#include #include -#include -#include namespace ESM { @@ -18,29 +15,4 @@ namespace ESM auto cell = std::get(mVariant); return *cell; } - LightCommon::LightCommon(const ESM::Light& light) - : mFlicker(light.mData.mFlags & ESM::Light::Flicker) - , mFlickerSlow(light.mData.mFlags & ESM::Light::FlickerSlow) - , mNegative(light.mData.mFlags & ESM::Light::Negative) - , mPulse(light.mData.mFlags & ESM::Light::Pulse) - , mPulseSlow(light.mData.mFlags & ESM::Light::PulseSlow) - , mOffDefault(light.mData.mFlags & ESM::Light::OffDefault) - , mColor(SceneUtil::colourFromRGB(light.mData.mColor)) - , mRadius(light.mData.mRadius) - - { - } - LightCommon::LightCommon(const ESM4::Light& light) - : mFlicker(light.mData.flags & ESM4::Light::Flicker) - , mFlickerSlow(light.mData.flags & ESM4::Light::FlickerSlow) - , mNegative(light.mData.flags & ESM::Light::Negative) - , mPulse(light.mData.flags & ESM4::Light::Pulse) - , mPulseSlow(light.mData.flags & ESM4::Light::PulseSlow) - , mOffDefault(light.mData.flags & ESM4::Light::OffDefault) - , mColor(SceneUtil::colourFromRGB(light.mData.colour)) - , mRadius(light.mData.radius) - - { - } - } diff --git a/components/esm/esmbridge.hpp b/components/esm/esmbridge.hpp index 0b54b21f25..5576fccc03 100644 --- a/components/esm/esmbridge.hpp +++ b/components/esm/esmbridge.hpp @@ -4,15 +4,12 @@ #include #include -#include - #include #include namespace ESM4 { struct Cell; - struct Light; } namespace ESM @@ -20,7 +17,6 @@ namespace ESM struct Cell; struct CellId; struct RefId; - struct Light; class CellVariant { @@ -69,22 +65,6 @@ namespace ESM ESM4::Reference& getEsm4() { return std::get(mVariant); } }; - struct LightCommon - { - explicit LightCommon(const ESM::Light& light); - explicit LightCommon(const ESM4::Light& light); - - bool mFlicker; - bool mFlickerSlow; - bool mNegative; - bool mPulse; - bool mPulseSlow; - bool mOffDefault; - - osg::Vec4 mColor; - float mRadius; - }; - template auto visit(F&& f, T&&... v) { diff --git a/components/sceneutil/lightcommon.cpp b/components/sceneutil/lightcommon.cpp new file mode 100644 index 0000000000..03d00811e2 --- /dev/null +++ b/components/sceneutil/lightcommon.cpp @@ -0,0 +1,33 @@ + +#include "lightcommon.hpp" +#include +#include +#include + +namespace SceneUtil +{ + LightCommon::LightCommon(const ESM::Light& light) + : mFlicker(light.mData.mFlags & ESM::Light::Flicker) + , mFlickerSlow(light.mData.mFlags & ESM::Light::FlickerSlow) + , mNegative(light.mData.mFlags & ESM::Light::Negative) + , mPulse(light.mData.mFlags & ESM::Light::Pulse) + , mPulseSlow(light.mData.mFlags & ESM::Light::PulseSlow) + , mOffDefault(light.mData.mFlags & ESM::Light::OffDefault) + , mColor(SceneUtil::colourFromRGB(light.mData.mColor)) + , mRadius(light.mData.mRadius) + + { + } + LightCommon::LightCommon(const ESM4::Light& light) + : mFlicker(light.mData.flags & ESM4::Light::Flicker) + , mFlickerSlow(light.mData.flags & ESM4::Light::FlickerSlow) + , mNegative(light.mData.flags & ESM::Light::Negative) + , mPulse(light.mData.flags & ESM4::Light::Pulse) + , mPulseSlow(light.mData.flags & ESM4::Light::PulseSlow) + , mOffDefault(light.mData.flags & ESM4::Light::OffDefault) + , mColor(SceneUtil::colourFromRGB(light.mData.colour)) + , mRadius(light.mData.radius) + + { + } +} diff --git a/components/sceneutil/lightcommon.hpp b/components/sceneutil/lightcommon.hpp new file mode 100644 index 0000000000..ed86427372 --- /dev/null +++ b/components/sceneutil/lightcommon.hpp @@ -0,0 +1,38 @@ + +#ifndef COMPONENTS_SCENEUTIL_LIGHTCOMMON +#define COMPONENTS_SCENEUTIL_LIGHTCOMMON +#include +#include + +#include + +namespace ESM4 +{ + struct Light; +} + +namespace ESM +{ + struct Light; +} + +namespace SceneUtil +{ + struct LightCommon + { + explicit LightCommon(const ESM::Light& light); + explicit LightCommon(const ESM4::Light& light); + + bool mFlicker; + bool mFlickerSlow; + bool mNegative; + bool mPulse; + bool mPulseSlow; + bool mOffDefault; + + osg::Vec4 mColor; + float mRadius; + }; + +} +#endif diff --git a/components/sceneutil/lightutil.cpp b/components/sceneutil/lightutil.cpp index 42a72670f8..940c7c3ceb 100644 --- a/components/sceneutil/lightutil.cpp +++ b/components/sceneutil/lightutil.cpp @@ -5,9 +5,9 @@ #include -#include #include #include +#include #include "lightcontroller.hpp" #include "lightmanager.hpp" @@ -87,7 +87,7 @@ namespace SceneUtil } osg::ref_ptr addLight( - osg::Group* node, const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior) + osg::Group* node, const SceneUtil::LightCommon& esmLight, unsigned int lightMask, bool isExterior) { SceneUtil::FindByNameVisitor visitor("AttachLight"); node->accept(visitor); @@ -106,7 +106,7 @@ namespace SceneUtil } osg::ref_ptr createLightSource( - const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient) + const SceneUtil::LightCommon& esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient) { osg::ref_ptr lightSource(new SceneUtil::LightSource); osg::ref_ptr light(new osg::Light); diff --git a/components/sceneutil/lightutil.hpp b/components/sceneutil/lightutil.hpp index dd6a1abb63..5dcbfa3c56 100644 --- a/components/sceneutil/lightutil.hpp +++ b/components/sceneutil/lightutil.hpp @@ -13,12 +13,12 @@ namespace osg namespace ESM { struct Light; - struct LightCommon; } namespace SceneUtil { class LightSource; + struct LightCommon; /// @brief Set up global attenuation settings for an osg::Light. /// @param radius The radius of the light source. @@ -33,14 +33,14 @@ namespace SceneUtil /// @param lightMask Mask to assign to the newly created LightSource. /// @param isExterior Is the light outside? May be used for deciding which attenuation settings to use. osg::ref_ptr addLight( - osg::Group* node, const ESM::LightCommon& esmLight, unsigned int lightMask, bool isExterior); + osg::Group* node, const SceneUtil::LightCommon& esmLight, unsigned int lightMask, bool isExterior); /// @brief Convert an ESM::Light to a SceneUtil::LightSource, and return it. /// @param esmLight The light definition coming from the game files containing radius, color, flicker, etc. /// @param lightMask Mask to assign to the newly created LightSource. /// @param isExterior Is the light outside? May be used for deciding which attenuation settings to use. /// @param ambient Ambient component of the light. - osg::ref_ptr createLightSource(const ESM::LightCommon& esmLight, unsigned int lightMask, + osg::ref_ptr createLightSource(const SceneUtil::LightCommon& esmLight, unsigned int lightMask, bool isExterior, const osg::Vec4f& ambient = osg::Vec4f(0, 0, 0, 1)); }