diff --git a/indra/newview/rlvenvironment.cpp b/indra/newview/rlvenvironment.cpp index 91e043da23..9372ec878d 100644 --- a/indra/newview/rlvenvironment.cpp +++ b/indra/newview/rlvenvironment.cpp @@ -472,6 +472,28 @@ LLEnvironment::EnvSelection_t RlvEnvironment::getTargetEnvironment() return RlvActions::canChangeEnvironment() ? LLEnvironment::ENV_LOCAL : LLEnvironment::ENV_EDIT; } +// static +LLSettingsSky::ptr_t RlvEnvironment::getTargetSky(bool forSetCmd) +{ + LLEnvironment* pEnv = LLEnvironment::getInstance(); + + if (forSetCmd) + { + bool isSharedEnv = !pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL), hasLocalDayCycle = !isSharedEnv && pEnv->getEnvironmentDay(LLEnvironment::ENV_LOCAL); + if ((isSharedEnv) || (hasLocalDayCycle)) + { + LLSettingsSky::ptr_t pSky = (isSharedEnv) ? pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_PARCEL, true)->buildClone() + : pEnv->getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL)->buildClone(); + pEnv->setEnvironment(LLEnvironment::ENV_LOCAL, pSky); + pEnv->setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT); + pEnv->updateEnvironment(LLEnvironment::TRANSITION_INSTANT); + } + } + + return pEnv->getCurrentSky(); +} + + // static bool RlvEnvironment::onHandleCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet, const std::string& strCmdPrefix, const handler_map_t& fnLookup, const legacy_handler_map_t& legacyFnLookup) { @@ -517,21 +539,21 @@ bool RlvEnvironment::onForceCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); return std::to_string(fn(pSky)); } template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); return fn(pSky).asString(); } template<> std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); LLVector2 replyVec = fn(pSky); return llformat("%f/%f", replyVec.mV[VX], replyVec.mV[VY]); } @@ -539,7 +561,7 @@ std::string RlvEnvironment::handleGetFn(const std::function std::string RlvEnvironment::handleGetFn(const std::function& fn) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(); LLColor3 replyColor = fn(pSky); return llformat("%f/%f/%f", replyColor.mV[VX], replyColor.mV[VY], replyColor.mV[VZ]); } @@ -551,7 +573,7 @@ ERlvCmdRet RlvEnvironment::handleSetFn(const std::string& strRlvOption, const st if (!RlvCommandOptionHelper::parseOption(strRlvOption, optionValue)) return RLV_RET_FAILED_PARAM; - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); fn(pSky, optionValue); pSky->update(); return RLV_RET_SUCCESS; @@ -562,7 +584,7 @@ std::string RlvEnvironment::handleLegacyGetFn(const std::function= 2) return LLStringUtil::null; - return std::to_string(getFn(LLEnvironment::instance().getCurrentSky()).mV[idxComponent]); + return std::to_string(getFn(getTargetSky()).mV[idxComponent]); } template<> @@ -570,11 +592,11 @@ std::string RlvEnvironment::handleLegacyGetFn(const std::function= VRED) && (idxComponent <= VBLUE) ) { - return std::to_string(getFn(LLEnvironment::instance().getCurrentSky()).mV[idxComponent]); + return std::to_string(getFn(getTargetSky()).mV[idxComponent]); } else if (idxComponent == VALPHA) { - const LLColor3& clr = getFn(LLEnvironment::instance().getCurrentSky()); + const LLColor3& clr = getFn(getTargetSky()); return std::to_string(llmax(clr.mV[VRED], clr.mV[VGREEN], clr.mV[VBLUE])); } return LLStringUtil::null; @@ -586,7 +608,7 @@ ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLVec if (idxComponent >= 2) return RLV_RET_FAILED_UNKNOWN; - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); curValue.mV[idxComponent] = optionValue; setFn(pSky, curValue); pSky->update(); @@ -597,7 +619,7 @@ ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLVec template<> ERlvCmdRet RlvEnvironment::handleLegacySetFn(float optionValue, LLColor3 curValue, const std::function& setFn, U32 idxComponent) { - LLSettingsSky::ptr_t pSky = LLEnvironment::instance().getCurrentSky(); + LLSettingsSky::ptr_t pSky = getTargetSky(true); if ( (idxComponent >= VRED) && (idxComponent <= VBLUE) ) { curValue.mV[idxComponent] = optionValue; @@ -691,7 +713,7 @@ void RlvEnvironment::registerLegacySkyFn(const std::string& strFnName, const std float optionValue; if (!RlvCommandOptionHelper::parseOption(strRlvOption, optionValue)) return RLV_RET_FAILED_PARAM; - return handleLegacySetFn(optionValue, getFn(LLEnvironment::instance().getCurrentSky()), setFn, idxComponent);; + return handleLegacySetFn(optionValue, getFn(getTargetSky(true)), setFn, idxComponent);; })); } diff --git a/indra/newview/rlvenvironment.h b/indra/newview/rlvenvironment.h index 2d19ab2341..146160ea79 100644 --- a/indra/newview/rlvenvironment.h +++ b/indra/newview/rlvenvironment.h @@ -34,6 +34,7 @@ public: bool onForceCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet) override; protected: static LLEnvironment::EnvSelection_t getTargetEnvironment(); + static LLSettingsSky::ptr_t getTargetSky(bool forSetCmd = false); typedef std::map> handler_map_t; typedef std::map> legacy_handler_map_t; static bool onHandleCommand(const RlvCommand& rlvCmd, ERlvCmdRet& cmdRet, const std::string& strCmdPrefix, const handler_map_t& fnLookup, const legacy_handler_map_t& legacyFnLookup);