Skip to content

Commit

Permalink
added PlotHistogram in SimPerfStats, unified theme with SimActorStats
Browse files Browse the repository at this point in the history
  • Loading branch information
tritonas00 committed Nov 15, 2021
1 parent 7436667 commit 70dc969
Show file tree
Hide file tree
Showing 3 changed files with 25 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
26 changes: 22 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 @@ -42,14 +43,31 @@ void SimPerfStats::Draw()
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());
ImGui::Text("%s", _LC("SimPerfStats", " Current Average Worst Best"));

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

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 70dc969

Please # to comment.