Give proper foldl' and foldr methods for LTrees
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 4.5 KiB |
+1
-1
@@ -78,7 +78,7 @@ doDrawing pdata w = do
|
|||||||
if w ^. config . wall_textured
|
if w ^. config . wall_textured
|
||||||
then renderTextureWalls pdata nWalls
|
then renderTextureWalls pdata nWalls
|
||||||
else renderBlankWalls pdata nWalls
|
else renderBlankWalls pdata nWalls
|
||||||
_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic $ foregroundPics w)
|
_ <- renderFoldable pdata $ (picToAlt (Just 0) (polysToPic $ foregroundPics w) :: [RenderType])
|
||||||
_ <- renderFoldable pdata $ picToLTree (Just 0) pic
|
_ <- renderFoldable pdata $ picToLTree (Just 0) pic
|
||||||
_ <- renderShader (_textureArrayShader pdata) (_floorTiles w)
|
_ <- renderShader (_textureArrayShader pdata) (_floorTiles w)
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -4,8 +4,8 @@ module Picture.Data
|
|||||||
where
|
where
|
||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
|
|
||||||
--import Data.Foldable
|
import Data.Foldable
|
||||||
|
--import qualified Data.List as L
|
||||||
--import Data.Monoid
|
--import Data.Monoid
|
||||||
--import Data.Traversable
|
--import Data.Traversable
|
||||||
--import qualified Data.Foldable as F
|
--import qualified Data.Foldable as F
|
||||||
@@ -54,6 +54,14 @@ instance Foldable LTree where
|
|||||||
foldMap g (LBranches ts) = mconcat $ map (foldMap g) ts
|
foldMap g (LBranches ts) = mconcat $ map (foldMap g) ts
|
||||||
foldMap g (LLeaf a) = g a
|
foldMap g (LLeaf a) = g a
|
||||||
{-# INLINE foldMap #-}
|
{-# INLINE foldMap #-}
|
||||||
|
foldr _ x (LBranches []) = x
|
||||||
|
foldr g x (LBranches (t:ts)) = foldr g (foldr g x (LBranches ts)) t
|
||||||
|
foldr g x (LLeaf y) = g y x
|
||||||
|
{-# INLINE foldr #-}
|
||||||
|
foldl' _ x (LBranches []) = x
|
||||||
|
foldl' g x (LBranches (t:ts)) = foldl' g x t `seq` foldl' g (foldl' g x t) (LBranches ts)
|
||||||
|
foldl' g x (LLeaf y) = g x y
|
||||||
|
{-# INLINE foldl' #-}
|
||||||
instance Functor LTree where
|
instance Functor LTree where
|
||||||
fmap f (LBranches ts) = LBranches $ fmap (fmap f) ts
|
fmap f (LBranches ts) = LBranches $ fmap (fmap f) ts
|
||||||
fmap f (LLeaf x) = LLeaf (f x)
|
fmap f (LLeaf x) = LLeaf (f x)
|
||||||
|
|||||||
+78
-42
@@ -1,6 +1,8 @@
|
|||||||
{- Transform a picture into renderable objects. -}
|
{- Transform a picture into renderable objects. -}
|
||||||
module Picture.Tree
|
module Picture.Tree
|
||||||
( picToLTree
|
( picToLTree
|
||||||
|
, picToRenderList
|
||||||
|
, picToAlt
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Picture.Data
|
import Picture.Data
|
||||||
@@ -9,7 +11,7 @@ import Geometry.Data
|
|||||||
|
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.List
|
import Data.List
|
||||||
--import Control.Applicative
|
import Control.Applicative
|
||||||
--import Data.Maybe (isNothing)
|
--import Data.Maybe (isNothing)
|
||||||
|
|
||||||
-- todo: refactor out the layer check somehow
|
-- todo: refactor out the layer check somehow
|
||||||
@@ -65,47 +67,81 @@ picToLTree (Just j) (OnLayer i pic) | j == i = picToLTree Nothing pic
|
|||||||
| otherwise = LBranches []
|
| otherwise = LBranches []
|
||||||
picToLTree Nothing (OnLayer _ pic) = picToLTree Nothing pic
|
picToLTree Nothing (OnLayer _ pic) = picToLTree Nothing pic
|
||||||
|
|
||||||
--picToRenderType
|
-- might want to use the Alt newType
|
||||||
-- :: Picture
|
picToAlt
|
||||||
-- -> RenderType
|
:: (Alternative t, Monoid (t RenderType))
|
||||||
--{-# INLINE picToRenderType #-}
|
=> Maybe Int -- ^ Layer filter. Draw 'Nothing' when value is the same as at the leaf.
|
||||||
--picToRenderType (Polygon ps)
|
-> Picture
|
||||||
-- = RenderPoly $ zip (map zeroZ $ polyToTris ps) $ repeat black
|
-> t RenderType
|
||||||
--picToRenderType (PolygonZ ps z)
|
{-# INLINE picToAlt #-}
|
||||||
-- = RenderPolyZ $ zip3 (map zeroZ $ polyToTris ps) (repeat black) (repeat z)
|
picToAlt _ Blank = empty
|
||||||
--picToRenderType (PolygonCol vs)
|
picToAlt j (Pictures pics) = foldMap (picToAlt j) pics
|
||||||
-- = RenderPoly $ zip (map zeroZ $ polyToTris ps) $ polyToTris cs
|
picToAlt j (OverPic f f' (OverPic g g' pic)) = picToAlt j $ OverPic (f . g) (f' . g') pic
|
||||||
-- where
|
--picToAlt j (OverPic f f' (Pictures ps)) = concat $ fmap (picToAlt j . OverPic f f') ps
|
||||||
-- (ps,cs) = unzip vs
|
picToAlt j (OverPic f f' pic) = overPos f . overCol f' <$> picToAlt j pic
|
||||||
--picToRenderType (Poly3D vs) = RenderPoly $ polyToTris vs
|
picToAlt (Just j) (OnLayer i pic)
|
||||||
--picToRenderType (BezierQuad vs) = RenderBezQ $ zip3 (map zeroZ ps) cols rs
|
| j == i = picToAlt Nothing pic
|
||||||
-- where
|
| otherwise = empty
|
||||||
-- (ps,cols,offps,rads) = unzip4 vs
|
picToAlt Nothing (OnLayer _ pic) = picToAlt Nothing pic
|
||||||
-- rs = zipWith (\(x,y) (z,w) -> (x,y,z,w)) offps rads
|
picToAlt _ pic = pure $ picToRenderType pic
|
||||||
--picToRenderType (Circle colC colE r) = RenderEllipse
|
|
||||||
-- [( (-r, r,0), colC)
|
picToRenderList
|
||||||
-- ,( (-r,-r,0), colE)
|
:: Maybe Int -- ^ Layer filter. Draw 'Nothing' when value is the same as at the leaf.
|
||||||
-- ,( ( r,-r,0), black)
|
-> Picture
|
||||||
-- ]
|
-> [RenderType]
|
||||||
--picToRenderType (ThickArc startA endA rad wdth) = RenderArc
|
{-# INLINE picToRenderList #-}
|
||||||
-- [( (0,0,0),black,(0,0,wdth))
|
picToRenderList _ Blank = []
|
||||||
-- ,((xa,ya,0),black,(1,0,wdth))
|
picToRenderList j (Pictures pics) = concatMap (picToRenderList j) pics
|
||||||
-- ,((xb,yb,0),black,(1,1,wdth))
|
picToRenderList j (OverPic f f' (OverPic g g' pic)) = picToRenderList j $ OverPic (f . g) (f' . g') pic
|
||||||
-- ,( (0,0,0),black,(0,0,wdth))
|
picToRenderList j (OverPic f f' (Pictures ps)) = concatMap (picToRenderList j . OverPic f f') ps
|
||||||
-- ,((xb,yb,0),black,(1,1,wdth))
|
picToRenderList j (OverPic f f' pic) = overPos f . overCol f' <$> picToRenderList j pic
|
||||||
-- ,((xc,yc,0),black,(0,1,wdth))
|
picToRenderList (Just j) (OnLayer i pic)
|
||||||
-- ]
|
| j == i = picToRenderList Nothing pic
|
||||||
-- where
|
| otherwise = []
|
||||||
-- (xa,ya) = rotateV startA (rad,0)
|
picToRenderList Nothing (OnLayer _ pic) = picToRenderList Nothing pic
|
||||||
-- (xb,yb) = rotateV (0.5 * (startA + endA)) (rad * sqrt 2,0)
|
picToRenderList _ pic = [picToRenderType pic]
|
||||||
-- (xc,yc) = rotateV endA (rad,0)
|
|
||||||
--picToRenderType (Line ps)
|
picToRenderType
|
||||||
-- = RenderLine $ zip (map zeroZ $ doubleLine ps) $ repeat white
|
:: Picture
|
||||||
--picToRenderType (LineCol vs)
|
-> RenderType
|
||||||
-- = RenderLine $ zip (map zeroZ $ doubleLine ps) $ doubleLine cs
|
{-# INLINE picToRenderType #-}
|
||||||
-- where (ps,cs) = unzip vs
|
picToRenderType (Polygon ps)
|
||||||
--picToRenderType _ = error "Tried to make a render type from a tree picture"
|
= RenderPoly $ zip (map zeroZ $ polyToTris ps) $ repeat black
|
||||||
--picToRenderType (Text s) = RenderText $ stringToList s
|
picToRenderType (PolygonZ ps z)
|
||||||
|
= RenderPolyZ $ zip3 (map zeroZ $ polyToTris ps) (repeat black) (repeat z)
|
||||||
|
picToRenderType (PolygonCol vs)
|
||||||
|
= RenderPoly $ zip (map zeroZ $ polyToTris ps) $ polyToTris cs
|
||||||
|
where
|
||||||
|
(ps,cs) = unzip vs
|
||||||
|
picToRenderType (Poly3D vs) = RenderPoly $ polyToTris vs
|
||||||
|
picToRenderType (BezierQuad vs) = RenderBezQ $ zip3 (map zeroZ ps) cols rs
|
||||||
|
where
|
||||||
|
(ps,cols,offps,rads) = unzip4 vs
|
||||||
|
rs = zipWith (\(x,y) (z,w) -> (x,y,z,w)) offps rads
|
||||||
|
picToRenderType (Circle colC colE r) = RenderEllipse
|
||||||
|
[( (-r, r,0), colC)
|
||||||
|
,( (-r,-r,0), colE)
|
||||||
|
,( ( r,-r,0), black)
|
||||||
|
]
|
||||||
|
picToRenderType (ThickArc startA endA rad wdth) = RenderArc
|
||||||
|
[( (0,0,0),black,(0,0,wdth))
|
||||||
|
,((xa,ya,0),black,(1,0,wdth))
|
||||||
|
,((xb,yb,0),black,(1,1,wdth))
|
||||||
|
,( (0,0,0),black,(0,0,wdth))
|
||||||
|
,((xb,yb,0),black,(1,1,wdth))
|
||||||
|
,((xc,yc,0),black,(0,1,wdth))
|
||||||
|
]
|
||||||
|
where
|
||||||
|
(xa,ya) = rotateV startA (rad,0)
|
||||||
|
(xb,yb) = rotateV (0.5 * (startA + endA)) (rad * sqrt 2,0)
|
||||||
|
(xc,yc) = rotateV endA (rad,0)
|
||||||
|
picToRenderType (Line ps)
|
||||||
|
= RenderLine $ zip (map zeroZ $ doubleLine ps) $ repeat white
|
||||||
|
picToRenderType (LineCol vs)
|
||||||
|
= RenderLine $ zip (map zeroZ $ doubleLine ps) $ doubleLine cs
|
||||||
|
where (ps,cs) = unzip vs
|
||||||
|
picToRenderType (Text s) = RenderText $ stringToList s
|
||||||
|
picToRenderType _ = error "Tried to make a render type from a tree picture"
|
||||||
--
|
--
|
||||||
--picToAlternative
|
--picToAlternative
|
||||||
-- :: Alternative t
|
-- :: Alternative t
|
||||||
|
|||||||
Reference in New Issue
Block a user