public void AddSample(ResourceSample sample) { this.currentIndex = (this.currentIndex + 1) % this.samples.Length; ResourceSample resourceSample = this.samples[this.currentIndex]; this.useLevelSampleCounts[(int)resourceSample.UseLevel]--; this.samples[this.currentIndex] = sample; this.useLevelSampleCounts[(int)sample.UseLevel]++; }
public ResourceSampleStabilizer(int maxSamples, ResourceSample initialSample) { ArgumentValidator.ThrowIfInvalidValue <int>("maxSamples", maxSamples, (int count) => count > 1); this.samples = new ResourceSample[maxSamples]; for (int i = 0; i < maxSamples; i++) { this.samples[i] = new ResourceSample(initialSample.UseLevel, initialSample.Pressure); } this.useLevelSampleCounts[(int)initialSample.UseLevel] = maxSamples; }
public void Refresh() { this.rawResourceMeter.Refresh(); ResourceSample sample = new ResourceSample(this.rawResourceMeter.ResourceUse.CurrentUseLevel, this.rawResourceMeter.Pressure); ResourceSample stabilizedSample = this.stabilizer.GetStabilizedSample(sample); ResourceUse resourceUse = new ResourceUse(this.Resource, stabilizedSample.UseLevel, this.resourceUse.CurrentUseLevel); this.resourceUse = resourceUse; this.pressure = stabilizedSample.Pressure; }
public StabilizedResourceMeter(IResourceMeter rawResourceMeter, int sampleCount) { ArgumentValidator.ThrowIfNull("rawResourceMeter", rawResourceMeter); ArgumentValidator.ThrowIfInvalidValue <int>("sampleCount", sampleCount, (int count) => count > 1); this.rawResourceMeter = rawResourceMeter; this.rawResourceMeter.Refresh(); ResourceSample initialSample = new ResourceSample(this.rawResourceMeter.ResourceUse.CurrentUseLevel, this.rawResourceMeter.Pressure); this.stabilizer = new ResourceSampleStabilizer(sampleCount, initialSample); this.pressure = this.rawResourceMeter.Pressure; this.resourceUse = new ResourceUse(this.rawResourceMeter.Resource, this.rawResourceMeter.ResourceUse.CurrentUseLevel, this.rawResourceMeter.ResourceUse.PreviousUseLevel); }
public ResourceSample GetStabilizedSample(ResourceSample sample) { this.AddSample(sample); return(this.CalculateStableSample()); }