~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Bullet Continuous Collision Detection and Physics Library
 
3
Copyright (c) 2003-2006 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
*/
1
15
 
2
16
 
3
17
#include "LinearMath/btScalar.h"
7
21
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
8
22
#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
9
23
 
10
 
#include <stdio.h>
 
24
//#include <stdio.h>
11
25
#include "LinearMath/btQuickprof.h"
12
26
 
13
27
btSimulationIslandManager::btSimulationIslandManager()
25
39
}
26
40
                
27
41
 
28
 
void btSimulationIslandManager::findUnions(btDispatcher* dispatcher)
 
42
void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btCollisionWorld* colWorld)
29
43
{
30
44
        
31
45
        {
32
 
                for (int i=0;i<dispatcher->getNumManifolds();i++)
 
46
                btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr();
 
47
 
 
48
                for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++)
33
49
                {
34
 
                        const btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
35
 
                        //static objects (invmass btScalar(0.)) don't merge !
36
 
 
37
 
                         const  btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
38
 
                         const  btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
 
50
                        const btBroadphasePair& collisionPair = pairPtr[i];
 
51
                        btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
 
52
                        btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
39
53
 
40
54
                        if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
41
55
                                ((colObj1) && ((colObj1)->mergesSimulationIslands())))
71
85
        }
72
86
        // do the union find
73
87
        
74
 
        findUnions(dispatcher);
 
88
        findUnions(dispatcher,colWorld);
75
89
        
76
90
 
77
91
        
91
105
                for (i=0;i<colWorld->getCollisionObjectArray().size();i++)
92
106
                {
93
107
                        btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i];
94
 
                        if (collisionObject->mergesSimulationIslands())
 
108
                        if (!collisionObject->isStaticOrKinematicObject())
95
109
                        {
96
110
                                collisionObject->setIslandTag( m_unionFind.find(index) );
97
111
                                collisionObject->setCompanionId(-1);
129
143
};
130
144
 
131
145
 
132
 
 
133
 
 
134
 
 
135
 
//
136
 
// todo: this is random access, it can be walked 'cache friendly'!
137
 
//
138
 
void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback)
 
146
void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects)
139
147
{
140
148
 
141
 
        
142
 
        
143
 
        /*if (0)
144
 
        {
145
 
                int maxNumManifolds = dispatcher->getNumManifolds();
146
 
                btCollisionDispatcher* colDis = (btCollisionDispatcher*)dispatcher;
147
 
                btPersistentManifold** manifold = colDis->getInternalManifoldPointer();
148
 
                callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, 0);
149
 
                return;
150
 
        }
151
 
        */
152
 
 
153
 
 
154
 
        BEGIN_PROFILE("islandUnionFindAndHeapSort");
155
 
        
 
149
        BT_PROFILE("islandUnionFindAndQuickSort");
 
150
        
 
151
        m_islandmanifold.resize(0);
 
152
 
156
153
        //we are going to sort the unionfind array, and store the element id in the size
157
154
        //afterwards, we clean unionfind, to make sure no-one uses it anymore
158
155
        
183
180
                        btCollisionObject* colObj0 = collisionObjects[i];
184
181
                        if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
185
182
                        {
186
 
                                printf("error in island management\n");
 
183
//                              printf("error in island management\n");
187
184
                        }
188
185
 
189
186
                        assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
210
207
                                btCollisionObject* colObj0 = collisionObjects[i];
211
208
                                if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
212
209
                                {
213
 
                                        printf("error in island management\n");
 
210
//                                      printf("error in island management\n");
214
211
                                }
215
212
 
216
213
                                assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
231
228
                                btCollisionObject* colObj0 = collisionObjects[i];
232
229
                                if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
233
230
                                {
234
 
                                        printf("error in island management\n");
 
231
//                                      printf("error in island management\n");
235
232
                                }
236
233
 
237
234
                                assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
247
244
                }
248
245
        }
249
246
 
250
 
        btAlignedObjectArray<btPersistentManifold*>  islandmanifold;
 
247
        
251
248
        int i;
252
249
        int maxNumManifolds = dispatcher->getNumManifolds();
253
 
        islandmanifold.reserve(maxNumManifolds);
254
 
 
 
250
 
 
251
#define SPLIT_ISLANDS 1
 
252
#ifdef SPLIT_ISLANDS
 
253
 
 
254
        
 
255
#endif //SPLIT_ISLANDS
 
256
 
 
257
        
255
258
        for (i=0;i<maxNumManifolds ;i++)
256
259
        {
257
260
                 btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
265
268
                {
266
269
                
267
270
                        //kinematic objects don't merge islands, but wake up all connected objects
268
 
                        if (colObj0->isStaticOrKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING)
 
271
                        if (colObj0->isKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING)
269
272
                        {
270
273
                                colObj1->activate();
271
274
                        }
272
 
                        if (colObj1->isStaticOrKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING)
 
275
                        if (colObj1->isKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING)
273
276
                        {
274
277
                                colObj0->activate();
275
278
                        }
276
 
 
277
 
                        //filtering for response
 
279
#ifdef SPLIT_ISLANDS
 
280
        //              //filtering for response
278
281
                        if (dispatcher->needsResponse(colObj0,colObj1))
279
 
                                islandmanifold.push_back(manifold);
 
282
                                m_islandmanifold.push_back(manifold);
 
283
#endif //SPLIT_ISLANDS
280
284
                }
281
285
        }
282
 
 
283
 
        int numManifolds = int (islandmanifold.size());
284
 
 
 
286
}
 
287
 
 
288
 
 
289
 
 
290
//
 
291
// todo: this is random access, it can be walked 'cache friendly'!
 
292
//
 
293
void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback)
 
294
{
 
295
 
 
296
        buildIslands(dispatcher,collisionObjects);
 
297
 
 
298
        int endIslandIndex=1;
 
299
        int startIslandIndex;
 
300
        int numElem = getUnionFind().getNumElements();
 
301
 
 
302
        BT_PROFILE("processIslands");
 
303
 
 
304
#ifndef SPLIT_ISLANDS
 
305
        btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
 
306
        
 
307
        callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1);
 
308
#else
285
309
        // Sort manifolds, based on islands
286
310
        // Sort the vector using predicate and std::sort
287
311
        //std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
288
312
 
 
313
        int numManifolds = int (m_islandmanifold.size());
 
314
 
289
315
        //we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
290
 
        islandmanifold.heapSort(btPersistentManifoldSortPredicate());
 
316
        m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
291
317
 
292
318
        //now process all active islands (sets of manifolds for now)
293
319
 
296
322
 
297
323
        //int islandId;
298
324
 
299
 
        END_PROFILE("islandUnionFindAndHeapSort");
300
 
 
301
 
        btAlignedObjectArray<btCollisionObject*>        islandBodies;
302
 
 
 
325
        
 
326
 
 
327
//      printf("Start Islands\n");
303
328
 
304
329
        //traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
305
330
        for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex)
313
338
                {
314
339
                        int i = getUnionFind().getElement(endIslandIndex).m_sz;
315
340
                        btCollisionObject* colObj0 = collisionObjects[i];
316
 
                                                islandBodies.push_back(colObj0);
 
341
                                                m_islandBodies.push_back(colObj0);
317
342
                        if (!colObj0->isActive())
318
343
                                islandSleeping = true;
319
344
                }
325
350
 
326
351
                if (startManifoldIndex<numManifolds)
327
352
                {
328
 
                        int curIslandId = getIslandId(islandmanifold[startManifoldIndex]);
 
353
                        int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]);
329
354
                        if (curIslandId == islandId)
330
355
                        {
331
 
                                startManifold = &islandmanifold[startManifoldIndex];
 
356
                                startManifold = &m_islandmanifold[startManifoldIndex];
332
357
                        
333
 
                                for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(islandmanifold[endManifoldIndex]));endManifoldIndex++)
 
358
                                for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++)
334
359
                                {
335
360
 
336
361
                                }
342
367
 
343
368
                if (!islandSleeping)
344
369
                {
345
 
                        callback->ProcessIsland(&islandBodies[0],islandBodies.size(),startManifold,numIslandManifolds, islandId);
 
370
                        callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId);
 
371
//                      printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
346
372
                }
347
373
                
348
374
                if (numIslandManifolds)
350
376
                        startManifoldIndex = endManifoldIndex;
351
377
                }
352
378
 
353
 
                islandBodies.resize(0);
 
379
                m_islandBodies.resize(0);
354
380
        }
355
 
 
356
 
        
 
381
#endif //SPLIT_ISLANDS
 
382
 
 
383
 
357
384
}