DebugHud.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Copyright (c) 2008-2014 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 Font;
  29. class Text;
  30. class XMLFile;
  31. static const unsigned DEBUGHUD_SHOW_NONE = 0x0;
  32. static const unsigned DEBUGHUD_SHOW_STATS = 0x1;
  33. static const unsigned DEBUGHUD_SHOW_MODE = 0x2;
  34. static const unsigned DEBUGHUD_SHOW_PROFILER = 0x4;
  35. static const unsigned DEBUGHUD_SHOW_ALL = 0x7;
  36. /// Displays rendering stats and profiling information.
  37. class ATOMIC_API DebugHud : public Object
  38. {
  39. OBJECT(DebugHud);
  40. public:
  41. /// Construct.
  42. DebugHud(Context* context);
  43. /// Destruct.
  44. ~DebugHud();
  45. /// Update. Called by HandlePostUpdate().
  46. void Update();
  47. /// Set UI elements' style from an XML file.
  48. void SetDefaultStyle(XMLFile* style);
  49. /// Set elements to show.
  50. void SetMode(unsigned mode);
  51. /// Set maximum profiler block depth, default unlimited.
  52. void SetProfilerMaxDepth(unsigned depth);
  53. /// Set profiler accumulation interval in seconds.
  54. void SetProfilerInterval(float interval);
  55. /// Set whether to show 3D geometry primitive/batch count only. Default false.
  56. void SetUseRendererStats(bool enable);
  57. /// Toggle elements.
  58. void Toggle(unsigned mode);
  59. /// Toggle all elements.
  60. void ToggleAll();
  61. /// Return the UI style file.
  62. XMLFile* GetDefaultStyle() const;
  63. /// Return rendering stats text.
  64. Text* GetStatsText() const { return statsText_; }
  65. /// Return rendering mode text.
  66. Text* GetModeText() const { return modeText_; }
  67. /// Return profiler text.
  68. Text* GetProfilerText() const { return profilerText_; }
  69. /// Return currently shown elements.
  70. unsigned GetMode() const { return mode_; }
  71. /// Return maximum profiler block depth.
  72. unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
  73. /// Return profiler accumulation interval in seconds
  74. float GetProfilerInterval() const;
  75. /// Return whether showing 3D geometry primitive/batch count only.
  76. bool GetUseRendererStats() const { return useRendererStats_; }
  77. /// Set application-specific stats.
  78. void SetAppStats(const String& label, const Variant& stats);
  79. /// Set application-specific stats.
  80. void SetAppStats(const String& label, const String& stats);
  81. /// Reset application-specific stats. Return true if it was erased successfully.
  82. bool ResetAppStats(const String& label);
  83. /// Clear all application-specific stats.
  84. void ClearAppStats();
  85. private:
  86. /// Handle logic post-update event. The HUD texts are updated here.
  87. void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
  88. /// Rendering stats text.
  89. SharedPtr<Text> statsText_;
  90. /// Rendering mode text.
  91. SharedPtr<Text> modeText_;
  92. /// Profiling information text.
  93. SharedPtr<Text> profilerText_;
  94. /// Hashmap containing application specific stats.
  95. HashMap<String, String> appStats_;
  96. /// Profiler timer.
  97. Timer profilerTimer_;
  98. /// Profiler max block depth.
  99. unsigned profilerMaxDepth_;
  100. /// Profiler accumulation interval.
  101. unsigned profilerInterval_;
  102. /// Show 3D geometry primitive/batch count flag.
  103. bool useRendererStats_;
  104. /// Current shown-element mode.
  105. unsigned mode_;
  106. };
  107. }