| 1 | /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | * SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/ |
| 23 | |
| 24 | //MARK: Post Step Callback Functions |
| 25 | |
| 26 | cpPostStepCallbackcxx . . $ cpPostStepCallback# * |
| 27 | cpSpaceGetPostStepCallbackcxx . . $ cpSpaceGetPostStepCallback(459e4e74dd8be64c).(cpSpacecxx . . $ cpSpace# *space, void *key) |
| 28 | { |
| 29 | cpArraycxx . . $ cpArray# *arr = space->postStepCallbackscxx . . $ cpSpace#postStepCallbacks.; |
| 30 | for(int i=0; i<arr->numcxx . . $ cpArray#num.; i++){ |
| 31 | cpPostStepCallbackcxx . . $ cpPostStepCallback# *callback = (cpPostStepCallbackcxx . . $ cpPostStepCallback# *)arr->arrcxx . . $ cpArray#arr.[i]; |
| 32 | if(callback && callback->keycxx . . $ cpPostStepCallback#key. == key) return callback; |
| 33 | } |
| 34 | |
| 35 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 36 | } |
| 37 | |
| 38 | static void PostStepDoNothingcxx . . $ PostStepDoNothing(967c2057ff39f02d).(cpSpacecxx . . $ cpSpace# *space, void *obj, void *data){} |
| 39 | |
| 40 | cpBoolcxx . . $ cpBool# |
| 41 | cpSpaceAddPostStepCallbackcxx . . $ cpSpaceAddPostStepCallback(1ff9997ad0bee464).(cpSpacecxx . . $ cpSpace# *space, cpPostStepFunccxx . . $ cpPostStepFunc# func, void *key, void *data) |
| 42 | { |
| 43 | cpAssertWarncxx . . $ `include/chipmunk/chipmunk.h:50:10`!(space->locked, |
| 44 | "Adding a post-step callback when the space is not locked is unnecessary. " |
| 45 | "Post-step callbacks will not called until the end of the next call to cpSpaceStep() or the next query."); |
| 46 | |
| 47 | if(!cpSpaceGetPostStepCallbackcxx . . $ cpSpaceGetPostStepCallback(459e4e74dd8be64c).(space, key)){ |
| 48 | cpPostStepCallbackcxx . . $ cpPostStepCallback# *callback = (cpPostStepCallbackcxx . . $ cpPostStepCallback# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpPostStepCallbackcxx . . $ cpPostStepCallback#)); |
| 49 | callback->funccxx . . $ cpPostStepCallback#func. = (func ? func : PostStepDoNothingcxx . . $ PostStepDoNothing(967c2057ff39f02d).); |
| 50 | callback->keycxx . . $ cpPostStepCallback#key. = key; |
| 51 | callback->datacxx . . $ cpPostStepCallback#data. = data; |
| 52 | |
| 53 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->postStepCallbackscxx . . $ cpSpace#postStepCallbacks., callback); |
| 54 | return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 55 | } else { |
| 56 | return cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | //MARK: Locking Functions |
| 61 | |
| 62 | void |
| 63 | cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 64 | { |
| 65 | space->lockedcxx . . $ cpSpace#locked.++; |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(cpSpacecxx . . $ cpSpace# *space, cpBoolcxx . . $ cpBool# runPostStep) |
| 70 | { |
| 71 | space->lockedcxx . . $ cpSpace#locked.--; |
| 72 | cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(space->locked >= 0, "Internal Error: Space lock underflow."); |
| 73 | |
| 74 | if(space->lockedcxx . . $ cpSpace#locked. == 0){ |
| 75 | cpArraycxx . . $ cpArray# *waking = space->rousedBodiescxx . . $ cpSpace#rousedBodies.; |
| 76 | |
| 77 | for(int i=0, count=waking->numcxx . . $ cpArray#num.; i<count; i++){ |
| 78 | cpSpaceActivateBodycxx . . $ cpSpaceActivateBody(f865e61ac2c3a7c6).(space, (cpBodycxx . . $ cpBody# *)waking->arrcxx . . $ cpArray#arr.[i]); |
| 79 | waking->arrcxx . . $ cpArray#arr.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 80 | } |
| 81 | |
| 82 | waking->numcxx . . $ cpArray#num. = 0; |
| 83 | |
| 84 | if(space->lockedcxx . . $ cpSpace#locked. == 0 && runPostStep && !space->skipPostStepcxx . . $ cpSpace#skipPostStep.){ |
| 85 | space->skipPostStepcxx . . $ cpSpace#skipPostStep. = cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 86 | |
| 87 | cpArraycxx . . $ cpArray# *arr = space->postStepCallbackscxx . . $ cpSpace#postStepCallbacks.; |
| 88 | for(int i=0; i<arr->numcxx . . $ cpArray#num.; i++){ |
| 89 | cpPostStepCallbackcxx . . $ cpPostStepCallback# *callback = (cpPostStepCallbackcxx . . $ cpPostStepCallback# *)arr->arrcxx . . $ cpArray#arr.[i]; |
| 90 | cpPostStepFunccxx . . $ cpPostStepFunc# func = callback->funccxx . . $ cpPostStepCallback#func.; |
| 91 | |
| 92 | // Mark the func as NULL in case calling it calls cpSpaceRunPostStepCallbacks() again. |
| 93 | // TODO: need more tests around this case I think. |
| 94 | callback->funccxx . . $ cpPostStepCallback#func. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 95 | if(func) func(space, callback->keycxx . . $ cpPostStepCallback#key., callback->datacxx . . $ cpPostStepCallback#data.); |
| 96 | |
| 97 | arr->arrcxx . . $ cpArray#arr.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 98 | cpfreecxx . . $ `include/chipmunk/chipmunk.h:82:10`!(callback); |
| 99 | } |
| 100 | |
| 101 | arr->numcxx . . $ cpArray#num. = 0; |
| 102 | space->skipPostStepcxx . . $ cpSpace#skipPostStep. = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | //MARK: Contact Buffer Functions |
| 108 | |
| 109 | struct cpContactBufferHeadercxx . . $ cpContactBufferHeader# { |
| 110 | cpTimestampcxx . . $ cpTimestamp# stampcxx . . $ cpContactBufferHeader#stamp.; |
| 111 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# *nextcxx . . $ cpContactBufferHeader#next.; |
| 112 | unsigned int numContactscxx . . $ cpContactBufferHeader#numContacts.; |
| 113 | }; |
| 114 | |
| 115 | #define CP_CONTACTS_BUFFER_SIZEcxx . . $ `src/cpSpaceStep.c:115:9`! ((CP_BUFFER_BYTEScxx . . $ `include/chipmunk/chipmunk.h:67:10`! - sizeof(cpContactBufferHeader))/sizeof(struct cpContact)) |
| 116 | typedef struct cpContactBuffercxx . . $ cpContactBuffer# { |
| 117 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# headercxx . . $ cpContactBuffer#header.; |
| 118 | struct cpContactcxx . . $ cpContact# contactscxx . . $ cpContactBuffer#contacts.[CP_CONTACTS_BUFFER_SIZEcxx . . $ `src/cpSpaceStep.c:115:9`!]; |
| 119 | } cpContactBuffercxx . . $ cpContactBuffer#; |
| 120 | |
| 121 | static cpContactBufferHeadercxx . . $ cpContactBufferHeader# * |
| 122 | cpSpaceAllocContactBuffercxx . . $ cpSpaceAllocContactBuffer(7115ffe1933cd87).(cpSpacecxx . . $ cpSpace# *space) |
| 123 | { |
| 124 | cpContactBuffercxx . . $ cpContactBuffer# *buffer = (cpContactBuffercxx . . $ cpContactBuffer# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpContactBuffercxx . . $ cpContactBuffer#)); |
| 125 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->allocatedBufferscxx . . $ cpSpace#allocatedBuffers., buffer); |
| 126 | return (cpContactBufferHeadercxx . . $ cpContactBufferHeader# *)buffer; |
| 127 | } |
| 128 | |
| 129 | static cpContactBufferHeadercxx . . $ cpContactBufferHeader# * |
| 130 | cpContactBufferHeaderInitcxx . . $ cpContactBufferHeaderInit(6796666264a8244a).(cpContactBufferHeadercxx . . $ cpContactBufferHeader# *header, cpTimestampcxx . . $ cpTimestamp# stamp, cpContactBufferHeadercxx . . $ cpContactBufferHeader# *splice) |
| 131 | { |
| 132 | header->stampcxx . . $ cpContactBufferHeader#stamp. = stamp; |
| 133 | header->nextcxx . . $ cpContactBufferHeader#next. = (splice ? splice->nextcxx . . $ cpContactBufferHeader#next. : header); |
| 134 | header->numContactscxx . . $ cpContactBufferHeader#numContacts. = 0; |
| 135 | |
| 136 | return header; |
| 137 | } |
| 138 | |
| 139 | void |
| 140 | cpSpacePushFreshContactBuffercxx . . $ cpSpacePushFreshContactBuffer(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 141 | { |
| 142 | cpTimestampcxx . . $ cpTimestamp# stamp = space->stampcxx . . $ cpSpace#stamp.; |
| 143 | |
| 144 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# *head = space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead.; |
| 145 | |
| 146 | if(!head){ |
| 147 | // No buffers have been allocated, make one |
| 148 | space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead. = cpContactBufferHeaderInitcxx . . $ cpContactBufferHeaderInit(6796666264a8244a).(cpSpaceAllocContactBuffercxx . . $ cpSpaceAllocContactBuffer(7115ffe1933cd87).(space), stamp, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 149 | } else if(stamp - head->nextcxx . . $ cpContactBufferHeader#next.->stampcxx . . $ cpContactBufferHeader#stamp. > space->collisionPersistencecxx . . $ cpSpace#collisionPersistence.){ |
| 150 | // The tail buffer is available, rotate the ring |
| 151 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# *tail = head->nextcxx . . $ cpContactBufferHeader#next.; |
| 152 | space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead. = cpContactBufferHeaderInitcxx . . $ cpContactBufferHeaderInit(6796666264a8244a).(tail, stamp, tail); |
| 153 | } else { |
| 154 | // Allocate a new buffer and push it into the ring |
| 155 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# *buffer = cpContactBufferHeaderInitcxx . . $ cpContactBufferHeaderInit(6796666264a8244a).(cpSpaceAllocContactBuffercxx . . $ cpSpaceAllocContactBuffer(7115ffe1933cd87).(space), stamp, head); |
| 156 | space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead. = head->nextcxx . . $ cpContactBufferHeader#next. = buffer; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 | struct cpContactcxx . . $ cpContact# * |
| 162 | cpContactBufferGetArraycxx . . $ cpContactBufferGetArray(31ea787ae2ee9686).(cpSpacecxx . . $ cpSpace# *space) |
| 163 | { |
| 164 | if(space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead.->numContactscxx . . $ cpContactBufferHeader#numContacts. + CP_MAX_CONTACTS_PER_ARBITERcxx . . $ `include/chipmunk/cpArbiter.h:32:9`! > CP_CONTACTS_BUFFER_SIZEcxx . . $ `src/cpSpaceStep.c:115:9`!){ |
| 165 | // contact buffer could overflow on the next collision, push a fresh one. |
| 166 | cpSpacePushFreshContactBuffercxx . . $ cpSpacePushFreshContactBuffer(728b9c9a69722ef8).(space); |
| 167 | } |
| 168 | |
| 169 | cpContactBufferHeadercxx . . $ cpContactBufferHeader# *head = space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead.; |
| 170 | return ((cpContactBuffercxx . . $ cpContactBuffer# *)head)->contactscxx . . $ cpContactBuffer#contacts. + head->numContactscxx . . $ cpContactBufferHeader#numContacts.; |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | cpSpacePushContactscxx . . $ cpSpacePushContacts(3274f250b6e81e27).(cpSpacecxx . . $ cpSpace# *space, int count) |
| 175 | { |
| 176 | cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(count <= CP_MAX_CONTACTS_PER_ARBITERcxx . . $ `include/chipmunk/cpArbiter.h:32:9`!, "Internal Error: Contact buffer overflow!"); |
| 177 | space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead.->numContactscxx . . $ cpContactBufferHeader#numContacts. += count; |
| 178 | } |
| 179 | |
| 180 | static void |
| 181 | cpSpacePopContactscxx . . $ cpSpacePopContacts(3274f250b6e81e27).(cpSpacecxx . . $ cpSpace# *space, int count){ |
| 182 | space->contactBuffersHeadcxx . . $ cpSpace#contactBuffersHead.->numContactscxx . . $ cpContactBufferHeader#numContacts. -= count; |
| 183 | } |
| 184 | |
| 185 | //MARK: Collision Detection Functions |
| 186 | |
| 187 | static void * |
| 188 | cpSpaceArbiterSetTranscxx . . $ cpSpaceArbiterSetTrans(6d7f3d5ec733f75c).(cpShapecxx . . $ cpShape# **shapes, cpSpacecxx . . $ cpSpace# *space) |
| 189 | { |
| 190 | if(space->pooledArbiterscxx . . $ cpSpace#pooledArbiters.->numcxx . . $ cpArray#num. == 0){ |
| 191 | // arbiter pool is exhausted, make more |
| 192 | int count = CP_BUFFER_BYTEScxx . . $ `include/chipmunk/chipmunk.h:67:10`!/sizeof(cpArbitercxx . . $ cpArbiter#); |
| 193 | cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(count, "Internal Error: Buffer size too small."); |
| 194 | |
| 195 | cpArbitercxx . . $ cpArbiter# *buffer = (cpArbitercxx . . $ cpArbiter# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, CP_BUFFER_BYTEScxx . . $ `include/chipmunk/chipmunk.h:67:10`!); |
| 196 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->allocatedBufferscxx . . $ cpSpace#allocatedBuffers., buffer); |
| 197 | |
| 198 | for(int i=0; i<count; i++) cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->pooledArbiterscxx . . $ cpSpace#pooledArbiters., buffer + i); |
| 199 | } |
| 200 | |
| 201 | return cpArbiterInitcxx . . $ cpArbiterInit(6f80f7667a17179d).((cpArbitercxx . . $ cpArbiter# *)cpArrayPopcxx . . $ cpArrayPop(deec8af08e758c71).(space->pooledArbiterscxx . . $ cpSpace#pooledArbiters.), shapes[0], shapes[1]); |
| 202 | } |
| 203 | |
| 204 | static inline cpBoolcxx . . $ cpBool# |
| 205 | QueryRejectConstraintcxx . . $ QueryRejectConstraint(515a1ef1431aeb8).(cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b) |
| 206 | { |
| 207 | CP_BODY_FOREACH_CONSTRAINTcxx . . $ `include/chipmunk/chipmunk_private.h:326:9`!(a, constraint){ |
| 208 | if( |
| 209 | !constraint->collideBodiescxx . . $ cpConstraint#collideBodies. && ( |
| 210 | (constraint->acxx . . $ cpConstraint#a. == a && constraint->bcxx . . $ cpConstraint#b. == b) || |
| 211 | (constraint->acxx . . $ cpConstraint#a. == b && constraint->bcxx . . $ cpConstraint#b. == a) |
| 212 | ) |
| 213 | ) return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 214 | } |
| 215 | |
| 216 | return cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 217 | } |
| 218 | |
| 219 | static inline cpBoolcxx . . $ cpBool# |
| 220 | QueryRejectcxx . . $ QueryReject(e3b6693df577fc8e).(cpShapecxx . . $ cpShape# *a, cpShapecxx . . $ cpShape# *b) |
| 221 | { |
| 222 | return ( |
| 223 | // BBoxes must overlap |
| 224 | !cpBBIntersectscxx . . $ cpBBIntersects(aa08641fa2db23dc).(a->bbcxx . . $ cpShape#bb., b->bbcxx . . $ cpShape#bb.) |
| 225 | // Don't collide shapes attached to the same body. |
| 226 | || a->bodycxx . . $ cpShape#body. == b->bodycxx . . $ cpShape#body. |
| 227 | // Don't collide shapes that are filtered. |
| 228 | || cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(a->filtercxx . . $ cpShape#filter., b->filtercxx . . $ cpShape#filter.) |
| 229 | // Don't collide bodies if they have a constraint with collideBodies == cpFalse. |
| 230 | || QueryRejectConstraintcxx . . $ QueryRejectConstraint(515a1ef1431aeb8).(a->bodycxx . . $ cpShape#body., b->bodycxx . . $ cpShape#body.) |
| 231 | ); |
| 232 | } |
| 233 | |
| 234 | // Callback from the spatial hash. |
| 235 | cpCollisionIDcxx . . $ cpCollisionID# |
| 236 | cpSpaceCollideShapescxx . . $ cpSpaceCollideShapes(2fb593a639e5759d).(cpShapecxx . . $ cpShape# *a, cpShapecxx . . $ cpShape# *b, cpCollisionIDcxx . . $ cpCollisionID# id, cpSpacecxx . . $ cpSpace# *space) |
| 237 | { |
| 238 | // Reject any of the simple cases |
| 239 | if(QueryRejectcxx . . $ QueryReject(e3b6693df577fc8e).(a,b)) return id; |
| 240 | |
| 241 | // Narrow-phase collision detection. |
| 242 | struct cpCollisionInfocxx . . $ cpCollisionInfo# info = cpCollidecxx . . $ cpCollide(f8bb8df86a1fa46f).(a, b, id, cpContactBufferGetArraycxx . . $ cpContactBufferGetArray(31ea787ae2ee9686).(space)); |
| 243 | |
| 244 | if(info.countcxx . . $ cpCollisionInfo#count. == 0) return info.idcxx . . $ cpCollisionInfo#id.; // Shapes are not colliding. |
| 245 | cpSpacePushContactscxx . . $ cpSpacePushContacts(3274f250b6e81e27).(space, info.countcxx . . $ cpCollisionInfo#count.); |
| 246 | |
| 247 | // Get an arbiter from space->arbiterSet for the two shapes. |
| 248 | // This is where the persistant contact magic comes from. |
| 249 | const cpShapecxx . . $ cpShape# *shape_pair[] = {info.acxx . . $ cpCollisionInfo#a., info.bcxx . . $ cpCollisionInfo#b.}; |
| 250 | cpHashValuecxx . . $ cpHashValue# arbHashID = CP_HASH_PAIRcxx . . $ `include/chipmunk/chipmunk_private.h:29:9`!((cpHashValue)info.a, (cpHashValue)info.b); |
| 251 | cpArbitercxx . . $ cpArbiter# *arb = (cpArbitercxx . . $ cpArbiter# *)cpHashSetInsertcxx . . $ cpHashSetInsert(65a72e7022b62d4d).(space->cachedArbiterscxx . . $ cpSpace#cachedArbiters., arbHashID, shape_pair, (cpHashSetTransFunccxx . . $ cpHashSetTransFunc#)cpSpaceArbiterSetTranscxx . . $ cpSpaceArbiterSetTrans(6d7f3d5ec733f75c)., space); |
| 252 | cpArbiterUpdatecxx . . $ cpArbiterUpdate(f9c6830ff1eaf914).(arb, &info, space); |
| 253 | |
| 254 | cpCollisionHandlercxx . . $ cpCollisionHandler# *handler = arb->handlercxx . . $ cpArbiter#handler.; |
| 255 | |
| 256 | // Call the begin function first if it's the first step |
| 257 | if(arb->statecxx . . $ cpArbiter#state. == CP_ARBITER_STATE_FIRST_COLLISIONcxx . . $ CP_ARBITER_STATE_FIRST_COLLISION. && !handler->beginFunccxx . . $ cpCollisionHandler#beginFunc.(arb, space, handler->userDatacxx . . $ cpCollisionHandler#userData.)){ |
| 258 | cpArbiterIgnorecxx . . $ cpArbiterIgnore(8db1597ce3e43121).(arb); // permanently ignore the collision until separation |
| 259 | } |
| 260 | |
| 261 | if( |
| 262 | // Ignore the arbiter if it has been flagged |
| 263 | (arb->statecxx . . $ cpArbiter#state. != CP_ARBITER_STATE_IGNOREcxx . . $ CP_ARBITER_STATE_IGNORE.) && |
| 264 | // Call preSolve |
| 265 | handler->preSolveFunccxx . . $ cpCollisionHandler#preSolveFunc.(arb, space, handler->userDatacxx . . $ cpCollisionHandler#userData.) && |
| 266 | // Check (again) in case the pre-solve() callback called cpArbiterIgnored(). |
| 267 | arb->statecxx . . $ cpArbiter#state. != CP_ARBITER_STATE_IGNOREcxx . . $ CP_ARBITER_STATE_IGNORE. && |
| 268 | // Process, but don't add collisions for sensors. |
| 269 | !(a->sensorcxx . . $ cpShape#sensor. || b->sensorcxx . . $ cpShape#sensor.) && |
| 270 | // Don't process collisions between two infinite mass bodies. |
| 271 | // This includes collisions between two kinematic bodies, or a kinematic body and a static body. |
| 272 | !(a->bodycxx . . $ cpShape#body.->mcxx . . $ cpBody#m. == INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`! && b->bodycxx . . $ cpShape#body.->mcxx . . $ cpBody#m. == INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!) |
| 273 | ){ |
| 274 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->arbiterscxx . . $ cpSpace#arbiters., arb); |
| 275 | } else { |
| 276 | cpSpacePopContactscxx . . $ cpSpacePopContacts(3274f250b6e81e27).(space, info.countcxx . . $ cpCollisionInfo#count.); |
| 277 | |
| 278 | arb->contactscxx . . $ cpArbiter#contacts. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 279 | arb->countcxx . . $ cpArbiter#count. = 0; |
| 280 | |
| 281 | // Normally arbiters are set as used after calling the post-solve callback. |
| 282 | // However, post-solve() callbacks are not called for sensors or arbiters rejected from pre-solve. |
| 283 | if(arb->statecxx . . $ cpArbiter#state. != CP_ARBITER_STATE_IGNOREcxx . . $ CP_ARBITER_STATE_IGNORE.) arb->statecxx . . $ cpArbiter#state. = CP_ARBITER_STATE_NORMALcxx . . $ CP_ARBITER_STATE_NORMAL.; |
| 284 | } |
| 285 | |
| 286 | // Time stamp the arbiter so we know it was used recently. |
| 287 | arb->stampcxx . . $ cpArbiter#stamp. = space->stampcxx . . $ cpSpace#stamp.; |
| 288 | return info.idcxx . . $ cpCollisionInfo#id.; |
| 289 | } |
| 290 | |
| 291 | // Hashset filter func to throw away old arbiters. |
| 292 | cpBoolcxx . . $ cpBool# |
| 293 | cpSpaceArbiterSetFiltercxx . . $ cpSpaceArbiterSetFilter(e9b4df504d3a695b).(cpArbitercxx . . $ cpArbiter# *arb, cpSpacecxx . . $ cpSpace# *space) |
| 294 | { |
| 295 | cpTimestampcxx . . $ cpTimestamp# ticks = space->stampcxx . . $ cpSpace#stamp. - arb->stampcxx . . $ cpArbiter#stamp.; |
| 296 | |
| 297 | cpBodycxx . . $ cpBody# *a = arb->body_acxx . . $ cpArbiter#body_a., *b = arb->body_bcxx . . $ cpArbiter#body_b.; |
| 298 | |
| 299 | // TODO: should make an arbiter state for this so it doesn't require filtering arbiters for dangling body pointers on body removal. |
| 300 | // Preserve arbiters on sensors and rejected arbiters for sleeping objects. |
| 301 | // This prevents errant separate callbacks from happenening. |
| 302 | if( |
| 303 | (cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(a) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC. || cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(a)) && |
| 304 | (cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(b) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC. || cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(b)) |
| 305 | ){ |
| 306 | return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 307 | } |
| 308 | |
| 309 | // Arbiter was used last frame, but not this one |
| 310 | if(ticks >= 1 && arb->statecxx . . $ cpArbiter#state. != CP_ARBITER_STATE_CACHEDcxx . . $ CP_ARBITER_STATE_CACHED.){ |
| 311 | arb->statecxx . . $ cpArbiter#state. = CP_ARBITER_STATE_CACHEDcxx . . $ CP_ARBITER_STATE_CACHED.; |
| 312 | cpCollisionHandlercxx . . $ cpCollisionHandler# *handler = arb->handlercxx . . $ cpArbiter#handler.; |
| 313 | handler->separateFunccxx . . $ cpCollisionHandler#separateFunc.(arb, space, handler->userDatacxx . . $ cpCollisionHandler#userData.); |
| 314 | } |
| 315 | |
| 316 | if(ticks >= space->collisionPersistencecxx . . $ cpSpace#collisionPersistence.){ |
| 317 | arb->contactscxx . . $ cpArbiter#contacts. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 318 | arb->countcxx . . $ cpArbiter#count. = 0; |
| 319 | |
| 320 | cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->pooledArbiterscxx . . $ cpSpace#pooledArbiters., arb); |
| 321 | return cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!; |
| 322 | } |
| 323 | |
| 324 | return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!; |
| 325 | } |
| 326 | |
| 327 | //MARK: All Important cpSpaceStep() Function |
| 328 | |
| 329 | void |
| 330 | cpShapeUpdateFunccxx . . $ cpShapeUpdateFunc(ebab24832b4ea92d).(cpShapecxx . . $ cpShape# *shape, void *unused) |
| 331 | { |
| 332 | cpShapeCacheBBcxx . . $ cpShapeCacheBB(e4bf0be2c162867c).(shape); |
| 333 | } |
| 334 | |
| 335 | void |
| 336 | cpSpaceStepcxx . . $ cpSpaceStep(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, cpFloatcxx . . $ cpFloat# dt) |
| 337 | { |
| 338 | // don't step if the timestep is 0! |
| 339 | if(dt == 0.0f) return; |
| 340 | |
| 341 | space->stampcxx . . $ cpSpace#stamp.++; |
| 342 | |
| 343 | cpFloatcxx . . $ cpFloat# prev_dt = space->curr_dtcxx . . $ cpSpace#curr_dt.; |
| 344 | space->curr_dtcxx . . $ cpSpace#curr_dt. = dt; |
| 345 | |
| 346 | cpArraycxx . . $ cpArray# *bodies = space->dynamicBodiescxx . . $ cpSpace#dynamicBodies.; |
| 347 | cpArraycxx . . $ cpArray# *constraints = space->constraintscxx . . $ cpSpace#constraints.; |
| 348 | cpArraycxx . . $ cpArray# *arbiters = space->arbiterscxx . . $ cpSpace#arbiters.; |
| 349 | |
| 350 | // Reset and empty the arbiter lists. |
| 351 | for(int i=0; i<arbiters->numcxx . . $ cpArray#num.; i++){ |
| 352 | cpArbitercxx . . $ cpArbiter# *arb = (cpArbitercxx . . $ cpArbiter# *)arbiters->arrcxx . . $ cpArray#arr.[i]; |
| 353 | arb->statecxx . . $ cpArbiter#state. = CP_ARBITER_STATE_NORMALcxx . . $ CP_ARBITER_STATE_NORMAL.; |
| 354 | |
| 355 | // If both bodies are awake, unthread the arbiter from the contact graph. |
| 356 | if(!cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(arb->body_acxx . . $ cpArbiter#body_a.) && !cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(arb->body_bcxx . . $ cpArbiter#body_b.)){ |
| 357 | cpArbiterUnthreadcxx . . $ cpArbiterUnthread(9130529b054e83ea).(arb); |
| 358 | } |
| 359 | } |
| 360 | arbiters->numcxx . . $ cpArray#num. = 0; |
| 361 | |
| 362 | cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); { |
| 363 | // Integrate positions |
| 364 | for(int i=0; i<bodies->numcxx . . $ cpArray#num.; i++){ |
| 365 | cpBodycxx . . $ cpBody# *body = (cpBodycxx . . $ cpBody# *)bodies->arrcxx . . $ cpArray#arr.[i]; |
| 366 | body->position_funccxx . . $ cpBody#position_func.(body, dt); |
| 367 | } |
| 368 | |
| 369 | // Find colliding pairs. |
| 370 | cpSpacePushFreshContactBuffercxx . . $ cpSpacePushFreshContactBuffer(728b9c9a69722ef8).(space); |
| 371 | cpSpatialIndexEachcxx . . $ cpSpatialIndexEach(63a26082660cb28c).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., (cpSpatialIndexIteratorFunccxx . . $ cpSpatialIndexIteratorFunc#)cpShapeUpdateFunccxx . . $ cpShapeUpdateFunc(ebab24832b4ea92d)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 372 | cpSpatialIndexReindexQuerycxx . . $ cpSpatialIndexReindexQuery(3ad3419756960b2c).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)cpSpaceCollideShapescxx . . $ cpSpaceCollideShapes(2fb593a639e5759d)., space); |
| 373 | } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!); |
| 374 | |
| 375 | // Rebuild the contact graph (and detect sleeping components if sleeping is enabled) |
| 376 | cpSpaceProcessComponentscxx . . $ cpSpaceProcessComponents(fa66a0a48611083e).(space, dt); |
| 377 | |
| 378 | cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); { |
| 379 | // Clear out old cached arbiters and call separate callbacks |
| 380 | cpHashSetFiltercxx . . $ cpHashSetFilter(ded8e246e9dd8428).(space->cachedArbiterscxx . . $ cpSpace#cachedArbiters., (cpHashSetFilterFunccxx . . $ cpHashSetFilterFunc#)cpSpaceArbiterSetFiltercxx . . $ cpSpaceArbiterSetFilter(e9b4df504d3a695b)., space); |
| 381 | |
| 382 | // Prestep the arbiters and constraints. |
| 383 | cpFloatcxx . . $ cpFloat# slop = space->collisionSlopcxx . . $ cpSpace#collisionSlop.; |
| 384 | cpFloatcxx . . $ cpFloat# biasCoef = 1.0f - cpfpowcxx . . $ `include/chipmunk/chipmunk_types.h:75:10`!(space->collisionBiascxx . . $ cpSpace#collisionBias., dt); |
| 385 | for(int i=0; i<arbiters->numcxx . . $ cpArray#num.; i++){ |
| 386 | cpArbiterPreStepcxx . . $ cpArbiterPreStep(53bd72b40478409e).((cpArbitercxx . . $ cpArbiter# *)arbiters->arrcxx . . $ cpArray#arr.[i], dt, slop, biasCoef); |
| 387 | } |
| 388 | |
| 389 | for(int i=0; i<constraints->numcxx . . $ cpArray#num.; i++){ |
| 390 | cpConstraintcxx . . $ cpConstraint# *constraint = (cpConstraintcxx . . $ cpConstraint# *)constraints->arrcxx . . $ cpArray#arr.[i]; |
| 391 | |
| 392 | cpConstraintPreSolveFunccxx . . $ cpConstraintPreSolveFunc# preSolve = constraint->preSolvecxx . . $ cpConstraint#preSolve.; |
| 393 | if(preSolve) preSolve(constraint, space); |
| 394 | |
| 395 | constraint->klasscxx . . $ cpConstraint#klass.->preStepcxx . . $ cpConstraintClass#preStep.(constraint, dt); |
| 396 | } |
| 397 | |
| 398 | // Integrate velocities. |
| 399 | cpFloatcxx . . $ cpFloat# damping = cpfpowcxx . . $ `include/chipmunk/chipmunk_types.h:75:10`!(space->dampingcxx . . $ cpSpace#damping., dt); |
| 400 | cpVectcxx . . $ cpVect# gravity = space->gravitycxx . . $ cpSpace#gravity.; |
| 401 | for(int i=0; i<bodies->numcxx . . $ cpArray#num.; i++){ |
| 402 | cpBodycxx . . $ cpBody# *body = (cpBodycxx . . $ cpBody# *)bodies->arrcxx . . $ cpArray#arr.[i]; |
| 403 | body->velocity_funccxx . . $ cpBody#velocity_func.(body, gravity, damping, dt); |
| 404 | } |
| 405 | |
| 406 | // Apply cached impulses |
| 407 | cpFloatcxx . . $ cpFloat# dt_coef = (prev_dt == 0.0f ? 0.0f : dt/prev_dt); |
| 408 | for(int i=0; i<arbiters->numcxx . . $ cpArray#num.; i++){ |
| 409 | cpArbiterApplyCachedImpulsecxx . . $ cpArbiterApplyCachedImpulse(9e1a510df1a8740d).((cpArbitercxx . . $ cpArbiter# *)arbiters->arrcxx . . $ cpArray#arr.[i], dt_coef); |
| 410 | } |
| 411 | |
| 412 | for(int i=0; i<constraints->numcxx . . $ cpArray#num.; i++){ |
| 413 | cpConstraintcxx . . $ cpConstraint# *constraint = (cpConstraintcxx . . $ cpConstraint# *)constraints->arrcxx . . $ cpArray#arr.[i]; |
| 414 | constraint->klasscxx . . $ cpConstraint#klass.->applyCachedImpulsecxx . . $ cpConstraintClass#applyCachedImpulse.(constraint, dt_coef); |
| 415 | } |
| 416 | |
| 417 | // Run the impulse solver. |
| 418 | for(int i=0; i<space->iterationscxx . . $ cpSpace#iterations.; i++){ |
| 419 | for(int j=0; j<arbiters->numcxx . . $ cpArray#num.; j++){ |
| 420 | cpArbiterApplyImpulsecxx . . $ cpArbiterApplyImpulse(9130529b054e83ea).((cpArbitercxx . . $ cpArbiter# *)arbiters->arrcxx . . $ cpArray#arr.[j]); |
| 421 | } |
| 422 | |
| 423 | for(int j=0; j<constraints->numcxx . . $ cpArray#num.; j++){ |
| 424 | cpConstraintcxx . . $ cpConstraint# *constraint = (cpConstraintcxx . . $ cpConstraint# *)constraints->arrcxx . . $ cpArray#arr.[j]; |
| 425 | constraint->klasscxx . . $ cpConstraint#klass.->applyImpulsecxx . . $ cpConstraintClass#applyImpulse.(constraint, dt); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | // Run the constraint post-solve callbacks |
| 430 | for(int i=0; i<constraints->numcxx . . $ cpArray#num.; i++){ |
| 431 | cpConstraintcxx . . $ cpConstraint# *constraint = (cpConstraintcxx . . $ cpConstraint# *)constraints->arrcxx . . $ cpArray#arr.[i]; |
| 432 | |
| 433 | cpConstraintPostSolveFunccxx . . $ cpConstraintPostSolveFunc# postSolve = constraint->postSolvecxx . . $ cpConstraint#postSolve.; |
| 434 | if(postSolve) postSolve(constraint, space); |
| 435 | } |
| 436 | |
| 437 | // run the post-solve callbacks |
| 438 | for(int i=0; i<arbiters->numcxx . . $ cpArray#num.; i++){ |
| 439 | cpArbitercxx . . $ cpArbiter# *arb = (cpArbitercxx . . $ cpArbiter# *) arbiters->arrcxx . . $ cpArray#arr.[i]; |
| 440 | |
| 441 | cpCollisionHandlercxx . . $ cpCollisionHandler# *handler = arb->handlercxx . . $ cpArbiter#handler.; |
| 442 | handler->postSolveFunccxx . . $ cpCollisionHandler#postSolveFunc.(arb, space, handler->userDatacxx . . $ cpCollisionHandler#userData.); |
| 443 | } |
| 444 | } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!); |
| 445 | } |