Blender  V3.3
deg_time_average.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
8 #pragma once
9 
10 namespace blender::deg {
11 
12 /* Utility class which takes care of calculating average of time series, such as FPS counters. */
13 template<int MaxSamples> class AveragedTimeSampler {
14  public:
16  {
17  }
18 
19  void add_sample(double value)
20  {
22 
23  /* Move to the next index, keeping wrapping at the end of array into account. */
25  if (next_sample_index_ == MaxSamples) {
27  }
28 
29  /* Update number of stored samples. */
30  if (num_samples_ != MaxSamples) {
31  ++num_samples_;
32  }
33  }
34 
35  double get_averaged() const
36  {
37  double sum = 0.0;
38  for (int i = 0; i < num_samples_; ++i) {
39  sum += samples_[i];
40  }
41  return sum / num_samples_;
42  }
43 
44  protected:
45  double samples_[MaxSamples];
46 
47  /* Number of samples which are actually stored in the array. */
49 
50  /* Index in the samples_ array under which next sample will be stored. */
52 };
53 
54 } // namespace blender::deg
static T sum(const btAlignedObjectArray< T > &items)