Mercurial > projects > chipmunkd
comparison trunk/chipmunkd/cpSpaceQuery.d @ 29:80058cee1a77
updated to chipmunk 5.3.4
author | Extrawurst |
---|---|
date | Thu, 16 Dec 2010 00:33:06 +0100 |
parents | 4ceef5833c8c |
children |
comparison
equal
deleted
inserted
replaced
28:4541ca17975b | 29:80058cee1a77 |
---|---|
27 void | 27 void |
28 cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data) | 28 cpSpacePointQuery(cpSpace *space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void *data) |
29 { | 29 { |
30 pointQueryContext context = {layers, group, func, data}; | 30 pointQueryContext context = {layers, group, func, data}; |
31 | 31 |
32 cpBool locked = space.locked; space.locked = cpTrue; { | 32 cpSpaceLock(space);{ |
33 cpSpaceHashPointQuery(space.activeShapes, point, cast(cpSpaceHashQueryFunc)&pointQueryHelper, &context); | 33 cpSpaceHashPointQuery(space.activeShapes, point, cast(cpSpaceHashQueryFunc)&pointQueryHelper, &context); |
34 cpSpaceHashPointQuery(space.staticShapes, point, cast(cpSpaceHashQueryFunc)&pointQueryHelper, &context); | 34 cpSpaceHashPointQuery(space.staticShapes, point, cast(cpSpaceHashQueryFunc)&pointQueryHelper, &context); |
35 } space.locked = locked; | 35 } cpSpaceUnlock(space); |
36 } | 36 } |
37 | 37 |
38 static void | 38 static void |
39 rememberLastPointQuery(cpShape *shape, cpShape **outShape) | 39 rememberLastPointQuery(cpShape *shape, cpShape **outShape) |
40 { | 40 { |
46 { | 46 { |
47 cpShape *shape = null; | 47 cpShape *shape = null; |
48 cpSpacePointQuery(space, point, layers, group, cast(cpSpacePointQueryFunc)&rememberLastPointQuery, &shape); | 48 cpSpacePointQuery(space, point, layers, group, cast(cpSpacePointQueryFunc)&rememberLastPointQuery, &shape); |
49 | 49 |
50 return shape; | 50 return shape; |
51 } | |
52 | |
53 void | |
54 cpSpaceEachBody(cpSpace *space, cpSpaceBodyIterator func, void *data) | |
55 { | |
56 cpArray *bodies = space.bodies; | |
57 | |
58 for(int i=0; i<bodies.num; i++) | |
59 func(cast(cpBody *)bodies.arr[i], data); | |
60 } | 51 } |
61 | 52 |
62 //#pragma mark Segment Query Functions | 53 //#pragma mark Segment Query Functions |
63 | 54 |
64 struct segQueryContext { | 55 struct segQueryContext { |
90 start, end, | 81 start, end, |
91 layers, group, | 82 layers, group, |
92 func, | 83 func, |
93 }; | 84 }; |
94 | 85 |
95 cpBool locked = space.locked; space.locked = cpTrue; { | 86 cpSpaceLock(space);{ |
96 cpSpaceHashSegmentQuery(space.staticShapes, &context, start, end, 1.0f, cast(cpSpaceHashSegmentQueryFunc)&segQueryFunc, data); | 87 cpSpaceHashSegmentQuery(space.staticShapes, &context, start, end, 1.0f, cast(cpSpaceHashSegmentQueryFunc)&segQueryFunc, data); |
97 cpSpaceHashSegmentQuery(space.activeShapes, &context, start, end, 1.0f, cast(cpSpaceHashSegmentQueryFunc)&segQueryFunc, data); | 88 cpSpaceHashSegmentQuery(space.activeShapes, &context, start, end, 1.0f, cast(cpSpaceHashSegmentQueryFunc)&segQueryFunc, data); |
98 } space.locked = locked; | 89 } cpSpaceUnlock(space); |
99 } | 90 } |
100 | 91 |
101 struct segQueryFirstContext { | 92 struct segQueryFirstContext { |
102 cpVect start, end; | 93 cpVect start, end; |
103 cpLayers layers; | 94 cpLayers layers; |
166 void | 157 void |
167 cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data) | 158 cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data) |
168 { | 159 { |
169 bbQueryContext context = {layers, group, func, data}; | 160 bbQueryContext context = {layers, group, func, data}; |
170 | 161 |
171 cpBool locked = space.locked; space.locked = cpTrue; { | 162 cpSpaceLock(space);{ |
172 cpSpaceHashQuery(space.activeShapes, &bb, bb, cast(cpSpaceHashQueryFunc)&bbQueryHelper, &context); | 163 cpSpaceHashQuery(space.activeShapes, &bb, bb, cast(cpSpaceHashQueryFunc)&bbQueryHelper, &context); |
173 cpSpaceHashQuery(space.staticShapes, &bb, bb, cast(cpSpaceHashQueryFunc)&bbQueryHelper, &context); | 164 cpSpaceHashQuery(space.staticShapes, &bb, bb, cast(cpSpaceHashQueryFunc)&bbQueryHelper, &context); |
174 } space.locked = locked; | 165 } cpSpaceUnlock(space); |
175 } | 166 } |
176 | 167 |
177 //#pragma mark Shape Query Functions | 168 //#pragma mark Shape Query Functions |
178 | 169 |
179 struct shapeQueryContext { | 170 struct shapeQueryContext { |
224 cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data) | 215 cpSpaceShapeQuery(cpSpace *space, cpShape *shape, cpSpaceShapeQueryFunc func, void *data) |
225 { | 216 { |
226 cpBB bb = cpShapeCacheBB(shape); | 217 cpBB bb = cpShapeCacheBB(shape); |
227 shapeQueryContext context = {func, data, cpFalse}; | 218 shapeQueryContext context = {func, data, cpFalse}; |
228 | 219 |
229 cpBool locked = space.locked; space.locked = cpTrue; { | 220 cpSpaceLock(space);{ |
230 cpSpaceHashQuery(space.activeShapes, shape, bb, cast(cpSpaceHashQueryFunc)&shapeQueryHelper, &context); | 221 cpSpaceHashQuery(space.activeShapes, shape, bb, cast(cpSpaceHashQueryFunc)&shapeQueryHelper, &context); |
231 cpSpaceHashQuery(space.staticShapes, shape, bb, cast(cpSpaceHashQueryFunc)&shapeQueryHelper, &context); | 222 cpSpaceHashQuery(space.staticShapes, shape, bb, cast(cpSpaceHashQueryFunc)&shapeQueryHelper, &context); |
232 } space.locked = locked; | 223 } cpSpaceUnlock(space); |
233 | 224 |
234 return context.anyCollision; | 225 return context.anyCollision; |
235 } | 226 } |