ImGuiHistogramQueue.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/containers/vector.h>
  10. namespace AtomSampleViewer
  11. {
  12. //! Tracks time values over multiple frames, computes the average, and draws a historgram.
  13. class ImGuiHistogramQueue
  14. {
  15. public:
  16. //! @param maxSamples the max number of samples that can be recorded in the queue and displayed in the histogram
  17. //! @param runningAverageSamples the number of samples to use for calculating running average hash-marks that are overlaid on the histogram
  18. //! @param numericDisplayUpdateDelay the number of seconds to delay between updates of the numeric display
  19. ImGuiHistogramQueue(
  20. AZStd::size_t maxSamples,
  21. AZStd::size_t runningAverageSamples,
  22. float numericDisplayUpdateDelay = 0.25f);
  23. struct WidgetSettings
  24. {
  25. bool m_reportInverse = false; //!< Use 1/average instead of average for displaying the numeric value
  26. const char* m_units = "";
  27. };
  28. void PushValue(float value);
  29. void Tick(float deltaTime, WidgetSettings settings);
  30. float GetDisplayedAverage() const { return m_displayedAverage; }
  31. float GetDisplayedMinimum() const { return m_displayedMinimum; }
  32. float GetDisplayedMaximum() const { return m_displayedMaximum; }
  33. private:
  34. float UpdateDisplayedValues(AZStd::size_t maxSampleCount, float& minValue, float& maxValue);
  35. AZStd::vector<float> m_valueLog;
  36. AZStd::vector<float> m_averageLog;
  37. const AZStd::size_t m_maxSamples;
  38. const AZStd::size_t m_runningAverageSamples;
  39. const float m_numericDisplayDelay;
  40. float m_timeSinceLastDisplayUpdate = 0.0f;
  41. int m_samplesSinceLastDisplayUpdate = 0;
  42. float m_displayedAverage = 0.0f;
  43. float m_displayedMinimum = 0.0f;
  44. float m_displayedMaximum = 0.0f;
  45. };
  46. } // namespace AtomSampleViewer