From 7573004efc47ac9a6bc9e35653ec3e98106b6b69 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Jul 2023 18:00:15 +0200 Subject: [PATCH 1/2] Implement the NegativeLight flag --- apps/openmw/mwrender/animation.cpp | 10 +++------- apps/openmw/mwworld/projectilemanager.cpp | 15 ++++----------- components/esm3/loadmgef.cpp | 8 ++++++++ components/esm3/loadmgef.hpp | 6 +++++- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 115f49a0b1..5de63030c3 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1490,11 +1490,6 @@ namespace MWRender void Animation::addSpellCastGlow(const ESM::MagicEffect* effect, float glowDuration) { - osg::Vec4f glowColor(1, 1, 1, 1); - glowColor.x() = effect->mData.mRed / 255.f; - glowColor.y() = effect->mData.mGreen / 255.f; - glowColor.z() = effect->mData.mBlue / 255.f; - if (!mGlowUpdater || (mGlowUpdater->isDone() || (mGlowUpdater->isPermanentGlowUpdater() == true))) { if (mGlowUpdater && mGlowUpdater->isDone()) @@ -1502,11 +1497,12 @@ namespace MWRender if (mGlowUpdater && mGlowUpdater->isPermanentGlowUpdater()) { - mGlowUpdater->setColor(glowColor); + mGlowUpdater->setColor(effect->getColor()); mGlowUpdater->setDuration(glowDuration); } else - mGlowUpdater = SceneUtil::addEnchantedGlow(mObjectRoot, mResourceSystem, glowColor, glowDuration); + mGlowUpdater + = SceneUtil::addEnchantedGlow(mObjectRoot, mResourceSystem, effect->getColor(), glowDuration); } } diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 785b19ea82..4fdcb4de31 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -136,21 +136,14 @@ namespace { // Calculate combined light diffuse color from magical effects osg::Vec4 lightDiffuseColor; - float lightDiffuseRed = 0.0f; - float lightDiffuseGreen = 0.0f; - float lightDiffuseBlue = 0.0f; - for (std::vector::const_iterator iter(effects.mList.begin()); iter != effects.mList.end(); - ++iter) + for (const ESM::ENAMstruct& enam : effects.mList) { const ESM::MagicEffect* magicEffect - = MWBase::Environment::get().getESMStore()->get().find(iter->mEffectID); - lightDiffuseRed += (static_cast(magicEffect->mData.mRed) / 255.f); - lightDiffuseGreen += (static_cast(magicEffect->mData.mGreen) / 255.f); - lightDiffuseBlue += (static_cast(magicEffect->mData.mBlue) / 255.f); + = MWBase::Environment::get().getESMStore()->get().find(enam.mEffectID); + lightDiffuseColor += magicEffect->getColor(); } int numberOfEffects = effects.mList.size(); - lightDiffuseColor = osg::Vec4(lightDiffuseRed / numberOfEffects, lightDiffuseGreen / numberOfEffects, - lightDiffuseBlue / numberOfEffects, 1.0f); + lightDiffuseColor /= numberOfEffects; return lightDiffuseColor; } diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 68225d44ef..7d3879a341 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -603,6 +603,14 @@ namespace ESM mDescription.clear(); } + osg::Vec4f MagicEffect::getColor() const + { + osg::Vec4f color{ mData.mRed / 255.f, mData.mGreen / 255.f, mData.mBlue / 255.f, 1.f }; + if (mData.mFlags & NegativeLight) + return osg::Vec4f(1.f, 1.f, 1.f, 2.f) - color; + return color; + } + const std::string& MagicEffect::indexToGmstString(int effectID) { if (effectID < 0 || static_cast(effectID) >= sGmstEffectIds.size()) diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index 1b4089e74a..9d68bad609 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -10,6 +10,8 @@ #include "components/esm/refid.hpp" #include "components/misc/strings/algorithm.hpp" +#include + namespace ESM { @@ -55,7 +57,7 @@ namespace ESM // Originally modifiable flags AllowSpellmaking = 0x200, // Can be used for spellmaking AllowEnchanting = 0x400, // Can be used for enchanting - NegativeLight = 0x800 // Unused + NegativeLight = 0x800 // Inverts the effect's color }; enum MagnitudeDisplayType @@ -113,6 +115,8 @@ namespace ESM /// Set record to default state (does not touch the ID/index). void blank(); + osg::Vec4f getColor() const; + enum Effects { WaterBreathing = 0, From 2fa9462d49aef17609912da7d5c82db550535058 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Jul 2023 19:46:12 +0200 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccd063ddbd..a0b64d26f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ Feature #7148: Optimize string literal lookup in mwscript Feature #7194: Ori to show texture paths Feature #7214: Searching in the in-game console + Feature #7477: NegativeLight Magic Effect flag Task #7113: Move from std::atoi to std::from_char Task #7117: Replace boost::scoped_array with std::vector Task #7151: Do not use std::strerror to get errno error message