apecs-physics 0.3.2 → 0.4.0
raw patch · 5 files changed
+31/−16 lines, 5 filesdep ~apecsPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: apecs
API changes (from Hackage documentation)
- Apecs.Physics: [collisionA] :: Collision -> Entity
- Apecs.Physics: [collisionB] :: Collision -> Entity
+ Apecs.Physics: [collisionBodyA] :: Collision -> Entity
+ Apecs.Physics: [collisionBodyB] :: Collision -> Entity
+ Apecs.Physics: [collisionShapeA] :: Collision -> Entity
+ Apecs.Physics: [collisionShapeB] :: Collision -> Entity
- Apecs.Physics: Collision :: Vec -> Entity -> Entity -> Collision
+ Apecs.Physics: Collision :: Vec -> Entity -> Entity -> Entity -> Entity -> Collision
Files
- CHANGELOG.md +4/−0
- apecs-physics.cabal +2/−2
- src/Apecs/Physics/Collision.hs +18/−11
- src/Apecs/Physics/Constraint.hs +3/−1
- src/Apecs/Physics/Types.hs +4/−2
CHANGELOG.md view
@@ -1,3 +1,7 @@+## [0.4.0]+### Added+- You now have access to colliding shapes in a `Collision`+ ## [0.3.2] ### Changed - Fixed links and added changelog to cabal file
apecs-physics.cabal view
@@ -1,5 +1,5 @@ name: apecs-physics-version: 0.3.2+version: 0.4.0 synopsis: 2D physics for apecs description: 2D physics for apecs. Uses Chipmunk physics library under the hood. homepage: https://github.com/jonascarpay/apecs#readme@@ -77,7 +77,7 @@ Apecs.Physics.Types Apecs.Physics.Query build-depends:- apecs >= 0.7 && < 0.8,+ apecs >= 0.7 && < 0.9, base >= 4.9 && < 5, containers >= 0.5 && < 0.8, inline-c >= 0.6 && < 1,
src/Apecs/Physics/Collision.hs view
@@ -13,7 +13,10 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ViewPatterns #-} -module Apecs.Physics.Collision where+module Apecs.Physics.Collision+ ( defaultHandler+ , mkBeginCB, mkSeparateCB, mkPreSolveCB, mkPostSolveCB+ ) where import Apecs import Apecs.Core@@ -37,16 +40,23 @@ defaultHandler :: CollisionHandler defaultHandler = CollisionHandler (Wildcard 0) Nothing Nothing Nothing Nothing +mkCollision :: Ptr Collision -> IO Collision+mkCollision arb = do+ nx <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).x } |]+ ny <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).y } |]+ ba <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (ba->userData); } |]+ bb <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (bb->userData); } |]+ sa <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_SHAPES($(cpArbiter* arb), sa, sb); return (intptr_t) (sa->userData); } |]+ sb <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_SHAPES($(cpArbiter* arb), sa, sb); return (intptr_t) (sb->userData); } |]+ return $ Collision (V2 nx ny) (Entity ba) (Entity bb) (Entity sa) (Entity sb)+ mkBeginCB :: (Collision -> System w Bool) -> System w BeginCB mkBeginCB sys = do w <- ask let cb arb _ _ = do- nx <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).x } |]- ny <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).y } |]- ea <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (ba->userData); } |]- eb <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (bb->userData); } |]- r <- liftIO$ runSystem (sys (Collision (V2 nx ny) (Entity ea) (Entity eb))) w+ col <- mkCollision arb+ r <- liftIO$ runSystem (sys col) w return . fromIntegral . fromEnum $ r return (BeginCB cb)@@ -56,11 +66,8 @@ w <- ask let cb arb _ _ = do- nx <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).x } |]- ny <- realToFrac <$> [C.exp| double { cpArbiterGetNormal($(cpArbiter* arb)).y } |]- ea <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (ba->userData); } |]- eb <- fromIntegral <$> [C.block| unsigned int { CP_ARBITER_GET_BODIES($(cpArbiter* arb), ba, bb); return (intptr_t) (bb->userData); } |]- liftIO$ runSystem (sys (Collision (V2 nx ny) (Entity ea) (Entity eb))) w+ col <- mkCollision arb+ liftIO$ runSystem (sys col) w return (SeparateCB cb)
src/Apecs/Physics/Constraint.hs view
@@ -13,7 +13,9 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ViewPatterns #-} -module Apecs.Physics.Constraint where+module Apecs.Physics.Constraint+ (+ ) where import Apecs import Apecs.Core
src/Apecs/Physics/Types.hs view
@@ -263,8 +263,10 @@ -- Corresponds to an 'arbiter' in Chipmunk data Collision = Collision { collisionNormal :: Vec- , collisionA :: Entity- , collisionB :: Entity+ , collisionBodyA :: Entity+ , collisionBodyB :: Entity+ , collisionShapeA :: Entity+ , collisionShapeB :: Entity } deriving (Eq, Show) data CollisionProperties = CollisionProperties