[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / objectivec / include / ObjectiveChipmunk / ChipmunkTileCache.h
1 // Copyright 2013 Howling Moon Software. All rights reserved.
2 // See http://chipmunk2d.net/legal.php for more information.
3
4 #import "ObjectiveChipmunk/ObjectiveChipmunk.h"
5 #import "ChipmunkAutoGeometry.h"
6
7
8 @class ChipmunkCachedTile;
9
10 /// A tile cache enables an efficient means of updating a large deformable terrain.
11 /// General usage would be to pass a rectangle covering the viewport to ensureRect:
12 /// and calling markDirtyRect: each time a change is made that requires an area to be resampled.
13 @interface ChipmunkAbstractTileCache : NSObject {
14 @private
15         ChipmunkAbstractSampler *_sampler;
16         ChipmunkSpace *_space;
17         
18         cpFloat _tileSize;
19         cpFloat _samplesPerTile;
20         cpVect _tileOffset;
21         
22         NSUInteger _tileCount, _cacheSize;
23         cpSpatialIndex *_tileIndex;
24         ChipmunkCachedTile *_cacheHead, *_cacheTail;
25         
26         cpBB _ensuredBB;
27         bool _ensuredDirty;
28         
29         bool _marchHard;
30 }
31
32 /// Should the marching be hard or soft?
33 /// See cpMarchHard() and cpMarchSoft() for more information.
34 @property(nonatomic, assign) bool marchHard;
35
36 /// Offset of the tile grid origin.
37 @property(nonatomic, assign) cpVect tileOffset;
38
39 /// The sampling function to use.
40 @property(nonatomic, readonly) ChipmunkAbstractSampler *sampler;
41
42 /// Create the cache from the given sampler, space to add the generated segments to,
43 /// size of the tiles, and the number of samples for each tile.
44 -(id)initWithSampler:(ChipmunkAbstractSampler *)sampler space:(ChipmunkSpace *)space tileSize:(cpFloat)tileSize samplesPerTile:(NSUInteger)samplesPerTile cacheSize:(NSUInteger)cacheSize;
45
46 /// Clear out all the cached tiles to force a full regen.
47 -(void)resetCache;
48
49 /// Mark a region as needing an update.
50 /// Geometry is not regenerated until ensureRect: is called.
51 -(void)markDirtyRect:(cpBB)bounds;
52
53 /// Ensure that the given rect has been fully generated and contains no dirty rects.
54 -(void)ensureRect:(cpBB)bounds;
55
56 /// Override this in a subclass to make custom polygon simplification behavior.
57 /// Defaults to cpPolylineSimplifyCurves(polyline, 2.0f)
58 -(cpPolyline *)simplify:(cpPolyline *)polyline;
59
60 /// Override this method to construct the segment shapes.
61 /// By default, it creates a 0 radius segment and sets 1.0 for friction and elasticity and nothing else.
62 -(ChipmunkSegmentShape *)makeSegmentFor:(ChipmunkBody *)staticBody from:(cpVect)a to:(cpVect)b;
63
64 @end
65
66
67 /// Generic tile cache. Configurable enough to be useful for most uses.
68 @interface ChipmunkBasicTileCache : ChipmunkAbstractTileCache {
69 @private
70         cpFloat _simplifyThreshold;
71         
72         cpFloat _segmentRadius;
73         
74         cpFloat _segmentFriction;
75         cpFloat _segmentElasticity;
76         
77         cpShapeFilter _segmentFilter;
78         
79         cpCollisionType _segmentCollisionType;
80 }
81
82 /// Threshold value used by cpPolylineSimplifyCurves().
83 @property(nonatomic, assign) cpFloat simplifyThreshold;
84
85 /// Radius of the generated segments.
86 @property(nonatomic, assign) cpFloat segmentRadius;
87
88 /// Friction of the generated segments.
89 @property(nonatomic, assign) cpFloat segmentFriction;
90
91 /// Elasticity of the generated segments.
92 @property(nonatomic, assign) cpFloat segmentElasticity;
93
94 /// Collision filter of the generated segments.
95 @property(nonatomic, assign) cpShapeFilter segmentFilter;
96
97 /// Collision type of the generated segments.
98 @property(nonatomic, assign) cpCollisionType segmentCollisionType;
99
100 @end