Pārlūkot izejas kodu

Applied DebugHud app stats patch from weitjong.

Lasse Öörni 13 gadi atpakaļ
vecāks
revīzija
0891aa62dc

+ 12 - 0
Bin/Data/Scripts/NinjaSnowWar.as

@@ -395,6 +395,18 @@ void HandleUpdate(StringHash eventType, VariantMap& eventData)
         if (command.length > 0)
             script.Execute(command);
     }
+
+    if (debugHud.mode != DEBUGHUD_SHOW_NONE)
+    {
+        Node@ playerNode = FindOwnNode();
+        if (playerNode !is null)
+        {
+            debugHud.SetAppStats("Player Pos", playerNode.worldPosition.ToString());
+            debugHud.SetAppStats("Player Yaw", Variant(playerNode.worldRotation.yaw));
+        }
+        else
+            debugHud.ClearAppStats();
+    }
 }
 
 void HandleFixedUpdate(StringHash eventType, VariantMap& eventData)

+ 4 - 0
Docs/ScriptAPI.dox

@@ -5034,6 +5034,10 @@ Methods:<br>
 - void SendEvent(const String&, VariantMap& arg1 = VariantMap ( ))
 - void Toggle(uint)
 - void ToggleAll()
+- void SetAppStats(const String&, const Variant&)
+- void SetAppStats(const String&, const String&)
+- void ResetAppStats(const String&)
+- void ClearAppStats()
 
 Properties:<br>
 - ShortStringHash type (readonly)

+ 31 - 12
Engine/Engine/DebugHud.cpp

@@ -58,7 +58,8 @@ DebugHud::DebugHud(Context* context) :
     Object(context),
     profilerMaxDepth_(M_MAX_UNSIGNED),
     profilerInterval_(1.0f),
-    useRendererStats_(false)
+    useRendererStats_(false),
+    mode_(DEBUGHUD_SHOW_NONE)
 {
     UI* ui = GetSubsystem<UI>();
     UIElement* uiRoot = ui->GetRoot();
@@ -121,6 +122,13 @@ void DebugHud::Update()
             renderer->GetNumShadowMaps(true),
             renderer->GetNumOccluders(true));
         
+        if (!appStats_.Empty())
+        {
+            stats.Append("\n");
+            for (HashMap<String, String>::ConstIterator i = appStats_.Begin(); i != appStats_.End(); ++i)
+                stats.AppendWithFormat("\n%s %s", i->first_.CString(), i->second_.CString());
+        }
+        
         statsText_->SetText(stats);
     }
     
@@ -179,6 +187,8 @@ void DebugHud::SetMode(unsigned mode)
     statsText_->SetVisible((mode & DEBUGHUD_SHOW_STATS) != 0);
     modeText_->SetVisible((mode & DEBUGHUD_SHOW_MODE) != 0);
     profilerText_->SetVisible((mode & DEBUGHUD_SHOW_PROFILER) != 0);
+    
+    mode_ = mode;
 }
 
 void DebugHud::SetProfilerMaxDepth(unsigned depth)
@@ -206,20 +216,29 @@ void DebugHud::ToggleAll()
     Toggle(DEBUGHUD_SHOW_ALL);
 }
 
-unsigned DebugHud::GetMode() const
+void DebugHud::SetAppStats(const String& label, const Variant& stats)
 {
-    unsigned mode = DEBUGHUD_SHOW_NONE;
-    
-    if (statsText_->IsVisible())
-        mode |= DEBUGHUD_SHOW_STATS;
-    if (modeText_->IsVisible())
-        mode |= DEBUGHUD_SHOW_MODE;
-    if (profilerText_->IsVisible())
-        mode |= DEBUGHUD_SHOW_PROFILER;
-    
-    return mode;
+    SetAppStats(label, stats.ToString());
 }
 
+void DebugHud::SetAppStats(const String& label, const String& stats)
+{
+    bool newLabel = !appStats_.Contains(label);
+    appStats_[label] = stats;
+    if (newLabel)
+        appStats_.Sort();
+}
+
+bool DebugHud::ResetAppStats(const String& label)
+{
+    return appStats_.Erase(label);
+}
+
+void DebugHud::ClearAppStats()
+{
+    appStats_.Clear();
+}
+    
 void DebugHud::HandleUpdate(StringHash eventType, VariantMap& eventData)
 {
     using namespace Update;

+ 13 - 1
Engine/Engine/DebugHud.h

@@ -76,13 +76,21 @@ public:
     /// Return profiler text.
     Text* GetProfilerText() const { return profilerText_; }
     /// Return currently shown elements.
-    unsigned GetMode() const;
+    unsigned GetMode() const { return mode_; }
     /// Return maximum profiler block depth.
     unsigned GetProfilerMaxDepth() const { return profilerMaxDepth_; }
     /// Return profiler accumulation interval.
     float GetProfilerInterval() const { return profilerInterval_; }
     /// Return whether showing 3D geometry primitive/batch count only.
     bool GetUseRendererStats() const { return useRendererStats_; }
+    /// Set application-specific stats.
+    void SetAppStats(const String& label, const Variant& stats);
+    /// Set application-specific stats.
+    void SetAppStats(const String& label, const String& stats);
+    /// Reset application-specific stats. Return true if it was erased successfully.
+    bool ResetAppStats(const String& label);
+    /// Clear all application-specific stats.
+    void ClearAppStats();
     
 private:
     /// Handle logic update event.
@@ -96,6 +104,8 @@ private:
     SharedPtr<Text> modeText_;
     /// Profiling information text.
     SharedPtr<Text> profilerText_;
+    /// Hashmap containing application specific stats.
+    HashMap<String, String> appStats_;
     /// Profiler timer.
     Timer profilerTimer_;
     /// Profiler max block depth.
@@ -104,6 +114,8 @@ private:
     float profilerInterval_;
     /// Show 3D geometry primitive/batch count flag.
     bool useRendererStats_;
+    /// Current shown-element mode.
+    unsigned mode_;
 };
 
 }

+ 4 - 0
Engine/Engine/EngineAPI.cpp

@@ -83,6 +83,10 @@ static void RegisterDebugHud(asIScriptEngine* engine)
     engine->RegisterObjectMethod("DebugHud", "Text@+ get_statsText() const", asMETHOD(DebugHud, GetStatsText), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugHud", "Text@+ get_modeText() const", asMETHOD(DebugHud, GetModeText), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugHud", "Text@+ get_profilerText() const", asMETHOD(DebugHud, GetProfilerText), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugHud", "void SetAppStats(const String&in, const Variant&in)", asMETHODPR(DebugHud, SetAppStats, (const String&, const Variant&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugHud", "void SetAppStats(const String&in, const String&in)", asMETHODPR(DebugHud, SetAppStats, (const String&, const String&), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugHud", "void ResetAppStats(const String&in)", asMETHOD(DebugHud, ResetAppStats), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugHud", "void ClearAppStats()", asMETHOD(DebugHud, ClearAppStats), asCALL_THISCALL);
     engine->RegisterGlobalFunction("DebugHud@+ get_debugHud()", asFUNCTION(GetDebugHud), asCALL_CDECL);
 }