Skip to content

Commit

Permalink
Add ticks64 (#294)
Browse files Browse the repository at this point in the history
This is a wrapper around SDL_GetTicks64
  • Loading branch information
dxtr authored Aug 26, 2023
1 parent 1fc9a54 commit 14fa0a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/SDL/Raw/Timer.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

module SDL.Raw.Timer (
-- * Timer Support
addTimer,
Expand All @@ -6,6 +8,10 @@ module SDL.Raw.Timer (
getPerformanceFrequency,
getTicks,
removeTimer

#ifdef RECENT_ISH
, getTicks64
#endif
) where

import Control.Monad.IO.Class
Expand All @@ -21,6 +27,10 @@ foreign import ccall "SDL.h SDL_GetPerformanceFrequency" getPerformanceFrequency
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 v1 v2 v3 = liftIO $ addTimerFFI v1 v2 v3
{-# INLINE addTimer #-}
Expand All @@ -44,3 +54,9 @@ getTicks = liftIO getTicksFFI
removeTimer :: MonadIO m => TimerID -> m Bool
removeTimer v1 = liftIO $ removeTimerFFI v1
{-# INLINE removeTimer #-}

#ifdef RECENT_ISH
getTicks64 :: MonadIO m => m Word64
getTicks64 = liftIO getTicks64FFI
{-# INLINE getTicks64 #-}
#endif
14 changes: 14 additions & 0 deletions src/SDL/Time.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module SDL.Time
( -- * Time Measurement
ticks
Expand All @@ -13,6 +15,10 @@ module SDL.Time
, RetriggerTimer(..)
, addTimer
, removeTimer

#ifdef RECENT_ISH
, ticks64
#endif
) where

import Control.Monad.IO.Class (MonadIO, liftIO)
Expand Down Expand Up @@ -93,3 +99,11 @@ addTimer timeout callback = liftIO $ do
-- See @<https://wiki.libsdl.org/SDL_RemoveTimer SDL_RemoveTimer>@ for C documentation.
removeTimer :: MonadIO m => Timer -> m Bool
removeTimer f = liftIO $ runTimerRemoval f

#ifdef RECENT_ISH
-- | Number of milliseconds since library initialization.
--
-- See @<https://wiki.libsdl.org/SDL_GetTicks64 SDL_GetTicks64>@ for C documentation.
ticks64 :: MonadIO m => m Word64
ticks64 = Raw.getTicks64
#endif

0 comments on commit 14fa0a5

Please sign in to comment.