| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Interface; |
| | 4 | |
|
| | 5 | | public interface ITimeReporter : IDisposable |
| | 6 | | { |
| | 7 | | void Configure(float normalizationFactor, float cycle); |
| | 8 | | void ReportTime(float time); |
| | 9 | | } |
| | 10 | |
|
| | 11 | | public class TimeReporter : ITimeReporter |
| | 12 | | { |
| | 13 | | private float timeNormalizationFactor; |
| | 14 | | private float cycleTime; |
| | 15 | | private bool wasTimeRunning; |
| | 16 | |
|
| | 17 | | internal delegate void OnReportEventHandler(float time, bool isPaused); |
| | 18 | | internal event OnReportEventHandler OnReport; |
| | 19 | |
|
| 3 | 20 | | public TimeReporter() |
| | 21 | | { |
| 3 | 22 | | OnReport += DoReport; |
| 3 | 23 | | } |
| | 24 | |
|
| | 25 | | public void Dispose() |
| | 26 | | { |
| 0 | 27 | | OnReport -= DoReport; |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public void Configure(float normalizationFactor, float cycle) |
| | 31 | | { |
| 0 | 32 | | timeNormalizationFactor = normalizationFactor; |
| 0 | 33 | | cycleTime = cycle; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public void ReportTime(float time) |
| | 37 | | { |
| 7 | 38 | | bool isTimeRunning = DataStore.i.skyboxConfig.useDynamicSkybox.Get(); |
| | 39 | |
|
| | 40 | | // NOTE: if not paused and pause state didn't change there is no need to report |
| | 41 | | // current time since it's being calculated on kernel side |
| 7 | 42 | | if (isTimeRunning && wasTimeRunning) |
| | 43 | | { |
| 1 | 44 | | return; |
| | 45 | | } |
| | 46 | |
|
| 6 | 47 | | wasTimeRunning = isTimeRunning; |
| 6 | 48 | | OnReport?.Invoke(time, !isTimeRunning); |
| 6 | 49 | | } |
| | 50 | |
|
| | 51 | | private void DoReport(float time, bool isPaused) |
| | 52 | | { |
| 6 | 53 | | WebInterface.ReportTime(time, isPaused, timeNormalizationFactor, cycleTime); |
| 6 | 54 | | } |
| | 55 | | } |