summaryrefslogtreecommitdiff
path: root/indra/newview/llsettingsdaycycle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llsettingsdaycycle.cpp')
-rw-r--r--indra/newview/llsettingsdaycycle.cpp179
1 files changed, 124 insertions, 55 deletions
diff --git a/indra/newview/llsettingsdaycycle.cpp b/indra/newview/llsettingsdaycycle.cpp
index bda3c7c138..2d97ea865f 100644
--- a/indra/newview/llsettingsdaycycle.cpp
+++ b/indra/newview/llsettingsdaycycle.cpp
@@ -47,6 +47,8 @@
#include "llenvironment.h"
+#include "llworld.h"
+
//=========================================================================
namespace
{
@@ -55,7 +57,16 @@ namespace
inline F32 get_wrapping_distance(F32 begin, F32 end)
{
- return 1.0 - fabs((begin + 1.0) - end);
+ if (begin < end)
+ {
+ return end - begin;
+ }
+ else if (begin > end)
+ {
+ return 1.0 - (begin - end);
+ }
+
+ return 0;
}
LLSettingsDayCycle::CycleTrack_t::iterator get_wrapping_atafter(LLSettingsDayCycle::CycleTrack_t &collection, F32 key)
@@ -81,11 +92,11 @@ namespace
LLSettingsDayCycle::CycleTrack_t::iterator it = collection.lower_bound(key);
if (it == collection.end())
- { // all offsets are lower, take the last one.
+ { // all keyframes are lower, take the last one.
--it; // we know the range is not empty
}
else if ((*it).first > key)
- { // the offset we are interested in is smaller than the found.
+ { // the keyframe we are interested in is smaller than the found.
if (it == collection.begin())
it = collection.end();
--it;
@@ -101,11 +112,13 @@ namespace
const std::string LLSettingsDayCycle::SETTING_DAYLENGTH("day_length");
const std::string LLSettingsDayCycle::SETTING_KEYID("key_id");
const std::string LLSettingsDayCycle::SETTING_KEYNAME("key_name");
-const std::string LLSettingsDayCycle::SETTING_KEYOFFSET("key_offset");
+const std::string LLSettingsDayCycle::SETTING_KEYKFRAME("key_keyframe");
const std::string LLSettingsDayCycle::SETTING_NAME("name");
const std::string LLSettingsDayCycle::SETTING_TRACKS("tracks");
-const S32 LLSettingsDayCycle::MINIMUM_DAYLENGTH( 14400); // 4 hours
+const S32 LLSettingsDayCycle::MINIMUM_DAYLENGTH( 300); // 5 mins
+
+//const S32 LLSettingsDayCycle::MINIMUM_DAYLENGTH( 14400); // 4 hours
const S32 LLSettingsDayCycle::MAXIMUM_DAYLENGTH(604800); // 7 days
const S32 LLSettingsDayCycle::TRACK_WATER(0); // water track is 0
@@ -113,13 +126,15 @@ const S32 LLSettingsDayCycle::TRACK_MAX(5); // 5 tracks, 4 skys, 1 water
//=========================================================================
LLSettingsDayCycle::LLSettingsDayCycle(const LLSD &data) :
- LLSettingsBase(data)
+ LLSettingsBase(data),
+ mHasParsed(false)
{
mDayTracks.resize(TRACK_MAX);
}
LLSettingsDayCycle::LLSettingsDayCycle() :
- LLSettingsBase()
+ LLSettingsBase(),
+ mHasParsed(false)
{
mDayTracks.resize(TRACK_MAX);
}
@@ -132,8 +147,8 @@ LLSD LLSettingsDayCycle::defaults()
dfltsetting[SETTING_NAME] = "_default_";
dfltsetting[SETTING_DAYLENGTH] = MINIMUM_DAYLENGTH;
dfltsetting[SETTING_TRACKS] = LLSDArray(
- LLSDArray(LLSDMap(SETTING_KEYOFFSET, LLSD::Real(0.0f))(SETTING_KEYNAME, "_default_"))
- (LLSDMap(SETTING_KEYOFFSET, LLSD::Real(0.0f))(SETTING_KEYNAME, "_default_")));
+ LLSDArray(LLSDMap(SETTING_KEYKFRAME, LLSD::Real(0.0f))(SETTING_KEYNAME, "_default_"))
+ (LLSDMap(SETTING_KEYKFRAME, LLSD::Real(0.0f))(SETTING_KEYNAME, "_default_")));
return dfltsetting;
}
@@ -146,14 +161,14 @@ LLSettingsDayCycle::ptr_t LLSettingsDayCycle::buildFromLegacyPreset(const std::s
newsettings[SETTING_DAYLENGTH] = MINIMUM_DAYLENGTH;
LLSD watertrack = LLSDArray(
- LLSDMap ( SETTING_KEYOFFSET, LLSD::Real(0.0f) )
+ LLSDMap ( SETTING_KEYKFRAME, LLSD::Real(0.0f) )
( SETTING_KEYNAME, "Default" ));
LLSD skytrack = LLSD::emptyArray();
for (LLSD::array_const_iterator it = oldsettings.beginArray(); it != oldsettings.endArray(); ++it)
{
- LLSD entry = LLSDMap(SETTING_KEYOFFSET, (*it)[0].asReal())
+ LLSD entry = LLSDMap(SETTING_KEYKFRAME, (*it)[0].asReal())
(SETTING_KEYNAME, (*it)[1].asString());
skytrack.append(entry);
}
@@ -185,7 +200,7 @@ void LLSettingsDayCycle::parseFromLLSD(LLSD &data)
LLSD curtrack = tracks[i];
for (LLSD::array_const_iterator it = curtrack.beginArray(); it != curtrack.endArray(); ++it)
{
- F32 offset = (*it)[SETTING_KEYOFFSET].asReal();
+ F32 keyframe = (*it)[SETTING_KEYKFRAME].asReal();
LLSettingsBase::ptr_t setting;
if ((*it).has(SETTING_KEYNAME))
@@ -201,9 +216,10 @@ void LLSettingsDayCycle::parseFromLLSD(LLSD &data)
}
if (setting)
- mDayTracks[i][offset] = setting;
+ mDayTracks[i][keyframe] = setting;
}
}
+ mHasParsed = true;
}
@@ -216,31 +232,85 @@ LLSettingsDayCycle::ptr_t LLSettingsDayCycle::buildClone()
return dayp;
}
-LLSettingsBase::ptr_t LLSettingsDayCycle::blend(const LLSettingsBase::ptr_t &other, F32 mix) const
+void LLSettingsDayCycle::blend(const LLSettingsBase::ptr_t &other, F32 mix)
{
LL_ERRS("DAYCYCLE") << "Day cycles are not blendable!" << LL_ENDL;
- return LLSettingsBase::ptr_t();
}
//=========================================================================
-F32 LLSettingsDayCycle::secondsToOffset(S32 seconds)
+F32 LLSettingsDayCycle::secondsToKeyframe(S32 seconds)
{
S32 daylength = getDayLength();
return static_cast<F32>(seconds % daylength) / static_cast<F32>(daylength);
}
-S32 LLSettingsDayCycle::offsetToSeconds(F32 offset)
+S32 LLSettingsDayCycle::keyframeToSeconds(F32 keyframe)
{
S32 daylength = getDayLength();
- return static_cast<S32>(offset * static_cast<F32>(daylength));
+ return static_cast<S32>(keyframe * static_cast<F32>(daylength));
}
//=========================================================================
void LLSettingsDayCycle::updateSettings()
{
+ if (!mHasParsed)
+ parseFromLLSD(mSettings);
+ //F64Seconds time_now(LLWorld::instance().getSpaceTimeUSec());
+ F64Seconds time_now(LLDate::now().secondsSinceEpoch());
+
+ // base class clears dirty flag so as to not trigger recursive update
+ LLSettingsBase::updateSettings();
+
+ if (!mBlendedWater)
+ {
+ mBlendedWater = LLEnvironment::instance().getCurrentWater()->buildClone();
+ LLEnvironment::instance().selectWater(mBlendedWater);
+ }
+
+ if (!mBlendedSky)
+ {
+ mBlendedSky = LLEnvironment::instance().getCurrentSky()->buildClone();
+ LLEnvironment::instance().selectSky(mBlendedSky);
+ }
+
+
+ if ((time_now < mLastUpdateTime) || ((time_now - mLastUpdateTime) > static_cast<F64Seconds>(0.1)))
+ {
+ F64Seconds daylength = static_cast<F64Seconds>(getDayLength());
+ F32 frame = fmod(time_now.value(), daylength.value()) / daylength.value();
+
+ CycleList_t::iterator itTrack = mDayTracks.begin();
+ TrackBound_t bounds = getBoundingEntries(*itTrack, frame);
+
+ mBlendedWater->replaceSettings((*bounds.first).second->getSettings());
+ if (bounds.first != bounds.second)
+ {
+ F32 blendf = get_wrapping_distance((*bounds.first).first, frame) / get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
+ mBlendedWater->blend((*bounds.second).second, blendf);
+ }
+
+ ++itTrack;
+ bounds = getBoundingEntries(*itTrack, frame);
+
+ //_WARNS("RIDER") << "Sky blending: frame=" << frame << " start=" << F64Seconds((*bounds.first).first) << " end=" << F64Seconds((*bounds.second).first) << LL_ENDL;
+
+ mBlendedSky->replaceSettings((*bounds.first).second->getSettings());
+ if (bounds.first != bounds.second)
+ {
+ F32 blendf = get_wrapping_distance((*bounds.first).first, frame) / get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
+ //_WARNS("RIDER") << "Distance=" << get_wrapping_distance((*bounds.first).first, frame) << "/" << get_wrapping_distance((*bounds.first).first, (*bounds.second).first) << " Blend factor=" << blendf << LL_ENDL;
+
+ mBlendedSky->blend((*bounds.second).second, blendf);
+ }
+
+ mLastUpdateTime = time_now;
+ }
+
+ // Always mark the day cycle as dirty.So that the blend check can be handled.
+ setDirtyFlag(true);
}
//=========================================================================
@@ -251,40 +321,40 @@ void LLSettingsDayCycle::setDayLength(S32 seconds)
setValue(SETTING_DAYLENGTH, seconds);
}
-LLSettingsDayCycle::OffsetList_t LLSettingsDayCycle::getTrackOffsets(S32 trackno)
+LLSettingsDayCycle::KeyframeList_t LLSettingsDayCycle::getTrackKeyframes(S32 trackno)
{
if ((trackno < 1) || (trackno >= TRACK_MAX))
{
LL_WARNS("DAYCYCLE") << "Attempt get track (#" << trackno << ") out of range!" << LL_ENDL;
- return OffsetList_t();
+ return KeyframeList_t();
}
- OffsetList_t offsets;
+ KeyframeList_t keyframes;
CycleTrack_t &track = mDayTracks[trackno];
- offsets.reserve(track.size());
+ keyframes.reserve(track.size());
for (CycleTrack_t::iterator it = track.begin(); it != track.end(); ++it)
{
- offsets.push_back((*it).first);
+ keyframes.push_back((*it).first);
}
- return offsets;
+ return keyframes;
}
LLSettingsDayCycle::TimeList_t LLSettingsDayCycle::getTrackTimes(S32 trackno)
{
- OffsetList_t offsets = getTrackOffsets(trackno);
+ KeyframeList_t keyframes = getTrackKeyframes(trackno);
- if (offsets.empty())
+ if (keyframes.empty())
return TimeList_t();
TimeList_t times;
- times.reserve(offsets.size());
- for (OffsetList_t::iterator it = offsets.begin(); it != offsets.end(); ++it)
+ times.reserve(keyframes.size());
+ for (KeyframeList_t::iterator it = keyframes.begin(); it != keyframes.end(); ++it)
{
- times.push_back(offsetToSeconds(*it));
+ times.push_back(keyframeToSeconds(*it));
}
return times;
@@ -292,13 +362,13 @@ LLSettingsDayCycle::TimeList_t LLSettingsDayCycle::getTrackTimes(S32 trackno)
void LLSettingsDayCycle::setWaterAtTime(const LLSettingsWaterPtr_t &water, S32 seconds)
{
- F32 offset = secondsToOffset(seconds);
- setWaterAtOffset(water, offset);
+ F32 keyframe = secondsToKeyframe(seconds);
+ setWaterAtKeyframe(water, keyframe);
}
-void LLSettingsDayCycle::setWaterAtOffset(const LLSettingsWaterPtr_t &water, F32 offset)
+void LLSettingsDayCycle::setWaterAtKeyframe(const LLSettingsWaterPtr_t &water, F32 keyframe)
{
- mDayTracks[TRACK_WATER][offset] = water;
+ mDayTracks[TRACK_WATER][keyframe] = water;
setDirtyFlag(true);
}
@@ -310,34 +380,33 @@ void LLSettingsDayCycle::setSkyAtOnTrack(const LLSettingsSkyPtr_t &sky, S32 seco
LL_WARNS("DAYCYCLE") << "Attempt to set sky track (#" << track << ") out of range!" << LL_ENDL;
return;
}
- F32 offset = secondsToOffset(seconds);
+ F32 keyframe = secondsToKeyframe(seconds);
- mDayTracks[track][offset] = sky;
+ mDayTracks[track][keyframe] = sky;
setDirtyFlag(true);
-
}
-LLSettingsDayCycle::TrackBound_t LLSettingsDayCycle::getBoundingEntries(CycleTrack_t &track, F32 offset)
+LLSettingsDayCycle::TrackBound_t LLSettingsDayCycle::getBoundingEntries(CycleTrack_t &track, F32 keyframe)
{
- return TrackBound_t(get_wrapping_atbefore(track, offset), get_wrapping_atafter(track, offset));
+ return TrackBound_t(get_wrapping_atbefore(track, keyframe), get_wrapping_atafter(track, keyframe));
}
-LLSettingsBase::ptr_t LLSettingsDayCycle::getBlendedEntry(CycleTrack_t &track, F32 offset)
-{
- TrackBound_t bounds = getBoundingEntries(track, offset);
-
- if (bounds.first == track.end())
- return LLSettingsBase::ptr_t(); // Track is empty nothing to blend.
-
- if (bounds.first == bounds.second)
- { // Single entry. Nothing to blend
- return (*bounds.first).second;
- }
-
- F32 blendf = get_wrapping_distance((*bounds.first).first, offset) / get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
-
- LLSettingsBase::ptr_t base = (*bounds.first).second;
- return base->blend((*bounds.second).second, blendf);
-}
+// LLSettingsBase::ptr_t LLSettingsDayCycle::getBlendedEntry(CycleTrack_t &track, F32 keyframe)
+// {
+// TrackBound_t bounds = getBoundingEntries(track, keyframe);
+//
+// if (bounds.first == track.end())
+// return LLSettingsBase::ptr_t(); // Track is empty nothing to blend.
+//
+// if (bounds.first == bounds.second)
+// { // Single entry. Nothing to blend
+// return (*bounds.first).second;
+// }
+//
+// F32 blendf = get_wrapping_distance((*bounds.first).first, keyframe) / get_wrapping_distance((*bounds.first).first, (*bounds.second).first);
+//
+// LLSettingsBase::ptr_t base = (*bounds.first).second;
+// return base->blend((*bounds.second).second, blendf);
+// }
//=========================================================================