packages feed

Hipmunk 5.1.0 → 5.2.0

raw patch · 6 files changed

+190/−266 lines, 6 filesdep +StateVarPVP ok

version bump matches the API change (PVP)

Dependencies added: StateVar

API changes (from Hackage documentation)

- Physics.Hipmunk.Body: getAngVel :: Body -> IO AngVel
- Physics.Hipmunk.Body: getAngle :: Body -> IO Angle
- Physics.Hipmunk.Body: getForce :: Body -> IO Force
- Physics.Hipmunk.Body: getMass :: Body -> IO Mass
- Physics.Hipmunk.Body: getMaxAngVel :: Body -> IO CpFloat
- Physics.Hipmunk.Body: getMaxVelocity :: Body -> IO CpFloat
- Physics.Hipmunk.Body: getMoment :: Body -> IO Moment
- Physics.Hipmunk.Body: getPosition :: Body -> IO Position
- Physics.Hipmunk.Body: getTorque :: Body -> IO Torque
- Physics.Hipmunk.Body: getVelocity :: Body -> IO Velocity
- Physics.Hipmunk.Body: setAngVel :: Body -> AngVel -> IO ()
- Physics.Hipmunk.Body: setAngle :: Body -> Angle -> IO ()
- Physics.Hipmunk.Body: setForce :: Body -> Force -> IO ()
- Physics.Hipmunk.Body: setMass :: Body -> Mass -> IO ()
- Physics.Hipmunk.Body: setMaxAngVel :: Body -> CpFloat -> IO ()
- Physics.Hipmunk.Body: setMaxVelocity :: Body -> CpFloat -> IO ()
- Physics.Hipmunk.Body: setMoment :: Body -> Moment -> IO ()
- Physics.Hipmunk.Body: setPosition :: Body -> Position -> IO ()
- Physics.Hipmunk.Body: setTorque :: Body -> Torque -> IO ()
- Physics.Hipmunk.Body: setVelocity :: Body -> Velocity -> IO ()
- Physics.Hipmunk.Common: getBiasCoef :: IO BiasCoef
- Physics.Hipmunk.Common: getCollisionSlop :: IO CpFloat
- Physics.Hipmunk.Common: getConstraintBiasCoef :: IO BiasCoef
- Physics.Hipmunk.Common: getContactPersistence :: IO CInt
- Physics.Hipmunk.Common: setBiasCoef :: BiasCoef -> IO ()
- Physics.Hipmunk.Common: setCollisionSlop :: CpFloat -> IO ()
- Physics.Hipmunk.Common: setConstraintBiasCoef :: BiasCoef -> IO ()
- Physics.Hipmunk.Common: setContactPersistence :: CInt -> IO ()
- Physics.Hipmunk.Shape: getBody :: Shape -> Body
- Physics.Hipmunk.Shape: getCollisionType :: Shape -> IO CollisionType
- Physics.Hipmunk.Shape: getElasticity :: Shape -> IO Elasticity
- Physics.Hipmunk.Shape: getFriction :: Shape -> IO Friction
- Physics.Hipmunk.Shape: getGroup :: Shape -> IO Group
- Physics.Hipmunk.Shape: getLayers :: Shape -> IO Layers
- Physics.Hipmunk.Shape: getSurfaceVel :: Shape -> IO SurfaceVel
- Physics.Hipmunk.Shape: moment :: Mass -> ShapeType -> Position -> Moment
- Physics.Hipmunk.Shape: setCollisionType :: Shape -> CollisionType -> IO ()
- Physics.Hipmunk.Shape: setElasticity :: Shape -> Elasticity -> IO ()
- Physics.Hipmunk.Shape: setFriction :: Shape -> Friction -> IO ()
- Physics.Hipmunk.Shape: setGroup :: Shape -> Group -> IO ()
- Physics.Hipmunk.Shape: setLayers :: Shape -> Layers -> IO ()
- Physics.Hipmunk.Shape: setSurfaceVel :: Shape -> SurfaceVel -> IO ()
- Physics.Hipmunk.Space: getDamping :: Space -> IO Damping
- Physics.Hipmunk.Space: getElasticIterations :: Space -> IO ElasticIterations
- Physics.Hipmunk.Space: getGravity :: Space -> IO Gravity
- Physics.Hipmunk.Space: getIterations :: Space -> IO Iterations
- Physics.Hipmunk.Space: getTimeStamp :: Space -> IO TimeStamp
- Physics.Hipmunk.Space: setDamping :: Space -> Damping -> IO ()
- Physics.Hipmunk.Space: setElasticIterations :: Space -> ElasticIterations -> IO ()
- Physics.Hipmunk.Space: setGravity :: Space -> Gravity -> IO ()
- Physics.Hipmunk.Space: setIterations :: Space -> Iterations -> IO ()
+ Physics.Hipmunk.Body: angVel :: Body -> StateVar AngVel
+ Physics.Hipmunk.Body: angle :: Body -> StateVar Angle
+ Physics.Hipmunk.Body: force :: Body -> StateVar Force
+ Physics.Hipmunk.Body: mass :: Body -> StateVar Mass
+ Physics.Hipmunk.Body: maxAngVel :: Body -> StateVar CpFloat
+ Physics.Hipmunk.Body: maxVelocity :: Body -> StateVar CpFloat
+ Physics.Hipmunk.Body: moment :: Body -> StateVar Moment
+ Physics.Hipmunk.Body: position :: Body -> StateVar Position
+ Physics.Hipmunk.Body: torque :: Body -> StateVar Torque
+ Physics.Hipmunk.Body: velocity :: Body -> StateVar Velocity
+ Physics.Hipmunk.Common: biasCoef :: StateVar BiasCoef
+ Physics.Hipmunk.Common: collisionSlop :: StateVar CpFloat
+ Physics.Hipmunk.Common: constraintBiasCoef :: StateVar BiasCoef
+ Physics.Hipmunk.Common: contactPersistence :: StateVar CInt
+ Physics.Hipmunk.Shape: body :: Shape -> Body
+ Physics.Hipmunk.Shape: collisionType :: Shape -> StateVar CollisionType
+ Physics.Hipmunk.Shape: elasticity :: Shape -> StateVar Elasticity
+ Physics.Hipmunk.Shape: friction :: Shape -> StateVar Friction
+ Physics.Hipmunk.Shape: group :: Shape -> StateVar Group
+ Physics.Hipmunk.Shape: layers :: Shape -> StateVar Layers
+ Physics.Hipmunk.Shape: momentForShape :: Mass -> ShapeType -> Position -> Moment
+ Physics.Hipmunk.Shape: surfaceVel :: Shape -> StateVar SurfaceVel
+ Physics.Hipmunk.Space: damping :: Space -> StateVar Damping
+ Physics.Hipmunk.Space: elasticIterations :: Space -> StateVar ElasticIterations
+ Physics.Hipmunk.Space: gravity :: Space -> StateVar Gravity
+ Physics.Hipmunk.Space: iterations :: Space -> StateVar Iterations
+ Physics.Hipmunk.Space: timeStamp :: Space -> GettableStateVar TimeStamp

Files

Hipmunk.cabal view
@@ -3,7 +3,7 @@ Tested-With:   GHC Category:      Physics, Game Name:          Hipmunk-Version:       5.1.0+Version:       5.2.0 Stability:     provisional License:       OtherLicense License-File:  LICENSE@@ -21,6 +21,12 @@       <http://hackage.haskell.org/package/HipmunkPlayground>       for a demonstration of this library.       .+      New in version 5.2.0:+      .+      * Use package StateVar for all variables.+      .+      * Do not use Chipmunk's debug mode.+      .       New in version 5.1.0:       .       * Updated to Chipmunk 5.0 revision 402.@@ -145,12 +151,14 @@     Build-Depends: base >= 3 && < 5,                    array >= 0.1 && < 0.4,                    containers >= 0.1 && < 0.4,-                   transformers >= 0.2 && < 0.3+                   transformers >= 0.2 && < 0.3,+                   StateVar >= 1.0 && < 1.1   else     Build-Depends: base >= 2 && < 3,-                   transformers >= 0.2 && < 0.3+                   transformers >= 0.2 && < 0.3,+                   StateVar >= 1.0 && < 1.1   Extensions:    CPP, ForeignFunctionInterface   Build-Tools:   hsc2hs   GHC-Options:   -Wall-  CC-Options:    -ffast-math -std=gnu99+  CC-Options:    -ffast-math -std=gnu99 -DNDEBUG   Extra-Libraries: m
NEWS view
@@ -1,3 +1,8 @@+Version 5.2.0+=============+ - Use package StateVar for all variables.+ - Do not use Chipmunk's debug mode.+ Version 5.1.0 =============  - Updated to Chipmunk 5.0 revision 402.  'setElasticIterations'
Physics/Hipmunk/Body.hsc view
@@ -21,42 +21,32 @@      -- ** Basic      -- *** Mass      Mass,-     getMass,-     setMass,+     mass,      -- *** Moment of inertia      Moment,-     getMoment,-     setMoment,+     moment,       -- ** Linear components of motion      -- *** Position-     getPosition,-     setPosition,+     position,      -- *** Velocity      Velocity,-     getVelocity,-     setVelocity,-     getMaxVelocity,-     setMaxVelocity,+     velocity,+     maxVelocity,      -- *** Force      Force,-     getForce,-     setForce,+     force,       -- ** Angular components of motion      -- *** Angle-     getAngle,-     setAngle,+     angle,      -- *** Angular velocity      AngVel,-     getAngVel,-     setAngVel,-     getMaxAngVel,-     setMaxAngVel,+     angVel,+     maxAngVel,      -- *** Torque      Torque,-     getTorque,-     setTorque,+     torque,       -- * Dynamic properties      slew,@@ -74,6 +64,7 @@     )     where +import Data.StateVar import Foreign hiding (rotate, new) #include "wrapper.h" @@ -85,10 +76,10 @@ -- --   It is recommended to call 'setPosition' afterwards. newBody :: Mass -> Moment -> IO Body-newBody mass inertia = do+newBody mass_ inertia = do   b <- mallocForeignPtrBytes #{size cpBody}   withForeignPtr b $ \ptr -> do-    cpBodyInit ptr mass inertia+    cpBodyInit ptr mass_ inertia   return (B b)  foreign import ccall unsafe "wrapper.h"@@ -98,15 +89,11 @@  type Mass = CpFloat -getMass :: Body -> IO Mass-getMass (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, m} ptr--setMass :: Body -> Mass -> IO ()-setMass (B b) m = do-  withForeignPtr b $ \ptr -> do-    cpBodySetMass ptr m+mass :: Body -> StateVar Mass+mass (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, m}+      setter = withForeignPtr b . flip cpBodySetMass  foreign import ccall unsafe "wrapper.h"     cpBodySetMass :: BodyPtr -> Mass -> IO ()@@ -114,124 +101,88 @@  type Moment = CpFloat -getMoment :: Body -> IO Moment-getMoment (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, i} ptr--setMoment :: Body -> Moment -> IO ()-setMoment (B b) i = do-  withForeignPtr b $ \ptr -> do-    cpBodySetMoment ptr i+moment :: Body -> StateVar Moment+moment (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, i}+      setter = withForeignPtr b . flip cpBodySetMoment  foreign import ccall unsafe "wrapper.h"     cpBodySetMoment :: BodyPtr -> CpFloat -> IO ()   -getAngle :: Body -> IO Angle-getAngle (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, a} ptr--setAngle :: Body -> Angle -> IO ()-setAngle (B b) a = do-  withForeignPtr b $ \ptr -> do-    cpBodySetAngle ptr a+angle :: Body -> StateVar Angle+angle (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, a}+      setter = withForeignPtr b . flip cpBodySetAngle  foreign import ccall unsafe "wrapper.h"     cpBodySetAngle :: BodyPtr -> CpFloat -> IO ()   -getPosition :: Body -> IO Position-getPosition (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, p} ptr- -- | Note that using this function to change the position --   on every step is not recommended as it may leave --   the velocity out of sync.-setPosition :: Body -> Position -> IO ()-setPosition (B b) pos = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, p} ptr pos+position :: Body -> StateVar Position+position (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, p}+      setter = withForeignPtr b . flip #{poke cpBody, p}   type Velocity = Vector -getVelocity :: Body -> IO Velocity-getVelocity (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, v} ptr--setVelocity :: Body -> Velocity -> IO ()-setVelocity (B b) v = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, v} ptr v+velocity :: Body -> StateVar Velocity+velocity (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, v}+      setter = withForeignPtr b . flip #{poke cpBody, v}  -- | Maximum linear velocity after integrating, defaults to infinity.-getMaxVelocity :: Body -> IO CpFloat-getMaxVelocity (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, v_limit} ptr--setMaxVelocity :: Body -> CpFloat -> IO ()-setMaxVelocity (B b) v_limit = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, v_limit} ptr v_limit+maxVelocity :: Body -> StateVar CpFloat+maxVelocity (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, v_limit}+      setter = withForeignPtr b . flip #{poke cpBody, v_limit}    type Force = Vector -getForce :: Body -> IO Force-getForce (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, f} ptr--setForce :: Body -> Force -> IO ()-setForce (B b) f = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, f} ptr f+force :: Body -> StateVar Force+force (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, f}+      setter = withForeignPtr b . flip #{poke cpBody, f}   type AngVel = CpFloat -getAngVel :: Body -> IO AngVel-getAngVel (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, w} ptr--setAngVel :: Body -> AngVel -> IO ()-setAngVel (B b) w = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, w} ptr w+angVel :: Body -> StateVar AngVel+angVel (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, w}+      setter = withForeignPtr b . flip #{poke cpBody, w}  -- | Maximum angular velocity after integrating, defaults to infinity.-getMaxAngVel :: Body -> IO CpFloat-getMaxAngVel (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, w_limit} ptr--setMaxAngVel :: Body -> CpFloat -> IO ()-setMaxAngVel (B b) w_limit = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, w_limit} ptr w_limit+maxAngVel :: Body -> StateVar CpFloat+maxAngVel (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, w_limit}+      setter = withForeignPtr b . flip #{poke cpBody, w_limit}    type Torque = CpFloat -getTorque :: Body -> IO Torque-getTorque (B b) = do-  withForeignPtr b $ \ptr -> do-    #{peek cpBody, t} ptr--setTorque :: Body -> Torque -> IO ()-setTorque (B b) t = do-  withForeignPtr b $ \ptr -> do-    #{poke cpBody, t} ptr t+torque :: Body -> StateVar Torque+torque (B b) = makeStateVar getter setter+    where+      getter = withForeignPtr b #{peek cpBody, t}+      setter = withForeignPtr b . flip #{poke cpBody, t}   -- | @slew b newpos dt@ changes the body @b@'s velocity@@ -281,8 +232,8 @@ --   acting on body @b@. resetForces :: Body -> IO () resetForces b = do-  setForce b 0-  setTorque b 0+  force  b $= 0+  torque b $= 0   -- | @applyForce b f r@ applies to the body @b@ the force@@ -308,8 +259,8 @@ --   case. applyOnlyForce :: Body -> Vector -> Position -> IO () applyOnlyForce b f p = do-  setForce b f-  setTorque b (p `cross` f)+  force  b $= f+  torque b $= p `cross` f   -- | @applyImpulse b j r@ applies to the body @b@ the impulse
Physics/Hipmunk/Common.hsc view
@@ -60,24 +60,20 @@       -- ** Contact persistence      -- $contact_persistence-     getContactPersistence,-     setContactPersistence,+     contactPersistence,       -- ** Collision slop      -- $collision_slop-     getCollisionSlop,-     setCollisionSlop,+     collisionSlop,       -- ** Bias coefficient      -- $bias_coef      BiasCoef,-     getBiasCoef,-     setBiasCoef,+     biasCoef,       -- ** Constraint bias coefficient      -- $constraint_bias_coef-     getConstraintBiasCoef,-     setConstraintBiasCoef,+     constraintBiasCoef,       -- * Vectors      Vector(..),@@ -96,6 +92,7 @@     )     where +import Data.StateVar import Foreign hiding (rotate) import Foreign.C.Types (CInt) #include "wrapper.h"@@ -170,11 +167,11 @@ --   It should be small as the cached contacts will only be --   close for a short time. (default is 3) -getContactPersistence :: IO CInt-getContactPersistence = peek cp_contact_persistence+contactPersistence :: StateVar CInt+contactPersistence = makeStateVarFromPtr cp_contact_persistence -setContactPersistence :: CInt -> IO ()-setContactPersistence = poke cp_contact_persistence+makeStateVarFromPtr :: Storable a => Ptr a -> StateVar a+makeStateVarFromPtr p = makeStateVar (peek p) (poke p)  foreign import ccall unsafe "wrapper.h &cp_contact_persistence"     cp_contact_persistence :: Ptr CInt@@ -186,11 +183,8 @@ --   small positive amount will help prevent oscillating --   contacts. (default is 0.1) -getCollisionSlop :: IO CpFloat-getCollisionSlop = peek cp_collision_slop--setCollisionSlop :: CpFloat -> IO ()-setCollisionSlop = poke cp_collision_slop+collisionSlop :: StateVar CpFloat+collisionSlop = makeStateVarFromPtr cp_collision_slop  foreign import ccall unsafe "wrapper.h &cp_collision_slop"     cp_collision_slop :: Ptr CpFloat@@ -202,11 +196,8 @@ --   fewer steps, but can cause vibration. (default is 0.1) type BiasCoef = CpFloat -getBiasCoef :: IO BiasCoef-getBiasCoef = peek cp_bias_coef--setBiasCoef :: BiasCoef -> IO ()-setBiasCoef = poke cp_bias_coef+biasCoef :: StateVar BiasCoef+biasCoef = makeStateVarFromPtr cp_bias_coef  foreign import ccall unsafe "wrapper.h &cp_bias_coef"     cp_bias_coef :: Ptr CpFloat@@ -216,11 +207,8 @@ --   Similar to the bias coefficient, but sets the default bias --   for all constraints. (default is 0.1) -getConstraintBiasCoef :: IO BiasCoef-getConstraintBiasCoef = peek cp_constraint_bias_coef--setConstraintBiasCoef :: BiasCoef -> IO ()-setConstraintBiasCoef = poke cp_constraint_bias_coef+constraintBiasCoef :: StateVar BiasCoef+constraintBiasCoef = makeStateVarFromPtr cp_constraint_bias_coef  foreign import ccall unsafe "wrapper.h &cp_constraint_bias_coef"     cp_constraint_bias_coef :: Ptr CpFloat
Physics/Hipmunk/Shape.hsc view
@@ -22,32 +22,26 @@      -- * Properties      -- ** Collision type      CollisionType,-     getCollisionType,-     setCollisionType,+     collisionType,      -- ** Group      Group,-     getGroup,-     setGroup,+     group,      -- ** Layers      Layers,-     getLayers,-     setLayers,+     layers,      -- ** Elasticity      Elasticity,-     getElasticity,-     setElasticity,+     elasticity,      -- ** Friction      Friction,-     getFriction,-     setFriction,+     friction,      -- ** Surface velocity      SurfaceVel,-     getSurfaceVel,-     setSurfaceVel,+     surfaceVel,       -- * Utilities-     getBody,-     moment,+     body,+     momentForShape,      momentForCircle,      momentForSegment,      momentForPoly,@@ -71,6 +65,7 @@     where  import Data.List (foldl', sortBy)+import Data.StateVar import Foreign hiding (rotate, new) import Foreign.C #include "wrapper.h"@@ -108,24 +103,24 @@ --   add the shape to a space otherwise it won't generate --   collisions. newShape :: Body -> ShapeType -> Position -> IO Shape-newShape body@(B b) (Circle r) off =+newShape body_@(B b) (Circle r) off =   withForeignPtr b $ \b_ptr ->   with off $ \off_ptr ->   mallocForeignPtrBytes #{size cpCircleShape} >>= \shape ->   withForeignPtr shape $ \shape_ptr -> do     wrCircleShapeInit shape_ptr b_ptr off_ptr r-    return (S shape body)+    return (S shape body_) -newShape body@(B b) (LineSegment p1 p2 r) off =+newShape body_@(B b) (LineSegment p1 p2 r) off =   withForeignPtr b $ \b_ptr ->   with (p1+off) $ \p1off_ptr ->   with (p2+off) $ \p2off_ptr ->   mallocForeignPtrBytes #{size cpSegmentShape} >>= \shape ->   withForeignPtr shape $ \shape_ptr -> do     wrSegmentShapeInit shape_ptr b_ptr p1off_ptr p2off_ptr r-    return (S shape body)+    return (S shape body_) -newShape body@(B b) (Polygon verts) off =+newShape body_@(B b) (Polygon verts) off =   withForeignPtr b $ \b_ptr ->   with off $ \off_ptr ->   withArrayLen verts $ \verts_len verts_ptr ->@@ -134,7 +129,7 @@     let verts_len' = fromIntegral verts_len     wrPolyShapeInit shape_ptr b_ptr verts_len' verts_ptr off_ptr     addForeignPtrFinalizer cpShapeDestroy shape-    return (S shape body)+    return (S shape body_)  foreign import ccall unsafe "wrapper.h"     wrCircleShapeInit :: ShapePtr -> BodyPtr -> VectorPtr@@ -149,10 +144,10 @@     cpShapeDestroy :: FunPtr (ShapePtr -> IO ())  --- | @getBody s@ is the body that this shape is associated+-- | @body s@ is the body that this shape is associated --   to. Useful especially in a space callback.-getBody :: Shape -> Body-getBody (S _ b) = b+body :: Shape -> Body+body (S _ b) = b   -- | The collision type is used to determine which collision@@ -162,13 +157,11 @@ --   zero)  type CollisionType = #{type cpCollisionType}-getCollisionType :: Shape -> IO CollisionType-getCollisionType (S shape _) =-  withForeignPtr shape #{peek cpShape, collision_type}-setCollisionType :: Shape -> CollisionType -> IO ()-setCollisionType (S shape _) col =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, collision_type} shape_ptr col+collisionType :: Shape -> StateVar CollisionType+collisionType (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, collision_type}+      setter = withForeignPtr shape . flip #{poke cpShape, collision_type}  -- | Groups are used to filter collisions between shapes. If --   the group is zero, then it imposes no restriction@@ -181,13 +174,11 @@ --   alternative to creating a callback that filters the --   collisions. type Group = #{type cpGroup}-getGroup :: Shape -> IO Group-getGroup (S shape _) =-  withForeignPtr shape #{peek cpShape, group}-setGroup :: Shape -> Group -> IO ()-setGroup (S shape _) gr =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, group} shape_ptr gr+group :: Shape -> StateVar Group+group (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, group}+      setter = withForeignPtr shape . flip #{poke cpShape, group}  -- | Layers are similar to groups, but use a bitmask. For a collision --   to occur, two shapes must have at least one layer in common.@@ -197,13 +188,11 @@ --   Note that although this type may have more than 32 bits, --   for portability you should only rely on the lower 32 bits. type Layers = #{type cpLayers}-getLayers :: Shape -> IO Layers-getLayers (S shape _) =-  withForeignPtr shape #{peek cpShape, layers}-setLayers :: Shape -> Layers -> IO ()-setLayers (S shape _) lay =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, layers} shape_ptr lay+layers :: Shape -> StateVar Layers+layers (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, layers}+      setter = withForeignPtr shape . flip #{poke cpShape, layers}  -- | The elasticity of the shape is such that @0.0@ gives no bounce --   while @1.0@ give a \"perfect\" bounce. Note that due to@@ -219,13 +208,11 @@ --   @setElasticIterations@ with something greater than zero, --   maybe @10@. type Elasticity = CpFloat-getElasticity :: Shape -> IO Elasticity-getElasticity (S shape _) =-  withForeignPtr shape #{peek cpShape, e}-setElasticity :: Shape -> Elasticity -> IO ()-setElasticity (S shape _) e =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, e} shape_ptr e+elasticity :: Shape -> StateVar Elasticity+elasticity (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, e}+      setter = withForeignPtr shape . flip #{poke cpShape, e}  -- | The friction coefficient of the shape according --   to Coulumb friction model (i.e. @0.0@ is frictionless,@@ -236,39 +223,35 @@ --   determined by multiplying the friction coefficient --   of both shapes. (default is zero) type Friction = CpFloat-getFriction :: Shape -> IO Friction-getFriction (S shape _) =-  withForeignPtr shape #{peek cpShape, u}-setFriction :: Shape -> Friction -> IO ()-setFriction (S shape _) u =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, u} shape_ptr u+friction :: Shape -> StateVar Friction+friction (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, u}+      setter = withForeignPtr shape . flip #{poke cpShape, u}  -- | The surface velocity of the shape. Useful to create --   conveyor belts and players that move around. This --   value is only used when calculating friction, not --   collision. (default is zero) type SurfaceVel = Vector-getSurfaceVel :: Shape -> IO SurfaceVel-getSurfaceVel (S shape _) =-  withForeignPtr shape #{peek cpShape, surface_v}-setSurfaceVel :: Shape -> SurfaceVel -> IO ()-setSurfaceVel (S shape _) sv =-  withForeignPtr shape $ \shape_ptr -> do-    #{poke cpShape, surface_v} shape_ptr sv+surfaceVel :: Shape -> StateVar SurfaceVel+surfaceVel (S shape _) = makeStateVar getter setter+    where+      getter = withForeignPtr shape #{peek cpShape, surface_v}+      setter = withForeignPtr shape . flip #{poke cpShape, surface_v}     --- | @moment m s off@ is a convenience function that calculates+-- | @momentForShape m s off@ is a convenience function that calculates --   the moment of inertia for shape @s@ with mass @m@ and at a --   offset @off@ of the body's center.  Uses 'momentForCircle', --   'momentForSegment' and 'momentForPoly' internally.-moment :: Mass -> ShapeType -> Position -> Moment-moment m (Circle r)            off = m*(r*r + (off `dot` off))-moment m (LineSegment p1 p2 _) off = momentForSegment m (p1+off) (p2+off)-moment m (Polygon verts)       off = momentForPoly m verts off+momentForShape :: Mass -> ShapeType -> Position -> Moment+momentForShape m (Circle r)            off = m*(r*r + (off `dot` off))+momentForShape m (LineSegment p1 p2 _) off = momentForSegment m (p1+off) (p2+off)+momentForShape m (Polygon verts)       off = momentForPoly m verts off  -- | @momentForCircle m (ri,ro) off@ is the moment of inertia --   of a circle of @m@ mass, inner radius of @ri@, outer radius
Physics/Hipmunk/Space.hsc view
@@ -27,22 +27,18 @@      -- * Properties      -- ** Iterations      Iterations,-     getIterations,-     setIterations,+     iterations,      -- ** Elastic iterations      ElasticIterations,-     getElasticIterations,-     setElasticIterations,+     elasticIterations,      -- ** Gravity      Gravity,-     getGravity,-     setGravity,+     gravity,      -- ** Damping-     getDamping,-     setDamping,+     damping,      -- ** Time stamp      TimeStamp,-     getTimeStamp,+     timeStamp,       -- * Spatial hashes      -- $resizing@@ -64,6 +60,7 @@ import Control.Exception (bracket) import Control.Monad (when) import Data.IORef+import Data.StateVar import Foreign hiding (new) import Foreign.C.Types (CInt) #include "wrapper.h"@@ -157,9 +154,9 @@                -> (SpacePtr -> Ptr b -> IO ())                -> (a -> Maybe Shape)                -> (Space -> a -> IO ())-spaceAddHelper get add toShape =+spaceAddHelper get_ add toShape =     \(P sp entities _) new_c ->-        let new  = get new_c+        let new  = get_ new_c             key  = unsafeForeignPtrToPtr $ castForeignPtr new             val  = case toShape new_c of                      Just shape -> Right shape@@ -172,9 +169,9 @@ spaceRemoveHelper :: (a -> ForeignPtr b)                   -> (SpacePtr -> Ptr b -> IO ())                   -> (Space -> a -> IO ())-spaceRemoveHelper get remove =+spaceRemoveHelper get_ remove =     \(P sp entities _) old_c -> do-      let old  = get old_c+      let old  = get_ old_c           key  = unsafeForeignPtrToPtr $ castForeignPtr old       modifyIORef' entities (M.delete key)       withForeignPtr sp $ \sp_ptr ->@@ -247,53 +244,45 @@ -- | The number of iterations to use when solving constraints. --   (default is 10). type Iterations = CInt-getIterations :: Space -> IO Iterations-getIterations (P sp _ _) =-    withForeignPtr sp #{peek cpSpace, iterations}-setIterations :: Space -> Iterations -> IO ()-setIterations (P sp _ _) it =-    withForeignPtr sp $ \sp_ptr -> do-      #{poke cpSpace, iterations} sp_ptr it+iterations :: Space -> StateVar Iterations+iterations (P sp _ _) = makeStateVar getter setter+    where+      getter = withForeignPtr sp #{peek cpSpace, iterations}+      setter = withForeignPtr sp . flip #{poke cpSpace, iterations}  -- | The number of elastic iterations to use when solving --   constraints.  If @0@, then old-style elastic code is used. --   (default is 0). type ElasticIterations = CInt-getElasticIterations :: Space -> IO ElasticIterations-getElasticIterations (P sp _ _) =-    withForeignPtr sp #{peek cpSpace, elasticIterations}-{-# DEPRECATED setElasticIterations "Elastic iterations should no longer be needed" #-}-setElasticIterations :: Space -> ElasticIterations -> IO ()-setElasticIterations (P sp _ _) it =-    withForeignPtr sp $ \sp_ptr -> do-      #{poke cpSpace, elasticIterations} sp_ptr it+{-# DEPRECATED elasticIterations "Elastic iterations should no longer be needed" #-}+elasticIterations :: Space -> StateVar ElasticIterations+elasticIterations (P sp _ _) = makeStateVar getter setter+    where+      getter = withForeignPtr sp #{peek cpSpace, elasticIterations}+      setter = withForeignPtr sp . flip #{poke cpSpace, elasticIterations}  -- | The gravity applied to the system. (default is 0) type Gravity = Vector-getGravity :: Space -> IO Gravity-getGravity (P sp _ _) =-    withForeignPtr sp #{peek cpSpace, gravity}-setGravity :: Space -> Gravity -> IO ()-setGravity (P sp _ _) g =-    withForeignPtr sp $ \sp_ptr -> do-      #{poke cpSpace, gravity} sp_ptr g+gravity :: Space -> StateVar Gravity+gravity (P sp _ _) = makeStateVar getter setter+    where+      getter = withForeignPtr sp #{peek cpSpace, gravity}+      setter = withForeignPtr sp . flip #{poke cpSpace, gravity}  -- | The amount of viscous damping applied to the system. --   (default is 1)-getDamping :: Space -> IO Damping-getDamping (P sp _ _) =-    withForeignPtr sp #{peek cpSpace, damping}-setDamping :: Space -> Damping -> IO ()-setDamping (P sp _ _) dm =-    withForeignPtr sp $ \sp_ptr -> do-      #{poke cpSpace, damping} sp_ptr dm+damping :: Space -> StateVar Damping+damping (P sp _ _) = makeStateVar getter setter+    where+      getter = withForeignPtr sp #{peek cpSpace, damping}+      setter = withForeignPtr sp . flip #{poke cpSpace, damping}  -- | The time stamp of the simulation, increased in 1 --   every time 'step' is called. type TimeStamp = CInt-getTimeStamp :: Space -> IO TimeStamp-getTimeStamp (P sp _ _) =-    withForeignPtr sp #{peek cpSpace, stamp}+timeStamp :: Space -> GettableStateVar TimeStamp+timeStamp (P sp _ _) = makeGettableStateVar $+                       withForeignPtr sp #{peek cpSpace, stamp}   @@ -370,11 +359,11 @@ --   and only once, for each of the shapes described above --   (and never for those who aren't). spaceQuery :: Space -> Position -> Layers -> Group -> (Shape -> IO ()) -> IO ()-spaceQuery spce@(P sp _ _) pos layers group callback =+spaceQuery spce@(P sp _ _) pos layers_ group_ callback =   withForeignPtr sp $ \sp_ptr ->   bracket (makePointQueryFunc cb) freeHaskellFunPtr $ \cb_ptr ->   with pos $ \pos_ptr ->-    wrSpacePointQuery sp_ptr pos_ptr layers group cb_ptr+    wrSpacePointQuery sp_ptr pos_ptr layers_ group_ cb_ptr  where    cb shape_ptr _ = retriveShape spce shape_ptr >>= callback @@ -391,9 +380,9 @@ --   returns a list of 'Shape's instead of calling a callback. --   This is just a convenience function. spaceQueryList :: Space -> Position -> Layers -> Group -> IO [Shape]-spaceQueryList spce pos layers group = do+spaceQueryList spce pos layers_ group_ = do   var <- newIORef []-  spaceQuery spce pos layers group $ modifyIORef var . (:)+  spaceQuery spce pos layers_ group_ $ modifyIORef var . (:)   readIORef var