Skip to content

Commit

Permalink
Auto-calculate metrics window size in DebugHud
Browse files Browse the repository at this point in the history
  • Loading branch information
rokups committed Jun 16, 2017
1 parent 3c3cfbd commit 38559a8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
80 changes: 42 additions & 38 deletions Source/Atomic/UI/SystemUI/DebugHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,9 @@ void DebugHud::ResetExtents()

void DebugHud::RecalculateWindowPositions()
{
auto withinExtents = [&](IntVector2 pos) -> IntVector2
{
if (pos.x_ < 0)
pos.x_ += extents_.right_;
else if (pos.x_ > 0)
pos.x_ += extents_.left_;
else
pos.x_ = extents_.left_;

if (pos.y_ < 0)
pos.y_ += extents_.bottom_;
else if (pos.y_ > 0)
pos.y_ += extents_.top_;
else
pos.y_ = extents_.top_;

return pos;
};

posMode_ = withinExtents({0, -30});
posStats_ = withinExtents({0, 0});
posProfiler_ = withinExtents({-530, 0});
posMode_ = WithinExtents({0, -30});
posStats_ = WithinExtents({0, 0});
posProfiler_ = WithinExtents({-530, 0});
}

void DebugHud::SetProfilerMode(DebugHudProfileMode mode)
Expand Down Expand Up @@ -210,6 +191,25 @@ void DebugHud::ClearAppStats()
appStats_.Clear();
}

IntVector2 DebugHud::WithinExtents(IntVector2 pos)
{
if (pos.x_ < 0)
pos.x_ += extents_.right_;
else if (pos.x_ > 0)
pos.x_ += extents_.left_;
else
pos.x_ = extents_.left_;

if (pos.y_ < 0)
pos.y_ += extents_.bottom_;
else if (pos.y_ > 0)
pos.y_ += extents_.top_;
else
pos.y_ = extents_.top_;

return pos;
};

void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData)
{
Renderer* renderer = GetSubsystem<Renderer>();
Expand Down Expand Up @@ -292,11 +292,12 @@ void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData)
if (mode_ & DEBUGHUD_SHOW_PROFILER)
{
ImGui::SetNextWindowPos(ImVec2(posProfiler_.x_, posProfiler_.y_));
if (ImGui::Begin("DebugHud Metrics", 0, ImVec2(530, 1080), 0, backgroundTextWindowFlags))
ImGui::SetNextWindowSize(ImVec2(sizeProfiler_.x_, sizeProfiler_.y_));
if (ImGui::Begin("DebugHud Metrics", 0, ImVec2(0, 0), 0, backgroundTextWindowFlags))
{
if (profilerMode_ == DEBUG_HUD_PROFILE_PERFORMANCE)
if (profilerTimer_.GetMSec(false) >= profilerInterval_)
{
if (profilerTimer_.GetMSec(false) >= profilerInterval_)
if (profilerMode_ == DEBUG_HUD_PROFILE_PERFORMANCE)
{
profilerTimer_.Reset();
Profiler* profiler = GetSubsystem<Profiler>();
Expand All @@ -306,25 +307,28 @@ void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData)
profiler->BeginInterval();
}
}
ImGui::Text(profilerOutput_.CString());
}
else
{
Metrics* metrics = GetSubsystem<Metrics>();
if (metrics)
else
{
if (metrics->GetEnabled())
Metrics* metrics = GetSubsystem<Metrics>();
if (metrics)
{
metricsSnapshot_.Clear();
metrics->Capture(&metricsSnapshot_);
ImGui::Text(metricsSnapshot_.PrintData(2).CString());
if (metrics->GetEnabled())
{
metricsSnapshot_.Clear();
metrics->Capture(&metricsSnapshot_);
profilerOutput_ = metricsSnapshot_.PrintData(2);
}
else
profilerOutput_ = "Metrics system not enabled";
}
else
ImGui::Text("Metrics system not enabled");
profilerOutput_ = "Metrics subsystem not found";
}
else
ImGui::Text("Metrics subsystem not found");
auto size = ImGui::CalcTextSize(profilerOutput_.CString());
sizeProfiler_ = IntVector2(size.x + 20, size.y + 20);
posProfiler_ = WithinExtents({-(size.x + 20), 0});
}
ImGui::Text(profilerOutput_.CString());
}
ImGui::End();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Atomic/UI/SystemUI/DebugHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class ATOMIC_API DebugHud : public Object
/// Render system ui.
void RenderUi(StringHash eventType, VariantMap& eventData);
void RecalculateWindowPositions();
IntVector2 WithinExtents(IntVector2 pos);

/// Hashmap containing application specific stats.
HashMap<String, String> appStats_;
Expand Down Expand Up @@ -127,6 +128,7 @@ class ATOMIC_API DebugHud : public Object
IntVector2 posMode_;
IntVector2 posStats_;
IntVector2 posProfiler_;
IntVector2 sizeProfiler_;
};

}

0 comments on commit 38559a8

Please sign in to comment.