Kaynağa Gözat

imgui Console in own class

Thomas Buck 9 yıl önce
ebeveyn
işleme
7a9ef2db0d
8 değiştirilmiş dosya ile 116 ekleme ve 38 silme
  1. 4
    0
      ChangeLog.md
  2. 1
    0
      TODO.md
  3. 23
    0
      include/Console.h
  4. 0
    1
      include/UI.h
  5. 1
    0
      src/CMakeLists.txt
  6. 49
    0
      src/Console.cpp
  7. 14
    36
      src/UI.cpp
  8. 24
    1
      src/main.cpp

+ 4
- 0
ChangeLog.md Dosyayı Görüntüle

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140908 ]
6
+    * Moved imgui Console into own (static) class
7
+    * Added FPS display
8
+
5 9
     [ 20140905 ]
6 10
     * Recreated working console using imgui
7 11
 

+ 1
- 0
TODO.md Dosyayı Görüntüle

@@ -13,6 +13,7 @@
13 13
 ## Bugs
14 14
 
15 15
 * Screenshots are sometimes not written, sometimes distorted?
16
+    * Seems to happen if OpenRaider.ini sets a resolution larger than the window can be
16 17
 
17 18
 ## Cmake
18 19
 

+ 23
- 0
include/Console.h Dosyayı Görüntüle

@@ -0,0 +1,23 @@
1
+/*!
2
+ * \file include/Console.h
3
+ * \brief Console class
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _CONSOLE_H_
9
+#define _CONSOLE_H_
10
+
11
+class Console {
12
+public:
13
+    static void display();
14
+
15
+private:
16
+    const static int bufferLength = 256;
17
+    static char buffer[bufferLength];
18
+    static bool scrollToBottom;
19
+    static unsigned long lastLogLength;
20
+};
21
+
22
+#endif
23
+

+ 0
- 1
include/UI.h Dosyayı Görüntüle

@@ -20,7 +20,6 @@ public:
20 20
     static int initialize();
21 21
     static void eventsFinished();
22 22
     static void display();
23
-    static void calculate();
24 23
     static void shutdown();
25 24
 
26 25
     static void setVisible(bool v);

+ 1
- 0
src/CMakeLists.txt Dosyayı Görüntüle

@@ -48,6 +48,7 @@ endif (PNG_FOUND)
48 48
 
49 49
 # Set Source files
50 50
 set (SRCS ${SRCS} "Camera.cpp")
51
+set (SRCS ${SRCS} "Console.cpp")
51 52
 set (SRCS ${SRCS} "Entity.cpp")
52 53
 set (SRCS ${SRCS} "Exception.cpp")
53 54
 set (SRCS ${SRCS} "Font.cpp")

+ 49
- 0
src/Console.cpp Dosyayı Görüntüle

@@ -0,0 +1,49 @@
1
+/*!
2
+ * \file src/Console.cpp
3
+ * \brief Console class
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Log.h"
10
+#include "UI.h"
11
+#include "commands/Command.h"
12
+#include "Console.h"
13
+
14
+char Console::buffer[bufferLength] = "";
15
+bool Console::scrollToBottom = false;
16
+unsigned long Console::lastLogLength = 0;
17
+
18
+void Console::display() {
19
+    if (ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f)) {
20
+        if (lastLogLength != getLog().size()) {
21
+            lastLogLength = getLog().size();
22
+            scrollToBottom = true;
23
+        }
24
+
25
+        ImGui::BeginChild("ConsoleText", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowSize().y - 70));
26
+        for (unsigned long i = 0; i < getLog().size(); i++) {
27
+            ImGui::Text("%s", getLog().get(i).c_str());
28
+        }
29
+        if (scrollToBottom) {
30
+            ImGui::SetScrollPosHere();
31
+            scrollToBottom = false;
32
+        }
33
+        ImGui::EndChild();
34
+
35
+        bool enter = false;
36
+        ImGui::InputText("Command", buffer, bufferLength, ImGuiInputTextFlags_AutoSelectAll, &enter);
37
+        if (enter) {
38
+            getLog() << "> " << buffer << Log::endl;
39
+            int error = Command::command(buffer);
40
+            if (error != 0) {
41
+                getLog() << "Error code: " << error << Log::endl;
42
+            }
43
+            buffer[0] = '\0';
44
+            scrollToBottom = true;
45
+        }
46
+    }
47
+    ImGui::End();
48
+}
49
+

+ 14
- 36
src/UI.cpp Dosyayı Görüntüle

@@ -8,6 +8,7 @@
8 8
 #include <algorithm>
9 9
 
10 10
 #include "global.h"
11
+#include "Console.h"
11 12
 #include "Game.h"
12 13
 #include "Log.h"
13 14
 #include "Menu.h"
@@ -138,6 +139,7 @@ void UI::eventsFinished() {
138 139
             if (std::get<1>(i)) {
139 140
                 if (getRunTime().getKeyBinding(menuAction) == std::get<0>(i)) {
140 141
                     getMenu().setVisible(!getMenu().isVisible());
142
+                    visible = false;
141 143
                 } else if (getRunTime().getKeyBinding(debugAction) == std::get<0>(i)) {
142 144
                     visible = !visible;
143 145
                 }
@@ -165,47 +167,23 @@ void UI::eventsFinished() {
165 167
 }
166 168
 
167 169
 void UI::display() {
168
-    if (visible)
169
-        ImGui::Render();
170
-}
170
+    if (!visible)
171
+        return;
171 172
 
172
-void UI::calculate() {
173
-    static char buffer[256];
174
-    static bool scrollToBottom = false;
173
+    Console::display();
175 174
 
176
-    ImGui::Begin("Console", NULL, ImVec2(600, 400), -1.0f);
177
-        ImGui::BeginChild("ConsoleText", ImVec2(ImGui::GetWindowWidth(), ImGui::GetWindowSize().y - 70));
178
-            for (int i = 0; i < getLog().size(); i++) {
179
-                ImGui::Text("%s", getLog().get(i).c_str());
180
-            }
181
-            if (scrollToBottom) {
182
-                ImGui::SetScrollPosHere();
183
-                scrollToBottom = false;
184
-            }
185
-        ImGui::EndChild();
186
-
187
-        bool enter = false;
188
-        ImGui::InputText("Command", buffer, 256, ImGuiInputTextFlags_AutoSelectAll, &enter);
189
-        if (enter) {
190
-            getLog() << "> " << buffer << Log::endl;
191
-            int error = Command::command(buffer);
192
-            if (error != 0) {
193
-                getLog() << "Error code: " << error << Log::endl;
194
-            }
195
-            buffer[0] = '\0';
196
-            scrollToBottom = true;
197
-        }
198
-    ImGui::End();
175
+    if (ImGui::Begin("Engine")) {
176
+        if (ImGui::CollapsingHeader("Debug", NULL, true, true)) {
199 177
 
200
-    //ImGui::Begin("UI Style");
201
-    //    ImGui::ShowStyleEditor();
202
-    //ImGui::End();
178
+        }
203 179
 
204
-    //ImGui::Begin("Help");
205
-    //    ImGui::ShowUserGuide();
206
-    //ImGui::End();
180
+        if (ImGui::CollapsingHeader("UI Help")) {
181
+            ImGui::ShowUserGuide();
182
+        }
183
+    }
184
+    ImGui::End();
207 185
 
208
-    //ImGui::ShowTestWindow();
186
+    ImGui::Render();
209 187
 }
210 188
 
211 189
 void UI::shutdown() {

+ 24
- 1
src/main.cpp Dosyayı Görüntüle

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include <iostream>
9 9
 #include <memory>
10
+#include <sstream>
10 11
 
11 12
 #include "global.h"
12 13
 #include "Exception.h"
@@ -203,7 +204,6 @@ int main(int argc, char* argv[]) {
203 204
 
204 205
     while (getRunTime().isRunning()) {
205 206
         getWindow().eventHandling();
206
-        UI::calculate();
207 207
         renderFrame();
208 208
     }
209 209
 
@@ -225,7 +225,30 @@ void renderFrame() {
225 225
     getGame().display();
226 226
     getMenu().display();
227 227
     UI::display();
228
+
229
+    const static unsigned long fpsUpdate = 250;
230
+    static unsigned long frameCount = 0;
231
+    static unsigned long lastTime = 0;
232
+    static unsigned long frameTimeSum = 0;
233
+    static unsigned long fps = 0;
234
+
235
+    if (getRunTime().getFPS()) {
236
+        std::ostringstream s;
237
+        s << fps << "FPS";
238
+        getWindow().glEnter2D();
239
+        getFont().drawText(10, getWindow().getHeight() - 25, 0.6f, BLUE, s.str());
240
+        getWindow().glExit2D();
241
+    }
242
+
228 243
     getWindow().swapBuffersGL();
244
+
245
+    frameCount++;
246
+    frameTimeSum += (systemTimerGet() - lastTime);
247
+    if (frameTimeSum >= fpsUpdate) {
248
+        fps = frameCount * (1000 / frameTimeSum);
249
+        frameCount = frameTimeSum = 0;
250
+    }
251
+    lastTime = systemTimerGet();
229 252
 }
230 253
 
231 254
 #endif // UNIT_TEST

Loading…
İptal
Kaydet