Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
33using namespace RoR;
34using 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 = 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
86std::string SimPerfStats::Convert(const float f)
87{
88 std::stringstream s;
89 s << std::fixed << std::setprecision(2) << f;
90 return s.str();
91}
System integration layer; inspired by OgreBites::ApplicationContext.
#define _LC(ctx, str)
Definition Language.h:38
Ogre::RenderWindow * GetRenderWindow()
Definition AppContext.h:67
std::string Convert(const float f)
GuiTheme & GetTheme()
Definition GUIManager.h:168
AppContext * GetAppContext()
GUIManager * GetGuiManager()