- stop threads when exiting demo that uses multi threading
- improved friction model for parallel solver (align the friction direction with projected velocity, unless the projection is close to zero (only then use 2 arbitrary axis orthogonal to contact normal)
This commit is contained in:
@@ -1026,6 +1026,9 @@ void processSolverTask(void* userPtr, void* lsMemory)
|
||||
btVector3 rel_pos1 = pos1 - rb0->getCenterOfMassPosition();
|
||||
btVector3 rel_pos2 = pos2 - rb1->getCenterOfMassPosition();
|
||||
|
||||
btScalar rel_vel;
|
||||
btVector3 vel;
|
||||
|
||||
// De-penetration
|
||||
{
|
||||
SpuSolverInternalConstraint& constraint = localMemory->m_tempInternalConstr[0];
|
||||
@@ -1034,7 +1037,6 @@ void processSolverTask(void* userPtr, void* lsMemory)
|
||||
constraint.m_localOffsetBodyB = offsB;
|
||||
|
||||
constraint.m_normal = cp.m_normalWorldOnB;
|
||||
|
||||
{
|
||||
//can be optimized, the cross products are already calculated
|
||||
constraint.m_jacDiagABInv = computeJacobianInverse (rb0, rb1, pos1, pos2, cp.m_normalWorldOnB);
|
||||
@@ -1046,11 +1048,9 @@ void processSolverTask(void* userPtr, void* lsMemory)
|
||||
btVector3 vel1 = rb0->getVelocityInLocalPoint(rel_pos1);
|
||||
btVector3 vel2 = rb1->getVelocityInLocalPoint(rel_pos2);
|
||||
|
||||
btVector3 vel = vel1 - vel2;
|
||||
btScalar rel_vel;
|
||||
vel = vel1 - vel2;
|
||||
rel_vel = cp.m_normalWorldOnB.dot(vel);
|
||||
|
||||
|
||||
constraint.m_penetration = cp.getDistance();///btScalar(infoGlobal.m_numIterations);
|
||||
constraint.m_friction = cp.m_combinedFriction;
|
||||
float rest = - rel_vel * cp.m_combinedRestitution;
|
||||
@@ -1082,8 +1082,16 @@ void processSolverTask(void* userPtr, void* lsMemory)
|
||||
|
||||
btVector3 frictionTangential0a, frictionTangential1b;
|
||||
|
||||
btPlaneSpace1(cp.m_normalWorldOnB,frictionTangential0a,frictionTangential1b);
|
||||
|
||||
frictionTangential0a = vel - cp.m_normalWorldOnB * rel_vel;
|
||||
btScalar lat_rel_vel = frictionTangential0a.length2();
|
||||
if (lat_rel_vel > SIMD_EPSILON)//0.0f)
|
||||
{
|
||||
frictionTangential0a /= btSqrt(lat_rel_vel);
|
||||
frictionTangential1b = frictionTangential0a.cross(cp.m_normalWorldOnB);
|
||||
} else
|
||||
{
|
||||
btPlaneSpace1(cp.m_normalWorldOnB,frictionTangential0a,frictionTangential1b);
|
||||
}
|
||||
|
||||
{
|
||||
SpuSolverInternalConstraint& constraint = localMemory->m_tempInternalConstr[1];
|
||||
|
||||
@@ -52,23 +52,27 @@ DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
||||
while (1)
|
||||
{
|
||||
WaitForSingleObject(status->m_eventStartHandle,INFINITE);
|
||||
btAssert(status->m_status);
|
||||
|
||||
|
||||
void* userPtr = status->m_userPtr;
|
||||
|
||||
if (userPtr)
|
||||
{
|
||||
btAssert(status->m_status);
|
||||
status->m_userThreadFunc(userPtr,status->m_lsMemory);
|
||||
status->m_status = 2;
|
||||
SetEvent(status->m_eventCompletetHandle);
|
||||
} else
|
||||
{
|
||||
//exit Thread
|
||||
status->m_status = 3;
|
||||
SetEvent(status->m_eventCompletetHandle);
|
||||
printf("Thread with taskId %i with handle %i exiting\n",status->m_taskId, status->m_threadHandle);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("Thread TERMINATED\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -202,7 +206,7 @@ void Win32ThreadSupport::startThreads(Win32ThreadConstructionInfo& threadConstru
|
||||
SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST);
|
||||
//SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL);
|
||||
|
||||
//SetThreadAffinityMask(handle, 1<<i);
|
||||
SetThreadAffinityMask(handle, 1<<i);
|
||||
|
||||
spuStatus.m_taskId = i;
|
||||
spuStatus.m_commandId = 0;
|
||||
@@ -225,10 +229,28 @@ void Win32ThreadSupport::startSPU()
|
||||
///tell the task scheduler we are done with the SPU tasks
|
||||
void Win32ThreadSupport::stopSPU()
|
||||
{
|
||||
// m_activeSpuStatus.pop_back();
|
||||
// WaitForSingleObject(spuStatus.bla, INFINITE);
|
||||
// CloseHandle(spuStatus.m_threadHandle);
|
||||
|
||||
int i;
|
||||
for (i=0;i<m_activeSpuStatus.size();i++)
|
||||
{
|
||||
btSpuStatus& spuStatus = m_activeSpuStatus[i];
|
||||
if (spuStatus.m_status>0)
|
||||
{
|
||||
WaitForSingleObject(spuStatus.m_eventCompletetHandle, INFINITE);
|
||||
}
|
||||
|
||||
|
||||
spuStatus.m_userPtr = 0;
|
||||
SetEvent(spuStatus.m_eventStartHandle);
|
||||
WaitForSingleObject(spuStatus.m_eventCompletetHandle, INFINITE);
|
||||
|
||||
CloseHandle(spuStatus.m_eventCompletetHandle);
|
||||
CloseHandle(spuStatus.m_eventStartHandle);
|
||||
CloseHandle(spuStatus.m_threadHandle);
|
||||
}
|
||||
|
||||
m_activeSpuStatus.clear();
|
||||
m_completeHandles.clear();
|
||||
|
||||
}
|
||||
|
||||
#endif //USE_WIN32_THREADING
|
||||
|
||||
Reference in New Issue
Block a user