// Checked: 2009-06-03 (RLVa-0.2.0h) | Added: RLVa-0.2.0h
void RlvWLSnapshot::restoreSnapshot(const RlvWLSnapshot* pWLSnapshot)
{
	LLWLParamManager* pWLParams = LLWLParamManager::instance();
	if ( (pWLSnapshot) && (pWLParams) )
	{
		pWLParams->mAnimator.mIsRunning = pWLSnapshot->fIsRunning;
		pWLParams->mAnimator.mUseLindenTime = pWLSnapshot->fUseLindenTime;
		pWLParams->mCurParams = pWLSnapshot->WLParams;
		pWLParams->propagateParameters();
	}
}
void RlvWLSnapshot::restoreSnapshot(const RlvWLSnapshot* pWLSnapshot)
{
	LLWLParamManager* pWLParams = LLWLParamManager::getInstance();
	if ( (pWLSnapshot) && (pWLParams) )
	{
		if (pWLSnapshot->fIsRunning)
		{
			pWLParams->mAnimator.activate(pWLSnapshot->fUseLindenTime ? LLWLAnimator::TIME_LINDEN : LLWLAnimator::TIME_CUSTOM);
		}
		pWLParams->mCurParams = pWLSnapshot->WLParams;
		pWLParams->propagateParameters();
	}
}
// static
void FSLightshare::processSky(LightsharePacket* ls_packet)
{
	LLWLParamManager* wlparammgr = LLWLParamManager::getInstance();
	wlparammgr->mAnimator.deactivate();
	LLWLParamSet & param_set = wlparammgr->mCurParams;
	
	param_set.setSunAngle(F_TWO_PI * ls_packet->sunMoonPosiiton);
	param_set.setEastAngle(F_TWO_PI * ls_packet->eastAngle);
	param_set.set("sunlight_color", ls_packet->sunMoonColor.red * 3.0f, ls_packet->sunMoonColor.green * 3.0f, ls_packet->sunMoonColor.blue * 3.0f, ls_packet->sunMoonColor.alpha * 3.0f);
	param_set.set("ambient", ls_packet->ambient.red * 3.0f, ls_packet->ambient.green * 3.0f, ls_packet->ambient.blue * 3.0f, ls_packet->ambient.alpha * 3.0f);
	param_set.set("blue_horizon", ls_packet->horizon.red * 2.0f, ls_packet->horizon.green *2.0f, ls_packet->horizon.blue * 2.0f, ls_packet->horizon.alpha * 2.0f);
	param_set.set("blue_density", ls_packet->blueDensity.red * 2.0f, ls_packet->blueDensity.green * 2.0f, ls_packet->blueDensity.blue * 2.0f, ls_packet->blueDensity.alpha * 2.0f);
	param_set.set("haze_horizon", ls_packet->hazeHorizon, ls_packet->hazeHorizon, ls_packet->hazeHorizon, 1.f);
	param_set.set("haze_density", ls_packet->hazeDensity, ls_packet->hazeDensity, ls_packet->hazeDensity, 1.f);
	param_set.set("cloud_shadow", ls_packet->cloudCoverage, ls_packet->cloudCoverage, ls_packet->cloudCoverage, ls_packet->cloudCoverage);
	param_set.set("density_multiplier", ls_packet->densityMultiplier / 1000.0f);
	param_set.set("distance_multiplier", ls_packet->distanceMultiplier, ls_packet->distanceMultiplier, ls_packet->distanceMultiplier, ls_packet->distanceMultiplier);
	param_set.set("max_y",(F32)ls_packet->maxAltitude);
	param_set.set("cloud_color", ls_packet->cloudColor.red, ls_packet->cloudColor.green, ls_packet->cloudColor.blue, ls_packet->cloudColor.alpha);
	param_set.set("cloud_pos_density1", ls_packet->cloudXYDensity.X, ls_packet->cloudXYDensity.Y, ls_packet->cloudXYDensity.Z);
	param_set.set("cloud_pos_density2", ls_packet->cloudDetailXYDensity.X, ls_packet->cloudDetailXYDensity.Y, ls_packet->cloudDetailXYDensity.Z);
	param_set.set("cloud_scale", ls_packet->cloudScale, 0.f, 0.f, 1.f);
	param_set.set("gamma", ls_packet->sceneGamma, ls_packet->sceneGamma, ls_packet->sceneGamma, 0.0f);
	param_set.set("glow",(2 - ls_packet->sunGlowSize) * 20 , 0.f, -ls_packet->sunGlowFocus * 5);
	param_set.setCloudScrollX(ls_packet->cloudScrollX + 10.0f);
	param_set.setCloudScrollY(ls_packet->cloudScrollY + 10.0f);
	param_set.setEnableCloudScrollX(!ls_packet->cloudScrollXLock);
	param_set.setEnableCloudScrollY(!ls_packet->cloudScrollYLock);
	param_set.setStarBrightness(ls_packet->starBrightness);
	
	LLWLParamKey ls_key;
	ls_key.name = "LightshareCurrentRegion";
	ls_key.scope = LLEnvKey::SCOPE_LOCAL;
	wlparammgr->setParamSet(ls_key, param_set);
	
	wlparammgr->propagateParameters();
}
Ejemplo n.º 4
0
// Checked: 2009-09-16 (RLVa-1.0.3c) | Modified: RLVa-1.0.3c
ERlvCmdRet RlvExtGetSet::onSetEnv(std::string strSetting, const std::string& strValue)
{
	// HACK: see RlvExtGetSet::onGetEnv
	if (!LLFloaterWindLight::isOpen())
	{
		LLFloaterWindLight::instance()->close();
		LLFloaterWindLight::instance()->syncMenu();
	}

	LLWLParamManager* pWLParams = LLWLParamManager::instance();
	WLFloatControl* pFloat = NULL;
	WLColorControl* pColour = NULL;

	F32 nValue = 0.0f;
	// Sanity check - make sure strValue specifies a number for all settings except "preset"
	if ( (RlvSettings::getNoSetEnv()) || ( (!LLStringUtil::convertToF32(strValue, nValue)) && ("preset" != strSetting) ))
		return RLV_RET_FAILED_OPTION;

	// Not quite correct, but RLV-1.16.0 will halt the default daytime cycle on invalid commands so we need to as well
	pWLParams->mAnimator.deactivate();
	//pWLParams->mAnimator.mUseLindenTime = false;

	// See LLWorldEnvSettings::handleEvent()
	if ("daytime" == strSetting)
	{
		if (0.0f <= nValue)
		{
			pWLParams->mAnimator.setDayTime(llmin(nValue, 1.0f));
			pWLParams->mAnimator.update(pWLParams->mCurParams);
		}
		else
		{
			pWLParams->mAnimator.activate(LLWLAnimator::TIME_LINDEN);	
		}
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onChangePresetName()
	else if ("preset" == strSetting)
	{
		// LLEnvManagerNew manages using presets now -KC
		//pWLParams->loadPreset(strValue, true);
		LLEnvManagerNew::instance().useSkyPreset(strValue);
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onStarAlphaMoved
	else if ("starbrightness" == strSetting)
	{
		pWLParams->mCurParams.setStarBrightness(nValue);
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onGlowRMoved() / LLFloaterWindLight::onGlowBMoved()
	else if ( ("sunglowfocus" == strSetting) || ("sunglowsize" == strSetting) )
	{
		WLColorControl *pColour = &pWLParams->mGlow;
		if ("sunglowfocus" == strSetting) 
			pColour->b = -nValue * 5;
		else
			pColour->r = (2 - nValue) * 20;

		pColour->update(pWLParams->mCurParams);
		pWLParams->propagateParameters();
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onSunMoved()
	else if ( ("eastangle" == strSetting) || ("sunmoonposition" == strSetting) )	
	{
		if ("eastangle" == strSetting)	
			pWLParams->mCurParams.setEastAngle(F_TWO_PI * nValue);
		else
			pWLParams->mCurParams.setSunAngle(F_TWO_PI * nValue);

		// TODO-RLVa: it looks like propagateParameters() will actually take care of this for us, making this redundant?
		WLColorControl* pColour = &pWLParams->mLightnorm;
		pColour->r = -sin(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
		pColour->g = sin(pWLParams->mCurParams.getSunAngle());
		pColour->b = cos(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
		pColour->i = 1.f;

		pColour->update(pWLParams->mCurParams);
		pWLParams->propagateParameters();
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onCloudScrollXMoved() / LLFloaterWindLight::onCloudScrollYMoved() 
	else if ("cloudscrollx" == strSetting)
	{
		pWLParams->mCurParams.setCloudScrollX(nValue + 10.0f);
		return RLV_RET_SUCCESS;
	}
	else if ("cloudscrolly" == strSetting)
	{
		pWLParams->mCurParams.setCloudScrollY(nValue + 10.0f);
		return RLV_RET_SUCCESS;
	}
	// See LLFloaterWindLight::onFloatControlMoved()
	else if ("cloudcoverage" == strSetting)			pFloat = &pWLParams->mCloudCoverage;
	else if ("cloudscale" == strSetting)			pFloat = &pWLParams->mCloudScale;
	else if ("densitymultiplier" == strSetting)		pFloat = &pWLParams->mDensityMult;
	else if ("distancemultiplier" == strSetting)	pFloat = &pWLParams->mDistanceMult;
	else if ("maxaltitude" == strSetting)			pFloat = &pWLParams->mMaxAlt;
	else if ("scenegamma" == strSetting)			pFloat = &pWLParams->mWLGamma;
	// See LLFloaterWindLight::onColorControlRMoved()
	else if ("hazedensity" == strSetting)	pColour = &pWLParams->mHazeDensity;
	else if ("hazehorizon" == strSetting)	pColour = &pWLParams->mHazeHorizon;

	if (pFloat)
	{
		pFloat->x = nValue / pFloat->mult;
		pFloat->update(pWLParams->mCurParams);
		pWLParams->propagateParameters();
		return RLV_RET_SUCCESS;
	} 
	else if (pColour)
	{
		pColour->r = nValue;
		pColour->update(pWLParams->mCurParams);
		pWLParams->propagateParameters();
		return RLV_RET_SUCCESS;
	}

	// RGBI settings
	char ch = strSetting[strSetting.length() - 1];
	if ('x' == ch)		ch = 'r';
	else if ('y' == ch)	ch = 'g';
	else if ('d' == ch)	ch = 'b';

	if ( ('r' == ch) || ('g' == ch) || ('b' == ch) || ('i' == ch) )
	{
		strSetting.erase(strSetting.length() - 1, 1);
		
		if ("ambient" == strSetting)			pColour = &pWLParams->mAmbient;
		else if ("bluedensity" == strSetting)	pColour = &pWLParams->mBlueDensity;
		else if ("bluehorizon" == strSetting)	pColour = &pWLParams->mBlueHorizon;
		else if ("sunmooncolor" == strSetting)	pColour = &pWLParams->mSunlight;
		else if ("cloudcolor" == strSetting)	pColour = &pWLParams->mCloudColor;
		else if ("cloud" == strSetting)			pColour = &pWLParams->mCloudMain;
		else if ("clouddetail" == strSetting)	pColour = &pWLParams->mCloudDetail;

		if (pColour)
		{
			if (pColour->isBlueHorizonOrDensity)   nValue *= 2.0f;
			else if (pColour->isSunOrAmbientColor) nValue *= 3.0f;

			if ('i' == ch)									// (See: LLFloaterWindLight::onColorControlIMoved)
			{
				if (!pColour->hasSliderName)
					return RLV_RET_FAILED_UNKNOWN;

				F32 curMax = llmax(pColour->r, pColour->g, pColour->b);
				if ( (0.0f == nValue) || (0.0f == curMax) )
					pColour->r = pColour->g = pColour->b = pColour->i = nValue;
				else
				{
					F32 nDelta = (nValue - curMax) / curMax;
					pColour->r *= (1.0f + nDelta);
					pColour->g *= (1.0f + nDelta);
					pColour->b *= (1.0f + nDelta);
					pColour->i = nValue;
				}
			}
			else											// (See: LLFloaterWindLight::onColorControlRMoved)
			{
				F32* pnValue = ('r' == ch) ? &pColour->r : ('g' == ch) ? &pColour->g : ('b' == ch) ? &pColour->b : NULL;
				if (pnValue)
					*pnValue = nValue;
				pColour->i = llmax(pColour->r, pColour->g, pColour->b);
			}

			pColour->update(pWLParams->mCurParams);
			pWLParams->propagateParameters();

			return RLV_RET_SUCCESS;
		}
	}
	return RLV_RET_FAILED_UNKNOWN;
}
// Checked: 2011-08-29 (RLVa-1.4.1a) | Added: RLVa-1.4.1a
bool RlvWindLight::setValue(const std::string& strRlvName, const std::string& strValue)
{
	F32 nValue = 0.0f;
	// Sanity check - make sure strValue specifies a number for all settings except "preset" and "daycycle"
	if ( (RlvSettings::getNoSetEnv()) || 
		 ( (!LLStringUtil::convertToF32(strValue, nValue)) && (("preset" != strRlvName) && ("daycycle" != strRlvName)) ) )
 	{
		return false;
	}

	LLWLParamManager* pWLParams = LLWLParamManager::getInstance(); 
	LLEnvManagerNew* pEnvMgr = LLEnvManagerNew::getInstance();

	if ("daytime" == strRlvName)
	{
		if (0.0f <= nValue)
		{
			pWLParams->mAnimator.deactivate();
			pWLParams->mAnimator.setDayTime(nValue);
			pWLParams->mAnimator.update(pWLParams->mCurParams);
		}
		else
		{
			pEnvMgr->useRegionSettings();
		}
		return true;
	}
	else if ("preset" == strRlvName)
	{
		std::string strPresetName = pWLParams->findPreset(strValue, LLEnvKey::SCOPE_LOCAL);
		if (!strPresetName.empty())
			pEnvMgr->useSkyPreset(strPresetName);
		return !strPresetName.empty();
	}
	else if ("daycycle" == strRlvName)
	{
		std::string strPresetName = LLDayCycleManager::instance().findPreset(strValue);
		if (!strPresetName.empty())
			pEnvMgr->useDayCycle(strValue, LLEnvKey::SCOPE_LOCAL);
		return !strPresetName.empty();
	}

	bool fError = false;
	pWLParams->mAnimator.deactivate();
	if (("sunglowfocus" == strRlvName) || ("sunglowsize" == strRlvName))
	{
		pWLParams->mGlow = pWLParams->mCurParams.getVector(pWLParams->mGlow.mName, fError);
		RLV_ASSERT_DBG(!fError);

		if ("sunglowfocus" == strRlvName)
			pWLParams->mGlow.b = -nValue * 5;
		else
			pWLParams->mGlow.r = (2 - nValue) * 20;

		pWLParams->mGlow.update(pWLParams->mCurParams);
		pWLParams->propagateParameters();
		return true;
	}
	else if ("starbrightness" == strRlvName)
	{
		pWLParams->mCurParams.setStarBrightness(nValue);
		return true;
	}
	else if (("eastangle" == strRlvName) || ("sunmoonposition" == strRlvName))
	{
		if ("eastangle" == strRlvName)
			pWLParams->mCurParams.setEastAngle(F_TWO_PI * nValue);
		else
			pWLParams->mCurParams.setSunAngle(F_TWO_PI * nValue);

		// Set the sun vector
		pWLParams->mLightnorm.r = -sin(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
		pWLParams->mLightnorm.g = sin(pWLParams->mCurParams.getSunAngle());
		pWLParams->mLightnorm.b = cos(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
		pWLParams->mLightnorm.i = 1.f;

		pWLParams->propagateParameters();
		return true;
	}
	else if ("cloudscrollx" == strRlvName)
	{
		pWLParams->mCurParams.setCloudScrollX(nValue + 10.0f);
		return true;
	}
	else if ("cloudscrolly" == strRlvName)
	{
		pWLParams->mCurParams.setCloudScrollY(nValue + 10.0f);
		return true;
	}

	std::map<std::string, RlvWindLightControl>::iterator itControl = m_ControlLookupMap.find(strRlvName);
	if (m_ControlLookupMap.end() != itControl)
	{
		switch (itControl->second.getControlType())
		{
			case RlvWindLightControl::TYPE_FLOAT:
				return itControl->second.setFloat(nValue);
			case RlvWindLightControl::TYPE_COLOR_R:
				return itControl->second.setColorComponent(RlvWindLightControl::COMPONENT_R, nValue);
			default:
				RLV_ASSERT(false);
		}
	}
	else
	{
		// Couldn't find the exact name, check for a color control name
		RlvWindLightControl::EColorComponent eComponent = RlvWindLightControl::getComponentFromCharacter(strRlvName[strRlvName.length() - 1]);
		if (RlvWindLightControl::COMPONENT_NONE != eComponent)
			itControl = m_ControlLookupMap.find(strRlvName.substr(0, strRlvName.length() - 1));
		if ( (m_ControlLookupMap.end() != itControl) && (itControl->second.isColorType()) )
			return itControl->second.setColorComponent(eComponent, nValue);
	}
	return false;
}