Rube Goldberg Machine 1.0
This is the base code for Rube Goldberg designed for the CS296 Software Systems Lab
src/main.cpp
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org
00003 *
00004 * This software is provided 'as-is', without any express or implied
00005 * warranty.  In no event will the authors be held liable for any damages
00006 * arising from the use of this software.
00007 * Permission is granted to anyone to use this software for any purpose,
00008 * including commercial applications, and to alter it and redistribute it
00009 * freely, subject to the following restrictions:
00010 * 1. The origin of this software must not be misrepresented; you must not
00011 * claim that you wrote the original software. If you use this software
00012 * in a product, an acknowledgment in the product documentation would be
00013 * appreciated but is not required.
00014 * 2. Altered source versions must be plainly marked as such, and must not be
00015 * misrepresented as being the original software.
00016 * 3. This notice may not be removed or altered from any source distribution.
00017 */
00018 
00019 /* 
00020  * Base code for CS 296 Software Systems Lab 
00021  * Department of Computer Science and Engineering, IIT Bombay
00022  * Instructor: Parag Chaudhuri
00023  */
00024 
00027 #include<iostream>
00028 #include "render.hpp"
00029 #include "cs296_base.hpp"
00030 #include "callbacks.hpp"
00031 #include <sys/time.h> //Timer Functions
00032 
00036 #ifndef __APPLE__
00037 #include "GL/glui.h"
00038 #else
00039 #include "GL/glui.h"
00040 #endif
00041 
00045 #include <cstdio>
00046 
00047 
00049 namespace cs296
00050 {
00051   extern int32 test_index;
00052   extern int32 test_selection;
00053   extern int32 test_count;
00054   extern cs296::sim_t* entry;
00055   extern cs296::base_sim_t* test;
00056   extern cs296::settings_t settings;
00057   extern const int32 frame_period;
00058   extern float settings_hz;
00059   extern int32 width;
00060   extern int32 height;
00061   extern int32 main_window;
00062 };
00063 
00065 using namespace cs296;
00066 
00067 
00069 void average_time(int32 no_of_steps){ 
00070     // settings_hz from callbacks.cpp  
00071     float32 step_size=1/settings_hz; 
00072    
00073     b2World* world = test->get_world(); 
00074     
00076     const b2Profile& world_profile = world->GetProfile(); 
00077     int32 step_Count=0; 
00078     
00079     float32 time_taken_for_step=0.0000;
00080     float32 time_taken_for_velocity_update=0.0000;
00081     float32 time_taken_for_collisions=0.0000;
00082     float32 time_taken_for_position_update=0.0000;
00083     
00084     struct timeval start, end;
00085     gettimeofday(&start,NULL);
00086     double t1 = 1000*(start.tv_sec) + start.tv_usec/1000.0;
00087     
00088     while (step_Count<no_of_steps)
00089     { 
00090         // Step function for Simulation in Box2D world.
00091         world->Step(step_size, settings.velocity_iterations, settings.position_iterations);     
00092         time_taken_for_step +=world_profile.step;
00093         time_taken_for_velocity_update += world_profile.solveVelocity;
00094         time_taken_for_collisions += world_profile.collide;
00095         time_taken_for_position_update += world_profile.solvePosition;
00096         step_Count++;
00097     }
00098     
00099     gettimeofday(&end, NULL); 
00100     double t2 = 1000*(end.tv_sec) + end.tv_usec/1000.0;
00101     double t= t2 - t1;
00102     //[Lab07]
00103     std::cout<<"Total Iterations: "<< no_of_steps<<"\n";
00104     std::cout<<"Average time per step is "<< time_taken_for_step/no_of_steps<<" ms\n";
00105     std::cout<<"Average time for collisions is "<<time_taken_for_collisions/no_of_steps<<" ms\n";
00106     std::cout<<"Average time for velocity updates is "<<time_taken_for_velocity_update/no_of_steps<<" ms\n";
00107     std::cout<<"Average time for position updates is "<<time_taken_for_position_update/no_of_steps<<" ms\n\n";
00108     std::cout<<"Total time for loop is "<<t<<" ms"<<std::endl;
00109     //std::cout <<t/1000
00110     //<<std::endl;
00111 }
00112 
00113 
00115 int main(int argc, char** argv)
00116 {
00117   test_count = 1;
00118   test_index = 0;
00119   test_selection = test_index;
00120   
00121   entry = sim;
00122   test = entry->create_fcn();
00123 
00124   // Command Line argument for number of iterations
00125   int no_of_steps = 0;
00126   if(argc == 1) no_of_steps = 100;   //Default Value
00127   else no_of_steps = atoi(argv[1]);
00129   average_time(no_of_steps);
00130  
00131   return 0;
00132 }
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines