本文整理汇总了C++中cpArrayPush函数的典型用法代码示例。如果您正苦于以下问题:C++ cpArrayPush函数的具体用法?C++ cpArrayPush怎么用?C++ cpArrayPush使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cpArrayPush函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mergeBodies
static inline void
mergeBodies(cpSpace *space, cpArray *components, cpArray *rogueBodies, cpBody *a, cpBody *b)
{
// Don't merge with the static body
if(cpBodyIsStatic(a) || cpBodyIsStatic(b)) return;
cpBody *a_root = componentNodeRoot(a);
cpBody *b_root = componentNodeRoot(b);
cpBool a_sleep = cpBodyIsSleeping(a_root);
cpBool b_sleep = cpBodyIsSleeping(b_root);
if(a_sleep && b_sleep){
return;
} else if(a_sleep || b_sleep){
componentActivate(a_root);
componentActivate(b_root);
}
// Add any rogue bodies (bodies not added to the space)
if(!a->space) cpArrayPush(rogueBodies, a);
if(!b->space) cpArrayPush(rogueBodies, b);
componentNodeMerge(a_root, b_root);
}
开发者ID:bcolombini,项目名称:Learn-iPhone-and-iPad-cocos2d-Game-Development,代码行数:25,代码来源:cpSpace.c
示例2: mergeBodies
static inline void
mergeBodies(cpSpace *space, cpArray *components, cpArray *rogueBodies, cpBody *a, cpBody *b)
{
// Ignore connections to static bodies
if(cpBodyIsStatic(a) || cpBodyIsStatic(b)) return;
cpBody *a_root = componentNodeRoot(a);
cpBody *b_root = componentNodeRoot(b);
cpBool a_sleep = cpBodyIsSleeping(a_root);
cpBool b_sleep = cpBodyIsSleeping(b_root);
if(a_sleep && b_sleep){
return;
} else if(a_sleep || b_sleep){
componentActivate(a_root);
componentActivate(b_root);
}
// Add any rogue bodies found to the list and reset the idle time of anything they touch.
if(cpBodyIsRogue(a)){ cpArrayPush(rogueBodies, a); b->node.idleTime = 0.0f; }
if(cpBodyIsRogue(b)){ cpArrayPush(rogueBodies, b); a->node.idleTime = 0.0f; }
componentNodeMerge(a_root, b_root);
}
开发者ID:hit1983,项目名称:cocos2d-iphone,代码行数:25,代码来源:cpSpaceComponent.c
示例3: cpSpaceActivateBody
void
cpSpaceActivateBody(cpSpace *space, cpBody *body)
{
if(space->locked){
// cpSpaceActivateBody() is called again once the space is unlocked
cpArrayPush(space->rousedBodies, body);
} else {
cpArrayPush(space->bodies, body);
for(cpShape *shape=body->shapesList; shape; shape=shape->next){
cpSpaceHashRemove(space->staticShapes, shape, shape->hashid);
cpSpaceHashInsert(space->activeShapes, shape, shape->hashid, shape->bb);
}
}
}
开发者ID:hit1983,项目名称:cocos2d-iphone,代码行数:14,代码来源:cpSpaceComponent.c
示例4: cpBodySleepWithGroup
void
cpBodySleepWithGroup(cpBody *body, cpBody *group){
cpAssert(!cpBodyIsStatic(body) && !cpBodyIsRogue(body), "Rogue and static bodies cannot be put to sleep.");
cpSpace *space = body->space;
cpAssert(space, "Cannot put a body to sleep that has not been added to a space.");
cpAssert(!space->locked, "Bodies can not be put to sleep during a query or a call to cpSpaceSte(). Put these calls into a post-step callback.");
cpAssert(!group || cpBodyIsSleeping(group), "Cannot use a non-sleeping body as a group identifier.");
if(cpBodyIsSleeping(body)) return;
for(cpShape *shape = body->shapesList; shape; shape = shape->next){
cpShapeCacheBB(shape);
cpSpaceHashRemove(space->activeShapes, shape, shape->hashid);
cpSpaceHashInsert(space->staticShapes, shape, shape->hashid, shape->bb);
}
if(group){
cpBody *root = componentNodeRoot(group);
cpComponentNode node = {root, root->node.next, 0, 0.0f};
body->node = node;
root->node.next = body;
} else {
cpComponentNode node = {NULL, body, 0, 0.0f};
body->node = node;
cpArrayPush(space->sleepingComponents, body);
}
cpArrayDeleteObj(space->bodies, body);
}
开发者ID:hit1983,项目名称:cocos2d-iphone,代码行数:32,代码来源:cpSpaceComponent.c
示例5: cpSpaceArbiterSetFilter
// Hashset filter func to throw away old arbiters.
static cpBool
cpSpaceArbiterSetFilter(cpArbiter *arb, cpSpace *space)
{
cpTimestamp ticks = space->stamp - arb->stamp;
cpBody *a = arb->body_a, *b = arb->body_b;
// TODO should make an arbiter state for this so it doesn't require filtering arbiters for dangling body pointers on body removal.
// Preserve arbiters on sensors and rejected arbiters for sleeping objects.
if(
(cpBodyIsStatic(a) || cpBodyIsSleeping(a)) &&
(cpBodyIsStatic(b) || cpBodyIsSleeping(b))
){
return cpTrue;
}
// Arbiter was used last frame, but not this one
if(ticks >= 1 && arb->state != cpArbiterStateCached){
cpArbiterCallSeparate(arb, space);
arb->state = cpArbiterStateCached;
}
if(ticks >= space->collisionPersistence){
arb->contacts = NULL;
arb->numContacts = 0;
cpArrayPush(space->pooledArbiters, arb);
return cpFalse;
}
return cpTrue;
}
开发者ID:50Cubes,项目名称:ClusterFear,代码行数:33,代码来源:cpSpaceStep.c
示例6: cpSpaceAllocContactBuffer
static cpContactBufferHeader *
cpSpaceAllocContactBuffer(cpSpace *space)
{
cpContactBuffer *buffer = (cpContactBuffer *)malloc(sizeof(cpContactBuffer));
cpArrayPush(space->allocatedBuffers, buffer);
return (cpContactBufferHeader *)buffer;
}
开发者ID:rickystone,项目名称:TwilightGolf,代码行数:7,代码来源:cpSpace.c
示例7: cachedArbitersFilter
static cpBool
cachedArbitersFilter(cpArbiter *arb, struct arbiterFilterContext *context)
{
cpShape *shape = context->shape;
cpBody *body = context->body;
// Match on the filter shape, or if it's NULL the filter body
if(
(body == arb->body_a && (shape == arb->a || shape == NULL)) ||
(body == arb->body_b && (shape == arb->b || shape == NULL))
){
// Call separate when removing shapes.
if(shape && arb->state != CP_ARBITER_STATE_CACHED){
// Invalidate the arbiter since one of the shapes was removed.
arb->state = CP_ARBITER_STATE_INVALIDATED;
cpCollisionHandler *handler = arb->handler;
handler->separateFunc(arb, context->space, handler->userData);
}
cpArbiterUnthread(arb);
cpArrayDeleteObj(context->space->arbiters, arb);
cpArrayPush(context->space->pooledArbiters, arb);
return cpFalse;
}
return cpTrue;
}
开发者ID:SanLiangSan,项目名称:DDNoOneWrong,代码行数:30,代码来源:cpSpace.c
示例8: PairFromPool
static Pair *
PairFromPool(cpBBTree *tree)
{
// Share the pool of the master tree.
// TODO would be lovely to move the pairs stuff into an external data structure.
tree = GetMasterTree(tree);
Pair *pair = tree->pooledPairs;
if(pair){
tree->pooledPairs = pair->a.next;
return pair;
} else {
// Pool is exhausted, make more
int count = CP_BUFFER_BYTES/sizeof(Pair);
cpAssertHard(count, "Internal Error: Buffer size is too small.");
Pair *buffer = (Pair *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(tree->allocatedBuffers, buffer);
// push all but the first one, return the first instead
for(int i=1; i<count; i++) PairRecycle(tree, buffer + i);
return buffer;
}
}
开发者ID:0xiaohui00,项目名称:Cocos2dx-Wechat,代码行数:25,代码来源:cpBBTree.c
示例9: contactSetTrans
// Transformation function for contactSet.
static void *
contactSetTrans(cpShape **shapes, cpSpace *space)
{
if(space->pooledArbiters->num == 0){
// arbiter pool is exhausted, make more
int count = CP_BUFFER_BYTES/sizeof(cpArbiter);
cpAssert(count, "Buffer size too small.");
cpArbiter *buffer = (cpArbiter *)cpmalloc(CP_BUFFER_BYTES);
cpArrayPush(space->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(space->pooledArbiters, buffer + i);
}
return cpArbiterInit((cpArbiter *) cpArrayPop(space->pooledArbiters), shapes[0], shapes[1]);
}
开发者ID:rickystone,项目名称:TwilightGolf,代码行数:17,代码来源:cpSpace.c
示例10: 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);
}
}
开发者ID:0x0c,项目名称:cocos2d-x,代码行数:47,代码来源:cpSpaceComponent.c
示例11: 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;
cpCollisionHandler *handler = lookupCollisionHandler(space, a->collision_type, b->collision_type);
cpBool sensor = a->sensor || b->sensor;
if(sensor && handler == &cpSpaceDefaultHandler) 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 = cpContactBufferGetArray(space);
int numContacts = cpCollideShapes(a, b, contacts);
if(!numContacts) return; // Shapes are not colliding.
cpSpacePushContacts(space, numContacts);
// 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((size_t)a, (size_t)b);
cpArbiter *arb = (cpArbiter *)cpHashSetInsert(space->contactSet, arbHashID, shape_pair, space);
cpArbiterUpdate(arb, contacts, numContacts, handler, a, b);
// Call the begin function first if it's the first step
if(arb->state == cpArbiterStateFirstColl && !handler->begin(arb, space, handler->data)){
cpArbiterIgnore(arb); // permanently ignore the collision until separation
}
if(
// Ignore the arbiter if it has been flagged
(arb->state != cpArbiterStateIgnore) &&
// Call preSolve
handler->preSolve(arb, space, handler->data) &&
// Process, but don't add collisions for sensors.
!sensor
){
cpArrayPush(space->arbiters, arb);
} else {
cpSpacePopContacts(space, numContacts);
arb->contacts = NULL;
arb->numContacts = 0;
// Normally arbiters are set as used after calling the post-step callback.
// However, post-step callbacks are not called for sensors or arbiters rejected from pre-solve.
if(arb->state != cpArbiterStateIgnore) arb->state = cpArbiterStateNormal;
}
// Time stamp the arbiter so we know it was used recently.
arb->stamp = space->stamp;
}
开发者ID:jelowang,项目名称:i51,代码行数:60,代码来源:cpSpaceStep.cpp
示例12: cpSpaceAddConstraint
cpConstraint *
cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint)
{
assert(!cpArrayContains(space->constraints, constraint));
cpArrayPush(space->constraints, constraint);
return constraint;
}
开发者ID:ShariqM,项目名称:Game,代码行数:9,代码来源:cpSpace.c
示例13: cpSpaceAddBody
cpBody *
cpSpaceAddBody(cpSpace *space, cpBody *body)
{
assert(!cpArrayContains(space->bodies, body));
cpArrayPush(space->bodies, body);
return body;
}
开发者ID:ShariqM,项目名称:Game,代码行数:9,代码来源:cpSpace.c
示例14: cpSpaceAddBody
cpBody *
cpSpaceAddBody(cpSpace *space, cpBody *body)
{
cpAssert(!cpArrayContains(space->bodies, body), "Cannot add the same body more than once.");
// cpAssertSpaceUnlocked(space); This should be safe as long as it's not from an integration callback
cpArrayPush(space->bodies, body);
return body;
}
开发者ID:krig,项目名称:cocos2d-iphone,代码行数:10,代码来源:cpSpace.c
示例15: cpSpaceAddConstraint
cpConstraint *
cpSpaceAddConstraint(cpSpace *space, cpConstraint *constraint)
{
cpAssert(!cpArrayContains(space->constraints, constraint), "Cannot add the same constraint more than once.");
// cpAssertSpaceUnlocked(space); This should be safe as long as its not from a constraint callback.
cpArrayPush(space->constraints, constraint);
return constraint;
}
开发者ID:krig,项目名称:cocos2d-iphone,代码行数:10,代码来源:cpSpace.c
示例16: handleSetTrans
static void *
handleSetTrans(void *obj, cpSpaceHash *hash)
{
if(hash->pooledHandles->num == 0){
// handle pool is exhausted, make more
int count = CP_BUFFER_BYTES/sizeof(cpHandle);
cpAssertSoft(count, "Buffer size is too small.");
cpHandle *buffer = (cpHandle *)cpcalloc(1, CP_BUFFER_BYTES);
cpArrayPush(hash->allocatedBuffers, buffer);
for(int i=0; i<count; i++) cpArrayPush(hash->pooledHandles, buffer + i);
}
cpHandle *hand = cpHandleInit((cpHandle *)cpArrayPop(hash->pooledHandles), obj);
cpHandleRetain(hand);
return hand;
}
开发者ID:EduardoFF,项目名称:argos2-RoboNetSim,代码行数:19,代码来源:cpSpaceHash.c
示例17: contactSetFilterRemovedShape
// Hashset filter func to throw away old arbiters.
static int
contactSetFilterRemovedShape(cpArbiter *arb, removalContext *context)
{
if(context->shape == arb->private_a || context->shape == arb->private_b){
arb->handler->separate(arb, context->space, arb->handler->data);
cpArrayPush(context->space->pooledArbiters, arb);
return 0;
}
return 1;
}
开发者ID:rickystone,项目名称:TwilightGolf,代码行数:12,代码来源:cpSpace.c
示例18: cpSpaceAddBody
cpBody *
cpSpaceAddBody(cpSpace *space, cpBody *body)
{
cpAssertWarn(body->m != INFINITY, "Did you really mean to add an infinite mass body to the space?");
cpAssert(!cpArrayContains(space->bodies, body), "Cannot add the same body more than once.");
// cpAssertSpaceUnlocked(space); This should be safe as long as it's not from an integration callback
cpArrayPush(space->bodies, body);
return body;
}
开发者ID:rickystone,项目名称:TwilightGolf,代码行数:11,代码来源:cpSpace.c
示例19: 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);
}
}
开发者ID:Bewolf2,项目名称:LoomSDK,代码行数:41,代码来源:cpSpaceComponent.c
示例20: cpSpaceAddBody
cpBody *
cpSpaceAddBody(cpSpace *space, cpBody *body)
{
cpAssertHard(body->space != space, "You have already added this body to this space. You must not add it a second time.");
cpAssertHard(!body->space, "You have already added this body to another space. You cannot add it to a second.");
cpAssertSpaceUnlocked(space);
cpArrayPush(cpSpaceArrayForBodyType(space, cpBodyGetType(body)), body);
body->space = space;
return body;
}
开发者ID:SanLiangSan,项目名称:DDNoOneWrong,代码行数:12,代码来源:cpSpace.c
注:本文中的cpArrayPush函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论