Chipmunk2D Pro API Reference  7.0.0
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 
cpFloat collisionSlop
Amount of encouraged penetration between colliding shapes.
Definition: ChipmunkSpace.h:74
Definition: chipmunk_private.h:641
Fast collision filtering type that is used to determine if two objects collide before calling collisi...
Definition: cpShape.h:52
cpFloat idleSpeedThreshold
If a body is moving slower than this speed, it is considered idle. The default value is 0...
Definition: ChipmunkSpace.h:60
Allows you to add composite objects to a space in a single method call.
Definition: ObjectiveChipmunk.h:46
BOOL locked
Returns true if the space is currently executing a timestep.
Definition: ChipmunkSpace.h:106
Rigid bodies are the basic unit of simulation in Chipmunk.
Definition: ChipmunkBody.h:29
uintptr_t cpCollisionType
Type used for cpSpace.collision_type.
Definition: chipmunk_types.h:223
unsigned int cpTimestamp
Type used for various timestamps in Chipmunk.
Definition: chipmunk_types.h:244
double cpFloat
Chipmunk&#39;s floating point type.
Definition: chipmunk_types.h:83
Chipmunk spaces are simulation containers.
Definition: ChipmunkSpace.h:32
void reindexStatic()
Update all the static shapes.
Definition: chipmunk_types.h:271
cpFloat collisionBias
Determines how fast overlapping shapes are pushed apart.
Definition: ChipmunkSpace.h:81
Abstract base class for collsion shape types.
Definition: ChipmunkShape.h:27
int iterations
The iteration count is how many solver passes the space should use when solving collisions and joints...
Definition: ChipmunkSpace.h:47
ChipmunkHastySpace is an Objective-Chipmunk wrapper for cpHastySpace.
Definition: ChipmunkSpace.h:276
Definition: ChipmunkShape.h:96
cpSpace * space
Returns a pointer to the underlying cpSpace C struct.
Definition: ChipmunkSpace.h:90
Holds collision information from segment queries. You should never need to create one...
Definition: ChipmunkShape.h:124
cpTimestamp collisionPersistence
Number of frames that contact information should persist.
Definition: ChipmunkSpace.h:87
Chipmunk&#39;s axis-aligned 2D bounding box type. (left, bottom, right, top)
Definition: cpBB.h:33
cpFloat currentTimeStep
Retrieves the current (if you are in a callback from [ChipmunkSpace step:]) or most recent (outside o...
Definition: ChipmunkSpace.h:101
NSArray * shapes()
Get a copy of the list of all the shapes in the space.
cpFloat sleepTimeThreshold
Elapsed time before a group of idle bodies is put to sleep (defaults to infinity which disables sleep...
Definition: ChipmunkSpace.h:66
void(^ ChipmunkPostStepBlock)(void)
Block type used with [ChipmunkSpace addPostStepBlock:].
Definition: ChipmunkSpace.h:214
ChipmunkBody * staticBody
The space&#39;s designated static body.
Definition: ChipmunkSpace.h:96
NSArray * constraints()
Get a copy of the list of all the constraints in the space.
NSArray * bodies()
Get a copy of the list of all the bodies in the space.
cpFloat damping
Global viscous damping value to use for all rigid bodies in this space (default value is 1...
Definition: ChipmunkSpace.h:57
id userData
An object that this space is associated with.
Definition: ChipmunkSpace.h:112
cpVect gravity
Global gravity value to use for all rigid bodies in this space (default value is cpvzero).
Definition: ChipmunkSpace.h:50