Page 1 of 1
cpHashset size does not decrease after removal of shape obje
Posted: Mon May 17, 2010 8:40 am
by psudheer28
Hello everyone,
i am using 25 objects ( shapes) in my game, cpHashSet size is 47, after collision object(shape) will remove from the space.
I think after removing the objects the cpHashSet size should be decrese, but its not.
I am unable to understand what exactly happening.
plz give explanation for this
thank you
sudheer
Re: cpHashset size does not decrease after removal of shape obje
Posted: Mon May 17, 2010 9:33 am
by Tam Toucan
Code: Select all
typedef struct cpHashSet {
// Number of elements stored in the table.
int entries;
// Number of cells in the table.
int size;
Why would the numer of cells decrease?
Re: cpHashset size does not decrease after removal of shape obje
Posted: Mon May 17, 2010 10:38 am
by slembcke
As Tam pointed out, hash tables have a separate table size and number of entries they store. Think of it as the amount of space allocated compared to the amount of space used.
Re: cpHashset size does not decrease after removal of shape obje
Posted: Tue May 18, 2010 6:14 am
by psudheer28
Thanks Tam and slembcke,
Now I understand concept of Hashset,and also able to visualize it. Thank you once again.
Actually I am developing a game and have to do a performance tuning. I think game performance can be improve by applying collision filtering(previously I filtering collision in call back function). recently I implement group filtering and performance improve a little bit. I think, more performance improve if I implement Bounding Box but I don't understand it and unable to implement it.
can you please explain me.
Thanks
Re: cpHashset size does not decrease after removal of shape obje
Posted: Tue May 18, 2010 7:19 am
by maximile
Chipmunk automatically rejects collisions if the bounding boxes don't intersect. There's no need to do anything extra there.
Re: cpHashset size does not decrease after removal of shape obje
Posted: Wed May 19, 2010 12:39 am
by psudheer28
Thanks maxmile,
is chipmunk automatically define bounding boxes for shape we create ?
and also are we able to define layer and group to same shape?
can you please explain me,How we can use layer I think description in the document is insufficient.
Re: cpHashset size does not decrease after removal of shape obje
Posted: Wed May 19, 2010 4:20 am
by Tam Toucan
For chipmunk to try the "expensive" collision code checking it first does the following fast checks to do early rejection.
Code: Select all
queryReject(cpShape *a, cpShape *b)
{
return
// BBoxes must overlap
!cpBBintersects(a->bb, b->bb)
// Don't collide shapes attached to the same body.
|| a->body == b->body
// Don't collide objects in the same non-zero group
|| (a->group && b->group && a->group == b->group)
// Don't collide objects that don't share at least on layer.
|| !(a->layers & b->layers);
}
So Chipmunk automatically does BB checking, it then checks that the shapes aren't in the same group (so you generally give all shapes for the same object the same (non-zero) group value.
Finally it checks that the two shapes share the same layer. Think of the layer a 32 flat planes stacked parallel to each other. The bit pattern of the layer value determines which planes the shape is on. For two shapes to collide they must have a common plane.
So if shapeA has layer = 0x00000001 and shapeB has layer = 0x00000003 they can collide since they are both on the plane for bit0. If shapeB didn't have bit0 set then it could never collide with shapeA.
Re: cpHashset size does not decrease after removal of shape obje
Posted: Mon May 24, 2010 4:46 am
by psudheer28
Hi Tam,
Thank you very much for such a good explanation about collision filtering.
I have implement group and layer, now game has much better performance.
Thanks