| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL; |
| | 4 | | using DCL.FPSDisplay; |
| | 5 | | using DCL.SettingsData; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | /// <summary> |
| | 9 | | /// An implementation of an AutoQualityController for uncapped FPS |
| | 10 | | /// </summary> |
| | 11 | | public class AutoQualityUncappedFPSController : IAutoQualityController |
| | 12 | | { |
| | 13 | | private const int EVALUATIONS_SIZE = 5; |
| | 14 | |
|
| | 15 | | internal int currentQualityIndex; |
| | 16 | | internal readonly QualitySettingsData qualitySettings; |
| | 17 | |
|
| 222 | 18 | | internal readonly List<float> fpsEvaluations = new List<float>(); |
| | 19 | |
|
| 222 | 20 | | public AutoQualityUncappedFPSController(int startIndex, QualitySettingsData qualitySettings) |
| | 21 | | { |
| 222 | 22 | | currentQualityIndex = startIndex; |
| 222 | 23 | | this.qualitySettings = qualitySettings; |
| 222 | 24 | | } |
| | 25 | |
|
| | 26 | | public int EvaluateQuality(PerformanceMetricsData metrics) |
| | 27 | | { |
| 9 | 28 | | if (metrics == null) |
| 0 | 29 | | return currentQualityIndex; |
| | 30 | |
|
| | 31 | | //TODO refine this evaluation |
| 9 | 32 | | fpsEvaluations.Add(metrics.fpsCount); |
| 9 | 33 | | if (fpsEvaluations.Count <= EVALUATIONS_SIZE) |
| 5 | 34 | | return currentQualityIndex; |
| | 35 | |
|
| 4 | 36 | | fpsEvaluations.RemoveAt(0); |
| 4 | 37 | | float average = fpsEvaluations.Average(); |
| | 38 | |
|
| 4 | 39 | | int newCurrentQualityIndex = currentQualityIndex; |
| 4 | 40 | | if (average <= FPSEvaluation.WORSE) |
| 2 | 41 | | newCurrentQualityIndex = Mathf.Max(0, currentQualityIndex - 1); |
| | 42 | |
|
| 4 | 43 | | if (average >= FPSEvaluation.GREAT) |
| 1 | 44 | | newCurrentQualityIndex = Mathf.Min(qualitySettings.Length - 1, currentQualityIndex + 1); |
| | 45 | |
|
| 4 | 46 | | if (newCurrentQualityIndex != currentQualityIndex) |
| 3 | 47 | | ResetEvaluation(); |
| | 48 | |
|
| 4 | 49 | | currentQualityIndex = newCurrentQualityIndex; |
| 4 | 50 | | return currentQualityIndex; |
| | 51 | | } |
| | 52 | |
|
| 188 | 53 | | public void ResetEvaluation() { fpsEvaluations.Clear(); } |
| | 54 | | } |