Turn shapeObject's vertices into a stream
This commit is contained in:
@@ -12,5 +12,5 @@ data ForegroundShape = ForegroundShape
|
|||||||
, _fsRad :: Float -- This should probably be a bounding box
|
, _fsRad :: Float -- This should probably be a bounding box
|
||||||
, _fsSPic :: SPic
|
, _fsSPic :: SPic
|
||||||
}
|
}
|
||||||
deriving (Eq,Show,Ord)
|
deriving ()
|
||||||
makeLenses ''ForegroundShape
|
makeLenses ''ForegroundShape
|
||||||
|
|||||||
+8
-8
@@ -45,14 +45,14 @@ initialAnoTree = OnwardList
|
|||||||
, AnRoom slowDoorRoom
|
, AnRoom slowDoorRoom
|
||||||
-- , AnRoom $ roomCCrits 10
|
-- , AnRoom $ roomCCrits 10
|
||||||
, AnTree firstBreather
|
, AnTree firstBreather
|
||||||
-- , AnTree $ telRoomLev 1 >>= rToOnward "telRoomLev" . pure . cleatOnward
|
, AnTree $ telRoomLev 1 >>= rToOnward "telRoomLev" . pure . cleatOnward
|
||||||
-- ]
|
]
|
||||||
--
|
|
||||||
--extraAnoList :: [Annotation]
|
extraAnoList :: [Annotation]
|
||||||
--extraAnoList =
|
extraAnoList =
|
||||||
---- , (SpecificRoom . return . tToBTree $ treePost [corridor,corridor,cleatOnward corridor])
|
-- , (SpecificRoom . return . tToBTree $ treePost [corridor,corridor,cleatOnward corridor])
|
||||||
-- [ AnRoom $ roomCCrits 10
|
[ AnRoom $ roomCCrits 10
|
||||||
-- , AnRoom $ roomCCrits 10
|
, AnRoom $ roomCCrits 10
|
||||||
, AnTree $ tToBTree "spawners" <$> spawnerRoom
|
, AnTree $ tToBTree "spawners" <$> spawnerRoom
|
||||||
, AnRoom pistolerRoom
|
, AnRoom pistolerRoom
|
||||||
, AnRoom doubleCorridorBarrels
|
, AnRoom doubleCorridorBarrels
|
||||||
|
|||||||
@@ -125,14 +125,14 @@ putShape sh = PutForeground $ defaultForeground
|
|||||||
& fsRad .~ radBounds bnds
|
& fsRad .~ radBounds bnds
|
||||||
& fsSPic .~ noPic (uncurryV translateSHf (-m) $ sh)
|
& fsSPic .~ noPic (uncurryV translateSHf (-m) $ sh)
|
||||||
where
|
where
|
||||||
bnds = shapeBounds sh
|
bnds = (0,0,0,0) -- shapeBounds sh
|
||||||
m = midBounds bnds
|
m = midBounds bnds
|
||||||
|
|
||||||
shapePoints :: Shape -> Stream (Of Point2) Identity ()
|
--shapePoints :: Shape -> Stream (Of Point2) Identity ()
|
||||||
shapePoints = S.each . concatMap (map (stripZ . _svPos) . _shVs)
|
--shapePoints = S.each . concatMap (map (stripZ . _svPos) . _shVs)
|
||||||
|
|
||||||
shapeBounds :: Shape -> (Float,Float,Float,Float)
|
--shapeBounds :: Shape -> (Float,Float,Float,Float)
|
||||||
shapeBounds = fromMaybe (0,0,0,0) . boundPoints . shapePoints
|
--shapeBounds = fromMaybe (0,0,0,0) . boundPoints . shapePoints
|
||||||
|
|
||||||
midBounds :: (Float,Float,Float,Float) -> Point2
|
midBounds :: (Float,Float,Float,Float) -> Point2
|
||||||
midBounds (n,s,e,w) = V2 ((n + s)/2) ((e + w)/2)
|
midBounds (n,s,e,w) = V2 ((n + s)/2) ((e + w)/2)
|
||||||
|
|||||||
+2
-1
@@ -5,6 +5,7 @@ module RandomHelp
|
|||||||
, module RandomHelp
|
, module RandomHelp
|
||||||
) where
|
) where
|
||||||
import Geometry
|
import Geometry
|
||||||
|
import StrictHelp
|
||||||
|
|
||||||
import System.Random
|
import System.Random
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
@@ -48,7 +49,7 @@ shuffle xs = do
|
|||||||
let f ys rand = let (as,b:bs) = splitAt rand ys
|
let f ys rand = let (as,b:bs) = splitAt rand ys
|
||||||
in (as ++ bs, b)
|
in (as ++ bs, b)
|
||||||
let (_,zs) = mapAccumR f xs rands
|
let (_,zs) = mapAccumR f xs rands
|
||||||
return zs
|
return $ forceElements zs `seq` zs
|
||||||
|
|
||||||
-- | Randomly shuffle the tail of a list, not safe.
|
-- | Randomly shuffle the tail of a list, not safe.
|
||||||
shuffleTail :: RandomGen g => [a] -> State g [a]
|
shuffleTail :: RandomGen g => [a] -> State g [a]
|
||||||
|
|||||||
+6
-2
@@ -19,6 +19,7 @@ import qualified Data.Vector.Unboxed as UV
|
|||||||
import qualified Data.Vector.Unboxed.Mutable as UMV
|
import qualified Data.Vector.Unboxed.Mutable as UMV
|
||||||
import qualified Data.Vector.Mutable as MV
|
import qualified Data.Vector.Mutable as MV
|
||||||
import qualified Data.Vector.Fusion.Stream.Monadic as VS
|
import qualified Data.Vector.Fusion.Stream.Monadic as VS
|
||||||
|
import Data.Vector.Fusion.Util
|
||||||
import Control.Monad.Primitive
|
import Control.Monad.Primitive
|
||||||
--import qualified Control.Monad.Parallel as MP
|
--import qualified Control.Monad.Parallel as MP
|
||||||
|
|
||||||
@@ -102,11 +103,11 @@ pokeShapeObj ptr iptr ieptr counts (ShapeObj shType shVerts) = case shType of
|
|||||||
pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort
|
pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort
|
||||||
-> Ptr GLushort
|
-> Ptr GLushort
|
||||||
-> (Int,Int,Int)
|
-> (Int,Int,Int)
|
||||||
-> [ShapeV]
|
-> VS.Stream IO ShapeV
|
||||||
-> IO (Int,Int,Int)
|
-> IO (Int,Int,Int)
|
||||||
{-# INLINE pokeTopPrism #-}
|
{-# INLINE pokeTopPrism #-}
|
||||||
pokeTopPrism size ptr iptr ieptr (nv,nshapeindices,nedgeindices) svs = do
|
pokeTopPrism size ptr iptr ieptr (nv,nshapeindices,nedgeindices) svs = do
|
||||||
nv' <- VS.foldM (pokeJustV ptr) nv (VS.fromList svs)
|
nv' <- VS.foldM (pokeJustV ptr) nv svs
|
||||||
nshapeindices' <- UV.foldM (pokeTopPrismIndex nv iptr) nshapeindices
|
nshapeindices' <- UV.foldM (pokeTopPrismIndex nv iptr) nshapeindices
|
||||||
(memoTopPrismIndices V.! size)
|
(memoTopPrismIndices V.! size)
|
||||||
nedgeindices' <- UV.foldM (pokeTopPrismEdgeIndex nv ieptr) nedgeindices
|
nedgeindices' <- UV.foldM (pokeTopPrismEdgeIndex nv ieptr) nedgeindices
|
||||||
@@ -117,6 +118,7 @@ pokeTopPrismEdgeIndex :: Int -> Ptr GLushort
|
|||||||
-> Int
|
-> Int
|
||||||
-> Int
|
-> Int
|
||||||
-> IO Int
|
-> IO Int
|
||||||
|
{-# INLINE pokeTopPrismEdgeIndex #-}
|
||||||
pokeTopPrismEdgeIndex nv eiptr nedgeindices ioff = do
|
pokeTopPrismEdgeIndex nv eiptr nedgeindices ioff = do
|
||||||
pokeElemOff eiptr nedgeindices (fromIntegral $ nv + ioff)
|
pokeElemOff eiptr nedgeindices (fromIntegral $ nv + ioff)
|
||||||
return $ nedgeindices + 1
|
return $ nedgeindices + 1
|
||||||
@@ -125,6 +127,7 @@ pokeTopPrismIndex :: Int -> Ptr GLushort
|
|||||||
-> Int
|
-> Int
|
||||||
-> Int
|
-> Int
|
||||||
-> IO Int
|
-> IO Int
|
||||||
|
{-# INLINE pokeTopPrismIndex #-}
|
||||||
pokeTopPrismIndex nv iptr nshapeindices ioff = do
|
pokeTopPrismIndex nv iptr nshapeindices ioff = do
|
||||||
pokeElemOff iptr nshapeindices (fromIntegral $ nv + ioff)
|
pokeElemOff iptr nshapeindices (fromIntegral $ nv + ioff)
|
||||||
return $ nshapeindices + 1
|
return $ nshapeindices + 1
|
||||||
@@ -165,6 +168,7 @@ pokeJustV :: Ptr Float
|
|||||||
-> Int
|
-> Int
|
||||||
-> ShapeV
|
-> ShapeV
|
||||||
-> IO Int
|
-> IO Int
|
||||||
|
{-# INLINE pokeJustV #-}
|
||||||
pokeJustV ptr nv sh = do
|
pokeJustV ptr nv sh = do
|
||||||
let off i = nv*7 + i
|
let off i = nv*7 + i
|
||||||
pokeElemOff ptr (off 0) a
|
pokeElemOff ptr (off 0) a
|
||||||
|
|||||||
+13
-12
@@ -15,12 +15,13 @@ module Shape
|
|||||||
, scaleSH
|
, scaleSH
|
||||||
, colorSH
|
, colorSH
|
||||||
, overColSH
|
, overColSH
|
||||||
, overColSHM
|
-- , overColSHM
|
||||||
, overPosSH
|
, overPosSH
|
||||||
) where
|
) where
|
||||||
import Geometry
|
import Geometry
|
||||||
import Shape.Data
|
import Shape.Data
|
||||||
import Color
|
import Color
|
||||||
|
import qualified Data.Vector.Fusion.Stream.Monadic as VS
|
||||||
|
|
||||||
emptySH :: Shape
|
emptySH :: Shape
|
||||||
{-# INLINE emptySH #-}
|
{-# INLINE emptySH #-}
|
||||||
@@ -44,7 +45,7 @@ prismPoly
|
|||||||
-> [Point3]
|
-> [Point3]
|
||||||
-> Shape
|
-> Shape
|
||||||
{-# INLINE prismPoly #-}
|
{-# INLINE prismPoly #-}
|
||||||
prismPoly upps downps = [ShapeObj (TopPrism n) (f upps downps)]
|
prismPoly upps downps = [ShapeObj (TopPrism n) (VS.fromList $ f upps downps)]
|
||||||
where
|
where
|
||||||
n = length upps
|
n = length upps
|
||||||
f (a:as) (b:bs) = g a:g b:f as bs
|
f (a:as) (b:bs) = g a:g b:f as bs
|
||||||
@@ -57,7 +58,7 @@ upperPrismPoly
|
|||||||
-> [Point2]
|
-> [Point2]
|
||||||
-> Shape
|
-> Shape
|
||||||
{-# INLINE upperPrismPoly #-}
|
{-# INLINE upperPrismPoly #-}
|
||||||
upperPrismPoly h ps = [ShapeObj (TopPrism n) (f ps)]
|
upperPrismPoly h ps = [ShapeObj (TopPrism n) (VS.fromList $ f ps)]
|
||||||
where
|
where
|
||||||
n = length ps
|
n = length ps
|
||||||
g h' (V2 x y) = pairToSV (V3 x y h', black)
|
g h' (V2 x y) = pairToSV (V3 x y h', black)
|
||||||
@@ -69,7 +70,7 @@ upperPrismPolyHalf
|
|||||||
-> [Point2]
|
-> [Point2]
|
||||||
-> Shape
|
-> Shape
|
||||||
{-# INLINE upperPrismPolyHalf #-}
|
{-# INLINE upperPrismPolyHalf #-}
|
||||||
upperPrismPolyHalf h ps = [ShapeObj (TopPrism n) (f upps downps)]
|
upperPrismPolyHalf h ps = [ShapeObj (TopPrism n) (VS.fromList $ f upps downps)]
|
||||||
where
|
where
|
||||||
n = length ps
|
n = length ps
|
||||||
upps = map f' ps
|
upps = map f' ps
|
||||||
@@ -87,9 +88,9 @@ overColSH :: (Point4 -> Point4) -> Shape -> Shape
|
|||||||
{-# INLINE overColSH #-}
|
{-# INLINE overColSH #-}
|
||||||
overColSH = fmap . overColObj
|
overColSH = fmap . overColObj
|
||||||
|
|
||||||
overColSHM :: Monad m => (Point4 -> m Point4) -> Shape -> m Shape
|
--overColSHM :: Monad m => (Point4 -> m Point4) -> Shape -> m Shape
|
||||||
{-# INLINE overColSHM #-}
|
--{-# INLINE overColSHM #-}
|
||||||
overColSHM = mapM . overColObjM
|
--overColSHM = mapM . overColObjM
|
||||||
|
|
||||||
overPosSHI :: (Point3 -> Point3) -> Shape -> Shape
|
overPosSHI :: (Point3 -> Point3) -> Shape -> Shape
|
||||||
{-# INLINE overPosSHI #-}
|
{-# INLINE overPosSHI #-}
|
||||||
@@ -125,11 +126,11 @@ scaleSH (V3 a b c) = overPosSHI (\(V3 x y z) -> V3 (x*a) (y*b) (z*c))
|
|||||||
|
|
||||||
overColObj :: (Point4 -> Point4) -> ShapeObj -> ShapeObj
|
overColObj :: (Point4 -> Point4) -> ShapeObj -> ShapeObj
|
||||||
{-# INLINE overColObj #-}
|
{-# INLINE overColObj #-}
|
||||||
overColObj f (ShapeObj st vs) = ShapeObj st (map (overColVertex f) vs)
|
overColObj f (ShapeObj st vs) = ShapeObj st (VS.map (overColVertex f) vs)
|
||||||
|
|
||||||
overColObjM :: Monad m => (Point4 -> m Point4) -> ShapeObj -> m ShapeObj
|
--overColObjM :: Monad m => (Point4 -> m Point4) -> ShapeObj -> m ShapeObj
|
||||||
{-# INLINE overColObjM #-}
|
--{-# INLINE overColObjM #-}
|
||||||
overColObjM f (ShapeObj st vs) = ShapeObj st <$> mapM (svCol f) vs
|
--overColObjM f (ShapeObj st vs) = ShapeObj st <$> mapM (svCol f) vs
|
||||||
|
|
||||||
overColVertex :: (Point4 -> Point4) -> ShapeV -> ShapeV
|
overColVertex :: (Point4 -> Point4) -> ShapeV -> ShapeV
|
||||||
{-# INLINE overColVertex #-}
|
{-# INLINE overColVertex #-}
|
||||||
@@ -137,7 +138,7 @@ overColVertex f (ShapeV a b) = ShapeV a (f b)
|
|||||||
|
|
||||||
overPosObj :: (Point3 -> Point3) -> ShapeObj -> ShapeObj
|
overPosObj :: (Point3 -> Point3) -> ShapeObj -> ShapeObj
|
||||||
{-# INLINE overPosObj #-}
|
{-# INLINE overPosObj #-}
|
||||||
overPosObj f (ShapeObj st vs) = ShapeObj st $ map (overPosVertex f) vs
|
overPosObj f (ShapeObj st vs) = ShapeObj st $ VS.map (overPosVertex f) vs
|
||||||
|
|
||||||
overPosVertex :: (Point3 -> Point3) -> ShapeV -> ShapeV
|
overPosVertex :: (Point3 -> Point3) -> ShapeV -> ShapeV
|
||||||
{-# INLINE overPosVertex #-}
|
{-# INLINE overPosVertex #-}
|
||||||
|
|||||||
+11
-8
@@ -7,15 +7,18 @@ module Shape.Data
|
|||||||
where
|
where
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
|
|
||||||
|
import qualified Data.Vector.Fusion.Stream.Monadic as VS
|
||||||
|
import Data.Vector.Fusion.Util
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
type Shape = [ShapeObj]
|
type Shape = [ShapeObj]
|
||||||
_shVertices :: Shape -> [ShapeV]
|
|
||||||
{-# INLINE _shVertices #-}
|
|
||||||
_shVertices = concatMap _shVs
|
|
||||||
|
|
||||||
shVList :: Shape -> [ShapeV]
|
--_shVertices :: Shape -> [ShapeV]
|
||||||
{-# INLINE shVList #-}
|
--{-# INLINE _shVertices #-}
|
||||||
shVList = _shVertices
|
--_shVertices = concatMap _shVs
|
||||||
|
|
||||||
|
--shVList :: Shape -> [ShapeV]
|
||||||
|
--{-# INLINE shVList #-}
|
||||||
|
--shVList = _shVertices
|
||||||
--shVList = DL.toList . _shVertices
|
--shVList = DL.toList . _shVertices
|
||||||
|
|
||||||
{-# INLINE shVfromList #-}
|
{-# INLINE shVfromList #-}
|
||||||
@@ -27,9 +30,9 @@ shEfromList = id
|
|||||||
|
|
||||||
data ShapeObj = ShapeObj
|
data ShapeObj = ShapeObj
|
||||||
{ _shType :: ShapeType
|
{ _shType :: ShapeType
|
||||||
, _shVs :: [ShapeV]
|
, _shVs :: VS.Stream IO ShapeV
|
||||||
}
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving ()
|
||||||
|
|
||||||
newtype ShapeType = TopPrism Int
|
newtype ShapeType = TopPrism Int
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|||||||
Reference in New Issue
Block a user