Fix bug in detecting which room you are in

This commit is contained in:
2021-09-03 01:22:46 +01:00
parent c69af7a5f4
commit 1bbeb926a5
14 changed files with 121 additions and 93 deletions
+36 -39
View File
@@ -14,18 +14,18 @@ import Dodge.Base.Collide
import Dodge.Config.KeyConfig
import Dodge.Item.Attachment.Data
import Geometry
import Geometry.ConvexPoly
--import Geometry.ConvexPoly
import Dodge.GameRoom
import qualified Data.List.NonEmpty as NEL
--import qualified Data.List.NonEmpty as NEL
import Control.Lens
--import Control.Applicative
import Data.Maybe
import qualified Data.Set as S
import qualified Data.IntMap.Strict as IM
import qualified SDL
import Data.Monoid
import Data.Semigroup
--import Data.Monoid
--import Data.Semigroup
import qualified Control.Foldl as L
{- Update the screen camera rotation and position, including any in rold scope/remote camera modifiers;
update where your avatar's view is from. -}
@@ -164,49 +164,46 @@ autoZoomCam w = over cameraZoom changeZoom w
theScopeZoom = fromMaybe 1 $ yourItem w ^? itAttachment . scopeZoom
farWallDist' :: Point2 -> World -> Float
farWallDist' p w = (winFac /) $ fromMaybe 800 $ L.fold L.maximum vdists
farWallDist' p w = (winFac /) $ fromMaybe maxViewDistance $ L.fold L.maximum vdists
where
hw = halfWidth w
hh = halfHeight w
winFac = min hw hh
vdists = map (flip (collideDirectionIndirect 800 p) wos)
vdists = map (flip (collideDirectionIndirect maxViewDistance p) wos)
vps
vps = concatMap _grViewpoints grs
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
wos = wallsOnScreen w
-- | Find the furthest viewable distance from a given point in the world
farWallDist :: Point2 -> World -> Float
--{-# INLINE farWallDist #-}
farWallDist cpos w
= getMin
. uncurry (<>)
$ bimap (toScale hw) (toScale hh)
$ sconcat
$ NEL.map distsMaybeTo viewTestValues
where
wos = wallsOnScreen w
camRot = _cameraRot w
hw = halfWidth w
hh = halfHeight w
toScale x = Min . (x /) . (+ 50) . maybe maxViewDistance getMax . getAp
distsMaybeTo x = (valueAtWidth x,valueAtHeight x)
valueAtHeight h = cpiv (cpos +.+ x) <> cpiv (cpos -.- x)
where
x = rotateV camRot $ V2 maxViewDistance h
cpiv p = Ap $ Max . horSize <$> collidePointIndirect cpos p wos
horSize = abs . dotV rv . (-.- cpos)
rv = rotateV camRot (V2 1 0)
valueAtWidth h = cpih (cpos +.+ x) <> cpih (cpos -.- x)
where
x = rotateV camRot $ V2 h maxViewDistance
cpih p = Ap $ Max . verSize <$> collidePointIndirect cpos p wos
verSize = abs . dotV rh . (-.- cpos)
rh = rotateV camRot (V2 0 1)
viewTestValues :: NEL.NonEmpty Float
viewTestValues = NEL.fromList [-maxViewDistance,negate $ 0.75*maxViewDistance..maxViewDistance]
---- | Find the furthest viewable distance from a given point in the world
--farWallDist :: Point2 -> World -> Float
----{-# INLINE farWallDist #-}
--farWallDist cpos w
-- = getMin
-- . uncurry (<>)
-- $ bimap (toScale hw) (toScale hh)
-- $ sconcat
-- $ NEL.map distsMaybeTo viewTestValues
-- where
-- wos = wallsOnScreen w
-- camRot = _cameraRot w
-- hw = halfWidth w
-- hh = halfHeight w
-- toScale x = Min . (x /) . (+ 50) . maybe maxViewDistance getMax . getAp
-- distsMaybeTo x = (valueAtWidth x,valueAtHeight x)
-- valueAtHeight h = cpiv (cpos +.+ x) <> cpiv (cpos -.- x)
-- where
-- x = rotateV camRot $ V2 maxViewDistance h
-- cpiv p = Ap $ Max . horSize <$> collidePointIndirect cpos p wos
-- horSize = abs . dotV rv . (-.- cpos)
-- rv = rotateV camRot (V2 1 0)
-- valueAtWidth h = cpih (cpos +.+ x) <> cpih (cpos -.- x)
-- where
-- x = rotateV camRot $ V2 h maxViewDistance
-- cpih p = Ap $ Max . verSize <$> collidePointIndirect cpos p wos
-- verSize = abs . dotV rh . (-.- cpos)
-- rh = rotateV camRot (V2 0 1)
--viewTestValues :: NEL.NonEmpty Float
--viewTestValues = NEL.fromList [-maxViewDistance,negate $ 0.75*maxViewDistance..maxViewDistance]
maxViewDistance :: Float
maxViewDistance = 800