Skip to content

Commit

Permalink
UPBGE: Allocate KX_CollisionContactPointList on stack instead of heap.
Browse files Browse the repository at this point in the history
This simplify the mechanism of allocation deletion.
  • Loading branch information
panzergame committed Jul 18, 2016
1 parent 302a78f commit 600eaed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,18 +1507,17 @@ void KX_GameObject::RegisterCollisionCallbacks()
pe->AddSensor(spc);
}
}
void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, KX_CollisionContactPointList *contactPointList)
void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, KX_CollisionContactPointList& contactPointList)
{
#ifdef WITH_PYTHON
if (!m_collisionCallbacks || PyList_GET_SIZE(m_collisionCallbacks) == 0) {
delete contactPointList;
return;
}

CListWrapper *listWrapper = contactPointList->GetListWrapper();
CListWrapper *listWrapper = contactPointList.GetListWrapper();
PyObject *args[] = {collider->GetProxy(),
PyObjectFrom(contactPointList->GetCollData()->GetWorldPoint(0, contactPointList->GetFirstObject())),
PyObjectFrom(contactPointList->GetCollData()->GetNormal(0, contactPointList->GetFirstObject())),
PyObjectFrom(contactPointList.GetCollData()->GetWorldPoint(0, contactPointList.GetFirstObject())),
PyObjectFrom(contactPointList.GetCollData()->GetNormal(0, contactPointList.GetFirstObject())),
listWrapper->GetProxy()};
RunPythonCallBackList(m_collisionCallbacks, args, 1, ARRAY_SIZE(args));

Expand All @@ -1529,7 +1528,6 @@ void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, KX_CollisionC
// Invalidate the collison contact point to avoid acces to it in next frame
listWrapper->InvalidateProxy();
delete listWrapper;
delete contactPointList;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ class KX_GameObject : public SCA_IObject

void RegisterCollisionCallbacks();
void UnregisterCollisionCallbacks();
void RunCollisionCallbacks(KX_GameObject *collider, KX_CollisionContactPointList *contactPointList);
void RunCollisionCallbacks(KX_GameObject *collider, KX_CollisionContactPointList& contactPointList);
/**
* Stop making progress
*/
Expand Down
4 changes: 2 additions & 2 deletions source/gameengine/Ketsji/KX_TouchEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ void KX_TouchEventManager::NextFrame()
}
// Run python callbacks
const PHY_CollData *colldata = cit->colldata;
KX_CollisionContactPointList *contactPointList0 = new KX_CollisionContactPointList(colldata, true);
KX_CollisionContactPointList *contactPointList1 = new KX_CollisionContactPointList(colldata, false);
KX_CollisionContactPointList contactPointList0 = KX_CollisionContactPointList(colldata, true);
KX_CollisionContactPointList contactPointList1 = KX_CollisionContactPointList(colldata, false);
kxObj1->RunCollisionCallbacks(kxObj2, contactPointList0);
kxObj2->RunCollisionCallbacks(kxObj1, contactPointList1);
}
Expand Down

0 comments on commit 600eaed

Please sign in to comment.