summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorGraham Madarasz (Graham) <graham@lindenlab.com>2013-03-08 15:31:37 -0800
committerGraham Madarasz (Graham) <graham@lindenlab.com>2013-03-08 15:31:37 -0800
commitf061b2b90e34d74b9c6db3606babb0402473a24d (patch)
treefeae72bd1acefaa7437250035ec0c32be02c731c /indra/llcommon
parent4b67d34c7e31e7dcc8185061e4a0b02c5da6560a (diff)
Optimize interp code to elim hundreds of divides per frame and fix jitter bugs.
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llcriticaldamp.cpp51
-rw-r--r--indra/llcommon/llcriticaldamp.h82
2 files changed, 96 insertions, 37 deletions
diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp
index 87d79b1ee0..27fef0e6dc 100644
--- a/indra/llcommon/llcriticaldamp.cpp
+++ b/indra/llcommon/llcriticaldamp.cpp
@@ -32,8 +32,9 @@
// static members
//-----------------------------------------------------------------------------
LLFrameTimer LLCriticalDamp::sInternalTimer;
-std::map<F32, F32> LLCriticalDamp::sInterpolants;
F32 LLCriticalDamp::sTimeDelta;
+F32 LLCriticalDamp::sInterpolants[kNumCachedInterpolants];
+F32 LLCriticalDamp::sInterpolatedValues[kNumCachedInterpolants];
//-----------------------------------------------------------------------------
// LLCriticalDamp()
@@ -41,6 +42,17 @@ F32 LLCriticalDamp::sTimeDelta;
LLCriticalDamp::LLCriticalDamp()
{
sTimeDelta = 0.f;
+
+ // Init the core interpolant values (to which many, many enums map)
+ //
+ setInterpolantConstant(InterpDelta_0_025, 0.025f);
+ setInterpolantConstant(InterpDelta_0_05, 0.05f );
+ setInterpolantConstant(InterpDelta_0_06, 0.06f);
+ setInterpolantConstant(InterpDelta_0_10, 0.10f);
+ setInterpolantConstant(InterpDelta_0_15, 0.15f);
+ setInterpolantConstant(InterpDelta_0_20, 0.20f);
+ setInterpolantConstant(InterpDelta_0_25, 0.25f);
+ setInterpolantConstant(InterpDelta_0_30, 0.30f);
}
// static
@@ -51,39 +63,10 @@ void LLCriticalDamp::updateInterpolants()
{
sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32();
- F32 time_constant;
-
- for (std::map<F32, F32>::iterator iter = sInterpolants.begin();
- iter != sInterpolants.end(); iter++)
- {
- 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;
- }
-}
-
-//-----------------------------------------------------------------------------
-// getInterpolant()
-//-----------------------------------------------------------------------------
-F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache)
-{
- if (time_constant == 0.f)
+ U32 i;
+ for (i = 0; i < kNumCachedInterpolants; i++)
{
- return 1.f;
+ sInterpolatedValues[i] = llclamp(sTimeDelta / sInterpolants[ i], 0.0f, 1.0f);
}
-
- if (use_cache && sInterpolants.count(time_constant))
- {
- return sInterpolants[time_constant];
- }
-
- F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
- interpolant = llclamp(interpolant, 0.f, 1.f);
- if (use_cache)
- {
- sInterpolants[time_constant] = interpolant;
- }
-
- return interpolant;
}
+
diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h
index 52f052ae25..19a2ddb77a 100644
--- a/indra/llcommon/llcriticaldamp.h
+++ b/indra/llcommon/llcriticaldamp.h
@@ -32,22 +32,98 @@
#include "llframetimer.h"
+// These enums each represent one fixed-time delta value
+// that we interpolate once given the actual sTimeDelta time
+// that has passed. This allows us to calculate the interp portion
+// of those values once and then look them up repeatedly per frame.
+//
+enum InterpDelta
+{
+ InterpDelta_0_025, // 0.025
+ InterpDeltaTeenier = InterpDelta_0_025,
+ InterpDeltaFolderOpenTime = InterpDelta_0_025,
+ InterpDeltaFolderCloseTime = InterpDelta_0_025,
+ InterpDeltaCameraFocusHalfLife = InterpDelta_0_025, // USED TO BE ZERO....
+
+ InterpDelta_0_05, // 0.05
+ InterpDeltaTeeny = InterpDelta_0_05,
+
+ InterpDelta_0_06, // 0.06
+ InterpDeltaObjectDampingConstant = InterpDelta_0_06,
+ InterpDeltaCameraZoomHalfLife = InterpDelta_0_06,
+ InterpDeltaFovZoomHalfLife = InterpDelta_0_06,
+ InterpDeltaManipulatorScaleHalfLife = InterpDelta_0_06,
+ InterpDeltaContextFadeTime = InterpDelta_0_06,
+
+ InterpDelta_0_10, // 0.10
+ InterpDeltaSmaller = InterpDelta_0_10,
+ InterpDeltaTargetLagHalfLife = InterpDelta_0_10,
+ InterpDeltaSpeedAdjustTime = InterpDelta_0_10,
+
+ InterpDelta_0_15, // 0.15
+ InterpDeltaFadeWeight = InterpDelta_0_15,
+ InterpDeltaHeadLookAtLagHalfLife = InterpDelta_0_15,
+
+ InterpDelta_0_20, // 0.20
+ InterpDeltaSmall = InterpDelta_0_20,
+ InterpDeltaTorsoLagHalfLife = InterpDelta_0_20,
+ InterpDeltaPositionDampingTC = InterpDelta_0_20,
+
+ InterpDelta_0_25, // 0.25
+ InterpDeltaCameraLagHalfLife = InterpDelta_0_25,
+ InterpDeltaTorsoTargetLagHalfLife = InterpDelta_0_25,
+ InterpDeltaTorsoLookAtLagHalfLife = InterpDelta_0_25,
+
+ InterpDelta_0_30, // 0.3
+ InterpDeltaSmallish = InterpDelta_0_30,
+
+ // Dynamically set interpolants which use setInterpolantConstant
+ //
+ InterpDeltaCameraSmoothingHalfLife,
+ InterpDeltaBehindnessLag,
+ InterpDeltaFocusLag,
+ InterpDeltaPositionLag,
+ InterpDeltaOpenTime,
+ InterpDeltaCloseTime,
+
+ kNumCachedInterpolants
+};
+
class LL_COMMON_API LLCriticalDamp
{
public:
LLCriticalDamp();
- // MANIPULATORS
+ // Updates all the known interp delta values for fast lookup in calls to getInterpolant(InterpDelta)
+ //
static void updateInterpolants();
+ static inline void setInterpolantConstant(InterpDelta whichDelta, const F32 time_constant)
+ {
+ llassert(whichDelta < kNumCachedInterpolants);
+ sInterpolants[whichDelta] = time_constant;
+ }
+
// ACCESSORS
- static F32 getInterpolant(const F32 time_constant, BOOL use_cache = TRUE);
+ static inline F32 getInterpolant(InterpDelta whichDelta)
+ {
+ llassert(whichDelta < kNumCachedInterpolants);
+ return sInterpolatedValues[whichDelta];
+ }
+
+ static inline F32 getInterpolant(const F32 time_constant)
+ {
+ return llclamp((sTimeDelta / time_constant), 0.0f, 1.0f);
+ }
protected:
static LLFrameTimer sInternalTimer; // frame timer for calculating deltas
- static std::map<F32, F32> sInterpolants;
+ //static std::map<F32, F32> sInterpolants;
+ static F32 sInterpolants[kNumCachedInterpolants];
+ static F32 sInterpolatedValues[kNumCachedInterpolants];
static F32 sTimeDelta;
};
#endif // LL_LLCRITICALDAMP_H
+