Просмотр исходного кода

Added FPS display, removed limit

Thomas Buck 11 лет назад
Родитель
Сommit
29e702c578
3 измененных файлов: 27 добавлений и 9 удалений
  1. 0
    2
      include/Config.h.in
  2. 1
    0
      include/OpenRaider.h
  3. 26
    7
      src/OpenRaider.cpp

+ 0
- 2
include/Config.h.in Просмотреть файл

5
 #define DEFAULT_CONFIG_FILE "OpenRaider.ini"
5
 #define DEFAULT_CONFIG_FILE "OpenRaider.ini"
6
 #define DEFAULT_WIDTH 640
6
 #define DEFAULT_WIDTH 640
7
 #define DEFAULT_HEIGHT 480
7
 #define DEFAULT_HEIGHT 480
8
-
9
-#define MAXIMUM_FPS 100

+ 1
- 0
include/OpenRaider.h Просмотреть файл

94
 
94
 
95
     bool mInit;
95
     bool mInit;
96
     bool mRunning;
96
     bool mRunning;
97
+    bool mFPS;
97
 
98
 
98
     KeyboardButton keyBindings[ActionEventCount];
99
     KeyboardButton keyBindings[ActionEventCount];
99
 };
100
 };

+ 26
- 7
src/OpenRaider.cpp Просмотреть файл

24
 #include "utils/time.h"
24
 #include "utils/time.h"
25
 #include "OpenRaider.h"
25
 #include "OpenRaider.h"
26
 
26
 
27
-#define MAX_MS_PER_FRAME (1000 / MAXIMUM_FPS)
28
-
29
 OpenRaider::OpenRaider() {
27
 OpenRaider::OpenRaider() {
30
     mInit = false;
28
     mInit = false;
31
     mRunning = false;
29
     mRunning = false;
30
+    mFPS = false;
32
     mBaseDir = NULL;
31
     mBaseDir = NULL;
33
     mPakDir = NULL;
32
     mPakDir = NULL;
34
     mAudioDir = NULL;
33
     mAudioDir = NULL;
214
         mConsole->print("  volume      BOOL");
213
         mConsole->print("  volume      BOOL");
215
         mConsole->print("  mouse_x     FLOAT");
214
         mConsole->print("  mouse_x     FLOAT");
216
         mConsole->print("  mouse_y     FLOAT");
215
         mConsole->print("  mouse_y     FLOAT");
216
+        mConsole->print("  fps         BOOL");
217
         mConsole->print("Enclose STRINGs with \"\"!");
217
         mConsole->print("Enclose STRINGs with \"\"!");
218
         mConsole->print("size expects a STRING in the specified format");
218
         mConsole->print("size expects a STRING in the specified format");
219
     } else if (strcmp(cmd, "bind") == 0) {
219
     } else if (strcmp(cmd, "bind") == 0) {
345
             return -7;
345
             return -7;
346
         }
346
         }
347
         mCameraRotationDeltaY = OR_DEG_TO_RAD(sense);
347
         mCameraRotationDeltaY = OR_DEG_TO_RAD(sense);
348
+    } else if (strcmp(var, "fps") == 0) {
349
+        bool fps = false;
350
+        if (readBool(value, &fps) != 0) {
351
+            mConsole->print("set-fps-Error: Invalid value (%s)", value);
352
+            return -8;
353
+        }
354
+        mFPS = fps;
348
     } else if (strcmp(var, "basedir") == 0) {
355
     } else if (strcmp(var, "basedir") == 0) {
349
         CHANGE_DIR_WITH_EXPANSION(mBaseDir);
356
         CHANGE_DIR_WITH_EXPANSION(mBaseDir);
350
     } else if (strcmp(var, "pakdir") == 0) {
357
     } else if (strcmp(var, "pakdir") == 0) {
642
     assert(mInit == true);
649
     assert(mInit == true);
643
     assert(mRunning == false);
650
     assert(mRunning == false);
644
 
651
 
652
+    static clock_t fpsSum = 0, fpsCount = 0;
653
+    static int fps = 0;
654
+
645
     mRunning = true;
655
     mRunning = true;
646
     while (mRunning) {
656
     while (mRunning) {
647
         clock_t startTime = systemTimerGet();
657
         clock_t startTime = systemTimerGet();
658
 
668
 
659
         // Draw 2D overlays (console and menu)
669
         // Draw 2D overlays (console and menu)
660
         mWindow->glEnter2D();
670
         mWindow->glEnter2D();
671
+
661
         mConsole->display();
672
         mConsole->display();
662
         mMenu->display();
673
         mMenu->display();
674
+
675
+        // Draw FPS counter
676
+        if (mFPS)
677
+            mWindow->drawText(10, mWindow->mHeight - 20, 0.5f, OR_BLUE, "%dFPS", fps);
678
+
663
         mWindow->glExit2D();
679
         mWindow->glExit2D();
664
 
680
 
665
         // Put new frame on screen
681
         // Put new frame on screen
670
         if (!mMapListFilled)
686
         if (!mMapListFilled)
671
             fillMapList();
687
             fillMapList();
672
 
688
 
673
-        // Check time it took to compute the last frame
674
-        // and delay for an appropriate amount of time
675
-        clock_t stopTime = systemTimerGet();
676
-        if (MAX_MS_PER_FRAME > (stopTime - startTime))
677
-            mWindow->delay(MAX_MS_PER_FRAME - (stopTime - startTime));
689
+        // Calculate FPS display value
690
+        fpsCount++;
691
+        fpsSum += (systemTimerGet() - startTime);
692
+        if (fpsSum >= 500) {
693
+            // Update every 500ms
694
+            fps = (int)((float)fpsCount * (1000.0f / (float)fpsSum));
695
+            fpsCount = fpsSum = 0;
696
+        }
678
     }
697
     }
679
 }
698
 }
680
 
699
 

Загрузка…
Отмена
Сохранить