From 7f7a1929d630ff9300cef8d3ecb9b291876b2a79 Mon Sep 17 00:00:00 2001 From: dxtr Date: Tue, 22 Aug 2023 23:49:59 +0200 Subject: [PATCH 1/4] Add ticks64 This is a wrapper around SDL_GetTicks64 --- src/SDL/Raw/Timer.hs | 6 ++++++ src/SDL/Time.hs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/SDL/Raw/Timer.hs b/src/SDL/Raw/Timer.hs index 0ac69d1d..3c85c880 100644 --- a/src/SDL/Raw/Timer.hs +++ b/src/SDL/Raw/Timer.hs @@ -5,6 +5,7 @@ module SDL.Raw.Timer ( getPerformanceCounter, getPerformanceFrequency, getTicks, + getTicks64, removeTimer ) where @@ -19,6 +20,7 @@ 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_GetTicks64" getTicks64FFI :: IO Word64 foreign import ccall "SDL.h SDL_RemoveTimer" removeTimerFFI :: TimerID -> IO Bool addTimer :: MonadIO m => Word32 -> TimerCallback -> Ptr () -> m TimerID @@ -41,6 +43,10 @@ getTicks :: MonadIO m => m Word32 getTicks = liftIO getTicksFFI {-# INLINE getTicks #-} +getTicks64 :: MonadIO m => m Word64 +getTicks64 = liftIO getTicks64FFI +{-# INLINE getTicks64 #-} + removeTimer :: MonadIO m => TimerID -> m Bool removeTimer v1 = liftIO $ removeTimerFFI v1 {-# INLINE removeTimer #-} diff --git a/src/SDL/Time.hs b/src/SDL/Time.hs index ea29f9f7..b9020b4b 100644 --- a/src/SDL/Time.hs +++ b/src/SDL/Time.hs @@ -4,6 +4,7 @@ module SDL.Time ( -- * Time Measurement ticks + , ticks64 , time -- * Timer @@ -33,6 +34,12 @@ import qualified SDL.Raw.Types as Raw ticks :: MonadIO m => m Word32 ticks = Raw.getTicks +-- | Number of milliseconds since library initialization. +-- +-- See @@ for C documentation. +ticks64 :: MonadIO m => m Word64 +ticks64 = Raw.getTicks64 + -- | The current time in seconds since some arbitrary starting point (consist over the life of the application). -- -- This time is derived from the system's performance counter - see @@ and @@ for C documentation about the implementation. From 646d05a9599fd4bc6f1e4479595bfcf1e48a1a7f Mon Sep 17 00:00:00 2001 From: dxtr Date: Sat, 26 Aug 2023 10:20:23 +0200 Subject: [PATCH 2/4] getTicks64 should only exist under the RECENT_ISH flag --- src/SDL/Raw/Timer.hs | 15 ++++++++++----- src/SDL/Time.hs | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/SDL/Raw/Timer.hs b/src/SDL/Raw/Timer.hs index 3c85c880..823a0626 100644 --- a/src/SDL/Raw/Timer.hs +++ b/src/SDL/Raw/Timer.hs @@ -20,9 +20,12 @@ 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_GetTicks64" getTicks64FFI :: IO Word64 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 #-} @@ -43,10 +46,12 @@ getTicks :: MonadIO m => m Word32 getTicks = liftIO getTicksFFI {-# INLINE getTicks #-} -getTicks64 :: MonadIO m => m Word64 -getTicks64 = liftIO getTicks64FFI -{-# INLINE getTicks64 #-} - 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 diff --git a/src/SDL/Time.hs b/src/SDL/Time.hs index b9020b4b..daf6df1c 100644 --- a/src/SDL/Time.hs +++ b/src/SDL/Time.hs @@ -1,10 +1,10 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} module SDL.Time ( -- * Time Measurement ticks - , ticks64 , time -- * Timer @@ -14,6 +14,10 @@ module SDL.Time , RetriggerTimer(..) , addTimer , removeTimer + +#ifdef RECENT_ISH + , ticks64 +#endif ) where import Control.Monad.IO.Class (MonadIO, liftIO) @@ -34,12 +38,6 @@ import qualified SDL.Raw.Types as Raw ticks :: MonadIO m => m Word32 ticks = Raw.getTicks --- | Number of milliseconds since library initialization. --- --- See @@ for C documentation. -ticks64 :: MonadIO m => m Word64 -ticks64 = Raw.getTicks64 - -- | The current time in seconds since some arbitrary starting point (consist over the life of the application). -- -- This time is derived from the system's performance counter - see @@ and @@ for C documentation about the implementation. @@ -100,3 +98,11 @@ addTimer timeout callback = liftIO $ do -- See @@ for C documentation. removeTimer :: MonadIO m => Timer -> m Bool removeTimer f = liftIO $ runTimerRemoval f + +#ifdef RECENT_ISH +-- | Number of milliseconds since library initialization. +-- +-- See @@ for C documentation. +ticks64 :: MonadIO m => m Word64 +ticks64 = Raw.getTicks64 +#endif From 195661f7d85e394b075e89c83510dd7569cf20e2 Mon Sep 17 00:00:00 2001 From: dxtr Date: Sat, 26 Aug 2023 10:21:57 +0200 Subject: [PATCH 3/4] Forgot to ifdef a line --- src/SDL/Raw/Timer.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SDL/Raw/Timer.hs b/src/SDL/Raw/Timer.hs index 823a0626..f314a078 100644 --- a/src/SDL/Raw/Timer.hs +++ b/src/SDL/Raw/Timer.hs @@ -5,8 +5,11 @@ module SDL.Raw.Timer ( getPerformanceCounter, getPerformanceFrequency, getTicks, - getTicks64, removeTimer + +#ifdef RECENT_ISH + , getTicks64 +#endif ) where import Control.Monad.IO.Class From 6553a2317ca51daa90df6fa5bce443919c42ce21 Mon Sep 17 00:00:00 2001 From: dxtr Date: Sat, 26 Aug 2023 11:15:35 +0200 Subject: [PATCH 4/4] Add the required LANGUAGE pragmas --- src/SDL/Raw/Timer.hs | 2 ++ src/SDL/Time.hs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/SDL/Raw/Timer.hs b/src/SDL/Raw/Timer.hs index f314a078..00e4d540 100644 --- a/src/SDL/Raw/Timer.hs +++ b/src/SDL/Raw/Timer.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + module SDL.Raw.Timer ( -- * Timer Support addTimer, diff --git a/src/SDL/Time.hs b/src/SDL/Time.hs index daf6df1c..861e4859 100644 --- a/src/SDL/Time.hs +++ b/src/SDL/Time.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-}