apecs-physics 0.4.0 → 0.4.1
raw patch · 4 files changed
+13/−12 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Apecs.Physics: PointQueryResult :: Entity -> WVec -> Double -> Double -> PointQueryResult
+ Apecs.Physics: PointQueryResult :: Entity -> WVec -> Double -> Vec -> PointQueryResult
- Apecs.Physics: [pqGradient] :: PointQueryResult -> Double
+ Apecs.Physics: [pqGradient] :: PointQueryResult -> Vec
Files
- CHANGELOG.md +4/−0
- apecs-physics.cabal +1/−1
- src/Apecs/Physics/Query.hs +5/−8
- src/Apecs/Physics/Types.hs +3/−3
CHANGELOG.md view
@@ -1,3 +1,7 @@+## [0.4.1]+### Changed+- Fix Point Query bug, should no longer give memory issues+ ## [0.4.0] ### Added - You now have access to colliding shapes in a `Collision`
apecs-physics.cabal view
@@ -1,5 +1,5 @@ name: apecs-physics-version: 0.4.0+version: 0.4.1 synopsis: 2D physics for apecs description: 2D physics for apecs. Uses Chipmunk physics library under the hood. homepage: https://github.com/jonascarpay/apecs#readme
src/Apecs/Physics/Query.hs view
@@ -37,25 +37,22 @@ pointQuery :: Has w IO Physics => WVec -> Double -> CollisionFilter -> System w (Maybe PointQueryResult) pointQuery (fmap realToFrac -> V2 px py) (realToFrac -> maxDistance) (CollisionFilter gr (Bitmask cs) (Bitmask mk)) = do Space _ _ _ _ spcPtr :: Space Physics <- getStore- liftIO$ do- pq <- malloc+ liftIO $ alloca $ \pq -> do withForeignPtr spcPtr $ \space -> [C.block| void {- cpPointQueryInfo *pq = $(cpPointQueryInfo *pq); cpSpacePointQueryNearest ( $(cpSpace *space) , cpv($(double px), $(double py)) , $(double maxDistance) , cpShapeFilterNew($(unsigned int gr), $(unsigned int cs), $(unsigned int mk))- , pq);+ , $(cpPointQueryInfo *pq)); }|] res <- peek pq- free pq if unEntity (pqShape res) == -1 then return Nothing else return (Just res) instance Storable PointQueryResult where- sizeOf ~_ = 40 -- sizeOf (undefined :: Ptr Shape) + 2*sizeOf (undefined :: CDouble) + sizeOf (undefined :: V2 CDouble)+ sizeOf ~_ = 48 -- sizeOf (undefined :: Ptr Shape) + sizeOf (undefined :: CDouble) + 2*sizeOf (undefined :: V2 CDouble) alignment ~_ = 8 peek ptr = do sPtr :: Ptr Shape <- peekByteOff ptr 0@@ -68,6 +65,6 @@ } }|] p :: V2 CDouble <- peekByteOff ptr 8 d :: CDouble <- peekByteOff ptr 24- g :: CDouble <- peekByteOff ptr 32- return $ PointQueryResult (Entity . fromIntegral $ s) (realToFrac <$> p) (realToFrac d) (realToFrac g)+ g :: V2 CDouble <- peekByteOff ptr 32+ return $ PointQueryResult (Entity . fromIntegral $ s) (realToFrac <$> p) (realToFrac d) (realToFrac <$> g) poke = undefined
src/Apecs/Physics/Types.hs view
@@ -294,8 +294,8 @@ -- ^ The closest point on the shape's surface (in world space) , pqDistance :: Double -- ^ The distance to the queried point- , pqGradient :: Double+ , pqGradient :: Vec -- ^ The gradient of the distance function.- -- This is equal to 'pqPoint'/'pqDistance' but accurate for even- -- very small distances. + -- This should be similar to 'pqPoint'/'pqDistance' but accurate even for+ -- very small distances. } deriving (Eq, Show)