mirror of
https://github.com/reanimate/reanimate.git
synced 2026-09-12 00:23:08 +00:00
hash frames (#157)
* cache frames via hashing * use reanimate-svg-0.10.3.0 * NFC: whitespace * Add hashable-1.3.0.0 to extra deps in lts-13,14 * allow-newer in lts-13 Co-authored-by: David Himmelstrup <lemmih@gmail.com>
This commit is contained in:
parent
1c7fa10f86
commit
e9f893b6e3
2 changed files with 12 additions and 5 deletions
|
|
@ -118,7 +118,7 @@ library
|
|||
fsnotify >=0.3.0.1,
|
||||
geojson >=3.0.4,
|
||||
ghcid >=0.7,
|
||||
hashable >=1.2.7.0,
|
||||
hashable >=1.3.0.0,
|
||||
hgeometry >=0.11.0.0,
|
||||
hgeometry-combinatorial >=0.11.0.0,
|
||||
lens >=4.16.1,
|
||||
|
|
@ -137,6 +137,7 @@ library
|
|||
temporary >=1.3,
|
||||
text >=1.2.3.0,
|
||||
time >=1.8.0.0,
|
||||
unordered-containers,
|
||||
vector >=0.12.0.0,
|
||||
vector-space >=0.13,
|
||||
websockets >=0.12.7.0,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import Control.Exception
|
|||
import Control.Monad (forM_, forever, unless, void, when)
|
||||
import Data.Either
|
||||
import Data.Function
|
||||
import qualified Data.HashMap.Strict as M
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as T
|
||||
import Data.Time
|
||||
|
|
@ -63,15 +64,20 @@ renderSvgs :: FilePath -> Int -> Bool -> Animation -> IO ()
|
|||
renderSvgs folder offset _prettyPrint ani = do
|
||||
print frameCount
|
||||
lock <- newMVar ()
|
||||
|
||||
hashedFrames <- newMVar M.empty
|
||||
handle errHandler $ concurrentForM_ (frameOrder rate frameCount) $ \nth' -> do
|
||||
let nth = (nth'+offset) `mod` frameCount
|
||||
now = (duration ani / (fromIntegral frameCount - 1)) * fromIntegral nth
|
||||
frame = frameAt (if frameCount <= 1 then 0 else now) ani
|
||||
svg = renderSvg Nothing Nothing frame
|
||||
path = folder </> show nth <.> "svg"
|
||||
|
||||
idempotentFile path $ writeFile path svg
|
||||
cachedFrame <- M.lookup frame <$> readMVar hashedFrames
|
||||
idempotentFile path $
|
||||
case cachedFrame of
|
||||
Nothing -> do
|
||||
let svg = renderSvg Nothing Nothing frame
|
||||
writeFile path svg
|
||||
modifyMVar_ hashedFrames $ \hm -> pure $ M.insert frame path hm
|
||||
Just frameFile -> copyFile frameFile path
|
||||
withMVar lock $ \_ -> do
|
||||
print nth
|
||||
hFlush stdout
|
||||
|
|
|
|||
Loading…
Reference in a new issue