Move wall collisions around

This commit is contained in:
2022-06-26 10:52:46 +01:00
parent ee9523dabb
commit 15b98e38ac
5 changed files with 33 additions and 58 deletions
+2
View File
@@ -13,9 +13,11 @@ module Dodge.Base
, module Dodge.Base.Coordinate , module Dodge.Base.Coordinate
, module Dodge.Base.Collide , module Dodge.Base.Collide
, module Dodge.Base.CardinalPoint , module Dodge.Base.CardinalPoint
, module Dodge.Base.Wall
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Base.WinScale import Dodge.Base.WinScale
import Dodge.Base.Wall
import Dodge.Base.Arithmetic import Dodge.Base.Arithmetic
import Dodge.Base.NewID import Dodge.Base.NewID
import Dodge.Base.Coordinate import Dodge.Base.Coordinate
+17 -47
View File
@@ -16,7 +16,7 @@ module Dodge.Base.Collide
, bounceBall , bounceBall
, bouncePoint , bouncePoint
, ssfold , ssfold
, collidePointUpToIndirectMinDist -- , collidePointUpToIndirectMinDist
, wlIsOpaque , wlIsOpaque
, wlIsSeeThrough , wlIsSeeThrough
, wallsOnCirc , wallsOnCirc
@@ -50,11 +50,10 @@ module Dodge.Base.Collide
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Zone import Dodge.Zone
import Dodge.Wall.Reflect import Dodge.Base.Wall
import Geometry import Geometry
import FoldableHelp import FoldableHelp
--import Data.List
import Data.Maybe import Data.Maybe
import Data.Function (on) import Data.Function (on)
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
@@ -64,36 +63,28 @@ import qualified FoldlHelp as L
import Data.Monoid import Data.Monoid
import Streaming import Streaming
import qualified Streaming.Prelude as S import qualified Streaming.Prelude as S
--import qualified Data.Map.Lazy as M -- note the use of Lazy, the idea being interoperation with Streaming
--
collidePoint :: Point2 -> Point2 collidePoint :: Point2 -> Point2
-> Stream (Of Wall) Identity () -> Stream (Of Wall) Identity ()
-> (Point2, Maybe Wall) -> (Point2, Maybe Wall)
{-# INLINE collidePoint #-} {-# INLINE collidePoint #-}
collidePoint sp ep = runIdentity collidePoint sp ep = runIdentity . S.fold_ findPoint (ep, Nothing) id
. S.fold_ findPoint (ep, Nothing) id
where where
findPoint (p,mwl) wl = maybe (p,mwl) (,Just wl) . uncurry (intersectSegSeg sp p) . _wlLine $ wl findPoint (p,mwl) wl = maybe (p,mwl) (,Just wl) . uncurry (intersectSegSeg sp p) . _wlLine $ wl
doBounce :: Float -> Point2 -> Point2 -> (Point2, Maybe Wall) -> Maybe (Point2, Point2)
doBounce x sp ep (p, mwl) = mwl <&> \wl ->
( p +.+ normalizeV (vNormal (uncurry (-.-) (_wlLine wl)))
, reflVelWallDamp x wl (ep -.- sp)
)
bounceBall :: Float -> Point2 -> Point2 -> Float bounceBall :: Float -> Point2 -> Point2 -> Float
-> Stream (Of Wall) Identity () -> Stream (Of Wall) Identity ()
-> Maybe (Point2,Point2) -> Maybe (Point2,Point2)
bounceBall x sp ep r w = do bounceBall x sp ep r = doBounce x sp ep . collideCircWallsStream sp ep r
wl <- mwl
return (p +.+ normalizeV (vNormal (uncurry (-.-) (_wlLine wl)))
, reflVelWallDamp x wl (ep -.- sp)
)
where
(p, mwl) = collideCircWallsStream sp ep r w
bouncePoint :: (Wall -> Bool) -> Float -> Point2 -> Point2 -> World -> Maybe (Point2,Point2) bouncePoint :: (Wall -> Bool) -> Float -> Point2 -> Point2 -> World -> Maybe (Point2,Point2)
bouncePoint t x sp ep w = do bouncePoint t x sp ep = doBounce x sp ep . collidePointWallsFilterStream t sp ep
wl <- mwl
return (p +.+ normalizeV (vNormal (uncurry (-.-) (_wlLine wl)))
, reflVelWallDamp x wl (ep -.- sp)
)
where
(p, mwl) = collidePointWallsFilterStream t sp ep w
-- this COULD be written in terms of collidePointWallsFilterStream, TODO test -- this COULD be written in terms of collidePointWallsFilterStream, TODO test
-- whether this is actually faster -- whether this is actually faster
@@ -107,49 +98,28 @@ collidePointWallsFilterStream t sp ep = collidePoint sp ep
. S.filter t . S.filter t
. wallsAlongLine sp ep . wallsAlongLine sp ep
--visibleWallWalls' :: Point2 -> Point2 -> World -> M.Map Float Wall
--visibleWallWalls' sp ep = L.purely S.fold L.map . visibleWallWalls sp ep
--orderStreamOn :: Ord b => (a -> b) -> Stream (Of a) Identity () -> Identity (Of (M.Map b a) ()) --orderStreamOn :: Ord b => (a -> b) -> Stream (Of a) Identity () -> Identity (Of (M.Map b a) ())
orderStreamOn :: Ord a => (b -> a) -> Stream (Of b) Identity () -> Stream (Of b) Identity () orderStreamOn :: Ord a => (b -> a) -> Stream (Of b) Identity () -> Stream (Of b) Identity ()
orderStreamOn f = S.each . runIdentity . L.purely S.fold_ L.map . S.map g orderStreamOn f = S.each . runIdentity . L.purely S.fold_ L.map . S.map g
where where
g x = (f x,x) g x = (f x,x)
overlapSegWalls :: Point2 -> Point2 -> Stream (Of Wall) Identity ()
-> Stream (Of (Point2,Wall)) Identity ()
overlapSegWalls sp ep = S.mapMaybe $ \wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
visibleWalls :: Point2 -> Point2 -> World -> Stream (Of (Point2,Wall)) Identity () visibleWalls :: Point2 -> Point2 -> World -> Stream (Of (Point2,Wall)) Identity ()
visibleWalls sp ep = S.take 1 <=< -- hlint, was using join and fmap visibleWalls sp ep = S.take 1 <=< -- hlint, was using join and fmap
( S.span (not . wlIsOpaque . snd) ( S.span (not . wlIsOpaque . snd)
. orderStreamOn (dist sp . fst) . orderStreamOn (dist sp . fst)
. S.mapMaybe f . overlapSegWalls sp ep
. wallsAlongLine sp ep ) . wallsAlongLine sp ep )
where
f wl = uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
allVisibleWalls :: World -> Stream (Of (Point2,Wall)) Identity () allVisibleWalls :: World -> Stream (Of (Point2,Wall)) Identity ()
allVisibleWalls w = concats $ S.subst (flip (visibleWalls vPos) w . (+.+ vPos)) $ S.each (nRays 20) allVisibleWalls w = concats $ S.subst (flip (visibleWalls vPos) w . (+.+ vPos)) $ S.each (nRays 20)
where where
vPos = _cameraViewFrom w vPos = _cameraViewFrom w
wlIsOpaque :: Wall -> Bool
wlIsOpaque wl = case _wlOpacity wl of
Opaque -> True
_ -> False
wlIsSeeThrough :: Wall -> Bool
wlIsSeeThrough wl = case _wlOpacity wl of
SeeThrough -> True
_ -> False
--collidePointUpToIndirect
-- :: Point2 -- ^start point
-- -> Point2 -- ^end point
-- -> IM.IntMap Wall
-- -> Point2
--{-# INLINE collidePointUpToIndirect #-}
--collidePointUpToIndirect p1 p2 = foldr f p2 . IM.filter wlIsOpaque
-- where
-- f wl x = fromMaybe x . uncurry (intersectSegSeg p1 x) $ _wlLine wl
collidePointUpToIndirectMinDist collidePointUpToIndirectMinDist
:: Point2 -- ^start point :: Point2 -- ^start point
-> Point2 -- ^end point -> Point2 -- ^end point
@@ -1,7 +1,16 @@
module Dodge.Wall.Reflect module Dodge.Base.Wall where
where
import Geometry
import Dodge.Data import Dodge.Data
import Geometry
wlIsOpaque :: Wall -> Bool
wlIsOpaque wl = case _wlOpacity wl of
Opaque -> True
_ -> False
wlIsSeeThrough :: Wall -> Bool
wlIsSeeThrough wl = case _wlOpacity wl of
SeeThrough -> True
_ -> False
reflDirWall :: Point2 -> Point2 -> Wall -> Float reflDirWall :: Point2 -> Point2 -> Wall -> Float
reflDirWall sp ep wl = argV (reflectIn (uncurry (-.-) (_wlLine wl)) (ep -.- sp)) reflDirWall sp ep wl = argV (reflectIn (uncurry (-.-) (_wlLine wl)) (ep -.- sp))
+1 -7
View File
@@ -2,15 +2,9 @@ module Dodge.Item.Weapon.LaserPath
( reflectLaserAlong ( reflectLaserAlong
) where ) where
import Dodge.Data import Dodge.Data
import Dodge.Wall.Reflect import Dodge.Base.Wall
--import Dodge.Creature.HandPos --import Dodge.Creature.HandPos
import Dodge.WorldEvent import Dodge.WorldEvent
import Dodge.Base.Collide
--import Dodge.Default
--import Dodge.Item.Weapon.InventoryDisplay
--import Dodge.Item.Weapon.TriggerType
--import Dodge.Item.Attachment
--import Dodge.Base
import Geometry import Geometry
--import Data.Maybe --import Data.Maybe
+1 -1
View File
@@ -2,7 +2,7 @@ module Dodge.Wall.DamageEffect where
import Dodge.Data import Dodge.Data
import Dodge.Particle.Spark import Dodge.Particle.Spark
import Dodge.Particle.Bullet.Spawn import Dodge.Particle.Bullet.Spawn
import Dodge.Wall.Reflect import Dodge.Base.Wall
import Dodge.Wall.Dust import Dodge.Wall.Dust
import Dodge.Block import Dodge.Block
import Geometry import Geometry