Add in "linear" lWorld to separate time reversable worlds
This commit is contained in:
@@ -44,7 +44,6 @@ import Dodge.Data.World
|
||||
import Dodge.Zoning
|
||||
import FoldableHelp
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
collidePoint ::
|
||||
Point2 ->
|
||||
@@ -141,7 +140,7 @@ allVisibleWalls :: World -> [(Point2, Wall)]
|
||||
{-# INLINE allVisibleWalls #-}
|
||||
allVisibleWalls w = concatMap (flip (visibleWalls vPos) w . (+.+ vPos)) $ nRays 20
|
||||
where
|
||||
vPos = w ^. cWorld . cwCam . cwcViewFrom
|
||||
vPos = w ^. cWorld . lWorld . cwCam . cwcViewFrom
|
||||
|
||||
--allVisibleWalls :: World -> StreamOf (Point2,Wall)
|
||||
--{-# INLINE allVisibleWalls #-}
|
||||
@@ -217,7 +216,7 @@ circOnAnyCr :: Point2 -> Float -> World -> Bool
|
||||
{-# INLINE circOnAnyCr #-}
|
||||
circOnAnyCr p r w = IS.foldr f False $ crIXsNearPoint p w
|
||||
where
|
||||
f cid bl = maybe False (\cr -> dist p (_crPos cr) < r + _crRad cr) (w ^? cWorld . creatures . ix cid) || bl
|
||||
f cid bl = maybe False (\cr -> dist p (_crPos cr) < r + _crRad cr) (w ^? cWorld . lWorld . creatures . ix cid) || bl
|
||||
|
||||
-- | More general collision tests follow
|
||||
hasLOS :: Point2 -> Point2 -> World -> Bool
|
||||
@@ -252,15 +251,15 @@ canSee :: Int -> Int -> World -> Bool
|
||||
{-# INLINE canSee #-}
|
||||
canSee i j w = hasLOS p1 p2 w
|
||||
where
|
||||
p1 = _crPos (_creatures (_cWorld w) IM.! i)
|
||||
p2 = _crPos (_creatures (_cWorld w) IM.! j) -- unsafe
|
||||
p1 = w ^?! cWorld . lWorld . creatures . ix i . crPos -- _crPos (_creatures (_cWorld w) IM.! i)
|
||||
p2 = w ^?! cWorld . lWorld . creatures . ix j . crPos -- _crPos (_creatures (_cWorld w) IM.! j) -- unsafe
|
||||
|
||||
canSeeIndirect :: Int -> Int -> World -> Bool
|
||||
{-# INLINE canSeeIndirect #-}
|
||||
canSeeIndirect i j w = hasLOSIndirect ipos jpos w
|
||||
where
|
||||
ipos = _crPos (_creatures (_cWorld w) IM.! i)
|
||||
jpos = _crPos (_creatures (_cWorld w) IM.! j)
|
||||
ipos = w ^?! cWorld . lWorld . creatures . ix i . crPos
|
||||
jpos = w ^?! cWorld . lWorld . creatures . ix j . crPos
|
||||
|
||||
anythingHitCirc :: Float -> Point2 -> Point2 -> World -> Bool
|
||||
anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
||||
@@ -270,7 +269,7 @@ anythingHitCirc rad sp ep w = hitCr || isJust (sequence hitWl)
|
||||
maybe
|
||||
False
|
||||
(\cr -> null $ intersectCircSeg (_crPos cr) (rad + _crRad cr) sp ep)
|
||||
(w ^? cWorld . creatures . ix cid)
|
||||
(w ^? cWorld . lWorld . creatures . ix cid)
|
||||
|| bl
|
||||
|
||||
hitWl = collideCircWalls sp ep rad $ wlsNearPoint ep w
|
||||
|
||||
@@ -9,9 +9,9 @@ import Control.Lens
|
||||
worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2
|
||||
worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- (w ^. cWorld . cwCam . cwcCenter)
|
||||
doZoom p = (w ^. cWorld . cwCam . cwcZoom) *.* p
|
||||
doRotate p = rotateV (negate (w ^. cWorld . cwCam . cwcRot)) p
|
||||
doTranslate p = p -.- (w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
doZoom p = (w ^. cWorld . lWorld . cwCam . cwcZoom) *.* p
|
||||
doRotate p = rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) p
|
||||
|
||||
{- | Transform world coordinates to scaled screen coordinates.
|
||||
- These have to be scaled according to the size of the window to get actual screen positions.
|
||||
@@ -19,9 +19,9 @@ worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTransla
|
||||
-}
|
||||
worldPosToScreen :: World -> Point2 -> Point2
|
||||
worldPosToScreen w =
|
||||
rotateV (negate $ w ^. cWorld . cwCam . cwcRot)
|
||||
. ((w ^. cWorld . cwCam . cwcZoom) *.*)
|
||||
. (-.- (w ^. cWorld . cwCam . cwcCenter))
|
||||
rotateV (negate $ w ^. cWorld . lWorld . cwCam . cwcRot)
|
||||
. ((w ^. cWorld . lWorld . cwCam . cwcZoom) *.*)
|
||||
. (-.- (w ^. cWorld . lWorld . cwCam . cwcCenter))
|
||||
|
||||
{- | Transform coordinates from the map position to screen
|
||||
coordinates.
|
||||
@@ -29,9 +29,11 @@ coordinates.
|
||||
cartePosToScreen :: Configuration -> World -> Point2 -> Point2
|
||||
cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate
|
||||
where
|
||||
doTranslate p = p -.- _carteCenter (_hud (_cWorld w))
|
||||
doZoom p = _carteZoom (_hud (_cWorld w)) *.* p
|
||||
doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p
|
||||
doTranslate p = p -.- (w ^. cWorld . lWorld . hud . carteCenter) -- _carteCenter (_hud (_cWorld w))
|
||||
--doZoom p = _carteZoom (_hud (_cWorld w)) *.* p
|
||||
doZoom p = (w ^. cWorld . lWorld . hud . carteZoom) *.* p
|
||||
--doRotate p = rotateV (negate $ _carteRot (_hud (_cWorld w))) p
|
||||
doRotate p = rotateV (negate $ w ^. cWorld . lWorld . hud . carteRot) p
|
||||
|
||||
crToMousePosOffset :: Creature -> World -> (Point2, Float)
|
||||
crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
|
||||
@@ -39,11 +41,14 @@ crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr, 0)
|
||||
-- | The mouse position in world coordinates.
|
||||
mouseWorldPos :: World -> Point2
|
||||
mouseWorldPos w =
|
||||
(w ^. cWorld . cwCam . cwcCenter)
|
||||
+.+ (1 / (w ^. cWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . cwCam . cwcRot) (_mousePos w)
|
||||
(w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
+.+ (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) (_mousePos w)
|
||||
|
||||
-- | The mouse position in map coordinates
|
||||
mouseCartePos :: World -> Point2
|
||||
mouseCartePos w =
|
||||
_carteCenter (_hud (_cWorld w))
|
||||
+.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w)
|
||||
mouseCartePos w = (w ^. cWorld . lWorld . hud . carteCenter)
|
||||
+.+
|
||||
(1 / (w ^. cWorld . lWorld . hud . carteZoom))
|
||||
*.* rotateV (w ^. cWorld . lWorld . hud . carteRot) (_mousePos w)
|
||||
-- _carteCenter (_hud (_cWorld w))
|
||||
-- +.+ (1 / _carteZoom (_hud (_cWorld w))) *.* rotateV (_carteRot (_hud (_cWorld w))) (_mousePos w)
|
||||
|
||||
@@ -15,16 +15,11 @@ import Control.Lens
|
||||
screenPolygon :: Configuration -> World -> [Point2]
|
||||
screenPolygon cfig w = map (scTran . scRot . scZoom) $ screenBox cfig
|
||||
where
|
||||
scRot = rotateV (w ^. cWorld . cwCam . cwcRot)
|
||||
scRot = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot)
|
||||
scZoom p
|
||||
| (w ^. cWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . cwCam . cwcZoom)) *.* p
|
||||
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
|
||||
| otherwise = p
|
||||
scTran p = p +.+ (w ^. cWorld . cwCam . cwcCenter)
|
||||
|
||||
-- tr = scTran $ scRot $ scZoom (V2 ( halfWidth w) ( halfHeight w))
|
||||
-- tl = scTran $ scRot $ scZoom (V2 (-halfWidth w) ( halfHeight w))
|
||||
-- br = scTran $ scRot $ scZoom (V2 ( halfWidth w) (-halfHeight w))
|
||||
-- bl = scTran $ scRot $ scZoom (V2 (-halfWidth w) (-halfHeight w))
|
||||
scTran p = p +.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)
|
||||
|
||||
-- | A box covering the screen in world coordinates, with a x and y border
|
||||
screenPolygonBord ::
|
||||
@@ -40,9 +35,9 @@ screenPolygonBord xbord ybord cfig w = [tr, tl, bl, br]
|
||||
hw = halfWidth cfig - xbord
|
||||
hh = halfHeight cfig - ybord
|
||||
scZoom p
|
||||
| (w ^. cWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . cwCam . cwcZoom)) *.* p
|
||||
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
|
||||
| otherwise = p
|
||||
theTransform = (+.+ (w ^. cWorld . cwCam . cwcCenter)) . rotateV (w ^. cWorld . cwCam . cwcRot) . scZoom
|
||||
theTransform = (+.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)) . rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) . scZoom
|
||||
tr = theTransform (V2 hw hh)
|
||||
tl = theTransform (V2 (- hw) hh)
|
||||
br = theTransform (V2 hw (- hh))
|
||||
|
||||
@@ -2,9 +2,11 @@ module Dodge.Base.You where
|
||||
|
||||
import Dodge.Data.World
|
||||
import qualified IntMapHelp as IM
|
||||
import Control.Lens
|
||||
|
||||
you :: World -> Creature
|
||||
you w = _creatures (_cWorld w) IM.! _yourID (_cWorld w)
|
||||
--you w = _creatures (_cWorld w) IM.! _yourID (_cWorld w)
|
||||
you w = w ^?! cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID)
|
||||
|
||||
yourItem :: World -> Maybe Item
|
||||
yourItem w = _crInv (you w) IM.!? crSel (you w)
|
||||
|
||||
Reference in New Issue
Block a user