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

+ 13
- 2
include/RunTime.h View File

9
 #define _RUNTIME_H_
9
 #define _RUNTIME_H_
10
 
10
 
11
 #include <string>
11
 #include <string>
12
+#include <vector>
12
 
13
 
13
 /*!
14
 /*!
14
  * \brief Main Game Singleton
15
  * \brief Main Game Singleton
33
     bool isRunning();
34
     bool isRunning();
34
     void setRunning(bool run);
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
   private:
44
   private:
40
     std::string baseDir;
45
     std::string baseDir;
45
     KeyboardButton keyBindings[ActionEventCount];
50
     KeyboardButton keyBindings[ActionEventCount];
46
     bool gameIsRunning;
51
     bool gameIsRunning;
47
     bool showFPS;
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
 RunTime& getRunTime();
61
 RunTime& getRunTime();

+ 35
- 2
src/RunTime.cpp View File

7
 
7
 
8
 #include "global.h"
8
 #include "global.h"
9
 #include "utils/strings.h"
9
 #include "utils/strings.h"
10
+#include "utils/time.h"
10
 #include "RunTime.h"
11
 #include "RunTime.h"
11
 
12
 
12
 RunTime::RunTime()
13
 RunTime::RunTime()
33
     keyBindings[backwardAction] = sKey;
34
     keyBindings[backwardAction] = sKey;
34
     keyBindings[leftAction] = aKey;
35
     keyBindings[leftAction] = aKey;
35
     keyBindings[rightAction] = dKey;
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
 std::string RunTime::getBaseDir() {
46
 std::string RunTime::getBaseDir() {
85
     gameIsRunning = run;
93
     gameIsRunning = run;
86
 }
94
 }
87
 
95
 
88
-bool RunTime::getFPS() {
96
+bool RunTime::getShowFPS() {
89
     return showFPS;
97
     return showFPS;
90
 }
98
 }
91
 
99
 
92
-void RunTime::setFPS(bool fps) {
100
+void RunTime::setShowFPS(bool fps) {
93
     showFPS = fps;
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
     Console::display();
186
     Console::display();
187
 
187
 
188
     if (ImGui::Begin("Engine")) {
188
     if (ImGui::Begin("Engine")) {
189
-        if (ImGui::CollapsingHeader("Info", NULL, true, true)) {
189
+        if (ImGui::CollapsingHeader("RunTime Info")) {
190
             ImGui::Text("Uptime: %lums", systemTimerGet());
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
         static bool visibleTex = false;
210
         static bool visibleTex = false;
194
         static bool visibleTile = false;
211
         static bool visibleTile = false;
195
-        if (ImGui::CollapsingHeader("Textures")) {
212
+        if (ImGui::CollapsingHeader("Texture Viewer")) {
196
             static bool game = getGame().isLoaded();
213
             static bool game = getGame().isLoaded();
197
             static int index = 0;
214
             static int index = 0;
198
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
215
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
244
             }
261
             }
245
         }
262
         }
246
 
263
 
247
-        if (ImGui::CollapsingHeader("Textiles")) {
264
+        if (ImGui::CollapsingHeader("Textile Viewer")) {
248
             if (getTextureManager().numTiles() > 0) {
265
             if (getTextureManager().numTiles() > 0) {
249
                 static int index = 0;
266
                 static int index = 0;
250
                 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
267
                 ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
288
             }
305
             }
289
         }
306
         }
290
 
307
 
291
-        if (ImGui::CollapsingHeader("SoundSamples")) {
308
+        if (ImGui::CollapsingHeader("SoundSample Player")) {
292
             if (!getSound().getEnabled()) {
309
             if (!getSound().getEnabled()) {
293
                 ImGui::Text("Please enable Sound before loading a level!");
310
                 ImGui::Text("Please enable Sound before loading a level!");
294
                 if (ImGui::Button("Enable Sound!")) {
311
                 if (ImGui::Button("Enable Sound!")) {

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

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

+ 3
- 15
src/main.cpp View File

233
     getMenu().display();
233
     getMenu().display();
234
     UI::display();
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
         std::ostringstream s;
237
         std::ostringstream s;
244
-        s << fps << "FPS";
238
+        s << getRunTime().getFPS() << "FPS";
245
         getWindow().glEnter2D();
239
         getWindow().glEnter2D();
246
         Font::drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
240
         Font::drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
247
         getWindow().glExit2D();
241
         getWindow().glExit2D();
249
 
243
 
250
     getWindow().swapBuffersGL();
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
 #endif // UNIT_TEST
249
 #endif // UNIT_TEST

Loading…
Cancel
Save