Move streaming data into its own file

This commit is contained in:
2022-06-29 08:05:20 +01:00
parent b1a7e1bf35
commit 5501d6f9b5
12 changed files with 25 additions and 38 deletions
+1
View File
@@ -66,6 +66,7 @@ import Dodge.GameRoom
import Color import Color
import Data.Tile import Data.Tile
import MaybeHelp import MaybeHelp
--import StreamingHelp.Data
--import qualified Data.Vector as V --import qualified Data.Vector as V
import qualified Linear.Quaternion as Q import qualified Linear.Quaternion as Q
+1 -1
View File
@@ -35,7 +35,7 @@ defaultWorld = World
, _creatures = IM.empty , _creatures = IM.empty
, _crZoning = Zoning IM.empty crZoneSize zoneOfCreature , _crZoning = Zoning IM.empty crZoneSize zoneOfCreature
, _creatureGroups = IM.empty , _creatureGroups = IM.empty
, _clouds = [] , _clouds = mempty
, _clZoning = Zoning IM.empty clZoneSize (zonePos (stripZ . _clPos)) , _clZoning = Zoning IM.empty clZoneSize (zonePos (stripZ . _clPos))
, _gusts = IM.empty , _gusts = IM.empty
, _gsZoning = Zoning IM.empty clZoneSize (zonePos _guPos) , _gsZoning = Zoning IM.empty clZoneSize (zonePos _guPos)
+1 -2
View File
@@ -93,10 +93,9 @@ removePathsCrossing :: Point2 -> Point2 -> World -> World
removePathsCrossing a b w = w removePathsCrossing a b w = w
& pathGraph .~ newGraph & pathGraph .~ newGraph
& pathGraphP .~ pg' & pathGraphP .~ pg'
& phZoning %~ \zn -> foldl' (flip $ insertInZoning (:)) (zn & znObjects .~ mempty) & phZoning %~ \zn -> foldl' (flip $ updateZoning (:)) (zn & znObjects .~ mempty)
(labNodes newGraph) (labNodes newGraph)
where where
pg' = Set.filter (isNothing . uncurry (intersectSegSeg a b)) $ _pathGraphP w pg' = Set.filter (isNothing . uncurry (intersectSegSeg a b)) $ _pathGraphP w
insertpoint zn (i,p) = insertInZoneWith (wlZoneOfPoint p) (++) [(i,p)] zn
-- insertPoint pp@(_,p) = insertInZoneWith (wlZoneOfPoint p) (++) [pp] -- insertPoint pp@(_,p) = insertInZoneWith (wlZoneOfPoint p) (++) [pp]
newGraph = pairsToGraph dist pg' newGraph = pairsToGraph dist pg'
+1
View File
@@ -73,6 +73,7 @@ extraPics cfig w = pictures (_decorations w)
<> concatMapPic (dbArg _lsPict) (_lightSources w) <> concatMapPic (dbArg _lsPict) (_lightSources w)
<> testPic cfig w <> testPic cfig w
<> _debugPicture w <> _debugPicture w
-- <> runIdentity (S.foldMap_ clDraw (_clouds w))
<> concatMapPic clDraw (_clouds w ) <> concatMapPic clDraw (_clouds w )
<> concatMapPic ppDraw (_pressPlates w ) <> concatMapPic ppDraw (_pressPlates w )
<> soundPics cfig w <> soundPics cfig w
+4 -23
View File
@@ -98,11 +98,8 @@ functionalUpdate cfig w = checkEndGame
zoneClouds :: World -> World zoneClouds :: World -> World
zoneClouds w = w & clZoning %~ \zn -> zoneClouds w = w & clZoning %~ \zn ->
foldl' (flip $ insertInZoning (:)) (zn & znObjects .~ mempty) (_clouds w) foldl' (flip $ updateZoning (:)) (zn & znObjects .~ mempty) (_clouds w)
-- where --runIdentity (S.fold_ (flip $ updateZoning (:)) (zn & znObjects .~ mempty) id (_clouds w))
-- cloudInZone cl = insertInZoneWith p (++) [cl]
-- where
-- p = clZoneOfPoint $ stripZ $ _clPos cl
updateWorldSelect :: World -> World updateWorldSelect :: World -> World
updateWorldSelect w = case w ^? mouseButtons . ix ButtonLeft of updateWorldSelect w = case w ^? mouseButtons . ix ButtonLeft of
@@ -150,25 +147,8 @@ doRewind w = case _maybeWorld w of
zoneCreatures :: World -> World zoneCreatures :: World -> World
zoneCreatures w = w & crZoning %~ \zn -> zoneCreatures w = w & crZoning %~ \zn ->
foldl' (flip $ insertInZoning (\cr -> IM.insert (_crID cr) cr)) foldl' (flip $ updateZoning (\cr -> IM.insert (_crID cr) cr))
(zn & znObjects .~ mempty) (_creatures w) (zn & znObjects .~ mempty) (_creatures w)
-- . znObjects .~
-- IM.foldl' zoneCreature IM.empty (_creatures w)
---- runIdentity (S.fold_ zoneCreature IM.empty id (S.each $ _creatures w))
--
--zoneCreature :: IM.IntMap (IM.IntMap (IM.IntMap Creature))
-- -> Creature
-- -> IM.IntMap (IM.IntMap (IM.IntMap Creature))
--zoneCreature m cr = runIdentity $ S.fold_ doinsert m id (zoneOfCreature cr)
-- where
-- doinsert m' (V2 x y) = insertIMInZone x y (_crID cr) cr m'
-- IM.foldl' (flip creatureInZone) IM.empty (_creatures w)
-- where
-- creatureInZone cr = insertIMInZone x y cid cr
-- where
-- V2 x y = crZoneOfPoint $ _crPos cr
-- cid = _crID cr
updateCreatureSoundPositions :: World -> World updateCreatureSoundPositions :: World -> World
updateCreatureSoundPositions w = M.foldlWithKey' insertSound w updateCreatureSoundPositions w = M.foldlWithKey' insertSound w
@@ -338,6 +318,7 @@ mvGust _ gu
updateClouds :: World -> World updateClouds :: World -> World
updateClouds w = w' & clouds .~ catMaybes mclouds updateClouds w = w' & clouds .~ catMaybes mclouds
where where
-- cls = _clouds w
(w',mclouds) = mapAccumR updateCloud w (_clouds w) (w',mclouds) = mapAccumR updateCloud w (_clouds w)
updateCloud :: World -> Cloud -> (World,Maybe Cloud) updateCloud :: World -> Cloud -> (World,Maybe Cloud)
+5 -7
View File
@@ -1,23 +1,21 @@
module Dodge.Wall.Zone module Dodge.Wall.Zone
where where
import Dodge.Data import Dodge.Data
import Geometry
import Dodge.Zone import Dodge.Zone
import Dodge.Base
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
--import Data.Foldable --import Data.Foldable
--import Streaming --import Streaming
import qualified Streaming.Prelude as S --import qualified Streaming.Prelude as S
insertWallInZones :: Wall -> World -> World insertWallInZones :: Wall -> World -> World
insertWallInZones wl = wlZoning %~ insertInZoning (IM.insert (_wlID wl)) wl insertWallInZones wl = wlZoning %~ updateZoning (IM.insert (_wlID wl)) wl
--insertWallInZones wl = wlZoning . znObjects --insertWallInZones wl = wlZoning .updatets
-- %~ (runIdentity . (\wlzns -> S.fold_ doinsert wlzns id (zoneOfWall wl))) -- %~ (runIdentity . (\wlzns -> S.fold_ doinsert wlzns id (zoneOfWall wl)))
-- where -- where
-- doinsert wlzns (V2 x y) = insertIMInZone x y (_wlID wl) wl wlzns -- doinsert wlzns (V2 x y) = insertIMInZone x y (_wlID wl) wl wlzns
deleteWallFromZones :: Wall -> World -> World deleteWallFromZones :: Wall -> World -> World
deleteWallFromZones wl = wlZoning %~ insertInZoning (const $ IM.delete (_wlID wl)) wl deleteWallFromZones wl = wlZoning %~ updateZoning (const $ IM.delete (_wlID wl)) wl
-- %~ flip (foldl' (flip $ \(a,b) -> deleteIMInZone a b (_wlID wl))) (zoneOfWall wl) -- %~ flip (foldl' (flip $ \(a,b) updateeIMInZone a b (_wlID wl))) (zoneOfWall wl)
+2
View File
@@ -13,6 +13,7 @@ import Geometry.Data
import Picture import Picture
import LensHelp import LensHelp
--import qualified Streaming.Prelude as S
--import Control.Lens --import Control.Lens
import System.Random import System.Random
@@ -25,6 +26,7 @@ makeCloudAt
-> World -> World
-> World -> World
makeCloudAt drawFunc rad t alt p = clouds .:~ Cloud makeCloudAt drawFunc rad t alt p = clouds .:~ Cloud
--makeCloudAt drawFunc rad t alt p = clouds %~ S.cons Cloud
{ _clPos = p { _clPos = p
, _clVel = V3 0 0 0 , _clVel = V3 0 0 0
, _clPict = drawFunc , _clPict = drawFunc
+1
View File
@@ -225,6 +225,7 @@ makeGasCloud
-> World -> World
makeGasCloud pos vel w = w makeGasCloud pos vel w = w
& clouds .:~ theCloud & clouds .:~ theCloud
-- & clouds %~ S.cons theCloud
& randGen .~ g & randGen .~ g
where where
theCloud = Cloud theCloud = Cloud
-1
View File
@@ -2,7 +2,6 @@ module Dodge.Zone.Object where
import Dodge.Data import Dodge.Data
import Geometry.Zone import Geometry.Zone
import Geometry.Data import Geometry.Data
import Geometry.Vector3D
import StreamingHelp import StreamingHelp
import qualified Streaming.Prelude as S import qualified Streaming.Prelude as S
+2 -2
View File
@@ -6,8 +6,8 @@ import qualified Data.IntMap.Strict as IM
import Geometry import Geometry
import LensHelp import LensHelp
insertInZoning :: Monoid (t a) => (a -> t a -> t a) -> a -> Zoning t a -> Zoning t a updateZoning :: Monoid (t a) => (a -> t a -> t a) -> a -> Zoning t a -> Zoning t a
insertInZoning f obj zn = runIdentity (S.fold_ doinsert zn id (_znFunc zn (_znSize zn) obj)) updateZoning f obj zn = runIdentity (S.fold_ doinsert zn id (_znFunc zn (_znSize zn) obj))
where where
doinsert znobs vxy = insertInZoneWith vxy (\_ -> f obj) (f obj mempty) znobs doinsert znobs vxy = insertInZoneWith vxy (\_ -> f obj) (f obj mempty) znobs
+2 -2
View File
@@ -1,15 +1,15 @@
module StreamingHelp module StreamingHelp
( minStreamOn ( minStreamOn
, sortStreamOn , sortStreamOn
, StreamOf
, module Streaming , module Streaming
, module StreamingHelp.Data
) where ) where
import Streaming import Streaming
import StreamingHelp.Data
import qualified Streaming.Prelude as S import qualified Streaming.Prelude as S
import qualified Control.Foldl as L import qualified Control.Foldl as L
import Data.Function (on) import Data.Function (on)
type StreamOf a = Stream (Of a) Identity ()
minStreamOn :: Ord a => (b -> a) -> StreamOf b -> Maybe b minStreamOn :: Ord a => (b -> a) -> StreamOf b -> Maybe b
{-# INLINE minStreamOn #-} {-# INLINE minStreamOn #-}
+5
View File
@@ -0,0 +1,5 @@
module StreamingHelp.Data where
import Streaming
type StreamOf a = Stream (Of a) Identity ()
newtype StreamOf' a = StreamOf' (Stream (Of a) Identity ())