More streaming refactoring

This commit is contained in:
2022-06-24 23:37:01 +01:00
parent 0270d423fd
commit 3c2df2542a
10 changed files with 96 additions and 198 deletions
+16 -21
View File
@@ -34,6 +34,8 @@ import Control.Applicative
--import qualified Data.Set as S
--import Data.Monoid
--import System.Random
import qualified Streaming.Prelude as S
--import Streaming
{- For most menus the only way to change the world is using event handling. -}
updateUniverse :: Universe -> Universe
@@ -286,19 +288,24 @@ ppEvents :: World -> World
ppEvents w = IM.foldl' (flip $ \pp -> _ppEvent pp pp) w $ _pressPlates w
-- this is not working correctly, maybe a problem with wallsAlongLine
--updateSeenWalls :: World -> World
--updateSeenWalls w = foldl' markWallSeen w wallsToUpdate
-- where
-- vPos = _cameraViewFrom w
-- wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ wallsAlongLine vPos (vPos +.+ p) w)
-- $ nRays 20
updateSeenWalls :: World -> World
updateSeenWalls w = foldl' markWallSeen w wallsToUpdate
updateSeenWalls w = runIdentity $ S.fold_ f w id (S.map (_wlID . snd) $ allVisibleWalls w)
where
vPos = _cameraViewFrom w
wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ wallsAlongLine vPos (vPos +.+ p) w)
$ nRays 20
-- wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ _walls w)
f w' i = w' & walls . ix i . wlSeen .~ True
-- wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ wallsAlongLine vPos (vPos +.+ p) w)
-- $ nRays 20
markWallSeen :: World -> Wall -> World
markWallSeen w wl = w { _walls = IM.adjust mw (_wlID wl) $ _walls w }
where
mw wl' = wl' {_wlSeen = True}
--markWallSeen :: World -> Wall -> World
--markWallSeen w wl = w { _walls = IM.adjust mw (_wlID wl) $ _walls w }
-- where
-- mw wl' = wl' {_wlSeen = True}
checkEndGame :: World -> World
checkEndGame w = case _deathDelay w of
@@ -398,18 +405,6 @@ crCrSpring c1 c2 w
overlap2 = ((comRad - diff) * _crMass c1 * 0.5 / massT) *.* errorNormalizeV 56 vec
massT = _crMass c1 + _crMass c2
{- Finds the visible walls from a point to another point. -}
visibleWalls :: Point2 -> Point2 -> IM.IntMap Wall -> [Wall]
visibleWalls p1 p2 ws
= takeUntil wlIsOpaque
. map snd
. sortOn (dist p1 . fromJust . fst)
. filter (isJust . fst)
. map f
$ IM.elems ws
where
f wl = (uncurry intersectSegSeg (_wlLine wl) p1 p2, wl)
updateDelayedEvents :: World -> World
updateDelayedEvents w = let (neww,newde) = mapAccumR f w (_delayedEvents w)
in neww & delayedEvents .~ catMaybes newde