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