Debian Codegraph @

src/cpSpaceComponent.c

raw symbols SCIP
1 /* Copyright (c) 2007 Scott Lembcke
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 <string.h>
23
24 #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/
25
26 //MARK: Sleeping Functions
27
28 void
29 cpSpaceActivateBodycxx . . $ cpSpaceActivateBody(f865e61ac2c3a7c6).(cpSpacecxx . . $ cpSpace# *space, cpBodycxx . . $ cpBody# *body)
30 {
31 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpBodyGetType(body) == CP_BODY_TYPE_DYNAMIC, "Internal error: Attempting to activate a non-dynamic body.");
32
33 if(space->lockedcxx . . $ cpSpace#locked.){
34 // cpSpaceActivateBody() is called again once the space is unlocked
35 if(!cpArrayContainscxx . . $ cpArrayContains(a67271b2b33b9265).(space->rousedBodiescxx . . $ cpSpace#rousedBodies., body)) cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->rousedBodiescxx . . $ cpSpace#rousedBodies., body);
36 } else {
37 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(body->sleeping.root == NULL && body->sleeping.next == NULL, "Internal error: Activating body non-NULL node pointers.");
38 cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->dynamicBodiescxx . . $ cpSpace#dynamicBodies., body);
39
40 CP_BODY_FOREACH_SHAPEcxx . . $ `include/chipmunk/chipmunk_private.h:338:9`!(body, shape){
41 cpSpatialIndexRemovecxx . . $ cpSpatialIndexRemove(58272ff302488c63).(space->staticShapescxx . . $ cpSpace#staticShapes., shape, shape->hashidcxx . . $ cpShape#hashid.);
42 cpSpatialIndexInsertcxx . . $ cpSpatialIndexInsert(58272ff302488c63).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., shape, shape->hashidcxx . . $ cpShape#hashid.);
43 }
44
45 CP_BODY_FOREACH_ARBITERcxx . . $ `include/chipmunk/chipmunk_private.h:335:9`!(body, arb){
46 cpBodycxx . . $ cpBody# *bodyA = arb->body_acxx . . $ cpArbiter#body_a.;
47
48 // Arbiters are shared between two bodies that are always woken up together.
49 // You only want to restore the arbiter once, so bodyA is arbitrarily chosen to own the arbiter.
50 // The edge case is when static bodies are involved as the static bodies never actually sleep.
51 // If the static body is bodyB then all is good. If the static body is bodyA, that can easily be checked.
52 if(body == bodyA || cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(bodyA) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.){
53 int numContacts = arb->countcxx . . $ cpArbiter#count.;
54 struct cpContactcxx . . $ cpContact# *contacts = arb->contactscxx . . $ cpArbiter#contacts.;
55
56 // Restore contact values back to the space's contact buffer memory
57 arb->contactscxx . . $ cpArbiter#contacts. = cpContactBufferGetArraycxx . . $ cpContactBufferGetArray(31ea787ae2ee9686).(space);
58 memcpycxx . . $ memcpy(cc817cb175f282d).(arb->contactscxx . . $ cpArbiter#contacts., contacts, numContacts*sizeof(struct cpContactcxx . . $ cpContact#));
59 cpSpacePushContactscxx . . $ cpSpacePushContacts(3274f250b6e81e27).(space, numContacts);
60
61 // Reinsert the arbiter into the arbiter cache
62 const cpShapecxx . . $ cpShape# *a = arb->acxx . . $ cpArbiter#a., *b = arb->bcxx . . $ cpArbiter#b.;
63 const cpShapecxx . . $ cpShape# *shape_pair[] = {a, b};
64 cpHashValuecxx . . $ cpHashValue# arbHashID = CP_HASH_PAIRcxx . . $ `include/chipmunk/chipmunk_private.h:29:9`!((cpHashValue)a, (cpHashValue)b);
65 cpHashSetInsertcxx . . $ cpHashSetInsert(65a72e7022b62d4d).(space->cachedArbiterscxx . . $ cpSpace#cachedArbiters., arbHashID, shape_pair, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, arb);
66
67 // Update the arbiter's state
68 arb->stampcxx . . $ cpArbiter#stamp. = space->stampcxx . . $ cpSpace#stamp.;
69 cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->arbiterscxx . . $ cpSpace#arbiters., arb);
70
71 cpfreecxx . . $ `include/chipmunk/chipmunk.h:82:10`!(contacts);
72 }
73 }
74
75 CP_BODY_FOREACH_CONSTRAINTcxx . . $ `include/chipmunk/chipmunk_private.h:326:9`!(body, constraint){
76 cpBodycxx . . $ cpBody# *bodyA = constraint->acxx . . $ cpConstraint#a.;
77 if(body == bodyA || cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(bodyA) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.) cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->constraintscxx . . $ cpSpace#constraints., constraint);
78 }
79 }
80 }
81
82 static void
83 cpSpaceDeactivateBodycxx . . $ cpSpaceDeactivateBody(f865e61ac2c3a7c6).(cpSpacecxx . . $ cpSpace# *space, cpBodycxx . . $ cpBody# *body)
84 {
85 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpBodyGetType(body) == CP_BODY_TYPE_DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");
86
87 cpArrayDeleteObjcxx . . $ cpArrayDeleteObj(5027a0abedaf1ddc).(space->dynamicBodiescxx . . $ cpSpace#dynamicBodies., body);
88
89 CP_BODY_FOREACH_SHAPEcxx . . $ `include/chipmunk/chipmunk_private.h:338:9`!(body, shape){
90 cpSpatialIndexRemovecxx . . $ cpSpatialIndexRemove(58272ff302488c63).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., shape, shape->hashidcxx . . $ cpShape#hashid.);
91 cpSpatialIndexInsertcxx . . $ cpSpatialIndexInsert(58272ff302488c63).(space->staticShapescxx . . $ cpSpace#staticShapes., shape, shape->hashidcxx . . $ cpShape#hashid.);
92 }
93
94 CP_BODY_FOREACH_ARBITERcxx . . $ `include/chipmunk/chipmunk_private.h:335:9`!(body, arb){
95 cpBodycxx . . $ cpBody# *bodyA = arb->body_acxx . . $ cpArbiter#body_a.;
96 if(body == bodyA || cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(bodyA) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.){
97 cpSpaceUncacheArbitercxx . . $ cpSpaceUncacheArbiter(caf4010db8518d2f).(space, arb);
98
99 // Save contact values to a new block of memory so they won't time out
100 size_t bytes = arb->countcxx . . $ cpArbiter#count.*sizeof(struct cpContactcxx . . $ cpContact#);
101 struct cpContactcxx . . $ cpContact# *contacts = (struct cpContactcxx . . $ cpContact# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, bytes);
102 memcpycxx . . $ memcpy(cc817cb175f282d).(contacts, arb->contactscxx . . $ cpArbiter#contacts., bytes);
103 arb->contactscxx . . $ cpArbiter#contacts. = contacts;
104 }
105 }
106
107 CP_BODY_FOREACH_CONSTRAINTcxx . . $ `include/chipmunk/chipmunk_private.h:326:9`!(body, constraint){
108 cpBodycxx . . $ cpBody# *bodyA = constraint->acxx . . $ cpConstraint#a.;
109 if(body == bodyA || cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(bodyA) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.) cpArrayDeleteObjcxx . . $ cpArrayDeleteObj(5027a0abedaf1ddc).(space->constraintscxx . . $ cpSpace#constraints., constraint);
110 }
111 }
112
113 static inline cpBodycxx . . $ cpBody# *
114 ComponentRootcxx . . $ ComponentRoot(f0ab3fbbbc170842).(cpBodycxx . . $ cpBody# *body)
115 {
116 return (body ? body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
117 }
118
119 void
120 cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(cpBodycxx . . $ cpBody# *body)
121 {
122 if(body != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! && cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(body) == CP_BODY_TYPE_DYNAMICcxx . . $ CP_BODY_TYPE_DYNAMIC.){
123 body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = 0.0f;
124
125 cpBodycxx . . $ cpBody# *root = ComponentRootcxx . . $ ComponentRoot(f0ab3fbbbc170842).(body);
126 if(root && cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(root)){
127 // TODO should cpBodyIsSleeping(root) be an assertion?
128 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(cpBodyGetType(root) == CP_BODY_TYPE_DYNAMIC, "Internal Error: Non-dynamic body component root detected.");
129
130 cpSpacecxx . . $ cpSpace# *space = root->spacecxx . . $ cpBody#space.;
131 cpBodycxx . . $ cpBody# *body = root;
132 while(body){
133 cpBodycxx . . $ cpBody# *next = body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next.;
134
135 body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = 0.0f;
136 body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
137 body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
138 cpSpaceActivateBodycxx . . $ cpSpaceActivateBody(f865e61ac2c3a7c6).(space, body);
139
140 body = next;
141 }
142
143 cpArrayDeleteObjcxx . . $ cpArrayDeleteObj(5027a0abedaf1ddc).(space->sleepingComponentscxx . . $ cpSpace#sleepingComponents., root);
144 }
145
146 CP_BODY_FOREACH_ARBITERcxx . . $ `include/chipmunk/chipmunk_private.h:335:9`!(body, arb){
147 // Reset the idle timer of things the body is touching as well.
148 // That way things don't get left hanging in the air.
149 cpBodycxx . . $ cpBody# *other = (arb->body_acxx . . $ cpArbiter#body_a. == body ? arb->body_bcxx . . $ cpArbiter#body_b. : arb->body_acxx . . $ cpArbiter#body_a.);
150 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(other) != CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.) other->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = 0.0f;
151 }
152 }
153 }
154
155 void
156 cpBodyActivateStaticcxx . . $ cpBodyActivateStatic(84a6c2742ea0ff64).(cpBodycxx . . $ cpBody# *body, cpShapecxx . . $ cpShape# *filter)
157 {
158 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpBodyGetType(body) == CP_BODY_TYPE_STATIC, "cpBodyActivateStatic() called on a non-static body.");
159
160 CP_BODY_FOREACH_ARBITERcxx . . $ `include/chipmunk/chipmunk_private.h:335:9`!(body, arb){
161 if(!filter || filter == arb->acxx . . $ cpArbiter#a. || filter == arb->bcxx . . $ cpArbiter#b.){
162 cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(arb->body_acxx . . $ cpArbiter#body_a. == body ? arb->body_bcxx . . $ cpArbiter#body_b. : arb->body_acxx . . $ cpArbiter#body_a.);
163 }
164 }
165
166 // TODO: should also activate joints?
167 }
168
169 static inline void
170 cpBodyPushArbitercxx . . $ cpBodyPushArbiter(271675367f35a667).(cpBodycxx . . $ cpBody# *body, cpArbitercxx . . $ cpArbiter# *arb)
171 {
172 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(cpArbiterThreadForBody(arb, body)->next == NULL, "Internal Error: Dangling contact graph pointers detected. (A)");
173 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(cpArbiterThreadForBody(arb, body)->prev == NULL, "Internal Error: Dangling contact graph pointers detected. (B)");
174
175 cpArbitercxx . . $ cpArbiter# *next = body->arbiterListcxx . . $ cpBody#arbiterList.;
176 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(next == NULL || cpArbiterThreadForBody(next, body)->prev == NULL, "Internal Error: Dangling contact graph pointers detected. (C)");
177 cpArbiterThreadForBodycxx . . $ cpArbiterThreadForBody(bf0458bfbfbbd30c).(arb, body)->nextcxx . . $ cpArbiterThread#next. = next;
178
179 if(next) cpArbiterThreadForBodycxx . . $ cpArbiterThreadForBody(bf0458bfbfbbd30c).(next, body)->prevcxx . . $ cpArbiterThread#prev. = arb;
180 body->arbiterListcxx . . $ cpBody#arbiterList. = arb;
181 }
182
183 static inline void
184 ComponentAddcxx . . $ ComponentAdd(840ea4280ff4fab3).(cpBodycxx . . $ cpBody# *root, cpBodycxx . . $ cpBody# *body){
185 body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. = root;
186
187 if(body != root){
188 body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = root->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next.;
189 root->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = body;
190 }
191 }
192
193 static inline void
194 FloodFillComponentcxx . . $ FloodFillComponent(840ea4280ff4fab3).(cpBodycxx . . $ cpBody# *root, cpBodycxx . . $ cpBody# *body)
195 {
196 // Kinematic bodies cannot be put to sleep and prevent bodies they are touching from sleeping.
197 // Static bodies are effectively sleeping all the time.
198 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(body) == CP_BODY_TYPE_DYNAMICcxx . . $ CP_BODY_TYPE_DYNAMIC.){
199 cpBodycxx . . $ cpBody# *other_root = ComponentRootcxx . . $ ComponentRoot(f0ab3fbbbc170842).(body);
200 if(other_root == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!){
201 ComponentAddcxx . . $ ComponentAdd(840ea4280ff4fab3).(root, body);
202 CP_BODY_FOREACH_ARBITERcxx . . $ `include/chipmunk/chipmunk_private.h:335:9`!(body, arb) FloodFillComponentcxx . . $ FloodFillComponent(840ea4280ff4fab3).(root, (body == arb->body_acxx . . $ cpArbiter#body_a. ? arb->body_bcxx . . $ cpArbiter#body_b. : arb->body_acxx . . $ cpArbiter#body_a.));
203 CP_BODY_FOREACH_CONSTRAINTcxx . . $ `include/chipmunk/chipmunk_private.h:326:9`!(body, constraint) FloodFillComponentcxx . . $ FloodFillComponent(840ea4280ff4fab3).(root, (body == constraint->acxx . . $ cpConstraint#a. ? constraint->bcxx . . $ cpConstraint#b. : constraint->acxx . . $ cpConstraint#a.));
204 } else {
205 cpAssertSoftcxx . . $ `include/chipmunk/chipmunk.h:51:10`!(other_root == root, "Internal Error: Inconsistency dectected in the contact graph.");
206 }
207 }
208 }
209
210 static inline cpBoolcxx . . $ cpBool#
211 ComponentActivecxx . . $ ComponentActive(729ef764507ca516).(cpBodycxx . . $ cpBody# *root, cpFloatcxx . . $ cpFloat# threshold)
212 {
213 CP_BODY_FOREACH_COMPONENTcxx . . $ `include/chipmunk/chipmunk_private.h:341:9`!(root, body){
214 if(body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. < threshold) return cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!;
215 }
216
217 return cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!;
218 }
219
220 void
221 cpSpaceProcessComponentscxx . . $ cpSpaceProcessComponents(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, cpFloatcxx . . $ cpFloat# dt)
222 {
223 cpBoolcxx . . $ cpBool# sleep = (space->sleepTimeThresholdcxx . . $ cpSpace#sleepTimeThreshold. != INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!);
224 cpArraycxx . . $ cpArray# *bodies = space->dynamicBodiescxx . . $ cpSpace#dynamicBodies.;
225
226 #ifndef NDEBUGcxx . . $ `<built-in>:413:9`!
227 for(int i=0; i<bodies->num; i++){
228 cpBody *body = (cpBody*)bodies->arr[i];
229
230 cpAssertSoft(body->sleeping.next == NULL, "Internal Error: Dangling next pointer detected in contact graph.");
231 cpAssertSoft(body->sleeping.root == NULL, "Internal Error: Dangling root pointer detected in contact graph.");
232 }
233 #endif
234
235 // Calculate the kinetic energy of all the bodies.
236 if(sleep){
237 cpFloatcxx . . $ cpFloat# dv = space->idleSpeedThresholdcxx . . $ cpSpace#idleSpeedThreshold.;
238 cpFloatcxx . . $ cpFloat# dvsq = (dv ? dv*dv : cpvlengthsqcxx . . $ cpvlengthsq(c4ef53c170268e01).(space->gravitycxx . . $ cpSpace#gravity.)*dt*dt);
239
240 // update idling and reset component nodes
241 for(int i=0; i<bodies->numcxx . . $ cpArray#num.; i++){
242 cpBodycxx . . $ cpBody# *body = (cpBodycxx . . $ cpBody#*)bodies->arrcxx . . $ cpArray#arr.[i];
243
244 // TODO should make a separate array for kinematic bodies.
245 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(body) != CP_BODY_TYPE_DYNAMICcxx . . $ CP_BODY_TYPE_DYNAMIC.) continue;
246
247 // Need to deal with infinite mass objects
248 cpFloatcxx . . $ cpFloat# keThreshold = (dvsq ? body->mcxx . . $ cpBody#m.*dvsq : 0.0f);
249 body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = (cpBodyKineticEnergycxx . . $ cpBodyKineticEnergy(2880d7999e0b34c3).(body) > keThreshold ? 0.0f : body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. + dt);
250 }
251 }
252
253 // Awaken any sleeping bodies found and then push arbiters to the bodies' lists.
254 cpArraycxx . . $ cpArray# *arbiters = space->arbiterscxx . . $ cpSpace#arbiters.;
255 for(int i=0, count=arbiters->numcxx . . $ cpArray#num.; i<count; i++){
256 cpArbitercxx . . $ cpArbiter# *arb = (cpArbitercxx . . $ cpArbiter#*)arbiters->arrcxx . . $ cpArray#arr.[i];
257 cpBodycxx . . $ cpBody# *a = arb->body_acxx . . $ cpArbiter#body_a., *b = arb->body_bcxx . . $ cpArbiter#body_b.;
258
259 if(sleep){
260 // TODO checking cpBodyIsSleepin() redundant?
261 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(b) == CP_BODY_TYPE_KINEMATICcxx . . $ CP_BODY_TYPE_KINEMATIC. || cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(a)) cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(a);
262 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(a) == CP_BODY_TYPE_KINEMATICcxx . . $ CP_BODY_TYPE_KINEMATIC. || cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(b)) cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(b);
263 }
264
265 cpBodyPushArbitercxx . . $ cpBodyPushArbiter(271675367f35a667).(a, arb);
266 cpBodyPushArbitercxx . . $ cpBodyPushArbiter(271675367f35a667).(b, arb);
267 }
268
269 if(sleep){
270 // Bodies should be held active if connected by a joint to a kinematic.
271 cpArraycxx . . $ cpArray# *constraints = space->constraintscxx . . $ cpSpace#constraints.;
272 for(int i=0; i<constraints->numcxx . . $ cpArray#num.; i++){
273 cpConstraintcxx . . $ cpConstraint# *constraint = (cpConstraintcxx . . $ cpConstraint# *)constraints->arrcxx . . $ cpArray#arr.[i];
274 cpBodycxx . . $ cpBody# *a = constraint->acxx . . $ cpConstraint#a., *b = constraint->bcxx . . $ cpConstraint#b.;
275
276 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(b) == CP_BODY_TYPE_KINEMATICcxx . . $ CP_BODY_TYPE_KINEMATIC.) cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(a);
277 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(a) == CP_BODY_TYPE_KINEMATICcxx . . $ CP_BODY_TYPE_KINEMATIC.) cpBodyActivatecxx . . $ cpBodyActivate(92943d3541b63e72).(b);
278 }
279
280 // Generate components and deactivate sleeping ones
281 for(int i=0; i<bodies->numcxx . . $ cpArray#num.;){
282 cpBodycxx . . $ cpBody# *body = (cpBodycxx . . $ cpBody#*)bodies->arrcxx . . $ cpArray#arr.[i];
283
284 if(ComponentRootcxx . . $ ComponentRoot(f0ab3fbbbc170842).(body) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!){
285 // Body not in a component yet. Perform a DFS to flood fill mark
286 // the component in the contact graph using this body as the root.
287 FloodFillComponentcxx . . $ FloodFillComponent(840ea4280ff4fab3).(body, body);
288
289 // Check if the component should be put to sleep.
290 if(!ComponentActivecxx . . $ ComponentActive(729ef764507ca516).(body, space->sleepTimeThresholdcxx . . $ cpSpace#sleepTimeThreshold.)){
291 cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->sleepingComponentscxx . . $ cpSpace#sleepingComponents., body);
292 CP_BODY_FOREACH_COMPONENTcxx . . $ `include/chipmunk/chipmunk_private.h:341:9`!(body, other) cpSpaceDeactivateBodycxx . . $ cpSpaceDeactivateBody(f865e61ac2c3a7c6).(space, other);
293
294 // cpSpaceDeactivateBody() removed the current body from the list.
295 // Skip incrementing the index counter.
296 continue;
297 }
298 }
299
300 i++;
301
302 // Only sleeping bodies retain their component node pointers.
303 body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
304 body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
305 }
306 }
307 }
308
309 void
310 cpBodySleepcxx . . $ cpBodySleep(92943d3541b63e72).(cpBodycxx . . $ cpBody# *body)
311 {
312 cpBodySleepWithGroupcxx . . $ cpBodySleepWithGroup(840ea4280ff4fab3).(body, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
313 }
314
315 void
316 cpBodySleepWithGroupcxx . . $ cpBodySleepWithGroup(840ea4280ff4fab3).(cpBodycxx . . $ cpBody# *body, cpBodycxx . . $ cpBody# *group){
317 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpBodyGetType(body) == CP_BODY_TYPE_DYNAMIC, "Non-dynamic bodies cannot be put to sleep.");
318
319 cpSpacecxx . . $ cpSpace# *space = body->spacecxx . . $ cpBody#space.;
320 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(!cpSpaceIsLocked(space), "Bodies cannot be put to sleep during a query or a call to cpSpaceStep(). Put these calls into a post-step callback.");
321 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpSpaceGetSleepTimeThreshold(space) < INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!, "Sleeping is not enabled on the space. You cannot sleep a body without setting a sleep time threshold on the space.");
322 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(group == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || cpBodyIsSleeping(group), "Cannot use a non-sleeping body as a group identifier.");
323
324 if(cpBodyIsSleepingcxx . . $ cpBodyIsSleeping(25bfad07631ec420).(body)){
325 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(ComponentRoot(body) == ComponentRoot(group), "The body is already sleeping and it's group cannot be reassigned.");
326 return;
327 }
328
329 CP_BODY_FOREACH_SHAPEcxx . . $ `include/chipmunk/chipmunk_private.h:338:9`!(body, shape) cpShapeCacheBBcxx . . $ cpShapeCacheBB(e4bf0be2c162867c).(shape);
330 cpSpaceDeactivateBodycxx . . $ cpSpaceDeactivateBody(f865e61ac2c3a7c6).(space, body);
331
332 if(group){
333 cpBodycxx . . $ cpBody# *root = ComponentRootcxx . . $ ComponentRoot(f0ab3fbbbc170842).(group);
334
335 body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. = root;
336 body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = root->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next.;
337 body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = 0.0f;
338
339 root->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = body;
340 } else {
341 body->sleepingcxx . . $ cpBody#sleeping..rootcxx . . $ cpBody#$anonymous_type_0#root. = body;
342 body->sleepingcxx . . $ cpBody#sleeping..nextcxx . . $ cpBody#$anonymous_type_0#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
343 body->sleepingcxx . . $ cpBody#sleeping..idleTimecxx . . $ cpBody#$anonymous_type_0#idleTime. = 0.0f;
344
345 cpArrayPushcxx . . $ cpArrayPush(5027a0abedaf1ddc).(space->sleepingComponentscxx . . $ cpSpace#sleepingComponents., body);
346 }
347
348 cpArrayDeleteObjcxx . . $ cpArrayDeleteObj(5027a0abedaf1ddc).(space->dynamicBodiescxx . . $ cpSpace#dynamicBodies., body);
349 }