Use streaming to improve speed of generating cullbox
This commit is contained in:
+26
-11
@@ -4,6 +4,7 @@ and the position that the character sees from: '_cameraViewFrom'. -}
|
||||
module Dodge.Update.Camera
|
||||
( updateCamera
|
||||
, farWallPoints
|
||||
-- , streamViewpoints
|
||||
, farWallDistDirection
|
||||
) where
|
||||
import Dodge.Data
|
||||
@@ -19,7 +20,7 @@ import LensHelp
|
||||
import qualified Data.Map.Strict as M
|
||||
--import qualified Data.List.NonEmpty as NEL
|
||||
--import Control.Applicative
|
||||
import Data.Foldable
|
||||
--import Data.Foldable
|
||||
import Data.Maybe
|
||||
import Control.Monad
|
||||
import qualified Data.Set as Set
|
||||
@@ -29,6 +30,7 @@ import qualified SDL
|
||||
--import Data.Semigroup
|
||||
import qualified Control.Foldl as L
|
||||
import qualified Streaming.Prelude as S
|
||||
import Streaming
|
||||
{- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers;
|
||||
update where your avatar's view is from. -}
|
||||
updateCamera :: Configuration -> World -> World
|
||||
@@ -209,18 +211,31 @@ farWallDist p cfig w = (winFac /)
|
||||
wos = wallsOnScreen cfig w
|
||||
distFromEqmnt = foldr max 1 $ IM.mapMaybe (_eqViewDist . _eqEq. _itUse) $ getCrEquipment $ you w
|
||||
|
||||
farWallDistDirection :: Point2 -> World -> (Float,Float,Float,Float)
|
||||
farWallDistDirection p w = foldl' (flip (m . f)) (0,0,0,0) vps
|
||||
streamViewpoints :: Monad m => Point2 -> World -> Stream (Of Point2) m ()
|
||||
{-# INLINE streamViewpoints #-}
|
||||
streamViewpoints p w = flip S.for (gameRoomViewpoints p)
|
||||
$ S.filter (pointInOrOnPolygon p . _grBound) $ S.each (_gameRooms w)
|
||||
|
||||
gameRoomViewpoints :: Monad m => Point2 -> GameRoom -> Stream (Of Point2) m ()
|
||||
gameRoomViewpoints p gr = S.each (_grViewpoints gr)
|
||||
<> S.map extend (S.each (_grViewpointsEx gr) <> S.map addDir (S.each $ _grLinkDirs gr))
|
||||
where
|
||||
--f q = g $ rotateV (negate $ _cameraRot w) $ collidePointWallsFilt' wlIsOpaque p q wos -.- p
|
||||
f q = g $ rotateV (negate $ _cameraRot w)
|
||||
-- $ collidePointWallsFilt wlIsOpaque p q (wallsAlongLine p q w) -.- p
|
||||
-- $ L.purely S.fold_ (collidePointWallsL p q) (wallsAlongLineStream p q w) -.- p
|
||||
extend outp = p +.+ maxViewDistance *.* squashNormalizeV (outp -.- p)
|
||||
addDir a = p +.+ unitVectorAtAngle a
|
||||
|
||||
farWallDistDirection :: Point2 -> World -> (Maybe Float,Maybe Float,Maybe Float,Maybe Float)
|
||||
farWallDistDirection p w = runIdentity $ L.purely S.fold_ ((,,,)
|
||||
<$> L.premap (^?! _2) L.maximum
|
||||
<*> L.premap (^?! _2) L.minimum
|
||||
<*> L.premap (^?! _1) L.maximum
|
||||
<*> L.premap (^?! _1) L.minimum
|
||||
)
|
||||
$ S.map f vps
|
||||
where
|
||||
f q = rotateV (negate $ _cameraRot w)
|
||||
$ runIdentity (L.purely S.fold_ (collidePointWallsL p q) (S.filter wlIsOpaque $ wallsAlongLineStream p q w)) -.- p
|
||||
g (V2 x y) = (y, negate y, x, negate x)
|
||||
m (a,b,c,d) (x,y,z,w') = (max a x, max b y, max c z, max d w')
|
||||
vps = concatMap _grViewpoints grs ++ extendedViewPoints p grs
|
||||
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||
vps = streamViewpoints p w
|
||||
|
||||
|
||||
extendedViewPoints :: Point2 -> [GameRoom] -> [Point2]
|
||||
extendedViewPoints p grs = map extend
|
||||
|
||||
Reference in New Issue
Block a user