diff options
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/llcriticaldamp.cpp | 77 | ||||
| -rw-r--r-- | indra/llcommon/llcriticaldamp.h | 32 | ||||
| -rw-r--r-- | indra/llcommon/lltracerecording.cpp | 17 | ||||
| -rw-r--r-- | indra/llcommon/lltracerecording.h | 8 | 
4 files changed, 80 insertions, 54 deletions
| diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp index 87d79b1ee0..59a31bf9df 100644 --- a/indra/llcommon/llcriticaldamp.cpp +++ b/indra/llcommon/llcriticaldamp.cpp @@ -27,18 +27,38 @@  #include "linden_common.h"  #include "llcriticaldamp.h" +#include <algorithm>  //-----------------------------------------------------------------------------  // static members  //----------------------------------------------------------------------------- -LLFrameTimer LLCriticalDamp::sInternalTimer; -std::map<F32, F32> LLCriticalDamp::sInterpolants; -F32 LLCriticalDamp::sTimeDelta; +LLFrameTimer LLSmoothInterpolation::sInternalTimer; +std::vector<LLSmoothInterpolation::Interpolant> LLSmoothInterpolation::sInterpolants; +F32 LLSmoothInterpolation::sTimeDelta; + +// helper functors +struct LLSmoothInterpolation::CompareTimeConstants +{ +	bool operator()(const F32& a, const LLSmoothInterpolation::Interpolant& b) const +	{ +		return a < b.mTimeScale; +	} + +	bool operator()(const LLSmoothInterpolation::Interpolant& a, const F32& b) const +	{ +		return a.mTimeScale < b; // bottom of a is higher than bottom of b +	} + +	bool operator()(const LLSmoothInterpolation::Interpolant& a, const LLSmoothInterpolation::Interpolant& b) const +	{ +		return a.mTimeScale < b.mTimeScale; // bottom of a is higher than bottom of b +	} +};  //----------------------------------------------------------------------------- -// LLCriticalDamp() +// LLSmoothInterpolation()  //----------------------------------------------------------------------------- -LLCriticalDamp::LLCriticalDamp() +LLSmoothInterpolation::LLSmoothInterpolation()  {  	sTimeDelta = 0.f;  } @@ -47,43 +67,54 @@ LLCriticalDamp::LLCriticalDamp()  //-----------------------------------------------------------------------------  // updateInterpolants()  //----------------------------------------------------------------------------- -void LLCriticalDamp::updateInterpolants() +void LLSmoothInterpolation::updateInterpolants()  {  	sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32(); -	F32 time_constant; - -	for (std::map<F32, F32>::iterator iter = sInterpolants.begin(); -		 iter != sInterpolants.end(); iter++) +	for (S32 i = 0; i < sInterpolants.size(); i++)  	{ -		time_constant = iter->first; -		F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); -		new_interpolant = llclamp(new_interpolant, 0.f, 1.f); -		sInterpolants[time_constant] = new_interpolant; +		Interpolant& interp = sInterpolants[i]; +		interp.mInterpolant = calcInterpolant(interp.mTimeScale);  	}  }   //-----------------------------------------------------------------------------  // getInterpolant()  //----------------------------------------------------------------------------- -F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache) +F32 LLSmoothInterpolation::getInterpolant(LLUnit<LLUnits::Seconds, F32> time_constant, bool use_cache)  {  	if (time_constant == 0.f)  	{  		return 1.f;  	} -	if (use_cache && sInterpolants.count(time_constant)) +	if (use_cache)  	{ -		return sInterpolants[time_constant]; +		interpolant_vec_t::iterator find_it = std::lower_bound(sInterpolants.begin(), sInterpolants.end(), time_constant.value(), CompareTimeConstants()); +		if (find_it != sInterpolants.end() && find_it->mTimeScale == time_constant)  +		{ +			return find_it->mInterpolant; +		} +		else +		{ +			Interpolant interp; +			interp.mTimeScale = time_constant.value(); +			interp.mInterpolant = calcInterpolant(time_constant.value()); +			sInterpolants.insert(find_it, interp); +			return interp.mInterpolant; +		}  	} -	 -	F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant); -	interpolant = llclamp(interpolant, 0.f, 1.f); -	if (use_cache) +	else  	{ -		sInterpolants[time_constant] = interpolant; +		return calcInterpolant(time_constant.value()); +  	} +} -	return interpolant; +//----------------------------------------------------------------------------- +// getInterpolant() +//----------------------------------------------------------------------------- +F32 LLSmoothInterpolation::calcInterpolant(F32 time_constant) +{ +	return llclamp(1.f - pow(2.f, -sTimeDelta / time_constant), 0.f, 1.f);  } diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h index 52f052ae25..ab5d4ba6e2 100644 --- a/indra/llcommon/llcriticaldamp.h +++ b/indra/llcommon/llcriticaldamp.h @@ -28,26 +28,46 @@  #ifndef LL_LLCRITICALDAMP_H  #define LL_LLCRITICALDAMP_H -#include <map> +#include <vector>  #include "llframetimer.h" +#include "llunit.h" -class LL_COMMON_API LLCriticalDamp  +class LL_COMMON_API LLSmoothInterpolation   {  public: -	LLCriticalDamp(); +	LLSmoothInterpolation();  	// MANIPULATORS  	static void updateInterpolants();  	// ACCESSORS -	static F32 getInterpolant(const F32 time_constant, BOOL use_cache = TRUE); +	static F32 getInterpolant(LLUnit<LLUnits::Seconds, F32> time_constant, bool use_cache = true); -protected:	 +	template<typename T>  +	static T lerp(T a, T b, LLUnit<LLUnits::Seconds, F32> time_constant, bool use_cache = true) +	{ +		F32 interpolant = getInterpolant(time_constant, use_cache); +		return ((a * (1.f - interpolant))  +				+ (b * interpolant)); +	} + +protected: +	static F32 calcInterpolant(F32 time_constant); + +	struct CompareTimeConstants;  	static LLFrameTimer sInternalTimer;	// frame timer for calculating deltas -	static std::map<F32, F32> 	sInterpolants; +	struct Interpolant +	{ +		F32 mTimeScale; +		F32 mInterpolant; +	}; +	typedef std::vector<Interpolant> interpolant_vec_t; +	static interpolant_vec_t 	sInterpolants;  	static F32					sTimeDelta;  }; +typedef LLSmoothInterpolation LLCriticalDamp; +  #endif  // LL_LLCRITICALDAMP_H diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index 6695ebeaca..259f5a7a27 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -291,23 +291,6 @@ U32 Recording::getSampleCount( const TraceType<CountAccumulator<S64> >& stat ) c  	return (*mMeasurementsFloat)[stat.getIndex()].getSampleCount();  } - -F64 Recording::getPerSec( const TraceType<MeasurementAccumulator<F64> >& stat ) const -{ -	F64 sum = (*mMeasurementsFloat)[stat.getIndex()].getSum(); -	return  (sum != 0.0)  -		? (sum / mElapsedSeconds) -		: 0.0; -} - -F64 Recording::getPerSec( const TraceType<MeasurementAccumulator<S64> >& stat ) const -{ -	S64 sum = (*mMeasurements)[stat.getIndex()].getSum(); -	return (sum != 0)  -		? ((F64)sum / mElapsedSeconds) -		: 0.0; -} -  F64 Recording::getMin( const TraceType<MeasurementAccumulator<F64> >& stat ) const  {  	return (*mMeasurementsFloat)[stat.getIndex()].getMin(); diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 70afe51d6e..751ff298ce 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -184,14 +184,6 @@ namespace LLTrace  			return (T)getSum(static_cast<const TraceType<MeasurementAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> >&> (stat));  		} -		F64 getPerSec(const TraceType<MeasurementAccumulator<F64> >& stat) const; -		F64 getPerSec(const TraceType<MeasurementAccumulator<S64> >& stat) const; -		template <typename T> -		T getPerSec(const MeasurementStatHandle<T>& stat) const -		{ -			return (T)getPerSec(static_cast<const TraceType<MeasurementAccumulator<typename LLUnits::HighestPrecisionType<T>::type_t> >&> (stat)); -		} -  		F64 getMin(const TraceType<MeasurementAccumulator<F64> >& stat) const;  		S64 getMin(const TraceType<MeasurementAccumulator<S64> >& stat) const;  		template <typename T> | 
