| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class ThrottlingCounter |
| | 7 | | { |
| 43 | 8 | | public bool enabled = true; |
| 3046 | 9 | | public double budgetPerFrame { get => enabled ? budgetPerFrameValue : double.MaxValue; set => budgetPerFrameValu |
| 43 | 10 | | private double budgetPerFrameValue = 2 / 1000.0; |
| | 11 | | private double timeBudgetCounter = 0f; |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// EvaluateTimeBudget decrements an internal time budget counter according to the given elapsedTime. |
| | 15 | | /// The method returns a bool value indicating that the time budget has been exceeded. When this happens, a fram |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="elapsedTime">The elapsed time in seconds.</param> |
| | 18 | | /// <returns>True if a frame skip is needed</returns> |
| | 19 | | public bool EvaluateTimeBudget(double elapsedTime) |
| | 20 | | { |
| 3046 | 21 | | if ( elapsedTime <= 0 ) |
| 0 | 22 | | return false; |
| | 23 | |
|
| 3046 | 24 | | timeBudgetCounter += elapsedTime; |
| | 25 | |
|
| 3046 | 26 | | if ( timeBudgetCounter > budgetPerFrame ) |
| | 27 | | { |
| 182 | 28 | | timeBudgetCounter = 0; |
| 182 | 29 | | return true; |
| | 30 | | } |
| | 31 | |
|
| 2864 | 32 | | return false; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public void Reset() |
| | 36 | | { |
| 0 | 37 | | timeBudgetCounter = 0; |
| 0 | 38 | | } |
| | 39 | | } |
| | 40 | | } |