Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ticks64 #294

Merged
merged 4 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading