Skip to content

Commit

Permalink
added PlotHistogram in SimPerfStats, unified theme
Browse files Browse the repository at this point in the history
  • Loading branch information
tritonas00 committed Nov 16, 2021
1 parent 7436667 commit 341b87f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions source/main/gui/panels/GUI_SimActorStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void SimActorStats::Draw(RoR::GfxActor* actorx)
ImGuiWindowFlags flags = ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar;
ImGui::SetNextWindowPos(ImVec2(theme.screen_edge_padding.x, (theme.screen_edge_padding.y + 150)));
ImGui::PushStyleColor(ImGuiCol_WindowBg, theme.semitransparent_window_bg);
ImGui::Begin("SimActorStats", nullptr, flags);

RoR::ImTextWrappedColorMarked(actorx->GetActor()->getTruckName());
Expand Down Expand Up @@ -221,6 +222,7 @@ void SimActorStats::Draw(RoR::GfxActor* actorx)

ImGui::NewLine();
ImGui::End();
ImGui::PopStyleColor(1); // WindowBg
}

void SimActorStats::UpdateStats(float dt, Actor* actor)
Expand Down
45 changes: 41 additions & 4 deletions source/main/gui/panels/GUI_SimPerfStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "AppContext.h"
#include "GUIManager.h"
#include "Language.h"
#include <iomanip>

#include <imgui.h>
#include <Ogre.h>
Expand All @@ -39,17 +40,53 @@ void SimPerfStats::Draw()
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar;
ImGui::SetNextWindowPos(theme.screen_edge_padding);
ImGui::PushStyleColor(ImGuiCol_WindowBg, theme.semitransparent_window_bg);
ImVec2 histogram_size = ImVec2(60.f, 35.f);
ImGui::Begin("FPS", &m_is_visible, flags);

const Ogre::RenderTarget::FrameStats& stats = App::GetAppContext()->GetRenderWindow()->getStatistics();
ImGui::Text("%s%.2f", _LC("SimPerfStats", "Current FPS: "), stats.lastFPS);
ImGui::Text("%s%.2f", _LC("SimPerfStats", "Average FPS: "), stats.avgFPS);
ImGui::Text("%s%.2f", _LC("SimPerfStats", "Worst FPS: "), stats.worstFPS);
ImGui::Text("%s%.2f", _LC("SimPerfStats", "Best FPS: "), stats.bestFPS);

std::string title = "FPS";
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - ImGui::CalcTextSize(title.c_str()).x) * 0.5f);
ImGui::Text(title.c_str());

std::string a = "Current";
ImGui::SetCursorPosX((histogram_size.x + (3 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(a.c_str()).x) * 0.5f);
ImGui::Text("%s", _LC("SimPerfStats", a.c_str()));
ImGui::SameLine();

std::string b = "Average";
ImGui::SetCursorPosX((histogram_size.x * 3 + (5 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(b.c_str()).x) * 0.5f);
ImGui::Text("%s", _LC("SimPerfStats", b.c_str()));
ImGui::SameLine();

std::string c = "Worst";
ImGui::SetCursorPosX((histogram_size.x * 5 + (7 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(c.c_str()).x) * 0.5f);
ImGui::Text("%s", _LC("SimPerfStats", c.c_str()));
ImGui::SameLine();

std::string d = "Best";
ImGui::SetCursorPosX((histogram_size.x * 7 + (9 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(d.c_str()).x) * 0.5f);
ImGui::Text("%s", _LC("SimPerfStats", d.c_str()));

ImGui::PlotHistogram("", &stats.lastFPS, 1, 0, this->Convert(stats.lastFPS).c_str(), 0.f, 300.f, histogram_size);
ImGui::SameLine();
ImGui::PlotHistogram("", &stats.avgFPS, 1, 0, this->Convert(stats.avgFPS).c_str(), 0.f, 300.f, histogram_size);
ImGui::SameLine();
ImGui::PlotHistogram("", &stats.worstFPS, 1, 0, this->Convert(stats.worstFPS).c_str(), 0.f, 300.f, histogram_size);
ImGui::SameLine();
ImGui::PlotHistogram("", &stats.bestFPS, 1, 0, this->Convert(stats.bestFPS).c_str(), 0.f, 300.f, histogram_size);

ImGui::Separator();
ImGui::Text("%s%zu", _LC("SimPerfStats", "Triangle count: "), stats.triangleCount);
ImGui::Text("%s%zu", _LC("SimPerfStats", "Batch count: "), stats.batchCount);

ImGui::End();
ImGui::PopStyleColor(1); // WindowBg
}

std::string SimPerfStats::Convert(const float f)
{
std::stringstream s;
s << std::fixed << std::setprecision(2) << f;
return s.str();
}
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_SimPerfStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SimPerfStats

private:
bool m_is_visible = false;
std::string Convert(const float f); // converts const float to std::string with precision
};

} // namespace GUI
Expand Down

0 comments on commit 341b87f

Please # to comment.