I just rebuilt my (very alpha) game with Chipmunk 6. In 5.3.4 I've been making heavy use of sensors for pathfinding, and they were working quite well.
In 5.3.4 if a dynamic body/shape were removed from the space, the separate collision handler for my sensors overlapping that shape would be invoked and my pathfinding code could update accordingly. In Chipmunk 6, however, the cpCollisionSeparateFunc is not invoked when a shape overlapping my sensor is removed from the space.
( My game dynamically destroys and adds new shapes at runtime to approximate dynamic cutting/reshaping/etc of my terrain. So it's important that the sensor callbacks are invoked when geometry is removed )
Is this a bug, or a feature of Chipmunk 6 I need to figure out a workaround for?
Here's my setup code for callbacks:
Code: Select all
cpSpaceAddCollisionHandler(
space,
_collisionType,
CollisionType::PATHFINDING_SENSOR_TYPE,
&Pathfinder_cpCollisionBegin,
NULL,
NULL,
&Pathfinder_cpCollisionSeparate,
this
);
Code: Select all
cpBool Pathfinder_cpCollisionBegin(cpArbiter *arb, struct cpSpace *space, void *data)
{
cpShape *a = NULL, *b = NULL;
cpArbiterGetShapes( arb, &a, &b );
Pathfinder *pathfinder = (Pathfinder*) data;
// my understanding is that 'b' should be my sensor...
Pathfinder::Probe *probe = (Pathfinder::Probe*) b->data;
if ( probe->incrementDynamicMark() ) pathfinder->_probeOccupationStatusChanged = true;
return false; // prevents further computation -- _cpCollisionSeparate will still be called however
}
void Pathfinder_cpCollisionSeparate(cpArbiter *arb, cpSpace *space, void *data)
{
cpShape *a = NULL, *b = NULL;
cpArbiterGetShapes( arb, &a, &b );
Pathfinder *pathfinder = (Pathfinder*) data;
// my understanding is that 'b' should be my sensor...
Pathfinder::Probe *probe = (Pathfinder::Probe*) b->data;
if ( probe->decrementDynamicMark() ) pathfinder->_probeOccupationStatusChanged = true;
}