RigsofRods
Soft-body Physics Simulation
GUI_SimPerfStats.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2019 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "GUI_SimPerfStats.h"
23 
24 #include "Actor.h"
25 #include "AppContext.h"
26 #include "GUIManager.h"
27 #include "Language.h"
28 #include <iomanip>
29 
30 #include <imgui.h>
31 #include <Ogre.h>
32 
33 using namespace RoR;
34 using namespace GUI;
35 
37 {
39 
40  ImGuiWindowFlags flags = ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoCollapse |
41  ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar;
42  ImGui::SetNextWindowPos(theme.screen_edge_padding);
43  ImGui::PushStyleColor(ImGuiCol_WindowBg, theme.semitransparent_window_bg);
44  ImVec2 histogram_size = ImVec2(60.f, 35.f);
45  ImGui::Begin("FPS", &m_is_visible, flags);
46 
47  const Ogre::RenderTarget::FrameStats& stats = App::GetAppContext()->GetRenderWindow()->getStatistics();
48 
49  std::string title = "FPS";
50  ImGui::SetCursorPosX((ImGui::GetWindowSize().x - ImGui::CalcTextSize(title.c_str()).x) * 0.5f);
51  ImGui::Text(title.c_str());
52 
53  std::string a = "Current";
54  ImGui::SetCursorPosX((histogram_size.x + (3 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(a.c_str()).x) * 0.5f);
55  ImGui::Text("%s", _LC("SimPerfStats", a.c_str()));
56  ImGui::SameLine();
57 
58  std::string b = "Average";
59  ImGui::SetCursorPosX((histogram_size.x * 3 + (5 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(b.c_str()).x) * 0.5f);
60  ImGui::Text("%s", _LC("SimPerfStats", b.c_str()));
61  ImGui::SameLine();
62 
63  std::string c = "Worst";
64  ImGui::SetCursorPosX((histogram_size.x * 5 + (7 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(c.c_str()).x) * 0.5f);
65  ImGui::Text("%s", _LC("SimPerfStats", c.c_str()));
66  ImGui::SameLine();
67 
68  std::string d = "Best";
69  ImGui::SetCursorPosX((histogram_size.x * 7 + (9 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(d.c_str()).x) * 0.5f);
70  ImGui::Text("%s", _LC("SimPerfStats", d.c_str()));
71 
72  ImGui::PlotHistogram("", &stats.lastFPS, 1, 0, this->Convert(stats.lastFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
73  ImGui::SameLine();
74  ImGui::PlotHistogram("", &stats.avgFPS, 1, 0, this->Convert(stats.avgFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
75  ImGui::SameLine();
76  ImGui::PlotHistogram("", &stats.worstFPS, 1, 0, this->Convert(stats.worstFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
77  ImGui::SameLine();
78  ImGui::PlotHistogram("", &stats.bestFPS, 1, 0, this->Convert(stats.bestFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
79 
80  ImGui::Separator();
81  ImGui::Text("%s%zu", _LC("SimPerfStats", "Triangle count: "), stats.triangleCount);
82  ImGui::Text("%s%zu", _LC("SimPerfStats", "Batch count: "), stats.batchCount);
83 
84  ImGui::End();
85  ImGui::PopStyleColor(1); // WindowBg
86 }
87 
88 std::string SimPerfStats::Convert(const float f)
89 {
90  std::stringstream s;
91  s << std::fixed << std::setprecision(2) << f;
92  return s.str();
93 }
RoR::GUI::SimPerfStats::Draw
void Draw()
Definition: GUI_SimPerfStats.cpp:36
RoR::GUIManager::GuiTheme
Definition: GUIManager.h:70
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
RoR::AppContext::GetRenderWindow
Ogre::RenderWindow * GetRenderWindow()
Definition: AppContext.h:67
RoR::App::GetAppContext
AppContext * GetAppContext()
Definition: Application.cpp:266
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
Language.h
RoR::GUIManager::GuiTheme::semitransparent_window_bg
ImVec4 semitransparent_window_bg
Definition: GUIManager.h:83
GUIManager.h
Actor.h
RoR::GUI::SimPerfStats::m_is_visible
bool m_is_visible
Definition: GUI_SimPerfStats.h:38
RoR::GUIManager::GetTheme
GuiTheme & GetTheme()
Definition: GUIManager.h:158
RoR::GUI::SimPerfStats::Convert
std::string Convert(const float f)
Definition: GUI_SimPerfStats.cpp:88
GUI_SimPerfStats.h
_LC
#define _LC(ctx, str)
Definition: Language.h:42
RoR::GUIManager::GuiTheme::screen_edge_padding
ImVec2 screen_edge_padding
Definition: GUIManager.h:87
RoR
Definition: AppContext.h:36
x
float x
Definition: (ValueTypes) quaternion.h:5