clean outputs
[physics.git] / src / main.cpp
index 8c3134b..a9984f6 100644 (file)
@@ -65,7 +65,7 @@ int target_UPS = 100;
 long int last_Block_Update;
 float update_Sum = 0;
 
-int ups, fps;
+int ups=100, fps=100;
 int update_Count, draw_Count;
 long int last_Second;
 
@@ -83,9 +83,10 @@ float rRun = 100;
 
 float num = 10;
 
+float total = 0;
 
 /// ***** MAIN Method *****
-int main()
+int main(int argc, char** args)
 {
     init();
     run();
@@ -100,23 +101,23 @@ void init()
     installSignal();
 
     graphics::init();
+    DPF(0, "Graphics initialized");
 
     game::init();
+    DPF(0, "Game initialized");
 
     input::init();
+    DPF(0, "Input initialized");
 
     cfg::init();
+    DPF(0, "Configs initialized");
 
-#ifdef DEBUGGING
-    cout << "Initialization Complete" << endl;
-#endif
+    DPF(0, "Initialization Complete");
 }
 
 void clean()
 {
-#ifdef DEBUGGING
-    cout << "Cleaning up" << endl;
-#endif
+    DPF(0, "Cleaning up");
 
     cfg::clean();
 
@@ -129,8 +130,6 @@ void clean()
 
 /// ***** Private Methods *****
 
-float total = 0;
-
 void run()
 {
     is_Running = true;
@@ -158,11 +157,12 @@ void run()
 void blockUpdate()
 {
     long int start = tickCountMicro();
+    long int diff = start - last_Block_Update;
 
     //cout << "Block" << endl;
 
     // Calculate the updates that should be run for the next draw
-    update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
+    update_Sum += (float)(diff * target_UPS) / 1000000;
 
     // insures the float to int cast is done once.
     int iupdate_sum = (int)update_Sum;
@@ -170,17 +170,22 @@ void blockUpdate()
     // TODO the main run loop needs to be tested and pruned
     if (iupdate_sum > 0)
     {
-        // Calculate a time step that spreads the updates out as much as possible
-        // used because really quick updates are nearly wasted
-        float time_step = ((float)(start - last_Block_Update)) / iupdate_sum / 1000;
+        // Calculate a time step that spreads the updates out as much as
+        // possible used because really quick updates are nearly wasted
+
+        //float time_step = ((float)diff) / iupdate_sum / 1000;
+        //float time_step = 1000 / (100000 / rUpdate) / iupdate_sum;
+        //float time_step = 1000 / ups / iupdate_sum;
+        float time_step = 10;
 
         // run the updates
-        for (int i = 1; i <= iupdate_sum; i++)
+        for (int i = 0; i < iupdate_sum; i++)
         {
             handleInput();
             update(time_step);
         }
-        // remove the updates that where run from the sum
+
+        // remove the updates that were run from the sum
         update_Sum -= iupdate_sum;
         last_Block_Update = tickCountMicro();
     }
@@ -258,7 +263,7 @@ void draw()
 
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-//        SDL_Delay(20);
+        //SDL_Delay(10);
     time = tickCountMicro() - time;
 
     rDraw = (rDraw*(num-1) + time) /num;