packages feed

timers-tick 0.3.0.0 → 0.4.0.0

raw patch · 4 files changed

+38/−20 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

changes.txt view
@@ -1,3 +1,9 @@+0.4.0.0+-------++- Fixed loop/expire bug.+- Released Thu 15 Mar 2018 11:51:15 CET.+ 0.3.0.0 ------- 
src/Control/Timer/Tick.hs view
@@ -18,7 +18,7 @@ module Control.Timer.Tick ( -- * Simple timers                             creaTimer,                             creaBoolTimer,-                            -- * Timed Resources+                            -- * Timed resources                             Timed,                             creaTimedRes,                             Loop(..),@@ -63,7 +63,8 @@                           tOrigLoop :: Loop,                            -- convenience-                          tMaxTicks :: Maybe Integer,+                          tLoopTicks   :: Integer,+                          tExpireTicks :: Maybe Integer,                            --  curr                           tCurrTick :: Integer,@@ -135,16 +136,17 @@ creaTimedRes :: Loop -> [(Integer, a)] -> Timed a creaTimedRes _ [] = error "Cannot create an empty TimedRes" creaTimedRes l ss = TimedRes ss l l-                             maxTricks+                             loopTicks expTicks                              0 False     where-          maxTricks :: Maybe Integer-          maxTricks = case l of-                        AlwaysLoop     -> Nothing-                        Times _ Elapse -> Just (sum . map fst $ ss)-                        Times _ Reach  -> Just (sum . map fst $ init ss)+          loopTicks = sum . map fst $ ss +          expTicks = case l of+                       AlwaysLoop     -> Nothing+                       Times _ Reach  -> Just $ sum . map fst $ init ss+                       Times _ Elapse -> Just $ loopTicks + ------------- -- OPERATE -- -------------@@ -152,13 +154,26 @@ -- | Ticks the timer (one step). tick :: Timed a -> Timed a tick t | isExpired t = t-       | otherwise   =-            let t' = t { tCurrTick = succ (tCurrTick t) } in+       | willExpire  = expire t'+       | willLoop    = loop t'+       | otherwise   = t'+    where+          newTicks = tCurrTick t + 1+          t'       = t { tCurrTick = newTicks } -            if Just (tCurrTick t') == tMaxTicks t'-              then expire t'-              else t'+          willExpire = case tLoop t of+                         Times 1 _ -> Just newTicks == tExpireTicks t+                         _         -> False+          willLoop   = not willExpire &&+                       newTicks == tLoopTicks t +loop :: Timed a -> Timed a+loop tm = case tLoop tm of+            AlwaysLoop -> tm { tCurrTick = 0 }+            -- il check è già dentro a tick+            Times n eb -> tm { tLoop = Times (n-1) eb,+                               tCurrTick = 0 }+ expire :: Timed a -> Timed a expire tm = -- need this as last tick on Elapse is OOB             if isElB (tLoop tm)@@ -166,14 +181,9 @@               else expx     where           expx = case tLoop tm of-                   -- infinite loop-                   AlwaysLoop -> tm { tCurrTick = 0 }-                   -- last loop of a timed resource                    Times 1 eb  -> tm { tLoop = Times 0 eb,                                        tExpired = True }-                   -- not-last loop of a timed resource-                   Times n eb -> tm { tLoop = Times (n-1) eb,-                                      tCurrTick = 0 }+                   _           -> error "non 1 Times in `expire`"            isElB (Times _ Elapse) = True           isElB _                = False
test/Control/Timer/TickSpec.hs view
@@ -47,6 +47,8 @@       isExpired (ticks 20 ta) `shouldBe` False     it "expires appropriately" $       isExpired (ticks 1 t) `shouldBe` False+    it "does not error on cycling" $+      fetchFrame (ticks 20 ta) `shouldBe` ()    describe "isExpired" $ do     let st = creaBoolTimer 10
timers-tick.cabal view
@@ -1,5 +1,5 @@ name:                timers-tick-version:             0.3.0.0+version:             0.4.0.0 synopsis:            tick based timers description:         Tick-based timers and utilities, for games and                      discrete-time programs.