renamed libpg to libbear
[physics.git] / src / main.cpp
index c9e8808..988f5d1 100644 (file)
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <bear/debug.h>
+#include <bear/Timer.h>
+using namespace bear;
+
+#include <iostream>
+using std::cout;
+using std::endl;
+
 #include <GL/gl.h>
 #include <GL/glu.h>
 #include <SDL/SDL.h>
 
-#include "debug.h"
 #include "handleSignal.h"
 
 #include "game.h"
-#include "ticks.h"
 
 #include "graphics/graphics.h"
 #include "input/inputManager.h"
@@ -79,7 +85,9 @@ static float    s_fAccDrawWait   = 0;
 
 static int s_iUPS, s_iFPS;
 static int s_iUpdateCount, s_iDrawCount;
-static MICRO s_micLastSecond;
+
+static Ticks s_micLastSecond;
+static Timer s_timer;
 
 static const float s_fGameStep    = 10;
 
@@ -103,10 +111,14 @@ void mainInit()
     installSignal();
 
     debug::init();
+
+    s_timer.init();
 }
 void mainClean()
 {
-    debug::clean();
+    s_timer.fini();
+
+    debug::fini();
 }
 
 void updatesInit()
@@ -171,7 +183,7 @@ void run()
 void updateFPSCounters()
 {
     // Check if a second has passed to recalculate UPS and FPS
-    if (tickCountMicro() - s_micLastSecond >= 1000000)
+    if (s_timer.query() - s_micLastSecond >= 1000000)
     {
         s_iUPS = s_iUpdateCount;
         s_iFPS = s_iDrawCount;
@@ -180,7 +192,7 @@ void updateFPSCounters()
         s_iUpdateCount -= s_iUPS;
         s_iDrawCount -= s_iFPS;
 
-        s_micLastSecond = tickCountMicro();
+        s_micLastSecond = s_timer.query();
 
         if(cfg::showFPS())
         {
@@ -227,18 +239,20 @@ int startUpdateThread(void*)
 {
     updatesInit();
 
-    s_micLastSecond = tickCountMicro();
+    s_micLastSecond = s_timer.query();
 
     while(s_bIsRunning)
     {
-        MICRO time = tickCountMicro();
+        Timer timer;
+        timer.init();
             handleInput();
             update(s_fGameStep);
 
             updateFPSCounters();
-        time = tickCountMicro() - time;
+        const Ticks ticks = timer.query();
+        timer.fini();
 
-        float wait = (1000000.0 / s_iTargetUPS - time);
+        float wait = (1000000.0 / s_iTargetUPS - ticks.microseconds());
         s_fAccUpdateWait += 0 < wait ? wait : 0;
 
         if(s_iMinWaitMicro < s_fAccUpdateWait)
@@ -260,11 +274,13 @@ int startDrawThread(void*)
 
     while(s_bIsRunning)
     {
-        MICRO time = tickCountMicro();
+        Timer timer;
+        timer.init();
             draw();
-        time = tickCountMicro() - time;
+        const Ticks ticks = timer.query();
+        timer.fini();
 
-        float wait = (1000000.0 / s_iTargetFPS - time);
+        float wait = (1000000.0 / s_iTargetFPS - ticks.microseconds());
         s_fAccDrawWait += 0 < wait ? wait : 0;
 
         if(s_iMinWaitMicro < s_fAccDrawWait)