|
@@ -24,11 +24,10 @@
|
24
|
24
|
#include "utils/time.h"
|
25
|
25
|
#include "OpenRaider.h"
|
26
|
26
|
|
27
|
|
-#define MAX_MS_PER_FRAME (1000 / MAXIMUM_FPS)
|
28
|
|
-
|
29
|
27
|
OpenRaider::OpenRaider() {
|
30
|
28
|
mInit = false;
|
31
|
29
|
mRunning = false;
|
|
30
|
+ mFPS = false;
|
32
|
31
|
mBaseDir = NULL;
|
33
|
32
|
mPakDir = NULL;
|
34
|
33
|
mAudioDir = NULL;
|
|
@@ -214,6 +213,7 @@ int OpenRaider::help(const char *cmd) {
|
214
|
213
|
mConsole->print(" volume BOOL");
|
215
|
214
|
mConsole->print(" mouse_x FLOAT");
|
216
|
215
|
mConsole->print(" mouse_y FLOAT");
|
|
216
|
+ mConsole->print(" fps BOOL");
|
217
|
217
|
mConsole->print("Enclose STRINGs with \"\"!");
|
218
|
218
|
mConsole->print("size expects a STRING in the specified format");
|
219
|
219
|
} else if (strcmp(cmd, "bind") == 0) {
|
|
@@ -345,6 +345,13 @@ int OpenRaider::set(const char *var, const char *value) {
|
345
|
345
|
return -7;
|
346
|
346
|
}
|
347
|
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
|
355
|
} else if (strcmp(var, "basedir") == 0) {
|
349
|
356
|
CHANGE_DIR_WITH_EXPANSION(mBaseDir);
|
350
|
357
|
} else if (strcmp(var, "pakdir") == 0) {
|
|
@@ -642,6 +649,9 @@ void OpenRaider::run() {
|
642
|
649
|
assert(mInit == true);
|
643
|
650
|
assert(mRunning == false);
|
644
|
651
|
|
|
652
|
+ static clock_t fpsSum = 0, fpsCount = 0;
|
|
653
|
+ static int fps = 0;
|
|
654
|
+
|
645
|
655
|
mRunning = true;
|
646
|
656
|
while (mRunning) {
|
647
|
657
|
clock_t startTime = systemTimerGet();
|
|
@@ -658,8 +668,14 @@ void OpenRaider::run() {
|
658
|
668
|
|
659
|
669
|
// Draw 2D overlays (console and menu)
|
660
|
670
|
mWindow->glEnter2D();
|
|
671
|
+
|
661
|
672
|
mConsole->display();
|
662
|
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
|
679
|
mWindow->glExit2D();
|
664
|
680
|
|
665
|
681
|
// Put new frame on screen
|
|
@@ -670,11 +686,14 @@ void OpenRaider::run() {
|
670
|
686
|
if (!mMapListFilled)
|
671
|
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
|
|