diff options
author | Rider Linden <rider@lindenlab.com> | 2018-05-17 16:16:33 -0700 |
---|---|---|
committer | Rider Linden <rider@lindenlab.com> | 2018-05-17 16:16:33 -0700 |
commit | 430c5cd23558ba42c7da0e31845a3677e66f1fed (patch) | |
tree | 70af45f8e29a485a08ee8e7848366755957b7cc2 /indra | |
parent | b117a9ea197a084eeec1e8330dbe7c562423e248 (diff) |
Self contained looping track blender. Will blend over time across an entire track in a day cycle.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llinventory/llsettingsbase.h | 6 | ||||
-rw-r--r-- | indra/llinventory/llsettingsdaycycle.h | 2 | ||||
-rw-r--r-- | indra/newview/llenvironment.cpp | 247 | ||||
-rw-r--r-- | indra/newview/llenvironment.h | 7 |
4 files changed, 147 insertions, 115 deletions
diff --git a/indra/llinventory/llsettingsbase.h b/indra/llinventory/llsettingsbase.h index d304638d20..6ab3032a3d 100644 --- a/indra/llinventory/llsettingsbase.h +++ b/indra/llinventory/llsettingsbase.h @@ -271,7 +271,8 @@ public: mInitial(initsetting), mFinal(endsetting) { - mTarget->replaceSettings(mInitial->getSettings()); + if (mInitial) + mTarget->replaceSettings(mInitial->getSettings()); } virtual ~LLSettingsBlender() {} @@ -309,7 +310,6 @@ public: protected: void triggerComplete(); -private: finish_signal_t mOnFinished; LLSettingsBase::ptr_t mTarget; @@ -347,7 +347,7 @@ public: virtual void update(F64 timedelta) override; -private: +protected: F64Seconds mBlendSpan; F64Seconds mLastUpdate; F64Seconds mTimeSpent; diff --git a/indra/llinventory/llsettingsdaycycle.h b/indra/llinventory/llsettingsdaycycle.h index a869d4970c..15a5b29f9f 100644 --- a/indra/llinventory/llsettingsdaycycle.h +++ b/indra/llinventory/llsettingsdaycycle.h @@ -60,7 +60,7 @@ public: typedef std::map<F32, LLSettingsBase::ptr_t> CycleTrack_t; typedef std::vector<CycleTrack_t> CycleList_t; - typedef std::shared_ptr<LLSettingsDay> ptr_t; + typedef std::shared_ptr<LLSettingsDay> ptr_t; typedef std::vector<F32> KeyframeList_t; typedef std::pair<CycleTrack_t::iterator, CycleTrack_t::iterator> TrackBound_t; diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp index f2d64f7e40..76192d1fe9 100644 --- a/indra/newview/llenvironment.cpp +++ b/indra/newview/llenvironment.cpp @@ -60,6 +60,125 @@ namespace { LLTrace::BlockTimerStatHandle FTM_ENVIRONMENT_UPDATE("Update Environment Tick"); LLTrace::BlockTimerStatHandle FTM_SHADER_PARAM_UPDATE("Update Shader Parameters"); + + //--------------------------------------------------------------------- + inline F32 get_wrapping_distance(F32 begin, F32 end) + { + if (begin < end) + { + return end - begin; + } + else if (begin > end) + { + return 1.0 - (begin - end); + } + + return 0; + } + + LLSettingsDay::CycleTrack_t::iterator get_wrapping_atafter(LLSettingsDay::CycleTrack_t &collection, F32 key) + { + if (collection.empty()) + return collection.end(); + + LLSettingsDay::CycleTrack_t::iterator it = collection.upper_bound(key); + + if (it == collection.end()) + { // wrap around + it = collection.begin(); + } + + return it; + } + + LLSettingsDay::CycleTrack_t::iterator get_wrapping_atbefore(LLSettingsDay::CycleTrack_t &collection, F32 key) + { + if (collection.empty()) + return collection.end(); + + LLSettingsDay::CycleTrack_t::iterator it = collection.lower_bound(key); + + if (it == collection.end()) + { // all keyframes are lower, take the last one. + --it; // we know the range is not empty + } + else if ((*it).first > key) + { // the keyframe we are interested in is smaller than the found. + if (it == collection.begin()) + it = collection.end(); + --it; + } + + return it; + } + + LLSettingsDay::TrackBound_t get_bounding_entries(LLSettingsDay::CycleTrack_t &track, F32 keyframe) + { + return LLSettingsDay::TrackBound_t(get_wrapping_atbefore(track, keyframe), get_wrapping_atafter(track, keyframe)); + } + + //--------------------------------------------------------------------- + class LLTrackBlenderLoopingTime : public LLSettingsBlenderTimeDelta + { + public: + 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), + mCycleLength(cyclelength), + mCycleOffset(cycleoffset) + { + LLSettingsDay::TrackBound_t initial = getBoundingEntries(getAdjustedNow()); + + mInitial = (*initial.first).second; + mFinal = (*initial.second).second; + mBlendSpan = getSpanTime(initial); + + setOnFinished([this](const LLSettingsBlender::ptr_t &){ onFinishedSpan(); }); + } + + protected: + LLSettingsDay::TrackBound_t getBoundingEntries(F64Seconds time) + { + LLSettingsDay::CycleTrack_t &wtrack = mDay->getCycleTrack(mTrackNo); + F64 position = convertTimeToPosition(time); + + LLSettingsDay::TrackBound_t bounds = get_bounding_entries(wtrack, position); + return bounds; + } + + F64Seconds getAdjustedNow() const + { + F64Seconds now(LLDate::now().secondsSinceEpoch()); + + return (now + mCycleOffset); + } + + F64Seconds getSpanTime(const LLSettingsDay::TrackBound_t &bounds) const + { + return mCycleLength * get_wrapping_distance((*bounds.first).first, (*bounds.second).first); + } + + F64 convertTimeToPosition(F64Seconds time) + { + F64 position = static_cast<F64>(fmod(time.value(), mCycleLength.value())) / static_cast<F64>(mCycleLength.value()); + return llclamp(position, 0.0, 1.0); + } + + private: + LLSettingsDay::ptr_t mDay; + S32 mTrackNo; + F64Seconds mCycleLength; + F64Seconds mCycleOffset; + + void onFinishedSpan() + { + LLSettingsDay::TrackBound_t next = getBoundingEntries(getAdjustedNow()); + F64Seconds nextspan = getSpanTime(next); + reset((*next.first).second, (*next.second).second, nextspan.value()); + } + }; + } //========================================================================= @@ -443,12 +562,6 @@ void LLEnvironment::updateEnvironment(F64Seconds transition, bool forced) } } -void LLEnvironment::onTransitionDone(const LLSettingsBlender::ptr_t blender, bool isSky) -{ - /*TODO: Test for both sky and water*/ - mCurrentEnvironment->animate(); -} - //------------------------------------------------------------------------- void LLEnvironment::update(const LLViewerCamera * cam) { @@ -1301,67 +1414,6 @@ void LLEnvironment::legacyLoadAllPresets() } //========================================================================= -namespace -{ - inline F32 get_wrapping_distance(F32 begin, F32 end) - { - if (begin < end) - { - return end - begin; - } - else if (begin > end) - { - return 1.0 - (begin - end); - } - - return 0; - } - - LLSettingsDay::CycleTrack_t::iterator get_wrapping_atafter(LLSettingsDay::CycleTrack_t &collection, F32 key) - { - if (collection.empty()) - return collection.end(); - - LLSettingsDay::CycleTrack_t::iterator it = collection.upper_bound(key); - - if (it == collection.end()) - { // wrap around - it = collection.begin(); - } - - return it; - } - - LLSettingsDay::CycleTrack_t::iterator get_wrapping_atbefore(LLSettingsDay::CycleTrack_t &collection, F32 key) - { - if (collection.empty()) - return collection.end(); - - LLSettingsDay::CycleTrack_t::iterator it = collection.lower_bound(key); - - if (it == collection.end()) - { // all keyframes are lower, take the last one. - --it; // we know the range is not empty - } - else if ((*it).first > key) - { // the keyframe we are interested in is smaller than the found. - if (it == collection.begin()) - it = collection.end(); - --it; - } - - return it; - } - - LLSettingsDay::TrackBound_t get_bounding_entries(LLSettingsDay::CycleTrack_t &track, F32 keyframe) - { - return LLSettingsDay::TrackBound_t(get_wrapping_atbefore(track, keyframe), get_wrapping_atafter(track, keyframe)); - } - -} -//========================================================================= - - LLEnvironment::DayInstance::DayInstance() : mDayCycle(), mSky(), @@ -1371,7 +1423,8 @@ LLEnvironment::DayInstance::DayInstance() : mBlenderSky(), mBlenderWater(), mInitialized(false), - mType(TYPE_INVALID) + mType(TYPE_INVALID), + mSkyTrack(1) { } void LLEnvironment::DayInstance::update(F64Seconds delta) @@ -1453,8 +1506,21 @@ void LLEnvironment::DayInstance::clear() mDayOffset = LLSettingsDay::DEFAULT_DAYOFFSET; mBlenderSky.reset(); mBlenderWater.reset(); + mSkyTrack = 1; } +void LLEnvironment::DayInstance::setSkyTrack(S32 trackno) +{ + /*TODO*/ +// if (trackno != mSkyTrack) +// { +// mSkyTrack = trackno; +// +// // *TODO*: Pick the sky track based on the skytrack. +// } +} + + void LLEnvironment::DayInstance::setBlenders(const LLSettingsBlender::ptr_t &skyblend, const LLSettingsBlender::ptr_t &waterblend) { mBlenderSky = skyblend; @@ -1491,21 +1557,13 @@ void LLEnvironment::DayInstance::animate() } else { - LLSettingsDay::TrackBound_t bounds = get_bounding_entries(wtrack, secondsToKeyframe(now)); - F64Seconds timespan = mDayLength * get_wrapping_distance((*bounds.first).first, (*bounds.second).first); - - mWater = std::static_pointer_cast<LLSettingsVOWater>((*bounds.first).second)->buildClone(); - mBlenderWater = std::make_shared<LLSettingsBlenderTimeDelta>(mWater, - (*bounds.first).second, (*bounds.second).second, timespan); - mBlenderWater->setOnFinished( - [this](LLSettingsBlender::ptr_t blender) { onTrackTransitionDone(0, blender); }); - - + 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(1); + LLSettingsDay::CycleTrack_t &track = mDayCycle->getCycleTrack(mSkyTrack); if (track.empty()) { @@ -1519,38 +1577,11 @@ void LLEnvironment::DayInstance::animate() } else { - LLSettingsDay::TrackBound_t bounds = get_bounding_entries(track, secondsToKeyframe(now)); - F64Seconds timespan = mDayLength * get_wrapping_distance((*bounds.first).first, (*bounds.second).first); - - mSky = std::static_pointer_cast<LLSettingsVOSky>((*bounds.first).second)->buildClone(); - mBlenderSky = std::make_shared<LLSettingsBlenderTimeDelta>(mSky, - (*bounds.first).second, (*bounds.second).second, timespan); - mBlenderSky->setOnFinished( - [this](LLSettingsBlender::ptr_t blender) { onTrackTransitionDone(1, blender); }); + mSky = LLSettingsVOSky::buildDefaultSky(); + mBlenderSky = std::make_shared<LLTrackBlenderLoopingTime>(mSky, mDayCycle, mSkyTrack, mDayLength, mDayOffset); } } -void LLEnvironment::DayInstance::onTrackTransitionDone(S32 trackno, const LLSettingsBlender::ptr_t blender) -{ - LL_WARNS("LAPRAS") << "onTrackTransitionDone for " << trackno << LL_ENDL; - F64Seconds now(LLDate::now().secondsSinceEpoch()); - - now += mDayOffset; - - LLSettingsDay::CycleTrack_t &track = mDayCycle->getCycleTrack(trackno); - - LLSettingsDay::TrackBound_t bounds = get_bounding_entries(track, secondsToKeyframe(now)); - - F32 distance = get_wrapping_distance((*bounds.first).first, (*bounds.second).first); - F64Seconds timespan = mDayLength * distance; - - LL_WARNS("LAPRAS") << "New sky blender. now=" << now << - " start=" << (*bounds.first).first << " end=" << (*bounds.second).first << - " span=" << timespan << LL_ENDL; - - blender->reset((*bounds.first).second, (*bounds.second).second, timespan.value()); -} - //------------------------------------------------------------------------- LLEnvironment::DayTransition::DayTransition(const LLSettingsSky::ptr_t &skystart, const LLSettingsWater::ptr_t &waterstart, LLEnvironment::DayInstance::ptr_t &end, S64Seconds time) : diff --git a/indra/newview/llenvironment.h b/indra/newview/llenvironment.h index ad7d93c3c8..e21f46d5b0 100644 --- a/indra/newview/llenvironment.h +++ b/indra/newview/llenvironment.h @@ -240,11 +240,14 @@ private: void clear(); + void setSkyTrack(S32 trackno); + LLSettingsDay::ptr_t getDayCycle() const { return mDayCycle; } LLSettingsSky::ptr_t getSky() const { return mSky; } LLSettingsWater::ptr_t getWater() const { return mWater; } S64Seconds getDayLength() const { return mDayLength; } S64Seconds getDayOffset() const { return mDayOffset; } + S32 getSkyTrack() const { return mSkyTrack; } virtual void animate(); @@ -254,6 +257,7 @@ private: LLSettingsDay::ptr_t mDayCycle; LLSettingsSky::ptr_t mSky; LLSettingsWater::ptr_t mWater; + S32 mSkyTrack; InstanceType_t mType; bool mInitialized; @@ -265,8 +269,6 @@ private: LLSettingsBlender::ptr_t mBlenderWater; F64 secondsToKeyframe(S64Seconds seconds); - - void onTrackTransitionDone(S32 trackno, const LLSettingsBlender::ptr_t blender); }; typedef std::array<DayInstance::ptr_t, ENV_END> InstanceArray_t; @@ -359,7 +361,6 @@ private: void recordEnvironment(S32 parcel_id, EnvironmentInfo::ptr_t environment); - void onTransitionDone(const LLSettingsBlender::ptr_t, bool isSky); //========================================================================= void legacyLoadAllPresets(); static LLSD legacyLoadPreset(const std::string& path); |