Improve level generation speed
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
{-
|
||||
Inanimate objects such as lamps, barrels, etc
|
||||
-}
|
||||
@@ -17,11 +17,13 @@ import Dodge.WorldEvent.Sound
|
||||
import Dodge.Creature.Update hiding (CRUpdate)
|
||||
import Picture
|
||||
import qualified IntMapHelp as IM
|
||||
import Geometry.Data
|
||||
import Geometry
|
||||
--import Geometry.Data
|
||||
import Geometry.Vector3D
|
||||
import Polyhedra
|
||||
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as L
|
||||
|
||||
defaultInanimate :: Creature
|
||||
defaultInanimate = defaultCreature & crActionPlan .~ Inanimate
|
||||
@@ -30,15 +32,30 @@ lamp :: Float -> Creature
|
||||
lamp h = defaultInanimate
|
||||
{ _crUpdate = initialiseLamp h
|
||||
, _crHP = 100
|
||||
, _crPict = picAtCrPos (lampPic h)
|
||||
, _crPict = picAtCrPosNoRot (lampPic h)
|
||||
, _crRad = 3
|
||||
, _crMass = 3
|
||||
}
|
||||
-- it is not clear that any of the attempts with Foldl help at all here
|
||||
lampPic :: Float -> Picture
|
||||
lampPic h = pictures
|
||||
[ setLayer 0 $ pictures . map (helpPoly3D . map ((, blue) . (-.-.- V3 2.5 2.5 0))) $ boxXYZ 5 5 (h-1)
|
||||
, setLayer 1 $ setDepth h $ color white $ circleSolid 3
|
||||
]
|
||||
--{-# INLINE lampPic #-}
|
||||
lampPic h = setLayer 1 (setDepth h . color white $ circleSolid 3)
|
||||
++ (concatMap (preTriFold f) $ boxXYZnobase 5 5 (h-1))
|
||||
where
|
||||
f pos = Verx (pos -.-.- V3 2.5 2.5 0) blue [] 0 polyNum
|
||||
|
||||
lTriFold :: a -> a -> L.Fold a [a]
|
||||
lTriFold s x = L.Fold (f s) (x,[]) snd
|
||||
where
|
||||
f s' (x1,l) x2 = (x2,s':x1:x2:l)
|
||||
|
||||
preTriFold :: (a -> b) -> [a] -> [b]
|
||||
preTriFold f (s:x:xs) = L.fold (L.premap f $ lTriFold (f s) (f x)) xs
|
||||
preTriFold _ _ = []
|
||||
|
||||
polyToTriFold :: [a] -> [a]
|
||||
polyToTriFold (s:x:xs) = L.fold (lTriFold s x) xs
|
||||
polyToTriFold _ = []
|
||||
|
||||
initialiseLamp :: Float -> CRUpdate
|
||||
initialiseLamp h w (f,g) cr = ( (addLS . f , g), Just $ cr & crUpdate .~ updateLamp h i)
|
||||
|
||||
Reference in New Issue
Block a user