Ver código fonte

SFML: make the timer do stuff

Streetwalrus Einstein 10 anos atrás
pai
commit
f0987dce42

+ 5 - 1
platform/sfml/Timing.cpp

@@ -1,7 +1,11 @@
 #include "Timing.h"
+#include <SFML/System/Clock.hpp>
+#include <cstdio>
 
 #define TIMING WalrusRPG::Timing
 
+sf::Clock clock;
+
 void TIMING::init()
 {
 }
@@ -12,5 +16,5 @@ void TIMING::deinit()
 
 unsigned TIMING::gettime()
 {
-    return 1;
+    return clock.getElapsedTime().asMicroseconds();
 }

+ 1 - 1
platform/sfml/public/platform.h

@@ -3,7 +3,7 @@
 
 #include <SFML/Graphics/Texture.hpp>
 
-#define TIMER_FREQ 1000
+#define TIMER_FREQ 1000000
 
 typedef sf::Texture texture_data_t;
 

+ 5 - 2
src/engine/StateMachine.cpp

@@ -55,8 +55,11 @@ void STATEMACHINE::run()
             last_frame = frame_stamp;
 
             Text::print_format(0, 0, "WalrusRPG test build %s", git_version);
-            Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
-                               TIMER_FREQ / update_time);
+            if (frame_time != 0 && update_time != 0)
+            {
+                Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
+                                   TIMER_FREQ / update_time);
+            }
             Graphics::frame_end();
         }