optimization with new graphics library

This commit is contained in:
nek0 2023-12-04 22:05:22 +01:00
parent 99d16557ec
commit ab2d4b9add

View file

@ -2,7 +2,7 @@ module Main where
import Linear as L
import Data.Matrix as M
import Data.Matrix as M hiding ((<->))
import qualified Data.Vector as V
import Data.Maybe
@ -76,19 +76,21 @@ main = do
return Nothing
_ -> return Nothing
outputs <- withMVar state draw
withMVar state (\s -> when (not (stop s)) $ do
let foutput = V.toList $
V.foldl (\acc a -> acc V.++ a V.++ V.singleton '\n')
V.empty
image <- withMVar state (\s -> do
let foutput =
V.foldl (\acc a -> acc <-> a)
emptyImage
( outputs
-- V.++ V.singleton (V.fromList $ show char)
-- V.++ V.singleton (V.fromList $ show (pos s) ++ " " ++ show (rot s))
V.++ V.singleton (V.empty)
V.++ V.singleton (V.empty)
V.++ V.singleton (V.empty)
V.++ V.singleton (emptyImage)
V.++ V.singleton (emptyImage)
V.++ V.singleton (emptyImage)
)
deepseq foutput (putStr foutput)
pure foutput
)
let picture = picForImage image
update vty picture
-- threadDelay msdelay
-- hSetEcho stdin True
-- showCursor
@ -114,17 +116,17 @@ handleInput char state = do
_ -> state
return nstate
draw :: State -> IO (V.Vector (V.Vector Char))
draw :: State -> IO (V.Vector Image)
draw (State ppos prot _ _ vty) = do
(w, h) <- displayBounds (outputIface vty)
let dims@(dw, dh) = (w, (h - 4))
out = (V.generate (fromIntegral dh)
((\mh ->
let dims@(dw, dh) = (w, h - 4)
out = V.generate (fromIntegral dh)
((\mh -> string defAttr $ V.toList $
V.map
(\mw -> drawPixel prot ppos dims (mw, mh))
(V.generate (fromIntegral dw) fromIntegral)
) . fromIntegral)
) `using` parVector
`using` parVector
return out
drawPixel :: Double -> V2 Double -> (Int, Int) -> (Double, Double) -> Char