Pārlūkot izejas kodu

Fixed system timer for BSDs

Thomas Buck 10 gadus atpakaļ
vecāks
revīzija
02ceb1687a
4 mainītis faili ar 20 papildinājumiem un 15 dzēšanām
  1. 1
    3
      include/utils/time.h
  2. 6
    4
      src/Console.cpp
  3. 3
    0
      src/main.cpp
  4. 10
    8
      src/utils/time.cpp

+ 1
- 3
include/utils/time.h Parādīt failu

@@ -8,13 +8,11 @@
8 8
 #ifndef _UTILS_TIME_H_
9 9
 #define _UTILS_TIME_H_
10 10
 
11
-#include <ctime>
12
-
13 11
 /*!
14 12
  * \brief Read the system timer
15 13
  * \returns number of ticks
16 14
  */
17
-clock_t systemTimerGet();
15
+unsigned long systemTimerGet();
18 16
 
19 17
 /*!
20 18
  * \brief Reset the system timer

+ 6
- 4
src/Console.cpp Parādīt failu

@@ -14,9 +14,9 @@
14 14
 #endif
15 15
 
16 16
 #include "config.h"
17
-#include "main.h"
18 17
 #include "Console.h"
19
-#include "utils/strings.h"
18
+#include "main.h"
19
+#include "utils/time.h"
20 20
 
21 21
 Console::Console() {
22 22
     mVisible = false;
@@ -45,15 +45,17 @@ void Console::display() {
45 45
         glRecti(0, 0, window->mWidth, window->mHeight / 2);
46 46
         glEnable(GL_TEXTURE_2D);
47 47
 
48
-        gOpenRaider->mWindow->drawText(25, (window->mHeight / 4) - 20, 0.75f, color, "Console");
48
+        gOpenRaider->mWindow->drawText(10, 10, 0.50f, color, "%lus uptime %s", systemTimerGet() / 1000, VERSION);
49 49
     }
50 50
 }
51 51
 
52 52
 void Console::handleKeyboard(KeyboardButton key, bool pressed) {
53
+    if (pressed && (key == enter)) {
53 54
 
55
+    }
54 56
 }
55 57
 
56 58
 void Console::handleText(char *text, bool notFinished) {
57
-    printf("Got %s (%s)\n", (notFinished ? "not finished" : "finished"));
59
+    printf("Got %s (%s)\n", text, (notFinished ? "not finished" : "finished"));
58 60
 }
59 61
 

+ 3
- 0
src/main.cpp Parādīt failu

@@ -11,6 +11,7 @@
11 11
 
12 12
 #include "config.h"
13 13
 #include "main.h"
14
+#include "utils/time.h"
14 15
 
15 16
 OpenRaider *gOpenRaider = NULL;
16 17
 
@@ -28,6 +29,8 @@ void cleanupHandler() {
28 29
 int main(int argc, char *argv[]) {
29 30
     const char *config = NULL;
30 31
 
32
+    systemTimerReset();
33
+
31 34
     // Handle arguments
32 35
     if (argc == 1) {
33 36
         // Use default rc file path

+ 10
- 8
src/utils/time.cpp Parādīt failu

@@ -5,19 +5,21 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include "utils/time.h"
8
+#include <sys/time.h>
9 9
 
10
-#define CLOCKS_PER_MS (CLOCKS_PER_SEC / 1000)
10
+#include "utils/time.h"
11 11
 
12
-clock_t system_timer_start;
13
-clock_t system_timer_stop;
12
+struct timeval system_timer_start;
13
+struct timeval system_timer_stop;
14
+struct timezone system_timer_zone;
14 15
 
15
-clock_t systemTimerGet() {
16
-    system_timer_stop = clock();
17
-    return (system_timer_stop - system_timer_start) / CLOCKS_PER_MS;
16
+unsigned long systemTimerGet() {
17
+    gettimeofday(&system_timer_stop, &system_timer_zone);
18
+    return ((system_timer_stop.tv_sec - system_timer_start.tv_sec) * 1000)
19
+        + (((system_timer_stop.tv_usec - system_timer_start.tv_usec) / 1000));
18 20
 }
19 21
 
20 22
 void systemTimerReset() {
21
-    system_timer_start = clock();
23
+    gettimeofday(&system_timer_start, &system_timer_zone);
22 24
 }
23 25
 

Notiek ielāde…
Atcelt
Saglabāt