Chipmunk2D Pro API Reference  7.0.3
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
ChipmunkSpace.h
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 
24 #define CHIPMUNK_SPACE_USE_HASTY_SPACE 1
25 
26 
32 @interface ChipmunkSpace : NSObject {
33 @protected
34  struct cpSpace *_space;
35  ChipmunkBody *_staticBody;
36 
37  NSMutableSet *_children;
38  NSMutableArray *_handlers;
39 
40  id _userData;
41 }
42 
47 @property(nonatomic, assign) int iterations;
48 
50 @property(nonatomic, assign) cpVect gravity;
51 
57 @property(nonatomic, assign) cpFloat damping;
58 
60 @property(nonatomic, assign) cpFloat idleSpeedThreshold;
61 
66 @property(nonatomic, assign) cpFloat sleepTimeThreshold;
67 
74 @property(nonatomic, assign) cpFloat collisionSlop;
75 
81 @property(nonatomic, assign) cpFloat collisionBias;
82 
87 @property(nonatomic, assign) cpTimestamp collisionPersistence;
88 
90 @property(nonatomic, readonly) cpSpace *space;
91 
96 @property(nonatomic, readonly) ChipmunkBody *staticBody;
97 
101 @property(nonatomic, readonly) cpFloat currentTimeStep;
102 
106 @property(nonatomic, readonly) BOOL isLocked;
107 @property(nonatomic, readonly) BOOL locked __deprecated;
108 
113 @property(nonatomic, assign) id userData;
114 
117 +(ChipmunkSpace *)spaceFromCPSpace:(cpSpace *)space;
118 
131 - (void)setDefaultCollisionHandler:(id)delegate
132  begin:(SEL)begin
133  preSolve:(SEL)preSolve
134  postSolve:(SEL)postSolve
135  separate:(SEL)separate;
136 
152 - (void)addCollisionHandler:(id)delegate
153  typeA:(cpCollisionType)a typeB:(cpCollisionType)b
154  begin:(SEL)begin
155  preSolve:(SEL)preSolve
156  postSolve:(SEL)postSolve
157  separate:(SEL)separate;
158 
159 
166 -(id)add:(NSObject<ChipmunkObject> *)obj;
167 
174 -(id)remove:(NSObject<ChipmunkObject> *)obj;
175 
177 -(BOOL)contains:(NSObject<ChipmunkObject> *)obj;
178 
180 - (id)smartAdd:(NSObject<ChipmunkObject> *)obj;
181 
183 - (id)smartRemove:(NSObject<ChipmunkObject> *)obj;
184 
187 - (NSArray *)addBounds:(cpBB)bounds thickness:(cpFloat)radius
188  elasticity:(cpFloat)elasticity friction:(cpFloat)friction
189  filter:(cpShapeFilter)filter collisionType:(id)collisionType;
190 
191 
212 - (BOOL)addPostStepCallback:(id)target selector:(SEL)selector key:(id)key;
213 
215 typedef void (^ChipmunkPostStepBlock)(void);
216 
218 - (BOOL)addPostStepBlock:(ChipmunkPostStepBlock)block key:(id)key;
219 
221 - (void)addPostStepAddition:(NSObject<ChipmunkObject> *)obj;
222 
224 - (void)addPostStepRemoval:(NSObject<ChipmunkObject> *)obj;
225 
228 - (NSArray *)pointQueryAll:(cpVect)point maxDistance:(cpFloat)maxDistance filter:(cpShapeFilter)filter;
229 
232 - (ChipmunkPointQueryInfo *)pointQueryNearest:(cpVect)point maxDistance:(cpFloat)maxDistance filter:(cpShapeFilter)filter;
233 
235 - (NSArray *)segmentQueryAllFrom:(cpVect)start to:(cpVect)end radius:(cpFloat)radius filter:(cpShapeFilter)filter;
236 
238 - (ChipmunkSegmentQueryInfo *)segmentQueryFirstFrom:(cpVect)start to:(cpVect)end radius:(cpFloat)radius filter:(cpShapeFilter)filter;
239 
241 - (NSArray *)bbQueryAll:(cpBB)bb filter:(cpShapeFilter)filter;
242 
244 - (NSArray *)shapeQueryAll:(ChipmunkShape *)shape;
245 
247 - (BOOL)shapeTest:(ChipmunkShape *)shape;
248 
250 - (NSArray *)bodies;
251 
253 - (NSArray *)shapes;
254 
256 - (NSArray *)constraints;
257 
259 - (void)reindexStatic;
260 
263 - (void)reindexShape:(ChipmunkShape *)shape;
264 
266 - (void)reindexShapesForBody:(ChipmunkBody *)body;
267 
269 - (void)step:(cpFloat)dt;
270 
271 @end
272 
273 
278 
283 @property(nonatomic, assign) NSUInteger threads;
284 
285 @end
286 
287 
288 //MARK: Misc
289 
301 #define CHIPMUNK_ARBITER_GET_SHAPES(__arb__, __a__, __b__) ChipmunkShape *__a__, *__b__; { \
302  cpShape *__shapeA__, *__shapeB__; \
303  cpArbiterGetShapes(__arb__, &__shapeA__, &__shapeB__); \
304  __a__ = cpShapeGetUserData(__shapeA__); __b__ = cpShapeGetUserData(__shapeB__); \
305 }
306 
307 #define CHIPMUNK_ARBITER_GET_BODIES(__arb__, __a__, __b__) ChipmunkBody *__a__, *__b__; { \
308  cpBody *__bodyA__, *__bodyB__; \
309  cpArbiterGetBodies(__arb__, &__bodyA__, &__bodyB__); \
310  __a__ = cpBodyGetUserData(__bodyA__); __b__ = cpBodyGetUserData(__bodyB__); \
311 }
312 
313