1 //
2 // Copyright (c) 2008-2017 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 
23 #pragma once
24 
25 #include "../Core/Object.h"
26 #include "../Core/Timer.h"
27 
28 namespace Urho3D
29 {
30 
31 class Engine;
32 class Font;
33 class Text;
34 class XMLFile;
35 
36 static const unsigned DEBUGHUD_SHOW_NONE = 0x0;
37 static const unsigned DEBUGHUD_SHOW_STATS = 0x1;
38 static const unsigned DEBUGHUD_SHOW_MODE = 0x2;
39 static const unsigned DEBUGHUD_SHOW_PROFILER = 0x4;
40 static const unsigned DEBUGHUD_SHOW_MEMORY = 0x8;
41 static const unsigned DEBUGHUD_SHOW_EVENTPROFILER = 0x10;
42 static const unsigned DEBUGHUD_SHOW_ALL = DEBUGHUD_SHOW_STATS | DEBUGHUD_SHOW_MODE | DEBUGHUD_SHOW_PROFILER | DEBUGHUD_SHOW_MEMORY;
43 
44 /// Displays rendering stats and profiling information.
45 class URHO3D_API DebugHud : public Object
46 {
47     URHO3D_OBJECT(DebugHud, Object);
48 
49 public:
50     /// Construct.
51     DebugHud(Context* context);
52     /// Destruct.
53     ~DebugHud();
54 
55     /// Update. Called by HandlePostUpdate().
56     void Update();
57     /// Set UI elements' style from an XML file.
58     void SetDefaultStyle(XMLFile* style);
59     /// Set elements to show.
60     void SetMode(unsigned mode);
61     /// Set maximum profiler block depth, default unlimited.
62     void SetProfilerMaxDepth(unsigned depth);
63     /// Set profiler accumulation interval in seconds.
64     void SetProfilerInterval(float interval);
65     /// Set whether to show 3D geometry primitive/batch count only. Default false.
66     void SetUseRendererStats(bool enable);
67     /// Toggle elements.
68     void Toggle(unsigned mode);
69     /// Toggle all elements.
70     void ToggleAll();
71 
72     /// Return the UI style file.
73     XMLFile* GetDefaultStyle() const;
74 
75     /// Return rendering stats text.
GetStatsText()76     Text* GetStatsText() const { return statsText_; }
77 
78     /// Return rendering mode text.
GetModeText()79     Text* GetModeText() const { return modeText_; }
80 
81     /// Return profiler text.
GetProfilerText()82     Text* GetProfilerText() const { return profilerText_; }
83 
84     /// Return memory text.
GetMemoryText()85     Text* GetMemoryText() const { return memoryText_; }
86 
87     /// Return currently shown elements.
GetMode()88     unsigned GetMode() const { return mode_; }
89 
90     /// Return maximum profiler block depth.
GetProfilerMaxDepth()91     unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
92 
93     /// Return profiler accumulation interval in seconds
94     float GetProfilerInterval() const;
95 
96     /// Return whether showing 3D geometry primitive/batch count only.
GetUseRendererStats()97     bool GetUseRendererStats() const { return useRendererStats_; }
98 
99     /// Set application-specific stats.
100     void SetAppStats(const String& label, const Variant& stats);
101     /// Set application-specific stats.
102     void SetAppStats(const String& label, const String& stats);
103     /// Reset application-specific stats. Return true if it was erased successfully.
104     bool ResetAppStats(const String& label);
105     /// Clear all application-specific stats.
106     void ClearAppStats();
107 
108 private:
109     /// Handle logic post-update event. The HUD texts are updated here.
110     void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
111 
112     /// Rendering stats text.
113     SharedPtr<Text> statsText_;
114     /// Rendering mode text.
115     SharedPtr<Text> modeText_;
116     /// Profiling information text.
117     SharedPtr<Text> profilerText_;
118     /// Event profiling information text.
119     SharedPtr<Text> eventProfilerText_;
120     /// Memory stats text.
121     SharedPtr<Text> memoryText_;
122     /// Hashmap containing application specific stats.
123     HashMap<String, String> appStats_;
124     /// Profiler timer.
125     Timer profilerTimer_;
126     /// Profiler max block depth.
127     unsigned profilerMaxDepth_;
128     /// Profiler accumulation interval.
129     unsigned profilerInterval_;
130     /// Show 3D geometry primitive/batch count flag.
131     bool useRendererStats_;
132     /// Current shown-element mode.
133     unsigned mode_;
134 };
135 
136 }
137