| 96 | } |
| 97 | |
| 98 | void SmoothAxisLimit::Update(double newMaximum, double lastFrameTimeSeconds) |
| 99 | { |
| 100 | if (newMaximum <= 0.0) |
| 101 | return; |
| 102 | |
| 103 | // Round the new maximum up to the nearest power of two |
| 104 | newMaximum = std::pow(2.0, std::ceil(std::log2(newMaximum))); |
| 105 | |
| 106 | if (m_maximum == newMaximum) |
| 107 | return; |
| 108 | |
| 109 | if (m_maximum == 0.0) |
| 110 | { |
| 111 | m_maximum = newMaximum; |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | double const adaptationSpeed = 4.0; |
| 116 | bool const adjustUp = m_maximum < newMaximum; |
| 117 | double const factor = exp(adaptationSpeed * lastFrameTimeSeconds * (adjustUp ? 1.0 : -1.0)); |
| 118 | m_maximum *= factor; |
| 119 | |
| 120 | if (adjustUp) |
| 121 | m_maximum = std::min(m_maximum, newMaximum); |
| 122 | else |
| 123 | m_maximum = std::max(m_maximum, newMaximum); |
| 124 | } |
| 125 | |
| 126 | ProfilerRecord& Profiler::AddRecord() |
| 127 | { |