Add in "linear" lWorld to separate time reversable worlds

This commit is contained in:
2022-10-28 12:24:51 +01:00
parent 5f6bd43599
commit 7e790b7153
130 changed files with 827 additions and 980 deletions
+28 -25
View File
@@ -41,11 +41,11 @@ updateCamera uv =
moveZoomCamera :: Universe -> Universe
moveZoomCamera uv =
uv
& uvWorld . cWorld . cwCam . cwcCenter .~ newcen
& uvWorld . cWorld . cwCam . cwcViewFrom .~ newvf
& uvWorld . cWorld . cwCam . cwcZoom .~ newzoom
& uvWorld . cWorld . cwCam . cwcDefaultZoom .~ newDefaultZoom
& uvWorld . cWorld . cwCam . cwcItemZoom .~ newItemZoom
& uvWorld . cWorld . lWorld . cwCam . cwcCenter .~ newcen
& uvWorld . cWorld . lWorld . cwCam . cwcViewFrom .~ newvf
& uvWorld . cWorld . lWorld . cwCam . cwcZoom .~ newzoom
& uvWorld . cWorld . lWorld . cwCam . cwcDefaultZoom .~ newDefaultZoom
& uvWorld . cWorld . lWorld . cwCam . cwcItemZoom .~ newItemZoom
where
cfig = _uvConfig uv
w = _uvWorld uv
@@ -60,23 +60,23 @@ moveZoomCamera uv =
guard (SDL.ButtonRight `M.member` _mouseButtons w)
yourItem w ^? _Just . itScope . scopePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset = rotateV (w ^. cWorld . cwCam . cwcRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos w
offset = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos w
newzoom = case yourItem w ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom
idealDefaultZoom = clipZoom wallZoom
newDefaultZoom = case yourItem w ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
_ -> changeZoom (w ^. cWorld . cwCam . cwcDefaultZoom) idealDefaultZoom
_ -> changeZoom (w ^. cWorld . lWorld . cwCam . cwcDefaultZoom) idealDefaultZoom
idealItemZoom = fromMaybe 1 $ do
guard $ crIsAiming (you w)
zoomFromItem' <$> (yourItem w ^? _Just . itUse . heldAim . aimZoom)
newItemZoom = changeZoom (w ^. cWorld . cwCam . cwcItemZoom) idealItemZoom
newItemZoom = changeZoom (w ^. cWorld . lWorld . cwCam . cwcItemZoom) idealItemZoom
changeZoom curZoom idealZoom
| curZoom > idealZoom + 0.01 = ((zoomOutSpeed -1) * curZoom + idealZoom) / zoomOutSpeed
| curZoom < idealZoom - 0.01 = ((zoomInSpeed -1) * curZoom + idealZoom) / zoomInSpeed
| otherwise = idealZoom
wallZoom = min4 (w ^. cWorld . cwCam . cwcBoundDist)
wallZoom = min4 (w ^. cWorld . lWorld . cwCam . cwcBoundDist)
min4 (a, b, c, d) = minimum [hh / maxd a, hh / maxd (- b), hw / maxd c, hw / maxd (- d)]
maxd = max distFromEqmnt
distFromEqmnt = foldl' max 1 $ IM.mapMaybe (_eeViewDist . _equipEffect . _itUse) $ getCrEquipment $ you w
@@ -91,7 +91,7 @@ updateScopeZoom :: World -> World
updateScopeZoom w
| SDL.ButtonRight `M.member` _mouseButtons w =
case w
^? cWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_cWorld w) IM.! 0))
^? cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
. itScope
. scopeZoomChange of
Just x
@@ -105,7 +105,7 @@ updateScopeZoom w
_ -> w
| otherwise =
w
& cWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_cWorld w) IM.! 0))
& cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
. itScope
%~ updateScope
where
@@ -125,11 +125,13 @@ zoomInLongGun w
| otherwise = w & wpPointer . itScope . scopeZoomChange .~ 0
where
decreaseScopeZoomChange = wpPointer . itScope . scopeZoomChange -~ 1
wpPointer = cWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_cWorld w) IM.! 0))
wp = _crInv (_creatures (_cWorld w) IM.! 0) IM.! crSel (_creatures (_cWorld w) IM.! 0)
wpPointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
--wp = _crInv (_creatures (_cWorld w) IM.! 0) IM.! crSel (_creatures (_cWorld w) IM.! 0)
wp = ycr ^?! crInv . ix (crSel ycr)
ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom
newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed
mousep = rotateV (w ^. cWorld . cwCam . cwcRot) $ _mousePos w
mousep = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot) $ _mousePos w
zoomOutLongGun :: World -> World
zoomOutLongGun w
@@ -143,8 +145,9 @@ zoomOutLongGun w
where
--mousep = rotateV (_cameraRot w) $ _mousePos w
increaseScopeZoomChange = wpPointer . itScope . scopeZoomChange +~ 1
wpPointer = cWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_cWorld w) IM.! 0))
wp = _crInv (_creatures (_cWorld w) IM.! 0) IM.! crSel (_creatures (_cWorld w) IM.! 0)
wpPointer = cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_lWorld (_cWorld w)) IM.! 0))
wp = ycr ^?! crInv . ix (crSel ycr)
ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom
ifConfigWallRotate :: Configuration -> World -> World
@@ -165,11 +168,11 @@ rotateToOverlappingWall w =
p = _crPos (you w)
doWallRotate :: Wall -> World -> World
doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . cwCam . cwcRot)
doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^. cWorld . lWorld . cwCam . cwcRot)
where
rotateUsing a
| b - b' > 0.01 = w & cWorld . cwCam . cwcRot +~ 0.01
| b - b' < negate 0.01 = w & cWorld . cwCam . cwcRot -~ 0.01
| b - b' > 0.01 = w & cWorld . lWorld . cwCam . cwcRot +~ 0.01
| b - b' < negate 0.01 = w & cWorld . lWorld . cwCam . cwcRot -~ 0.01
| otherwise = w
where
--b = a * (2 / pi)
@@ -179,8 +182,8 @@ doWallRotate wl' w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - (w ^.
rotateCameraBy :: Float -> World -> World
rotateCameraBy x w =
w
& cWorld . cwCam . cwcRot +~ x
& cWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_cWorld w) IM.! 0))
& cWorld . lWorld . cwCam . cwcRot +~ x
& cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (_creatures (_lWorld (_cWorld w)) IM.! 0))
. itScope
. scopePos
%~ rotateV x
@@ -197,7 +200,7 @@ rotateCamera cfig w
-- TODO check where/how this is used
notAtTerminal :: World -> Bool
notAtTerminal w = isNothing $ w ^? cWorld . hud . hudElement . subInventory . termID
notAtTerminal w = isNothing $ w ^? cWorld . lWorld . hud . hudElement . subInventory . termID
--zoomCamBy :: Float -> World -> World
--zoomCamBy x w = w {_cameraZoom = max (_cameraZoom w + x) 0.01}
@@ -215,8 +218,8 @@ clipZoom = min 20 . max 0.2
setViewDistance :: Configuration -> World -> World
setViewDistance cfig w =
w & cWorld . cwCam . cwcViewDistance
.~ sqrt (halfWidth cfig ** 2 + halfHeight cfig ** 2) / (w ^. cWorld . cwCam . cwcZoom)
w & cWorld . lWorld . cwCam . cwcViewDistance
.~ sqrt (halfWidth cfig ** 2 + halfHeight cfig ** 2) / (w ^. cWorld . lWorld . cwCam . cwcZoom)
getViewpoints :: Point2 -> World -> [Point2]
{-# INLINE getViewpoints #-}
@@ -238,7 +241,7 @@ farWallDistDirection p w =
boundPoints $
map f $ getViewpoints p w
where
f q = (rotateV (negate (w ^. cWorld . cwCam . cwcRot)) . (-.- p)) (foldl' findPoint q (wls q))
f q = (rotateV (negate (w ^. cWorld . lWorld . cwCam . cwcRot)) . (-.- p)) (foldl' findPoint q (wls q))
wls q = filter wlIsOpaque $ wlsNearSeg p q w
findPoint q = fromMaybe q . uncurry (intersectSegSeg p q) . _wlLine