// This is really really horrible, but can't be fixed without a rewrite.
void LLWLParamManager::initHack()
{
	// load the day
	std::string preferred_day = LLEnvManagerNew::instance().getDayCycleName();
	if (!LLDayCycleManager::instance().getPreset(preferred_day, mDay))
	{
		// Fall back to default.
		llwarns << "No day cycle named " << preferred_day << ", falling back to defaults" << llendl;
		mDay.loadDayCycleFromFile("Default.xml");

		// *TODO: Fix user preferences accordingly.
	}

	// *HACK - sets cloud scrolling to what we want... fix this better in the future
	std::string sky = LLEnvManagerNew::instance().getSkyPresetName();
	if (!getParamSet(LLWLParamKey(sky, LLWLParamKey::SCOPE_LOCAL), mCurParams))
	{
		llwarns << "No sky preset named " << sky << ", falling back to defaults" << llendl;
		getParamSet(LLWLParamKey("Default", LLWLParamKey::SCOPE_LOCAL), mCurParams);

		// *TODO: Fix user preferences accordingly.
	}

	// set it to noon
	resetAnimator(0.5, LLEnvManagerNew::instance().getUseDayCycle());

	// but use linden time sets it to what the estate is
	mAnimator.setTimeType(LLWLAnimator::TIME_LINDEN);

	// This shouldn't be called here. It has nothing to do with the initialization of this singleton.
	// Instead, call it one-time when the viewer starts. Calling it here causes a recursive entry
	// of LLWLParamManager::initSingleton().
	//LLEnvManagerNew::instance().usePrefs();
}
// static
void LLWLParamManager::initSingleton()
{
	LL_DEBUGS("Windlight") << "Initializing sky" << LL_ENDL;

	loadAllPresets();

	// load the day
	std::string preferred_day = LLEnvManagerNew::instance().getDayCycleName();
	if (!LLDayCycleManager::instance().getPreset(preferred_day, mDay))
	{
		// Fall back to default.
		llwarns << "No day cycle named " << preferred_day << ", falling back to defaults" << llendl;
		mDay.loadDayCycleFromFile("Default.xml");

		// *TODO: Fix user preferences accordingly.
	}

	// *HACK - sets cloud scrolling to what we want... fix this better in the future
	std::string sky = LLEnvManagerNew::instance().getSkyPresetName();
	if (!getParamSet(LLWLParamKey(sky, LLWLParamKey::SCOPE_LOCAL), mCurParams))
	{
		llwarns << "No sky preset named " << sky << ", falling back to defaults" << llendl;
		getParamSet(LLWLParamKey("Default", LLWLParamKey::SCOPE_LOCAL), mCurParams);

		// *TODO: Fix user preferences accordingly.
	}

	// set it to noon
	resetAnimator(0.5, LLEnvManagerNew::instance().getUseDayCycle());

	// but use linden time sets it to what the estate is
	mAnimator.setTimeType(LLWLAnimator::TIME_LINDEN);

	LLEnvManagerNew::instance().usePrefs();
}
bool LLWLParamManager::applySkyParams(const LLSD& params, bool interpolate /*= false*/)
{
	if (params.size() == 0)
	{
		llwarns << "Undefined sky params" << llendl;
		return false;
	}

	if (interpolate)
	{
		if (!mAnimator.getIsRunning())
			resetAnimator(0.f, true); 
		
		if (!params.has("mName") || mCurParams.mName != params["mName"])
			LLWLParamManager::getInstance()->mAnimator.startInterpolationSky(params);
	}
	else
	{
		mAnimator.deactivate();
		mCurParams.setAll(params);
	}

	return true;
}
bool LLWLParamManager::applyDayCycleParams(const LLSD& params, LLEnvKey::EScope scope, F32 time)
{
	mDay.loadDayCycle(params, scope);
	resetAnimator(time, true); // set to specified time and start animator
	return true;
}