    {-# LANGUAGE CPP #-}

    module SDL.Raw.Timer (
      -- * Timer Support
      addTimer,
      delay,
      getPerformanceCounter,
      getPerformanceFrequency,
      getTicks,
      removeTimer

    #ifdef RECENT_ISH
      , getTicks64
    #endif
    ) where

    import Control.Monad.IO.Class
    import Data.Word
    import Foreign.C.Types
    import Foreign.Ptr
    import SDL.Raw.Types

    foreign import ccall "SDL.h SDL_AddTimer" addTimerFFI :: Word32 -> TimerCallback -> Ptr () -> IO TimerID
    foreign import ccall "SDL.h SDL_Delay" delayFFI :: Word32 -> IO ()
    foreign import ccall "SDL.h SDL_GetPerformanceCounter" getPerformanceCounterFFI :: IO Word64
    foreign import ccall "SDL.h SDL_GetPerformanceFrequency" getPerformanceFrequencyFFI :: IO Word64
    foreign import ccall "SDL.h SDL_GetTicks" getTicksFFI :: IO Word32
    foreign import ccall "SDL.h SDL_RemoveTimer" removeTimerFFI :: TimerID -> IO Bool

    #ifdef RECENT_ISH
    foreign import ccall "SDL.h SDL_GetTicks64" getTicks64FFI :: IO Word64
    #endif

    addTimer :: MonadIO m => Word32 -> TimerCallback -> Ptr () -> m TimerID
    addTimer :: forall (m :: Type -> Type).
    MonadIO m =>
    Word32 -> TimerCallback -> Ptr () -> m TimerID
    addTimer Word32
    v1 TimerCallback
    v2 Ptr ()
    v3 = IO TimerID -> m TimerID
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO (IO TimerID -> m TimerID) -> IO TimerID -> m TimerID
    forall a b. (a -> b) -> a -> b
    $ Word32 -> TimerCallback -> Ptr () -> IO TimerID
    addTimerFFI Word32
    v1 TimerCallback
    v2 Ptr ()
    v3
    {-# INLINE addTimer #-}

    delay :: MonadIO m => Word32 -> m ()
    delay :: forall (m :: Type -> Type). MonadIO m => Word32 -> m ()
    delay Word32
    v1 = IO () -> m ()
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ Word32 -> IO ()
    delayFFI Word32
    v1
    {-# INLINE delay #-}

    getPerformanceCounter :: MonadIO m => m Word64
    getPerformanceCounter :: forall (m :: Type -> Type). MonadIO m => m Word64
    getPerformanceCounter = IO Word64 -> m Word64
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO IO Word64
    getPerformanceCounterFFI
    {-# INLINE getPerformanceCounter #-}

    getPerformanceFrequency :: MonadIO m => m Word64
    getPerformanceFrequency :: forall (m :: Type -> Type). MonadIO m => m Word64
    getPerformanceFrequency = IO Word64 -> m Word64
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO IO Word64
    getPerformanceFrequencyFFI
    {-# INLINE getPerformanceFrequency #-}

    getTicks :: MonadIO m => m Word32
    getTicks :: forall (m :: Type -> Type). MonadIO m => m Word32
    getTicks = IO Word32 -> m Word32
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO IO Word32
    getTicksFFI
    {-# INLINE getTicks #-}

    removeTimer :: MonadIO m => TimerID -> m Bool
    removeTimer :: forall (m :: Type -> Type). MonadIO m => TimerID -> m Bool
    removeTimer TimerID
    v1 = IO Bool -> m Bool
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
    forall a b. (a -> b) -> a -> b
    $ TimerID -> IO Bool
    removeTimerFFI TimerID
    v1
    {-# INLINE removeTimer #-}

    #ifdef RECENT_ISH
    getTicks64 :: MonadIO m => m Word64
    getTicks64 :: forall (m :: Type -> Type). MonadIO m => m Word64
    getTicks64 = IO Word64 -> m Word64
    forall a. IO a -> m a
    forall (m :: Type -> Type) a. MonadIO m => IO a -> m a
    liftIO IO Word64
    getTicks64FFI
    {-# INLINE getTicks64 #-}
    #endif