Make Shapes use Streaming rather than Vector streaming

This commit is contained in:
2022-07-03 23:04:58 +01:00
parent 02fcb5f072
commit f9a904d52b
11 changed files with 54 additions and 47 deletions
+12 -9
View File
@@ -22,6 +22,8 @@ import qualified Data.Vector.Fusion.Stream.Monadic as VS
--import Data.Vector.Fusion.Util
import Control.Monad.Primitive
--import qualified Control.Monad.Parallel as MP
import qualified Streaming.Prelude as S
import Streaming
pokeVerxs
:: MV.MVector (PrimState IO) FullShader
@@ -50,9 +52,9 @@ pokeWallsWindowsFloor
-> [ ( Point3 , Point3 ) ]
-> IO (Int,Int,Int)
pokeWallsWindowsFloor wlptr wiptr flptr wls wis fls = do
wlcounts1 <- VS.foldM (pokeW wlptr) 0 (VS.fromList wls)
wlcounts2 <- VS.foldM (pokeW wiptr) 0 (VS.fromList wis)
flcounts <- VS.foldM (pokeF flptr) 0 (VS.fromList fls)
wlcounts1 <- VS.foldM' (pokeW wlptr) 0 (VS.fromList wls)
wlcounts2 <- VS.foldM' (pokeW wiptr) 0 (VS.fromList wis)
flcounts <- VS.foldM' (pokeF flptr) 0 (VS.fromList fls)
return (wlcounts1,wlcounts2,flcounts)
pokeF :: Ptr Float -> Int -> (Point3,Point3) -> IO Int
@@ -80,9 +82,10 @@ pokeW ptr i' ((V2 a b,V2 c d),V4 e f g h) = do
return $ i' + 1
pokeShape :: Ptr Float -> Ptr GLushort -> Ptr GLushort
-> [ShapeObj]
-> Stream (Of ShapeObj) IO ()
-> IO (Int,Int,Int)
pokeShape ptr iptr ieptr = VS.foldM (pokeShapeObj ptr iptr ieptr) (0,0,0) . VS.fromList
pokeShape ptr iptr ieptr = S.foldM_ (pokeShapeObj ptr iptr ieptr) (return (0,0,0)) return
pokeShapeObj
:: Ptr Float
@@ -98,14 +101,14 @@ pokeShapeObj ptr iptr ieptr counts (ShapeObj shType shVerts) = case shType of
pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort
-> Ptr GLushort
-> (Int,Int,Int)
-> VS.Stream IO ShapeV
-> Stream (Of ShapeV) IO ()
-> IO (Int,Int,Int)
--{-# INLINE pokeTopPrism #-}
pokeTopPrism size ptr iptr ieptr (nv,nshapeindices,nedgeindices) svs = do
nv' <- VS.foldM (pokeJustV ptr) nv svs
nshapeindices' <- UV.foldM (pokeTopPrismIndex nv iptr) nshapeindices
nv' <- S.foldM_ (pokeJustV ptr) (return nv) return svs
nshapeindices' <- UV.foldM' (pokeTopPrismIndex nv iptr) nshapeindices
(memoTopPrismIndices V.! size)
nedgeindices' <- UV.foldM (pokeTopPrismEdgeIndex nv ieptr) nedgeindices
nedgeindices' <- UV.foldM' (pokeTopPrismEdgeIndex nv ieptr) nedgeindices
(memoTopPrismEdgeIndices V.! size)
return (nv', nshapeindices', nedgeindices')