Vadim ProductEngine avatar Vadim ProductEngine committed a134106

STORM-1481 FIXED Fixed jerky transition when switching region from fixed sky to a day cycle.

Comments (0)

Files changed (5)

indra/newview/llfloaterregioninfo.cpp

 // static
 void LLFloaterRegionInfo::processRegionInfo(LLMessageSystem* msg)
 {
-	LL_DEBUGS("Windlight") << "Processing region info" << LL_ENDL;
-
 	LLPanel* panel;
 	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	llinfos << "LLFloaterRegionInfo::processRegionInfo" << llendl;
 	if(!floater)
 	{
 		return;
 	// We need to re-request environment setting here,
 	// otherwise after we apply (send) updated region settings we won't get them back,
 	// so our environment won't be updated.
+	// This is also the way to know about externally changed region environment.
 	LLEnvManagerNew::instance().requestRegionSettings();
 	
 	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
 	getChildView("cancel_btn")->setEnabled(dirty);
 }
 
-void LLPanelEnvironmentInfo::sendRegionSunUpdate(F32 sun_angle)
+void LLPanelEnvironmentInfo::sendRegionSunUpdate()
 {
 	LLRegionInfoModel& region_info = LLRegionInfoModel::instance();
-	bool region_use_fixed_sky = sun_angle >= 0.f;
-
-	// Set sun hour.
+
+	// If the region is being switched to fixed sky,
+	// change the region's sun hour according to the (fixed) sun position.
+	// This is needed for llGetSunDirection() LSL function to work properly (STORM-1330).
+	const LLSD& sky_map = mNewRegionSettings.getSkyMap();
+	bool region_use_fixed_sky = sky_map.size() == 1;
 	if (region_use_fixed_sky)
 	{
 		LLWLParamSet param_set;
-		LLSD params;
-		std::string unused;
-		if (!getSelectedSkyParams(params, unused))
-		{
-			return;
-		}
-		param_set.setAll(params);
-
+		llassert(sky_map.isMap());
+		param_set.setAll(sky_map.beginMap()->second);
+		F32 sun_angle = param_set.getSunAngle();
+
+		LL_DEBUGS("Windlight Sync") << "Old sun hour: " << region_info.mSunHour << LL_ENDL;
 		// convert value range from 0..2pi to 6..30
 		region_info.mSunHour = fmodf((sun_angle / F_TWO_PI) * 24.f, 24.f) + 6.f;
 	}
 
 	region_info.setUseFixedSun(region_use_fixed_sky);
 	region_info.mUseEstateSun = !region_use_fixed_sky;
+	LL_DEBUGS("Windlight Sync") << "Sun hour: " << region_info.mSunHour << LL_ENDL;
 
 	region_info.sendRegionTerrain(LLFloaterRegionInfo::getLastInvoice());
 }
 	LLSD day_cycle;
 	LLSD sky_map;
 	LLSD water_params;
-	F32 sun_angle = -1.f; // invalid value meaning no fixed sky
 
 	if (use_defaults)
 	{
 			param_set.setAll(params);
 			refs[LLWLParamKey(preset_name, LLEnvKey::SCOPE_LOCAL)] = param_set; // scope doesn't matter here
 			sky_map = LLWLParamManager::createSkyMap(refs);
-
-			// Remember the sun angle to set fixed region sun hour below.
-			sun_angle = param_set.getSunAngle();
 		}
 		else // use day cycle
 		{
 				LL_DEBUGS("Windlight") << "Fixing negative time" << LL_ENDL;
 				day_cycle[0][0] = 0.0f;
 			}
-
-			// If the day cycle contains exactly one preset (i.e it's effectively a fixed sky),
-			// remember the preset's sun angle to set fixed region sun hour below.
-			if (sky_map.size() == 1)
-			{
-				LLWLParamSet param_set;
-				llassert(sky_map.isMap());
-				param_set.setAll(sky_map.beginMap()->second);
-				sun_angle = param_set.getSunAngle();
-			}
 		}
 
 		// Get water params.
 		return;
 	}
 
-	// Set the region sun phase/flags according to the chosen new preferences.
-	sendRegionSunUpdate(sun_angle);
+	// When the settings get applied, we'll also send the region sun position update.
+	// To determine the sun angle we're going to need the new settings.
+	mNewRegionSettings = new_region_settings;
 
 	// Start spinning the progress indicator.
 	setApplyProgress(true);
 
 void LLPanelEnvironmentInfo::onRegionSettingsApplied(bool ok)
 {
-	LL_DEBUGS("Windlight") << "Applying region settings finished, stopping indicator" << LL_ENDL;
 	// If applying new settings has failed, stop the indicator right away.
 	// Otherwise it will be stopped when we receive the updated settings from server.
-	if (!ok)
+	if (ok)
+	{
+		// Set the region sun phase/flags according to the chosen new preferences.
+		//
+		// If we do this earlier we may get jerky transition from fixed sky to a day cycle (STORM-1481).
+		// That is caused by the simulator re-sending the region info, which in turn makes us
+		// re-request and display old region environment settings while the new ones haven't been applied yet.
+		sendRegionSunUpdate();
+	}
+	else
 	{
 		setApplyProgress(false);
 

indra/newview/llfloaterregioninfo.h

 #include "llhost.h"
 #include "llpanel.h"
 
+#include "llenvmanager.h" // for LLEnvironmentSettings
+
 class LLAvatarName;
 class LLDispatcher;
 class LLLineEditor;
 	void setApplyProgress(bool started);
 	void setDirty(bool dirty);
 
-	void sendRegionSunUpdate(F32 sun_angle);
+	void sendRegionSunUpdate();
 
 	void populateWaterPresetsList();
 	void populateSkyPresetsList();
 	void onRegionSettingschange();
 	void onRegionSettingsApplied(bool ok);
 
+	/// New environment settings that are being applied to the region.
+	LLEnvironmentSettings	mNewRegionSettings;
+
 	bool			mEnableEditing;
 
 	LLRadioGroup*	mRegionSettingsRadioGroup;

indra/newview/llregioninfomodel.cpp

 
 	// actually the "last set" sun hour, not the current sun hour. JC
 	msg->getF32(_PREHASH_RegionInfo, _PREHASH_SunHour, mSunHour);
+	LL_DEBUGS("Windlight Sync") << "Got region sun hour: " << mSunHour << LL_ENDL;
 
 	// the only reasonable way to decide if we actually have any data is to
 	// check to see if any of these fields have nonzero sizes

indra/newview/llviewermessage.cpp

 
 	LLWorld::getInstance()->setSpaceTimeUSec(space_time_usec);
 
-	LL_DEBUGS("Windlight Sync") << "time_synch() - " << sun_direction << ", " << sun_ang_velocity
-		<< ", " << phase << LL_ENDL;
+	LL_DEBUGS("Windlight Sync") << "Sun phase: " << phase << " rad = " << fmodf(phase / F_TWO_PI + 0.25, 1.f) * 24.f << " h" << LL_ENDL;
 
 	gSky.setSunPhase(phase);
 	gSky.setSunTargetDirection(sun_direction, sun_ang_velocity);

indra/newview/llviewerregion.cpp

 {
 	// send it to 'observers'
 	// *TODO: switch the floaters to using LLRegionInfoModel
+	llinfos << "Processing region info" << llendl;
 	LLRegionInfoModel::instance().update(msg);
 	LLFloaterGodTools::processRegionInfo(msg);
 	LLFloaterRegionInfo::processRegionInfo(msg);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.