summaryrefslogtreecommitdiff
path: root/indra/newview/llenvironment.cpp
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2018-06-01 15:34:21 +0100
committerGraham Linden <graham@lindenlab.com>2018-06-01 15:34:21 +0100
commit37e8fd20c3823482f3a15b4bfd544f7847070db8 (patch)
treeb31e3a1ef86431cda7703621f779b38a98c14a3e /indra/newview/llenvironment.cpp
parent64302d3000b69b31e72eb6a3bd8a981c80cb88de (diff)
parentbd84cbfa11fbe2b3aa5ceba5978841310488b8e4 (diff)
Merge to 5.1.6
Diffstat (limited to 'indra/newview/llenvironment.cpp')
-rw-r--r--indra/newview/llenvironment.cpp164
1 files changed, 136 insertions, 28 deletions
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index 0177f88b6d..e9c27a7794 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -28,6 +28,8 @@
#include "llenvironment.h"
+#include <algorithm>
+
#include "llagent.h"
#include "llviewercontrol.h" // for gSavedSettings
#include "llviewerregion.h"
@@ -128,7 +130,7 @@ namespace
LLTrackBlenderLoopingTime(const LLSettingsBase::ptr_t &target, const LLSettingsDay::ptr_t &day, S32 trackno, F64Seconds cyclelength, F64Seconds cycleoffset) :
LLSettingsBlenderTimeDelta(target, LLSettingsBase::ptr_t(), LLSettingsBase::ptr_t(), F64Seconds(1.0)),
mDay(day),
- mTrackNo(trackno),
+ mTrackNo(0),
mCycleLength(cyclelength),
mCycleOffset(cycleoffset)
{
@@ -138,10 +140,57 @@ namespace
mFinal = (*initial.second).second;
mBlendSpan = getSpanTime(initial);
+ mTrackNo = selectTrackNumber(trackno);
+
setOnFinished([this](const LLSettingsBlender::ptr_t &){ onFinishedSpan(); });
}
+
+ void switchTrack(S32 trackno, F64) override
+ {
+ S32 use_trackno = selectTrackNumber(trackno);
+
+ if (use_trackno == mTrackNo)
+ { // results in no change
+ return;
+ }
+
+ mTrackTransitionStart = mTarget->buildDerivedClone();
+ mTrackNo = use_trackno;
+
+ F64Seconds now = getAdjustedNow() + LLEnvironment::TRANSITION_ALTITUDE;
+ LLSettingsDay::TrackBound_t bounds = getBoundingEntries(now);
+
+ LLSettingsBase::ptr_t pendsetting = (*bounds.first).second->buildDerivedClone();
+ F64 targetpos = convertTimeToPosition(now) - (*bounds.first).first;
+ F64 targetspan = get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
+
+ F64 blendf = calculateBlend(targetpos, targetspan);
+ pendsetting->blend((*bounds.second).second, blendf);
+
+ reset(mTrackTransitionStart, pendsetting, LLEnvironment::TRANSITION_ALTITUDE.value());
+ }
+
+
protected:
+ S32 selectTrackNumber(S32 trackno)
+ {
+ if (trackno == 0)
+ { // We are dealing with the water track. There is only ever one.
+ return 0;
+ }
+
+ for (S32 test = trackno; test == 0; --test)
+ { // Find the track below the requested one with data.
+ LLSettingsDay::CycleTrack_t &track = mDay->getCycleTrack(mTrackNo);
+
+ if (!track.empty())
+ return test;
+ }
+
+ return 1;
+ }
+
LLSettingsDay::TrackBound_t getBoundingEntries(F64Seconds time)
{
LLSettingsDay::CycleTrack_t &wtrack = mDay->getCycleTrack(mTrackNo);
@@ -174,6 +223,7 @@ namespace
S32 mTrackNo;
F64Seconds mCycleLength;
F64Seconds mCycleOffset;
+ LLSettingsBase::ptr_t mTrackTransitionStart;
void onFinishedSpan()
{
@@ -190,6 +240,7 @@ const F32Seconds LLEnvironment::TRANSITION_INSTANT(0.0f);
const F32Seconds LLEnvironment::TRANSITION_FAST(1.0f);
const F32Seconds LLEnvironment::TRANSITION_DEFAULT(5.0f);
const F32Seconds LLEnvironment::TRANSITION_SLOW(10.0f);
+const F32Seconds LLEnvironment::TRANSITION_ALTITUDE(5.0f);
const F32 LLEnvironment::SUN_DELTA_YAW(F_PI); // 180deg
@@ -205,7 +256,8 @@ LLEnvironment::LLEnvironment():
mDayCycleByName(),
mDayCycleById(),
mUserPrefs(),
- mSelectedEnvironment(LLEnvironment::ENV_LOCAL)
+ mSelectedEnvironment(LLEnvironment::ENV_LOCAL),
+ mCurrentTrack(1)
{
}
@@ -231,11 +283,13 @@ void LLEnvironment::initSingleton()
requestRegionEnvironment();
- LLRegionInfoModel::instance().setUpdateCallback(boost::bind(&LLEnvironment::onParcelChange, this));
- gAgent.addParcelChangedCallback(boost::bind(&LLEnvironment::onParcelChange, this));
+ LLRegionInfoModel::instance().setUpdateCallback([this]() { onParcelChange(); });
+ gAgent.addParcelChangedCallback([this]() { onParcelChange(); });
//TODO: This frequently results in one more request than we need. It isn't breaking, but should be nicer.
- gAgent.addRegionChangedCallback(boost::bind(&LLEnvironment::requestRegionEnvironment, this));
+ gAgent.addRegionChangedCallback([this]() { requestRegionEnvironment(); });
+
+ gAgent.whenPositionChanged([this](const LLVector3 &localpos, const LLVector3d &) { onAgentPositionHasChanged(localpos); });
}
LLEnvironment::~LLEnvironment()
@@ -432,6 +486,7 @@ void LLEnvironment::setEnvironment(LLEnvironment::EnvSelection_t env, const LLSe
environment->clear();
environment->setDay(pday, daylength, dayoffset);
+ environment->setSkyTrack(mCurrentTrack);
environment->animate();
/*TODO: readjust environment*/
}
@@ -1004,6 +1059,10 @@ void LLEnvironment::recordEnvironment(S32 parcel_id, LLEnvironment::EnvironmentI
LL_WARNS("LAPRAS") << "Had requested parcel environment #" << parcel_id << " but got region." << LL_ENDL;
clearEnvironment(ENV_PARCEL);
}
+
+ mTrackAltitudes = envinfo->mAltitudes;
+
+ LL_WARNS("LAPRAS") << "Altitudes set to {" << mTrackAltitudes[0] << ", "<< mTrackAltitudes[1] << ", " << mTrackAltitudes[2] << ", " << mTrackAltitudes[3] << LL_ENDL;
}
else
{
@@ -1293,7 +1352,7 @@ LLEnvironment::EnvironmentInfo::EnvironmentInfo():
mDayOffset(0),
mDayHash(0),
mDaycycleData(),
- mAltitudes(),
+ mAltitudes({ { 0.0, 0.0, 0.0, 0.0 } }),
mIsDefault(false),
mIsRegion(false)
{
@@ -1318,7 +1377,16 @@ LLEnvironment::EnvironmentInfo::ptr_t LLEnvironment::EnvironmentInfo::extract(LL
if (environment.has("is_default"))
pinfo->mIsDefault = environment["is_default"].asBoolean();
if (environment.has("track_altitudes"))
- pinfo->mAltitudes = environment["track_altitudes"];
+ {
+ LL_WARNS("LAPRAS") << "track_altitudes=" << environment["track_altitudes"] << LL_ENDL;
+
+ /*LAPRAS: TODO: Fix the simulator message. Shouldn't be 5, just 4*/
+ int idx = 1;
+ for (F32 &altitude : pinfo->mAltitudes)
+ {
+ altitude = environment["track_altitudes"][idx++].asReal();
+ }
+ }
return pinfo;
}
@@ -1361,6 +1429,16 @@ LLSettingsSky::ptr_t LLEnvironment::createSkyFromLegacyPreset(const std::string
return sky;
}
+LLSettingsDay::ptr_t LLEnvironment::createDayCycleFromLegacyPreset(const std::string filename)
+{
+ // for the moment just look it up from the preloaded.
+ std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(filename), true));
+
+ LLSettingsDay::ptr_t day = instance().findDayCycleByName(name);
+ return day;
+}
+
+
LLSD LLEnvironment::legacyLoadPreset(const std::string& path)
{
llifstream xml_file;
@@ -1521,6 +1599,38 @@ void LLEnvironment::legacyLoadAllPresets()
}
}
+void LLEnvironment::onAgentPositionHasChanged(const LLVector3 &localpos)
+{
+ S32 trackno = calculateSkyTrackForAltitude(localpos.mV[VZ]);
+ if (trackno == mCurrentTrack)
+ return;
+
+ LL_WARNS("LAPRAS") << "Wants to switch to track #" << trackno << LL_ENDL;
+
+ mCurrentTrack = trackno;
+ for (S32 env = ENV_LOCAL; env < ENV_DEFAULT; ++env)
+ {
+ if (mEnvironments[env])
+ mEnvironments[env]->setSkyTrack(mCurrentTrack);
+ }
+}
+
+S32 LLEnvironment::calculateSkyTrackForAltitude(F64 altitude)
+{
+// //*LAPRAS* temp base on region's response.
+// return llmin((static_cast<S32>(altitude) / 100) + 1, (LLSettingsDay::TRACK_MAX - 1));
+
+ auto it = std::find_if_not(mTrackAltitudes.begin(), mTrackAltitudes.end(), [altitude](F32 test) { return altitude > test; });
+
+ if (it == mTrackAltitudes.begin())
+ return 1;
+ else if (it == mTrackAltitudes.end())
+ return 4;
+
+ return std::min(static_cast<S32>(std::distance(mTrackAltitudes.begin(), it)), 4);
+}
+
+
//=========================================================================
LLEnvironment::DayInstance::DayInstance() :
mDayCycle(),
@@ -1628,13 +1738,11 @@ void LLEnvironment::DayInstance::clear()
void LLEnvironment::DayInstance::setSkyTrack(S32 trackno)
{
- /*TODO*/
-// if (trackno != mSkyTrack)
-// {
-// mSkyTrack = trackno;
-//
-// // *TODO*: Pick the sky track based on the skytrack.
-// }
+ mSkyTrack = trackno;
+ if (mBlenderSky)
+ {
+ mBlenderSky->switchTrack(trackno);
+ }
}
@@ -1667,35 +1775,35 @@ void LLEnvironment::DayInstance::animate()
mWater.reset();
mBlenderWater.reset();
}
- else if (wtrack.size() == 1)
- {
- mWater = std::static_pointer_cast<LLSettingsWater>((*(wtrack.begin())).second);
- mBlenderWater.reset();
- }
+// else if (wtrack.size() == 1)
+// {
+// mWater = std::static_pointer_cast<LLSettingsWater>((*(wtrack.begin())).second);
+// mBlenderWater.reset();
+// }
else
{
mWater = LLSettingsVOWater::buildDefaultWater();
mBlenderWater = std::make_shared<LLTrackBlenderLoopingTime>(mWater, mDayCycle, 0, mDayLength, mDayOffset);
}
- // Day track 1 only for the moment
- // sky
- LLSettingsDay::CycleTrack_t &track = mDayCycle->getCycleTrack(mSkyTrack);
+ // sky, initalize to track 1
+ LLSettingsDay::CycleTrack_t &track = mDayCycle->getCycleTrack(1);
if (track.empty())
{
mSky.reset();
mBlenderSky.reset();
}
- else if (track.size() == 1)
- {
- mSky = std::static_pointer_cast<LLSettingsSky>((*(track.begin())).second);
- mBlenderSky.reset();
- }
+// else if (track.size() == 1)
+// {
+// mSky = std::static_pointer_cast<LLSettingsSky>((*(track.begin())).second);
+// mBlenderSky.reset();
+// }
else
{
mSky = LLSettingsVOSky::buildDefaultSky();
- mBlenderSky = std::make_shared<LLTrackBlenderLoopingTime>(mSky, mDayCycle, mSkyTrack, mDayLength, mDayOffset);
+ mBlenderSky = std::make_shared<LLTrackBlenderLoopingTime>(mSky, mDayCycle, 1, mDayLength, mDayOffset);
+ mBlenderSky->switchTrack(mSkyTrack);
}
}