{-# LINE 1 "src/Chiphunk/Low/Callback.chs" #-}
module Chiphunk.Low.Callback
( CollisionCallback
, CollisionHandler (..)
, CollisionHandlerPtr
, spaceAddCollisionHandler
, spaceAddWildcardHandler
, spaceAddDefaultCollisionHandler
, modifyCollisionHandler
, mkCallback
, mkCallbackB
, PostStepFunc
, spaceAddPostStepCallback
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Storable as C2HSImp
import Control.Applicative (liftA)
import Control.Exception.Safe
import Data.Bool (bool)
import Foreign
import Chiphunk.Low.Types
{-# LINE 22 "src/Chiphunk/Low/Callback.chs" #-}
type CollisionCallback ret = Arbiter -> Space -> DataPtr -> IO ret
data CollisionHandler = CollisionHandler
{ CollisionHandler -> CollisionType
chTypeA :: !CollisionType
, CollisionHandler -> CollisionType
chTypeB :: !CollisionType
, CollisionHandler -> FunPtr (CollisionCallback CPBool)
chBeginFunc :: !(FunPtr (CollisionCallback CPBool))
, CollisionHandler -> FunPtr (CollisionCallback CPBool)
chPreSolveFunc :: !(FunPtr (CollisionCallback CPBool))
, CollisionHandler -> FunPtr (CollisionCallback ())
chPostSolveFunc :: !(FunPtr (CollisionCallback ()))
, CollisionHandler -> FunPtr (CollisionCallback ())
chSeparateFunc :: !(FunPtr (CollisionCallback ()))
, CollisionHandler -> DataPtr
cpUserData :: !DataPtr
} deriving Int -> CollisionHandler -> ShowS
[CollisionHandler] -> ShowS
CollisionHandler -> String
(Int -> CollisionHandler -> ShowS)
-> (CollisionHandler -> String)
-> ([CollisionHandler] -> ShowS)
-> Show CollisionHandler
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CollisionHandler] -> ShowS
$cshowList :: [CollisionHandler] -> ShowS
show :: CollisionHandler -> String
$cshow :: CollisionHandler -> String
showsPrec :: Int -> CollisionHandler -> ShowS
$cshowsPrec :: Int -> CollisionHandler -> ShowS
Show
instance Storable CollisionHandler where
sizeOf :: CollisionHandler -> Int
sizeOf CollisionHandler
_ = Int
56
{-# LINE 60 "src/Chiphunk/Low/Callback.chs" #-}
alignment _ = 8
{-# LINE 61 "src/Chiphunk/Low/Callback.chs" #-}
poke p (CollisionHandler typA typB beginFunc preSolveFunc postSolveFunc separateFunc userData) = do
(\ptr val -> do {C2HSImp.pokeByteOff ptr 0 (val :: C2HSImp.CULong)}) p $ fromIntegral typA
(\ptr val -> do {C2HSImp.pokeByteOff ptr 8 (val :: C2HSImp.CULong)}) p $ fromIntegral typB
(\ptr val -> do {C2HSImp.pokeByteOff ptr 16 (val :: (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO C2HSImp.CUChar))))))}) p beginFunc
(\ptr val -> do {C2HSImp.pokeByteOff ptr 24 (val :: (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO C2HSImp.CUChar))))))}) p preSolveFunc
(\ptr val -> do {C2HSImp.pokeByteOff ptr 32 (val :: (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO ()))))))}) p postSolveFunc
(\ptr val -> do {C2HSImp.pokeByteOff ptr 40 (val :: (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO ()))))))}) p separateFunc
(\ptr val -> do {C2HSImp.pokeByteOff ptr 48 (val :: (C2HSImp.Ptr ()))}) p userData
peek :: Ptr CollisionHandler -> IO CollisionHandler
peek Ptr CollisionHandler
p = CollisionType
-> CollisionType
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler
CollisionHandler (CollisionType
-> CollisionType
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
-> IO CollisionType
-> IO
(CollisionType
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CULong -> CollisionType
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULong -> CollisionType) -> IO CULong -> IO CollisionType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler -> Int -> IO CULong
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
0 :: IO C2HSImp.CULong}) Ptr CollisionHandler
p)
IO
(CollisionType
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
-> IO CollisionType
-> IO
(FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CULong -> CollisionType
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULong -> CollisionType) -> IO CULong -> IO CollisionType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler -> Int -> IO CULong
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
8 :: IO C2HSImp.CULong}) Ptr CollisionHandler
p)
IO
(FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
-> IO (FunPtr (CollisionCallback CPBool))
-> IO
(FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler
-> Int -> IO (FunPtr (CollisionCallback CPBool))
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
16 :: IO (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO C2HSImp.CUChar)))))}) Ptr CollisionHandler
p
IO
(FunPtr (CollisionCallback CPBool)
-> FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ())
-> DataPtr
-> CollisionHandler)
-> IO (FunPtr (CollisionCallback CPBool))
-> IO
(FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ()) -> DataPtr -> CollisionHandler)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler
-> Int -> IO (FunPtr (CollisionCallback CPBool))
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
24 :: IO (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO C2HSImp.CUChar)))))}) Ptr CollisionHandler
p
IO
(FunPtr (CollisionCallback ())
-> FunPtr (CollisionCallback ()) -> DataPtr -> CollisionHandler)
-> IO (FunPtr (CollisionCallback ()))
-> IO
(FunPtr (CollisionCallback ()) -> DataPtr -> CollisionHandler)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler -> Int -> IO (FunPtr (CollisionCallback ()))
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
32 :: IO (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO ())))))}) Ptr CollisionHandler
p
IO (FunPtr (CollisionCallback ()) -> DataPtr -> CollisionHandler)
-> IO (FunPtr (CollisionCallback ()))
-> IO (DataPtr -> CollisionHandler)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler -> Int -> IO (FunPtr (CollisionCallback ()))
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
40 :: IO (C2HSImp.FunPtr ((Arbiter) -> ((Space) -> ((DataPtr) -> (IO ())))))}) Ptr CollisionHandler
p
IO (DataPtr -> CollisionHandler)
-> IO DataPtr -> IO CollisionHandler
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (\Ptr CollisionHandler
ptr -> do {Ptr CollisionHandler -> Int -> IO DataPtr
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CollisionHandler
ptr Int
48 :: IO (C2HSImp.Ptr ())}) Ptr CollisionHandler
p
foreign import ccall unsafe "wrapper"
mkCallback' :: CollisionCallback () -> IO (FunPtr (CollisionCallback ()))
mkCallback :: CollisionCallback () -> IO (FunPtr (CollisionCallback ()))
mkCallback :: CollisionCallback () -> IO (FunPtr (CollisionCallback ()))
mkCallback = CollisionCallback () -> IO (FunPtr (CollisionCallback ()))
mkCallback'
foreign import ccall unsafe "wrapper"
mkCallbackB' :: CollisionCallback CPBool -> IO (FunPtr (CollisionCallback CPBool))
mkCallbackB :: CollisionCallback Bool -> IO (FunPtr (CollisionCallback CPBool))
mkCallbackB :: CollisionCallback Bool -> IO (FunPtr (CollisionCallback CPBool))
mkCallbackB = CollisionCallback CPBool -> IO (FunPtr (CollisionCallback CPBool))
mkCallbackB' (CollisionCallback CPBool
-> IO (FunPtr (CollisionCallback CPBool)))
-> (CollisionCallback Bool -> CollisionCallback CPBool)
-> CollisionCallback Bool
-> IO (FunPtr (CollisionCallback CPBool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Space -> DataPtr -> IO Bool) -> Space -> DataPtr -> IO CPBool)
-> CollisionCallback Bool -> CollisionCallback CPBool
forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
liftA (((DataPtr -> IO Bool) -> DataPtr -> IO CPBool)
-> (Space -> DataPtr -> IO Bool) -> Space -> DataPtr -> IO CPBool
forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
liftA (((DataPtr -> IO Bool) -> DataPtr -> IO CPBool)
-> (Space -> DataPtr -> IO Bool) -> Space -> DataPtr -> IO CPBool)
-> ((DataPtr -> IO Bool) -> DataPtr -> IO CPBool)
-> (Space -> DataPtr -> IO Bool)
-> Space
-> DataPtr
-> IO CPBool
forall a b. (a -> b) -> a -> b
$ (IO Bool -> IO CPBool)
-> (DataPtr -> IO Bool) -> DataPtr -> IO CPBool
forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
liftA ((IO Bool -> IO CPBool)
-> (DataPtr -> IO Bool) -> DataPtr -> IO CPBool)
-> (IO Bool -> IO CPBool)
-> (DataPtr -> IO Bool)
-> DataPtr
-> IO CPBool
forall a b. (a -> b) -> a -> b
$ (Bool -> CPBool) -> IO Bool -> IO CPBool
forall (f :: * -> *) a b. Applicative f => (a -> b) -> f a -> f b
liftA ((Bool -> CPBool) -> IO Bool -> IO CPBool)
-> (Bool -> CPBool) -> IO Bool -> IO CPBool
forall a b. (a -> b) -> a -> b
$ CPBool -> CPBool -> Bool -> CPBool
forall a. a -> a -> Bool -> a
bool CPBool
0 CPBool
1)
type CollisionHandlerPtr = C2HSImp.Ptr (CollisionHandler)
{-# LINE 93 "src/Chiphunk/Low/Callback.chs" #-}
spaceAddCollisionHandler :: (Space) -> (CollisionType)
-> (CollisionType)
-> IO ((CollisionHandlerPtr))
spaceAddCollisionHandler :: Space
-> CollisionType -> CollisionType -> IO (Ptr CollisionHandler)
spaceAddCollisionHandler Space
a1 CollisionType
a2 CollisionType
a3 =
let {a1' :: Space
a1' = Space -> Space
forall a. a -> a
id Space
a1} in
let {a2' :: CULong
a2' = CollisionType -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral CollisionType
a2} in
let {a3' :: CULong
a3' = CollisionType -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral CollisionType
a3} in
Space -> CULong -> CULong -> IO (Ptr CollisionHandler)
spaceAddCollisionHandler'_ Space
a1' CULong
a2' CULong
a3' IO (Ptr CollisionHandler)
-> (Ptr CollisionHandler -> IO (Ptr CollisionHandler))
-> IO (Ptr CollisionHandler)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CollisionHandler
res ->
let {res' :: Ptr CollisionHandler
res' = Ptr CollisionHandler -> Ptr CollisionHandler
forall a. a -> a
id Ptr CollisionHandler
res} in
Ptr CollisionHandler -> IO (Ptr CollisionHandler)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr CollisionHandler
res')
{-# LINE 104 "src/Chiphunk/Low/Callback.chs" #-}
spaceAddWildcardHandler :: (Space) -> (CollisionType)
-> IO ((CollisionHandlerPtr))
spaceAddWildcardHandler :: Space -> CollisionType -> IO (Ptr CollisionHandler)
spaceAddWildcardHandler Space
a1 CollisionType
a2 =
let {a1' :: Space
a1' = Space -> Space
forall a. a -> a
id Space
a1} in
let {a2' :: CULong
a2' = CollisionType -> CULong
forall a b. (Integral a, Num b) => a -> b
fromIntegral CollisionType
a2} in
Space -> CULong -> IO (Ptr CollisionHandler)
spaceAddWildcardHandler'_ Space
a1' CULong
a2' IO (Ptr CollisionHandler)
-> (Ptr CollisionHandler -> IO (Ptr CollisionHandler))
-> IO (Ptr CollisionHandler)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CollisionHandler
res ->
let {res' :: Ptr CollisionHandler
res' = Ptr CollisionHandler -> Ptr CollisionHandler
forall a. a -> a
id Ptr CollisionHandler
res} in
Ptr CollisionHandler -> IO (Ptr CollisionHandler)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr CollisionHandler
res')
{-# LINE 117 "src/Chiphunk/Low/Callback.chs" #-}
spaceAddDefaultCollisionHandler :: (Space) -> IO ((CollisionHandlerPtr))
spaceAddDefaultCollisionHandler a1 =
let {a1' = id a1} in
spaceAddDefaultCollisionHandler'_ a1' >>= \res ->
let {res' = id res} in
return (res')
{-# LINE 124 "src/Chiphunk/Low/Callback.chs" #-}
modifyCollisionHandler :: CollisionHandlerPtr -> (CollisionHandler -> IO CollisionHandler) -> IO ()
modifyCollisionHandler :: Ptr CollisionHandler
-> (CollisionHandler -> IO CollisionHandler) -> IO ()
modifyCollisionHandler Ptr CollisionHandler
chPtr CollisionHandler -> IO CollisionHandler
inner = Ptr CollisionHandler -> IO CollisionHandler
forall a. Storable a => Ptr a -> IO a
peek Ptr CollisionHandler
chPtr IO CollisionHandler
-> (CollisionHandler -> IO CollisionHandler) -> IO CollisionHandler
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CollisionHandler -> IO CollisionHandler
inner IO CollisionHandler -> (CollisionHandler -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CollisionHandler -> CollisionHandler -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr CollisionHandler
chPtr
type PostStepFunc
= Space
-> Ptr ()
-> Ptr ()
-> IO ()
foreign import ccall "wrapper"
mkPostStep :: PostStepFunc -> IO (FunPtr PostStepFunc)
spaceAddPostStepCallback :: (Space)
-> (PostStepFunc)
-> (Ptr ())
-> (Ptr ())
-> IO ((Bool))
spaceAddPostStepCallback :: Space -> PostStepFunc -> DataPtr -> DataPtr -> IO Bool
spaceAddPostStepCallback Space
a1 PostStepFunc
a2 DataPtr
a3 DataPtr
a4 =
let {a1' :: Space
a1' = Space -> Space
forall a. a -> a
id Space
a1} in
PostStepFunc -> (FunPtr PostStepFunc -> IO Bool) -> IO Bool
forall c. PostStepFunc -> (FunPtr PostStepFunc -> IO c) -> IO c
mk PostStepFunc
a2 ((FunPtr PostStepFunc -> IO Bool) -> IO Bool)
-> (FunPtr PostStepFunc -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \FunPtr PostStepFunc
a2' ->
let {a3' :: DataPtr
a3' = DataPtr -> DataPtr
forall a. a -> a
id DataPtr
a3} in
let {a4' :: DataPtr
a4' = DataPtr -> DataPtr
forall a. a -> a
id DataPtr
a4} in
Space -> FunPtr PostStepFunc -> DataPtr -> DataPtr -> IO CPBool
spaceAddPostStepCallback'_ Space
a1' FunPtr PostStepFunc
a2' DataPtr
a3' DataPtr
a4' IO CPBool -> (CPBool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CPBool
res ->
let {res' :: Bool
res' = CPBool -> Bool
forall a. (Eq a, Num a) => a -> Bool
C2HSImp.toBool CPBool
res} in
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 157 "src/Chiphunk/Low/Callback.chs" #-}
where
mk f = mkPostStep f `bracket` freeHaskellFunPtr
foreign import ccall unsafe "Chiphunk/Low/Callback.chs.h cpSpaceAddCollisionHandler"
spaceAddCollisionHandler'_ :: ((Space) -> (C2HSImp.CULong -> (C2HSImp.CULong -> (IO (CollisionHandlerPtr)))))
foreign import ccall unsafe "Chiphunk/Low/Callback.chs.h cpSpaceAddWildcardHandler"
spaceAddWildcardHandler'_ :: ((Space) -> (C2HSImp.CULong -> (IO (CollisionHandlerPtr))))
foreign import ccall unsafe "Chiphunk/Low/Callback.chs.h cpSpaceAddDefaultCollisionHandler"
spaceAddDefaultCollisionHandler'_ :: ((Space) -> (IO (CollisionHandlerPtr)))
foreign import ccall unsafe "Chiphunk/Low/Callback.chs.h cpSpaceAddPostStepCallback"
spaceAddPostStepCallback'_ :: ((Space) -> ((C2HSImp.FunPtr ((Space) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO ()))))) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CUChar)))))