DebugHud.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2017 the Atomic project.
  3. // Copyright (c) 2008-2015 the Urho3D project.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "../../Core/Object.h"
  25. #include "../../Core/Timer.h"
  26. #include "../../Metrics/Metrics.h"
  27. #include "../UIEnums.h"
  28. namespace Atomic
  29. {
  30. static const unsigned DEBUGHUD_SHOW_NONE = 0x0;
  31. static const unsigned DEBUGHUD_SHOW_STATS = 0x1;
  32. static const unsigned DEBUGHUD_SHOW_MODE = 0x2;
  33. static const unsigned DEBUGHUD_SHOW_PROFILER = 0x4;
  34. static const unsigned DEBUGHUD_SHOW_ALL = 0x7;
  35. /// Displays rendering stats and profiling information.
  36. class ATOMIC_API DebugHud : public Object
  37. {
  38. ATOMIC_OBJECT(DebugHud, Object)
  39. public:
  40. /// Construct.
  41. DebugHud(Context* context);
  42. /// Destruct.
  43. ~DebugHud();
  44. /// Set elements to show.
  45. void SetMode(unsigned mode);
  46. /// Cycle through elements
  47. void CycleMode();
  48. /// Set maximum profiler block depth, default unlimited.
  49. void SetProfilerMaxDepth(unsigned depth);
  50. /// Set profiler accumulation interval in seconds.
  51. void SetProfilerInterval(float interval);
  52. /// Set the profiler mode to either performance or metrics
  53. void SetProfilerMode(DebugHudProfileMode mode);
  54. /// Set whether to show 3D geometry primitive/batch count only. Default false.
  55. void SetUseRendererStats(bool enable);
  56. /// Toggle elements.
  57. void Toggle(unsigned mode);
  58. /// Toggle all elements.
  59. void ToggleAll();
  60. /// Return currently shown elements.
  61. unsigned GetMode() const { return mode_; }
  62. /// Return the profiler mode (performance, metrics, etc)
  63. DebugHudProfileMode GetProfilerMode() const { return profilerMode_; }
  64. /// Return maximum profiler block depth.
  65. unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
  66. /// Return profiler accumulation interval in seconds
  67. float GetProfilerInterval() const;
  68. /// Return whether showing 3D geometry primitive/batch count only.
  69. bool GetUseRendererStats() const { return useRendererStats_; }
  70. /// Set application-specific stats.
  71. void SetAppStats(const String& label, const Variant& stats);
  72. /// Set application-specific stats.
  73. void SetAppStats(const String& label, const String& stats);
  74. /// Reset application-specific stats. Return true if it was erased successfully.
  75. bool ResetAppStats(const String& label);
  76. /// Clear all application-specific stats.
  77. void ClearAppStats();
  78. void SetExtents(bool useRootExtents = true, const IntVector2& position = IntVector2::ZERO, const IntVector2& size = IntVector2::ZERO);
  79. void ResetExtents();
  80. private:
  81. /// Render system ui.
  82. void RenderUi(StringHash eventType, VariantMap& eventData);
  83. void RecalculateWindowPositions();
  84. /// Hashmap containing application specific stats.
  85. HashMap<String, String> appStats_;
  86. /// Profiler timer.
  87. Timer profilerTimer_;
  88. /// Profiler max block depth.
  89. unsigned profilerMaxDepth_;
  90. /// Profiler mode
  91. DebugHudProfileMode profilerMode_;
  92. /// Profiler accumulation interval.
  93. unsigned profilerInterval_;
  94. /// Show 3D geometry primitive/batch count flag.
  95. bool useRendererStats_;
  96. /// Current shown-element mode.
  97. unsigned mode_;
  98. /// Time since last fps display update
  99. float fpsTimeSinceUpdate_;
  100. /// Frames since last fps display update
  101. float fpsFramesSinceUpdate_;
  102. /// Calculated fps
  103. unsigned fps_;
  104. /// Cached profiler output.
  105. String profilerOutput_;
  106. /// Metrics data snapshot.
  107. MetricsSnapshot metricsSnapshot_;
  108. /// DebugHud extents that data will be rendered in.
  109. IntRect extents_;
  110. IntVector2 posMode_;
  111. IntVector2 posStats_;
  112. IntVector2 posProfiler_;
  113. };
  114. }