Browse Source

Added FPS histogram

Thomas Buck 10 years ago
parent
commit
2c6806450e
6 changed files with 77 additions and 25 deletions
  1. 3
    0
      ChangeLog.md
  2. 13
    2
      include/RunTime.h
  3. 35
    2
      src/RunTime.cpp
  4. 21
    4
      src/UI.cpp
  5. 2
    2
      src/commands/CommandSet.cpp
  6. 3
    15
      src/main.cpp

+ 3
- 0
ChangeLog.md View File

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141128 ]
6
+    * Added FPS Histogram Debug UI
7
+
5 8
     [ 20141127 ]
6 9
     * Started work on loading the object texture mapping, with debug UI
7 10
     * Textiles debug UI also draws triangles “properly”

+ 13
- 2
include/RunTime.h View File

@@ -9,6 +9,7 @@
9 9
 #define _RUNTIME_H_
10 10
 
11 11
 #include <string>
12
+#include <vector>
12 13
 
13 14
 /*!
14 15
  * \brief Main Game Singleton
@@ -33,8 +34,12 @@ class RunTime {
33 34
     bool isRunning();
34 35
     void setRunning(bool run);
35 36
 
36
-    bool getFPS();
37
-    void setFPS(bool fps);
37
+    bool getShowFPS();
38
+    void setShowFPS(bool fps);
39
+
40
+    void updateFPS();
41
+    unsigned long getFPS();
42
+    const std::vector<float>& getHistoryFPS();
38 43
 
39 44
   private:
40 45
     std::string baseDir;
@@ -45,6 +50,12 @@ class RunTime {
45 50
     KeyboardButton keyBindings[ActionEventCount];
46 51
     bool gameIsRunning;
47 52
     bool showFPS;
53
+
54
+    unsigned long lastTime;
55
+    unsigned long frameCount, frameCount2;
56
+    unsigned long frameTimeSum, frameTimeSum2;
57
+    unsigned long fps;
58
+    std::vector<float> history;
48 59
 };
49 60
 
50 61
 RunTime& getRunTime();

+ 35
- 2
src/RunTime.cpp View File

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "utils/strings.h"
10
+#include "utils/time.h"
10 11
 #include "RunTime.h"
11 12
 
12 13
 RunTime::RunTime()
@@ -33,6 +34,13 @@ RunTime::RunTime()
33 34
     keyBindings[backwardAction] = sKey;
34 35
     keyBindings[leftAction] = aKey;
35 36
     keyBindings[rightAction] = dKey;
37
+
38
+    lastTime = 0;
39
+    frameCount = 0;
40
+    frameCount2 = 0;
41
+    frameTimeSum = 0;
42
+    frameTimeSum2 = 0;
43
+    fps = 0;
36 44
 }
37 45
 
38 46
 std::string RunTime::getBaseDir() {
@@ -85,11 +93,36 @@ void RunTime::setRunning(bool run) {
85 93
     gameIsRunning = run;
86 94
 }
87 95
 
88
-bool RunTime::getFPS() {
96
+bool RunTime::getShowFPS() {
89 97
     return showFPS;
90 98
 }
91 99
 
92
-void RunTime::setFPS(bool fps) {
100
+void RunTime::setShowFPS(bool fps) {
93 101
     showFPS = fps;
94 102
 }
95 103
 
104
+void RunTime::updateFPS() {
105
+    frameCount++;
106
+    frameTimeSum += (systemTimerGet() - lastTime);
107
+    frameTimeSum2 += (systemTimerGet() - lastTime);
108
+    lastTime = systemTimerGet();
109
+    if (frameTimeSum >= 200) {
110
+        fps = frameCount * (1000 / frameTimeSum);
111
+        frameCount = frameTimeSum = 0;
112
+    }
113
+
114
+    if (frameTimeSum2 >= 1000) {
115
+        history.push_back(frameCount2);
116
+        frameCount2 = frameTimeSum2 = 0;
117
+    }
118
+    frameCount2++;
119
+}
120
+
121
+unsigned long RunTime::getFPS() {
122
+    return fps;
123
+}
124
+
125
+const std::vector<float>& RunTime::getHistoryFPS() {
126
+    return history;
127
+}
128
+

+ 21
- 4
src/UI.cpp View File

@@ -186,13 +186,30 @@ void UI::display() {
186 186
     Console::display();
187 187
 
188 188
     if (ImGui::Begin("Engine")) {
189
-        if (ImGui::CollapsingHeader("Info", NULL, true, true)) {
189
+        if (ImGui::CollapsingHeader("RunTime Info")) {
190 190
             ImGui::Text("Uptime: %lums", systemTimerGet());
191
+            ImGui::Text("Frames per Second: %luFPS", getRunTime().getFPS());
192
+            if (getRunTime().getHistoryFPS().size() > 1) {
193
+                static bool scroll = true;
194
+                if (scroll) {
195
+                    int offset = getRunTime().getHistoryFPS().size() - 1;
196
+                    if (offset > 15)
197
+                        offset = 15;
198
+                    ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
199
+                            getRunTime().getHistoryFPS().size() - 1,
200
+                            getRunTime().getHistoryFPS().size() - offset - 1);
201
+                } else {
202
+                    ImGui::PlotLines("FPS", &getRunTime().getHistoryFPS()[1],
203
+                            getRunTime().getHistoryFPS().size() - 1);
204
+                }
205
+                ImGui::SameLine();
206
+                ImGui::Checkbox("Scroll##fpsscroll", &scroll);
207
+            }
191 208
         }
192 209
 
193 210
         static bool visibleTex = false;
194 211
         static bool visibleTile = false;
195
-        if (ImGui::CollapsingHeader("Textures")) {
212
+        if (ImGui::CollapsingHeader("Texture Viewer")) {
196 213
             static bool game = getGame().isLoaded();
197 214
             static int index = 0;
198 215
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
@@ -244,7 +261,7 @@ void UI::display() {
244 261
             }
245 262
         }
246 263
 
247
-        if (ImGui::CollapsingHeader("Textiles")) {
264
+        if (ImGui::CollapsingHeader("Textile Viewer")) {
248 265
             if (getTextureManager().numTiles() > 0) {
249 266
                 static int index = 0;
250 267
                 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
@@ -288,7 +305,7 @@ void UI::display() {
288 305
             }
289 306
         }
290 307
 
291
-        if (ImGui::CollapsingHeader("SoundSamples")) {
308
+        if (ImGui::CollapsingHeader("SoundSample Player")) {
292 309
             if (!getSound().getEnabled()) {
293 310
                 ImGui::Text("Please enable Sound before loading a level!");
294 311
                 if (ImGui::Button("Enable Sound!")) {

+ 2
- 2
src/commands/CommandSet.cpp View File

@@ -117,7 +117,7 @@ int CommandSet::execute(std::istream& args) {
117 117
             getLog() << "set-fps-Error: Invalid value" << Log::endl;
118 118
             return -8;
119 119
         }
120
-        getRunTime().setFPS(fps);
120
+        getRunTime().setShowFPS(fps);
121 121
     } else if (var.compare("basedir") == 0) {
122 122
         std::string temp;
123 123
         args >> temp;
@@ -191,7 +191,7 @@ int CommandGet::execute(std::istream& args) {
191 191
     } else if (var.compare("mouse_y") == 0) {
192 192
         getLog() << OR_RAD_TO_DEG(getCamera().getSensitivityY()) << Log::endl;
193 193
     } else if (var.compare("fps") == 0) {
194
-        getLog() << getRunTime().getFPS() << Log::endl;
194
+        getLog() << getRunTime().getShowFPS() << Log::endl;
195 195
     } else if (var.compare("basedir") == 0) {
196 196
         getLog() << getRunTime().getBaseDir() << Log::endl;
197 197
     } else if (var.compare("pakdir") == 0) {

+ 3
- 15
src/main.cpp View File

@@ -233,15 +233,9 @@ void renderFrame() {
233 233
     getMenu().display();
234 234
     UI::display();
235 235
 
236
-    const static unsigned long fpsUpdate = 250;
237
-    static unsigned long frameCount = 0;
238
-    static unsigned long lastTime = 0;
239
-    static unsigned long frameTimeSum = 0;
240
-    static unsigned long fps = 0;
241
-
242
-    if (getRunTime().getFPS()) {
236
+    if (getRunTime().getShowFPS()) {
243 237
         std::ostringstream s;
244
-        s << fps << "FPS";
238
+        s << getRunTime().getFPS() << "FPS";
245 239
         getWindow().glEnter2D();
246 240
         Font::drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
247 241
         getWindow().glExit2D();
@@ -249,13 +243,7 @@ void renderFrame() {
249 243
 
250 244
     getWindow().swapBuffersGL();
251 245
 
252
-    frameCount++;
253
-    frameTimeSum += (systemTimerGet() - lastTime);
254
-    if (frameTimeSum >= fpsUpdate) {
255
-        fps = frameCount * (1000 / frameTimeSum);
256
-        frameCount = frameTimeSum = 0;
257
-    }
258
-    lastTime = systemTimerGet();
246
+    getRunTime().updateFPS();
259 247
 }
260 248
 
261 249
 #endif // UNIT_TEST

Loading…
Cancel
Save