Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / Benchmarks / main.cpp
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #include "BenchmarkDemo.h"
17 #include "btBulletDynamicsCommon.h"
18 #include "LinearMath/btHashMap.h"
19 #include <stdio.h>
20
21 #ifdef USE_GRAPHICAL_BENCHMARK
22         #include "GlutStuff.h"
23         #include "GLDebugDrawer.h"
24         GLDebugDrawer   gDebugDrawer;
25 #define benchmarkDemo benchmarkDemo2
26 #endif //USE_GRAPHICAL_BENCHMARK
27
28
29 #define NUM_DEMOS 7
30 #define NUM_TESTS 200
31
32 extern bool gDisableDeactivation;
33
34 int main(int argc,char** argv)
35 {
36         gDisableDeactivation = true;
37
38         BenchmarkDemo1 benchmarkDemo1;
39         BenchmarkDemo2 benchmarkDemo2;
40         BenchmarkDemo3 benchmarkDemo3;
41         BenchmarkDemo4 benchmarkDemo4;
42         BenchmarkDemo5 benchmarkDemo5;
43         BenchmarkDemo6 benchmarkDemo6;
44         BenchmarkDemo7 benchmarkDemo7;
45
46         BenchmarkDemo* demoArray[NUM_DEMOS] = {&benchmarkDemo1,&benchmarkDemo2,&benchmarkDemo3,&benchmarkDemo4,&benchmarkDemo5,&benchmarkDemo6,&benchmarkDemo7};
47         const char* demoNames[NUM_DEMOS] = {"3000 fall", "1000 stack", "136 ragdolls","1000 convex", "prim-trimesh", "convex-trimesh","raytests"};
48         float totalTime[NUM_DEMOS] = {0.f,0.f,0.f,0.f,0.f,0.f,0.f};
49
50 #ifdef USE_GRAPHICAL_BENCHMARK
51         benchmarkDemo.initPhysics();
52         benchmarkDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
53         benchmarkDemo.setDebugMode(benchmarkDemo.getDebugMode() | btIDebugDraw::DBG_NoDeactivation);
54         return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&benchmarkDemo);
55
56 #else //USE_GRAPHICAL_BENCHMARK
57         int d;
58
59         for (d=0;d<NUM_DEMOS;d++)
60         {
61                 demoArray[d]->initPhysics();
62                 
63
64                 for (int i=0;i<NUM_TESTS;i++)
65                 {
66                         demoArray[d]->clientMoveAndDisplay();
67                         float frameTime = CProfileManager::Get_Time_Since_Reset();
68                         if ((i % 25)==0)
69                         {
70                                 printf("BenchmarkDemo: %s, Frame %d, Duration (ms): %f\n",demoNames[d],i,frameTime);
71                         }
72                         totalTime[d] += frameTime;
73                         if (i==NUM_TESTS-1)
74                                 CProfileManager::dumpAll();
75
76                         
77                 }
78         demoArray[d]->exitPhysics();
79         }
80
81         for (d=0;d<NUM_DEMOS;d++)
82         {
83                 printf("\nResults for %s: %f",demoNames[d],totalTime[d]*(1.f/NUM_TESTS));
84         }
85
86 #endif //USE_GRAPHICAL_BENCHMARK
87         return 0;
88 }
89