Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
RunningAverage.cs
浏览该文件的文档.
1using System.Diagnostics;
2
3namespace Game {
4 public class RunningAverage {
5 public long m_startTicks;
6
7 public long m_period;
8
9 public float m_sumValues;
10
11 public int m_countValues;
12
13 public float m_value;
14
15 public float Value => m_value;
16
17 public RunningAverage(float period) => m_period = (long)(period * Stopwatch.Frequency);
18
19 public void AddSample(float sample) {
20 m_sumValues += sample;
22 long timestamp = Stopwatch.GetTimestamp();
23 if (timestamp >= m_startTicks + m_period) {
25 m_sumValues = 0f;
26 m_countValues = 0;
27 m_startTicks = timestamp;
28 }
29 }
30 }
31}
void AddSample(float sample)