diff options
author | Steve Bennetts <steve@lindenlab.com> | 2009-10-19 17:31:05 -0700 |
---|---|---|
committer | Steve Bennetts <steve@lindenlab.com> | 2009-10-19 17:31:05 -0700 |
commit | 1d5be6eca1969da3e6b923cbf5326d3bdc8b066f (patch) | |
tree | a03a2e782f5022ebbbe1ef933e3a11c1b9de00a6 /indra/llcommon/llkeythrottle.h | |
parent | 97d2b740d3e700d86665183d5fc5cfcb3efe72d6 (diff) | |
parent | d78520f6b7fd4a20bbb1d1291a34761efc1fd740 (diff) |
merge
Diffstat (limited to 'indra/llcommon/llkeythrottle.h')
-rw-r--r-- | indra/llcommon/llkeythrottle.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/indra/llcommon/llkeythrottle.h b/indra/llcommon/llkeythrottle.h index 873f50a65e..7544ab1d11 100644 --- a/indra/llcommon/llkeythrottle.h +++ b/indra/llcommon/llkeythrottle.h @@ -118,6 +118,63 @@ public: THROTTLE_BLOCKED, // rate exceed, block key }; + F64 getActionCount(const T& id) + { + U64 now = 0; + if ( mIsRealtime ) + { + now = LLKeyThrottleImpl<T>::getTime(); + } + else + { + now = LLKeyThrottleImpl<T>::getFrame(); + } + + if (now >= (m.startTime + m.intervalLength)) + { + if (now < (m.startTime + 2 * m.intervalLength)) + { + // prune old data + delete m.prevMap; + m.prevMap = m.currMap; + m.currMap = new typename LLKeyThrottleImpl<T>::EntryMap; + + m.startTime += m.intervalLength; + } + else + { + // lots of time has passed, all data is stale + delete m.prevMap; + delete m.currMap; + m.prevMap = new typename LLKeyThrottleImpl<T>::EntryMap; + m.currMap = new typename LLKeyThrottleImpl<T>::EntryMap; + + m.startTime = now; + } + } + + U32 prevCount = 0; + + typename LLKeyThrottleImpl<T>::EntryMap::const_iterator prev = m.prevMap->find(id); + if (prev != m.prevMap->end()) + { + prevCount = prev->second.count; + } + + typename LLKeyThrottleImpl<T>::Entry& curr = (*m.currMap)[id]; + + // curr.count is the number of keys in + // this current 'time slice' from the beginning of it until now + // prevCount is the number of keys in the previous + // time slice scaled to be one full time slice back from the current + // (now) time. + + // compute current, windowed rate + F64 timeInCurrent = ((F64)(now - m.startTime) / m.intervalLength); + F64 averageCount = curr.count + prevCount * (1.0 - timeInCurrent); + return averageCount; + } + // call each time the key wants use State noteAction(const T& id, S32 weight = 1) { |