Chipmunk2D Pro API Reference  7.0.1
 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 locked;
107 
112 @property(nonatomic, assign) id userData;
113 
116 +(ChipmunkSpace *)spaceFromCPSpace:(cpSpace *)space;
117 
130 - (void)setDefaultCollisionHandler:(id)delegate
131  begin:(SEL)begin
132  preSolve:(SEL)preSolve
133  postSolve:(SEL)postSolve
134  separate:(SEL)separate;
135 
151 - (void)addCollisionHandler:(id)delegate
152  typeA:(cpCollisionType)a typeB:(cpCollisionType)b
153  begin:(SEL)begin
154  preSolve:(SEL)preSolve
155  postSolve:(SEL)postSolve
156  separate:(SEL)separate;
157 
158 
165 -(id)add:(NSObject<ChipmunkObject> *)obj;
166 
173 -(id)remove:(NSObject<ChipmunkObject> *)obj;
174 
176 -(BOOL)contains:(NSObject<ChipmunkObject> *)obj;
177 
179 - (id)smartAdd:(NSObject<ChipmunkObject> *)obj;
180 
182 - (id)smartRemove:(NSObject<ChipmunkObject> *)obj;
183 
186 - (NSArray *)addBounds:(cpBB)bounds thickness:(cpFloat)radius
187  elasticity:(cpFloat)elasticity friction:(cpFloat)friction
188  filter:(cpShapeFilter)filter collisionType:(id)collisionType;
189 
190 
211 - (BOOL)addPostStepCallback:(id)target selector:(SEL)selector key:(id)key;
212 
214 typedef void (^ChipmunkPostStepBlock)(void);
215 
217 - (BOOL)addPostStepBlock:(ChipmunkPostStepBlock)block key:(id)key;
218 
220 - (void)addPostStepAddition:(NSObject<ChipmunkObject> *)obj;
221 
223 - (void)addPostStepRemoval:(NSObject<ChipmunkObject> *)obj;
224 
227 - (NSArray *)pointQueryAll:(cpVect)point maxDistance:(cpFloat)maxDistance filter:(cpShapeFilter)filter;
228 
231 - (ChipmunkPointQueryInfo *)pointQueryNearest:(cpVect)point maxDistance:(cpFloat)maxDistance filter:(cpShapeFilter)filter;
232 
234 - (NSArray *)segmentQueryAllFrom:(cpVect)start to:(cpVect)end radius:(cpFloat)radius filter:(cpShapeFilter)filter;
235 
237 - (ChipmunkSegmentQueryInfo *)segmentQueryFirstFrom:(cpVect)start to:(cpVect)end radius:(cpFloat)radius filter:(cpShapeFilter)filter;
238 
240 - (NSArray *)bbQueryAll:(cpBB)bb filter:(cpShapeFilter)filter;
241 
243 - (NSArray *)shapeQueryAll:(ChipmunkShape *)shape;
244 
246 - (BOOL)shapeTest:(ChipmunkShape *)shape;
247 
249 - (NSArray *)bodies;
250 
252 - (NSArray *)shapes;
253 
255 - (NSArray *)constraints;
256 
258 - (void)reindexStatic;
259 
262 - (void)reindexShape:(ChipmunkShape *)shape;
263 
265 - (void)reindexShapesForBody:(ChipmunkBody *)body;
266 
268 - (void)step:(cpFloat)dt;
269 
270 @end
271 
272 
277 
282 @property(nonatomic, assign) NSUInteger threads;
283 
284 @end
285 
286 
287 //MARK: Misc
288 
300 #define CHIPMUNK_ARBITER_GET_SHAPES(__arb__, __a__, __b__) ChipmunkShape *__a__, *__b__; { \
301  cpShape *__shapeA__, *__shapeB__; \
302  cpArbiterGetShapes(__arb__, &__shapeA__, &__shapeB__); \
303  __a__ = cpShapeGetUserData(__shapeA__); __b__ = cpShapeGetUserData(__shapeB__); \
304 }
305 
306 #define CHIPMUNK_ARBITER_GET_BODIES(__arb__, __a__, __b__) ChipmunkBody *__a__, *__b__; { \
307  cpBody *__bodyA__, *__bodyB__; \
308  cpArbiterGetBodies(__arb__, &__bodyA__, &__bodyB__); \
309  __a__ = cpBodyGetUserData(__bodyA__); __b__ = cpBodyGetUserData(__bodyB__); \
310 }
311 
312