Skip to content

Commit

Permalink
more optimization work (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJerez committed Aug 10, 2018
1 parent ee8e5e0 commit 2ecd47f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
33 changes: 2 additions & 31 deletions sdk/dgPhysics/dgBodyMasterList.cpp
Expand Up @@ -38,26 +38,10 @@ dgBodyMasterListRow::~dgBodyMasterListRow()
dgAssert (GetCount() == 0);
}

void dgBodyMasterListRow::OrderContactJoint(dgBodyMasterListRow::dgListNode* const node)
{
dgScopeSpinLock lock(&m_body->m_criticalSectionLock);

dgContact* const contact = (dgContact*)node->GetInfo().m_joint;
if (contact->m_maxDOF) {
RotateToBegin(node);
} else {
dgListNode* ptr = GetLast();
for (; ptr && (ptr->GetInfo().m_joint->GetId() != dgConstraint::m_contactConstraint); ptr = ptr->GetPrev());
if (ptr && (ptr != node)) {
InsertAfter(ptr, node);
}
}
}

dgBodyMasterListRow::dgListNode* dgBodyMasterListRow::AddContactJoint (dgConstraint* const joint, dgBody* const body)
{
// no need for lock since this is called from the main thread only
// dgScopeSpinLock lock(&m_body->m_criticalSectionLock);
//no need for lock since this is called from the main thread only
//dgScopeSpinLock lock(&m_body->m_criticalSectionLock);

dgListNode* node;
dgContact* const contact = (dgContact*)joint;
Expand Down Expand Up @@ -336,26 +320,13 @@ void dgBodyMasterList::RemoveConstraint (dgConstraint* const constraint)
}
}

void dgBodyMasterList::OrderContactJoint(dgContact* const contact)
{
dgBody* const body0 = contact->m_body0;
dgBody* const body1 = contact->m_body1;
dgAssert(body0);
dgAssert(body1);
dgBodyMasterListRow& row0 = body0->m_masterNode->GetInfo();
dgBodyMasterListRow& row1 = body1->m_masterNode->GetInfo();
row0.OrderContactJoint(contact->GetLink0());
row1.OrderContactJoint(contact->GetLink1());
}

DG_INLINE dgUnsigned32 dgBodyMasterList::MakeSortMask(const dgBody* const body) const
{
dgUnsigned32 val0 = body->IsRTTIType(dgBody::m_dynamicBodyRTTI) ? (body->GetInvMass().m_w > 0.0f) << 30 : 0;
dgUnsigned32 val1 = body->IsRTTIType(dgBody::m_kinematicBodyRTTI) ? 1<<29 : 0;
return body->m_uniqueID | val0 | val1;
}


void dgBodyMasterList::SortMasterList()
{
GetFirst()->GetInfo().SortList();
Expand Down
5 changes: 1 addition & 4 deletions sdk/dgPhysics/dgBodyMasterList.h
Expand Up @@ -54,10 +54,8 @@ class dgBodyMasterListRow: public dgList<dgBodyMasterListCell>

void RemoveContactJoint (dgListNode* const link);
void RemoveBilateralJoint (dgListNode* const link);

void RemoveAllJoints ();
void OrderContactJoint(dgBodyMasterListRow::dgListNode* const node);


dgBody* m_body;
friend class dgBodyMasterList;
};
Expand All @@ -72,7 +70,6 @@ class dgBodyMasterList: public dgList<dgBodyMasterListRow>
void RemoveBody (dgBody* const body);
void RemoveConstraint (dgConstraint* const constraint);
void AttachConstraint (dgConstraint* const constraint, dgBody* const body0, dgBody* const body1);
void OrderContactJoint(dgContact* const contact);

dgContact* FindContactJoint (const dgBody* body0, const dgBody* body1) const;
dgBilateralConstraint* FindBilateralJoint (const dgBody* body0, const dgBody* body1) const;
Expand Down
7 changes: 0 additions & 7 deletions sdk/dgPhysics/dgBroadPhase.cpp
Expand Up @@ -1491,15 +1491,13 @@ void dgBroadPhase::UpdateRigidBodyContacts(dgBroadphaseSyncDescriptor* const des
DG_TRACKTIME(__FUNCTION__);
dgContactsList::dgListNode* node = nodePtr;
dgContactsList* const contactList = m_world;
dgBodyMasterList* const masterList = m_world;
const dgFloat32 timestep = descriptor->m_timestep;
const dgInt32 threadCount = m_world->GetThreadCount();
const dgUnsigned32 lru = m_lru - DG_CONTACT_DELAY_FRAMES;

while (node) {
dgContact* const contact = node->GetInfo();

bool stateChange = contact->m_maxDOF ? true : false;
const dgBody* const body0 = contact->GetBody0();
const dgBody* const body1 = contact->GetBody1();
if (!(body0->m_equilibrium & body1->m_equilibrium)) {
Expand Down Expand Up @@ -1555,11 +1553,6 @@ void dgBroadPhase::UpdateRigidBodyContacts(dgBroadphaseSyncDescriptor* const des
contact->m_broadphaseLru = m_lru;
}

stateChange = stateChange ^ (contact->m_maxDOF ? true : false);
if (stateChange) {
masterList->OrderContactJoint(contact);
}

for (dgInt32 i = 0; i < threadCount; i++) {
node = node ? node->GetNext() : NULL;
}
Expand Down

0 comments on commit 2ecd47f

Please sign in to comment.