本文整理汇总了C++中cpfree函数的典型用法代码示例。如果您正苦于以下问题:C++ cpfree函数的具体用法?C++ cpfree怎么用?C++ cpfree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpfree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: postStepCallbackSetFilter
// Hashset filter func to call and throw away post step callbacks.
static int
postStepCallbackSetFilter(postStepCallback *callback, cpSpace *space)
{
callback->func(space, callback->obj, callback->data);
cpfree(callback);
return 0;
}
示例2: cpArbiterFree
void
cpArbiterFree(cpArbiter *arb)
{
if(arb){
cpArbiterDestroy(arb);
cpfree(arb);
}
}
示例3: cpSpaceFree
void
cpSpaceFree(cpSpace *space)
{
if(space) {
cpSpaceDestroy(space);
cpfree(space);
}
}
示例4: cpSpaceRemoveCollisionHandler
void
cpSpaceRemoveCollisionHandler(cpSpace *space, cpCollisionType a, cpCollisionType b)
{
cpAssertSpaceUnlocked(space);
struct{cpCollisionType a, b;} ids = {a, b};
cpCollisionHandler *old_handler = (cpCollisionHandler *) cpHashSetRemove(space->collFuncSet, CP_HASH_PAIR(a, b), &ids);
cpfree(old_handler);
}
示例5: cpSpaceHashAllocTable
// Frees the old table, and allocates a new one.
static void
cpSpaceHashAllocTable(cpSpaceHash *hash, int numcells)
{
if(hash->table)
cpfree(hash->table);
hash->numcells = numcells;
hash->table = (cpSpaceHashBin **)cpcalloc(numcells, sizeof(cpSpaceHashBin *));
}
示例6: cpHashSetDestroy
void
cpHashSetDestroy(cpHashSet *set)
{
// Free the table.
cpfree(set->table);
if(set->allocatedBuffers) cpArrayEach(set->allocatedBuffers, freeWrap, NULL);
cpArrayFree(set->allocatedBuffers);
}
示例7: freeBins
// Free the recycled hash bins.
static void
freeBins(cpSpaceHash *hash)
{
cpSpaceHashBin *bin = hash->bins;
while(bin){
cpSpaceHashBin *next = bin->next;
cpfree(bin);
bin = next;
}
}
示例8: cpPolylineSetDestroy
void
cpPolylineSetDestroy(cpPolylineSet *set, cpBool freePolylines)
{
if(freePolylines){
for(int i=0; i<set->count; i++){
cpPolylineFree(set->lines[i]);
}
}
cpfree(set->lines);
}
示例9: cpSpaceHashDestroy
static void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
if(hash->table) clearTable(hash);
cpfree(hash->table);
cpHashSetFree(hash->handleSet);
cpArrayFreeEach(hash->allocatedBuffers, cpfree);
cpArrayFree(hash->allocatedBuffers);
cpArrayFree(hash->pooledHandles);
}
示例10: cpSpaceHashDestroy
void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
clearHash(hash);
freeBins(hash);
// Free the handles.
cpHashSetEach(hash->handleSet, &handleFreeWrap, NULL);
cpHashSetFree(hash->handleSet);
cpfree(hash->table);
}
示例11: cpSpaceHashDestroy
void
cpSpaceHashDestroy(cpSpaceHash *hash)
{
clearHash(hash);
cpHashSetFree(hash->handleSet);
cpArrayEach(hash->allocatedBuffers, freeWrap, NULL);
cpArrayFree(hash->allocatedBuffers);
cpArrayFree(hash->pooledHandles);
cpfree(hash->table);
}
示例12: cpSpaceActivateBody
void
cpSpaceActivateBody(cpSpace *space, cpBody *body)
{
cpAssertHard(!cpBodyIsRogue(body), "Internal error: Attempting to activate a rogue body.");
if(space->locked){
// cpSpaceActivateBody() is called again once the space is unlocked
if(!cpArrayContains(space->rousedBodies, body)) cpArrayPush(space->rousedBodies, body);
} else {
cpAssertSoft(body->node.root == NULL && body->node.next == NULL, "Internal error: Activating body non-NULL node pointers.");
cpArrayPush(space->bodies, body);
CP_BODY_FOREACH_SHAPE(body, shape){
cpSpatialIndexRemove(space->staticShapes, shape, shape->hashid);
cpSpatialIndexInsert(space->activeShapes, shape, shape->hashid);
}
CP_BODY_FOREACH_ARBITER(body, arb){
cpBody *bodyA = arb->body_a;
// Arbiters are shared between two bodies that are always woken up together.
// You only want to restore the arbiter once, so bodyA is arbitrarily chosen to own the arbiter.
// The edge case is when static bodies are involved as the static bodies never actually sleep.
// If the static body is bodyB then all is good. If the static body is bodyA, that can easily be checked.
if(body == bodyA || cpBodyIsStatic(bodyA)){
int numContacts = arb->numContacts;
cpContact *contacts = arb->contacts;
// Restore contact values back to the space's contact buffer memory
arb->contacts = cpContactBufferGetArray(space);
memcpy(arb->contacts, contacts, numContacts*sizeof(cpContact));
cpSpacePushContacts(space, numContacts);
// Reinsert the arbiter into the arbiter cache
cpShape *a = arb->a, *b = arb->b;
cpShape *shape_pair[] = {a, b};
cpHashValue arbHashID = CP_HASH_PAIR((cpHashValue)a, (cpHashValue)b);
cpHashSetInsert(space->cachedArbiters, arbHashID, shape_pair, arb, NULL);
// Update the arbiter's state
arb->stamp = space->stamp;
arb->handler = cpSpaceLookupHandler(space, a->collision_type, b->collision_type);
cpArrayPush(space->arbiters, arb);
cpfree(contacts);
}
}
示例13: queryFunc
// Callback from the spatial hash.
static void
queryFunc(cpShape *a, cpShape *b, cpSpace *space)
{
// Reject any of the simple cases
if(queryReject(a,b)) return;
// Find the collision pair function for the shapes.
struct{cpCollisionType a, b;} ids = {a->collision_type, b->collision_type};
cpHashValue collHashID = CP_HASH_PAIR(a->collision_type, b->collision_type);
cpCollisionHandler *handler = (cpCollisionHandler *)cpHashSetFind(space->collFuncSet, collHashID, &ids);
int sensor = a->sensor || b->sensor;
if(sensor && handler == &space->defaultHandler) return;
// Shape 'a' should have the lower shape type. (required by cpCollideShapes() )
if(a->klass->type > b->klass->type){
cpShape *temp = a;
a = b;
b = temp;
}
// Narrow-phase collision detection.
cpContact *contacts = NULL;
int numContacts = cpCollideShapes(a, b, &contacts);
if(!numContacts) return; // Shapes are not colliding.
// Get an arbiter from space->contactSet for the two shapes.
// This is where the persistant contact magic comes from.
cpShape *shape_pair[] = {a, b};
cpHashValue arbHashID = CP_HASH_PAIR(a, b);
cpArbiter *arb = (cpArbiter *)cpHashSetInsert(space->contactSet, arbHashID, shape_pair, NULL);
cpArbiterUpdate(arb, contacts, numContacts, handler, a, b); // retains the contacts array
// Call the begin function first if we need to
int beginPass = (arb->stamp >= 0) || (handler->begin(arb, space, handler->data));
if(beginPass && handler->preSolve(arb, space, handler->data) && !sensor){
cpArrayPush(space->arbiters, arb);
} else {
cpfree(arb->contacts);
arb->contacts = NULL;
}
// Time stamp the arbiter so we know it was used recently.
arb->stamp = space->stamp;
}
示例14: cpSpaceActivateBody
void
cpSpaceActivateBody(cpSpace *space, cpBody *body)
{
cpAssertHard(!cpBodyIsRogue(body), "Internal error: Attempting to activate a rouge body.");
if(space->locked){
// cpSpaceActivateBody() is called again once the space is unlocked
if(!cpArrayContains(space->rousedBodies, body)) cpArrayPush(space->rousedBodies, body);
} else {
cpArrayPush(space->bodies, body);
CP_BODY_FOREACH_SHAPE(body, shape){
cpSpatialIndexRemove(space->staticShapes, shape, shape->hashid);
cpSpatialIndexInsert(space->activeShapes, shape, shape->hashid);
}
CP_BODY_FOREACH_ARBITER(body, arb){
cpBody *bodyA = arb->body_a;
if(body == bodyA || cpBodyIsStatic(bodyA)){
int numContacts = arb->numContacts;
cpContact *contacts = arb->contacts;
// Restore contact values back to the space's contact buffer memory
arb->contacts = cpContactBufferGetArray(space);
memcpy(arb->contacts, contacts, numContacts*sizeof(cpContact));
cpSpacePushContacts(space, numContacts);
// Reinsert the arbiter into the arbiter cache
cpShape *a = arb->a, *b = arb->b;
cpShape *shape_pair[] = {a, b};
cpHashValue arbHashID = CP_HASH_PAIR((cpHashValue)a, (cpHashValue)b);
cpHashSetInsert(space->cachedArbiters, arbHashID, shape_pair, arb, NULL);
// Update the arbiter's state
arb->stamp = space->stamp;
arb->handler = cpSpaceLookupHandler(space, a->collision_type, b->collision_type);
cpArrayPush(space->arbiters, arb);
cpfree(contacts);
}
}
示例15: cpBBTreeOptimize
void
cpBBTreeOptimize(cpSpatialIndex *index)
{
if(index->klass != &klass){
cpAssertWarn(cpFalse, "Ignoring cpBBTreeOptimize() call to non-tree spatial index.");
return;
}
cpBBTree *tree = (cpBBTree *)index;
Node *root = tree->root;
if(!root) return;
int count = cpBBTreeCount(tree);
Node **nodes = (Node **)cpcalloc(count, sizeof(Node *));
Node **cursor = nodes;
cpHashSetEach(tree->leaves, (cpHashSetIteratorFunc)fillNodeArray, &cursor);
SubtreeRecycle(tree, root);
tree->root = partitionNodes(tree, nodes, count);
cpfree(nodes);
}