Home

API improvements: Group references python api, for better control over groups and instances
Closed, ResolvedPublic

Description
This patch is an API extension for KX_GameObject class, that allows the user to gain better control over group instances at runtime. At level creation time, the user have to work with empty objects (proxies) for the grouped objects, but at runtime the proxy creates the whole group instances.

The problem:
There is no connection between the group proxy and the instanced objects. The patch provides two new read-only properties for KX_GameObject's, so you can easily access all instanced objects from the group empty, or you can access the group proxy from an instanced object.

For more informations you can checkout the complete proposal:
https://gitorious.org/bge-sandbox/pages/GroupRef

The files for testing this feature and for showing some possibilities:

http://dl.dropbox.com/u/2779060/BGE/group-reference.patch
http://dl.dropbox.com/u/2779060/BGE/group-reference_object_access.blend
http://dl.dropbox.com/u/2779060/BGE/group-reference_parenting.blend
http://dl.dropbox.com/u/2779060/BGE/group-reference_properties.blend
kupoman (Daniel Stokes) added a comment.Via Old WorldJun 5 2012, 2:59 AM
I am not sure how you created your patch, but I had to tweak the file a little to get it to apply right.

More importantly though, if you edit the python API make sure to edit the docs corresponding to that part of the API. This is doable in the appropriate rst file in the doc/python_api folder.
moguri (Mitchell Stokes) added a comment.Via Old WorldJul 29 2012, 2:12 AM
There is a memory leak: KX_GameObject::m_pInstanceObjects is never cleaned up.
Okay, I've uploaded a version of the patch with better refcounting. Visual Leak Detector is not reporting any more leaks with this version. :)
moguri (Mitchell Stokes) added a comment.Via Old WorldJul 29 2012, 2:42 AM
I just noticed that you have added some KX_PYMETHODs in KX_GameObject.h that are never actually getting used, and can be removed.
moguri (Mitchell Stokes) added a comment.Via Old WorldJul 30 2012, 1:45 AM
Looks like the improved patch can still cause leaks with replica objects. Some additional processing might have to be done in KX_GameObject::GetReplica().
moerdn (Martin Sell) added a comment.Via Old WorldAug 6 2012, 8:28 PM
Your patch causes a zombie object for every group proxy, that is deleted.
I have added a check for group objects in newDeleteObject():
If the group object is deleted, all members should loose their reference to the group object.

+ if(newobj->GetInstanceObjects()) {
+ for (int i = 0; i < newobj->GetInstanceObjects()->GetCount(); i++) {
+ KX_GameObject* instance = (KX_GameObject*)newobj->GetInstanceObjects()->GetValue(i);
+ instance->RemoveDupliGroupObject();
+ }
+ }

I still have some stuff to cleanup, an assertion is not needed in RemoveDupliGroupObject() and I will also cleanup the KX_PYMETHODs.
Tried to upload, the patch, did not work the first time..
I've been using this patch quite a bit in my current game project, and I'm not getting any more zombie objects. I'm attaching the copy of the patch that I've been using. It's mostly the same as Martin's last patch, but I've removed an assert (it was right in front of a NULL check anyways), and I made the patch with TortoiseSVN.

I'm assigning this to Campbell for final review/okay.
moerdn (Martin Sell) added a comment.Via Old WorldSep 19 2012, 8:32 PM
Thanks for your support, Mitchell!
moguri (Mitchell Stokes) added a comment.Via Old WorldOct 7 2012, 2:10 AM
This patch has now been committed as r51131.

Congrats on finally getting this into trunk!
moguri (Mitchell Stokes) closed this task as "Resolved".Via Old WorldOct 7 2012, 2:10 AM

Add Comment