MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
collisiondispatcher.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _physicscollisiondispatcher_cpp
41 #define _physicscollisiondispatcher_cpp
42 
43 #include "Physics/collisiondispatcher.h.cpp"
44 #include "Physics/physicsmanager.h"
45 #include "Physics/collision.h"
46 #include "entresol.h"
47 
48 namespace Mezzanine
49 {
50  namespace Physics
51  {
52  ///////////////////////////////////////////////////////////
53  // CollisionDispatcher functions
54 
55  CollisionDispatcher::CollisionDispatcher(btCollisionConfiguration* CollisionConfig)
56  : btCollisionDispatcher(CollisionConfig)
57  {
58  }
59 
61  {
62  }
63 
64  ///////////////////////////////////////////////////////////////////////////////
65  // New Implementation based on Algorithm creation
66 
68  {
69  void* ToReturn = btCollisionDispatcher::allocateCollisionAlgorithm(size);
70  btCollisionAlgorithm* Casted = (btCollisionAlgorithm*)ToReturn;
71  AlgoCreationQueue.push_back(Casted);
72  return ToReturn;
73  }
75  {
76  btCollisionAlgorithm* Casted = (btCollisionAlgorithm*)ptr;
77  // first check the queue
78  if(!AlgoCreationQueue.empty())
79  {
80  for(AlgoList::iterator QueIt = AlgoCreationQueue.begin() ; QueIt != AlgoCreationQueue.end() ; QueIt++ )
81  {
82  if(Casted == (*QueIt))
83  {
84  AlgoCreationQueue.erase(QueIt);
85  btCollisionDispatcher::freeCollisionAlgorithm(ptr);
86  return;
87  }
88  }
89  }
90  // now check the already generated collisions
92  for( Physics::PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
93  {
94  if(Casted == (*ColIt).second->InternalAlgo)
95  {
96  //ManifoldDestructionQueue.push_back(ColIt);
97  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
98  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
99  delete (*ColIt).second;
100  PhysMan->Collisions.erase(ColIt);
101  break;
102  }
103  }
104  btCollisionDispatcher::freeCollisionAlgorithm(ptr);
105  }
107  {
108  return &AlgoCreationQueue;
109  }
110 
111  ///////////////////////////////////////////////////////////////////////////////
112  // Old Implementation based on Manifold creation
113 
114  /*btPersistentManifold* CollisionDispatcher::getNewManifold(void* b0, void* b1)
115  {
116  // Get the manifold
117  btPersistentManifold* NewManifold = btCollisionDispatcher::getNewManifold(b0,b1);
118  // Store the manifold for processing later
119  ManifoldCreationQueue.push_back(NewManifold);
120  return NewManifold;
121  }
122  void CollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
123  {
124  // first check the queue
125  if(!ManifoldCreationQueue.empty())
126  {
127  for(std::list<btPersistentManifold*>::iterator QueIt = ManifoldCreationQueue.begin() ; QueIt != ManifoldCreationQueue.end() ; QueIt++ )
128  {
129  if(manifold == (*QueIt))
130  {
131  ManifoldCreationQueue.erase(QueIt);
132  btCollisionDispatcher::releaseManifold(manifold);
133  return;
134  }
135  }
136  }
137  // now check the already generated collisions
138  PhysicsManager* PhysMan = Entresol::GetSingletonPtr()->GetPhysicsManager();
139  for( PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
140  {
141  if(manifold == (*ColIt).second->InternalAlgo)
142  {
143  //ManifoldDestructionQueue.push_back(ColIt);
144  // ©ollision* ToBeDestroyed = (*ColIt).second;
145  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
146  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
147  delete (*ColIt).second;
148  PhysMan->Collisions.erase(ColIt);
149  //delete ToBeDestroyed;
150  break;
151  }
152  }
153  btCollisionDispatcher::releaseManifold(manifold);
154  }
155  void CollisionDispatcher::releaseManifoldManual(btPersistentManifold* manifold)
156  {
157  PhysicsManager* PhysMan = Entresol::GetSingletonPtr()->GetPhysicsManager();
158  for( PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
159  {
160  if(manifold == (*ColIt).second->Manifold)
161  {
162  Collision* ToBeDestroyed = (*ColIt).second;
163  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
164  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
165  PhysMan->Collisions.erase(ColIt);
166  delete ToBeDestroyed;
167  break;
168  }
169  }
170  btCollisionDispatcher::releaseManifold(manifold);
171  }// */
172 
173  ///////////////////////////////////////////////////////////
174  // ParallelCollisionDispatcher functions
175 
176  ParallelCollisionDispatcher::ParallelCollisionDispatcher(btThreadSupportInterface* ThreadInterface, unsigned int MaxNumTasks, btCollisionConfiguration* CollisionConfig)
177  : SpuGatheringCollisionDispatcher(ThreadInterface,MaxNumTasks,CollisionConfig)
178  {
179  }
180 
182  {
183  }
184 
185  ///////////////////////////////////////////////////////////////////////////////
186  // New Implementation based on Algorithm creation
187 
189  {
190  void* ToReturn = btCollisionDispatcher::allocateCollisionAlgorithm(size);
191  btCollisionAlgorithm* Casted = (btCollisionAlgorithm*)ToReturn;
192  AlgoCreationQueue.push_back(Casted);
193  return ToReturn;
194  }
196  {
197  btCollisionAlgorithm* Casted = (btCollisionAlgorithm*)ptr;
198  // first check the queue
199  if(!AlgoCreationQueue.empty())
200  {
201  for(AlgoList::iterator QueIt = AlgoCreationQueue.begin() ; QueIt != AlgoCreationQueue.end() ; QueIt++ )
202  {
203  if(Casted == (*QueIt))
204  {
205  AlgoCreationQueue.erase(QueIt);
206  btCollisionDispatcher::freeCollisionAlgorithm(ptr);
207  return;
208  }
209  }
210  }
211  // now check the already generated collisions
213  for( Physics::PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
214  {
215  if(Casted == (*ColIt).second->InternalAlgo)
216  {
217  //ManifoldDestructionQueue.push_back(ColIt);
218  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
219  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
220  delete (*ColIt).second;
221  PhysMan->Collisions.erase(ColIt);
222  break;
223  }
224  }
225  btCollisionDispatcher::freeCollisionAlgorithm(ptr);
226  }
228  {
229  return &AlgoCreationQueue;
230  }
231 
232  ///////////////////////////////////////////////////////////////////////////////
233  // Old Implementation based on Manifold creation
234 
235  /*btPersistentManifold* ParallelCollisionDispatcher::getNewManifold(void* b0, void* b1)
236  {
237  // Get the manifold
238  btPersistentManifold* NewManifold = btCollisionDispatcher::getNewManifold(b0,b1);
239  // Store the manifold for processing later
240  ManifoldCreationQueue.push_back(NewManifold);
241  return NewManifold;
242  }
243  void ParallelCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
244  {
245  // first check the queue
246  if(!ManifoldCreationQueue.empty())
247  {
248  for(std::list<btPersistentManifold*>::iterator QueIt = ManifoldCreationQueue.begin() ; QueIt != ManifoldCreationQueue.end() ; QueIt++ )
249  {
250  if(manifold == (*QueIt))
251  {
252  ManifoldCreationQueue.erase(QueIt);
253  btCollisionDispatcher::releaseManifold(manifold);
254  return;
255  }
256  }
257  }
258  // now check the already generated collisions
259  PhysicsManager* PhysMan = Entresol::GetSingletonPtr()->GetPhysicsManager();
260  for( PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
261  {
262  if(manifold == (*ColIt).second->InternalAlgo)
263  {
264  //ManifoldDestructionQueue.push_back(ColIt);
265  // ©ollision* ToBeDestroyed = (*ColIt).second;
266  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
267  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
268  delete (*ColIt).second;
269  PhysMan->Collisions.erase(ColIt);
270  //delete ToBeDestroyed;
271  break;
272  }
273  }
274  btCollisionDispatcher::releaseManifold(manifold);
275  }
276  void ParallelCollisionDispatcher::releaseManifoldManual(btPersistentManifold* manifold)
277  {
278  PhysicsManager* PhysMan = Entresol::GetSingletonPtr()->GetPhysicsManager();
279  for( PhysicsManager::CollisionIterator ColIt = PhysMan->Collisions.begin() ; ColIt != PhysMan->Collisions.end() ; ++ColIt )
280  {
281  if(manifold == (*ColIt).second->Manifold)
282  {
283  Collision* ToBeDestroyed = (*ColIt).second;
284  //ToBeDestroyed->GetActorA()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
285  //ToBeDestroyed->GetActorB()->_NotifyCollisionState(ToBeDestroyed,Collision::Col_End);
286  PhysMan->Collisions.erase(ColIt);
287  delete ToBeDestroyed;
288  break;
289  }
290  }
291  btCollisionDispatcher::releaseManifold(manifold);
292  }// */
293  }//Physics
294 }//Mezzanine
295 
296 #endif