DebugHud.h 4.9 KB

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