From 67ecbcfc95a8d2c214fac546fc7d2e83d4c4fc10 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 15 May 2018 21:24:01 +0200 Subject: Don't update level when unneccessary --- trivmix/Trivmix.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'trivmix') diff --git a/trivmix/Trivmix.hs b/trivmix/Trivmix.hs index 5cddf6f..7c18965 100644 --- a/trivmix/Trivmix.hs +++ b/trivmix/Trivmix.hs @@ -194,7 +194,9 @@ trivmix Options{..} = do mulBalance (bToScientific -> b) x = either error id $ asScientific (*) (Lin . either error id $ refine b) x newLevel <- mulBalance <$> readMVar balance <*> readMVar level currentLevel <- (\(CFloat f) -> Lin . either error id . refine $ realToFrac f) <$> readMVar level' - mapM_ (\x -> (swapMVar level' $! toRealFloat . unrefine . toLin $ linInt' x currentLevel newLevel) >> threadDelay delay) (takeWhile (<= 1) $ iterate (+ recip frames) 0) + case compare currentLevel newLevel of + EQ -> threadDelay . round $ interval * 1e6 + _ -> mapM_ (\x -> (swapMVar level' $! toRealFloat . unrefine . toLin $ linInt' x currentLevel newLevel) >> threadDelay delay) (takeWhile (<= 1) $ iterate (+ recip frames) 0) notifyReady forever $ threadDelay (round $ watchdogInterval * 1e6) >> notifyWatchdog -- cgit v1.2.3