示例#1
0
        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]++;
        }
示例#2
0
 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;
 }
示例#3
0
        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;
        }
示例#4
0
        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);
        }
示例#5
0
 public ResourceSample GetStabilizedSample(ResourceSample sample)
 {
     this.AddSample(sample);
     return(this.CalculateStableSample());
 }