RigsofRods  2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 |
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 = fmt::format("FPS: {:5.1f}, Batch: {:5}, Tri: {:6}", stats.lastFPS, stats.batchCount, stats.triangleCount);
50  ImGui::SetCursorPosX((ImGui::GetWindowSize().x - ImGui::CalcTextSize(title.c_str()).x) * 0.5f);
51  ImGui::Text(title.c_str());
52 
53  ImGui::Separator();
54 
55  std::string a = "Current";
56  ImGui::SetCursorPosX((histogram_size.x + (3 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(a.c_str()).x) * 0.5f);
57  ImGui::Text("%s", _LC("SimPerfStats", a.c_str()));
58  ImGui::SameLine();
59 
60  std::string b = "Average";
61  ImGui::SetCursorPosX((histogram_size.x * 3 + (5 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(b.c_str()).x) * 0.5f);
62  ImGui::Text("%s", _LC("SimPerfStats", b.c_str()));
63  ImGui::SameLine();
64 
65  std::string c = "Worst";
66  ImGui::SetCursorPosX((histogram_size.x * 5 + (7 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(c.c_str()).x) * 0.5f);
67  ImGui::Text("%s", _LC("SimPerfStats", c.c_str()));
68  ImGui::SameLine();
69 
70  std::string d = "Best";
71  ImGui::SetCursorPosX((histogram_size.x * 7 + (9 * ImGui::GetStyle().ItemSpacing.x) + ImGui::GetStyle().FramePadding.x - ImGui::CalcTextSize(d.c_str()).x) * 0.5f);
72  ImGui::Text("%s", _LC("SimPerfStats", d.c_str()));
73 
74  ImGui::PlotHistogram("", &stats.lastFPS, 1, 0, this->Convert(stats.lastFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
75  ImGui::SameLine();
76  ImGui::PlotHistogram("", &stats.avgFPS, 1, 0, this->Convert(stats.avgFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
77  ImGui::SameLine();
78  ImGui::PlotHistogram("", &stats.worstFPS, 1, 0, this->Convert(stats.worstFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
79  ImGui::SameLine();
80  ImGui::PlotHistogram("", &stats.bestFPS, 1, 0, this->Convert(stats.bestFPS).c_str(), 0.f, stats.bestFPS, histogram_size);
81 
82  ImGui::End();
83  ImGui::PopStyleColor(1); // WindowBg
84 }
85 
86 std::string SimPerfStats::Convert(const float f)
87 {
88  std::stringstream s;
89  s << std::fixed << std::setprecision(2) << f;
90  return s.str();
91 }
Script2Game::ImGuiWindowFlags_AlwaysAutoResize
enum Script2Game::ImGuiStyleVar ImGuiWindowFlags_AlwaysAutoResize
Resize every window to its content every frame.
RoR::GUI::SimPerfStats::Draw
void Draw()
Definition: GUI_SimPerfStats.cpp:36
RoR::GUIManager::GuiTheme
Definition: GUIManager.h:79
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:286
Script2Game::ImGuiWindowFlags_NoCollapse
enum Script2Game::ImGuiStyleVar ImGuiWindowFlags_NoCollapse
Disable user collapsing window by double-clicking on it.
RoR::AppContext::GetRenderWindow
Ogre::RenderWindow * GetRenderWindow()
Definition: AppContext.h:67
RoR::App::GetAppContext
AppContext * GetAppContext()
Definition: Application.cpp:283
format
Truck file format(technical spec)
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
Script2Game::ImGuiWindowFlags_NoInputs
enum Script2Game::ImGuiStyleVar ImGuiWindowFlags_NoInputs
ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus,...
AngelImGui::CalcTextSize
vector2 CalcTextSize(const string &in, bool hide_text_after_double_hash=false, float wrap_width=-1.0f)
Language.h
RoR::GUIManager::GuiTheme::semitransparent_window_bg
ImVec4 semitransparent_window_bg
Definition: GUIManager.h:92
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:168
RoR::GUI::SimPerfStats::Convert
std::string Convert(const float f)
Definition: GUI_SimPerfStats.cpp:86
GUI_SimPerfStats.h
_LC
#define _LC(ctx, str)
Definition: Language.h:38
RoR::GUIManager::GuiTheme::screen_edge_padding
ImVec2 screen_edge_padding
Definition: GUIManager.h:96
Script2Game::ImGuiWindowFlags_NoTitleBar
enum Script2Game::ImGuiStyleVar ImGuiWindowFlags_NoTitleBar
Disable title-bar.
RoR
Definition: AppContext.h:36
x
float x
Definition: (ValueTypes) quaternion.h:5
Script2Game::ImGuiCol_WindowBg
enum Script2Game::ImGuiStyleVar ImGuiCol_WindowBg
Background of normal windows.
Script2Game::ImGuiWindowFlags_NoMove
enum Script2Game::ImGuiStyleVar ImGuiWindowFlags_NoMove
Disable user moving the window.