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
+1 -1
View File
@@ -12,7 +12,7 @@ cloudPoisonDamage c w = w & dodamagesto (filter f $ crsNearPoint clpos w)
dodamagesto :: [Creature] -> World -> World
dodamagesto scrs mcrs = foldl' (flip doDam) mcrs scrs
doDam cr =
cWorld . creatures . ix (_crID cr) . crState . csDamage
cWorld . lWorld . creatures . ix (_crID cr) . crState . csDamage
.:~ Damage POISONDAM 1 clpos clpos clpos NoDamageEffect
f cr = dist3 (addZ 20 $ _crPos cr) (_clPos c) < _crRad cr + _clRad c + 10
clpos = stripZ $ _clPos c
+25 -66
View File
@@ -1,79 +1,37 @@
module Dodge.Update.Scroll where
import qualified Data.Map.Strict as M
import Data.Maybe
import qualified Data.Set as S
import qualified Data.Text as T
import Dodge.Base
import Dodge.Combine
import Dodge.Data.Universe
import Dodge.Event.Keyboard
import Dodge.HeldScroll
import Dodge.InputFocus
import Dodge.Inventory
import Dodge.SoundLogic
import Dodge.Terminal
import Dodge.Tweak
import Dodge.Combine
import Dodge.Event.Keyboard
import Control.Applicative
import Data.List
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import Data.Maybe
import Dodge.Base
import Dodge.Beam
import Dodge.InputFocus
import Dodge.Bullet
import Dodge.HeldScroll
import Dodge.CrGroupUpdate
import Dodge.Creature.Update
import Dodge.CullBox
import Dodge.Data.Universe
import Dodge.Distortion
import Dodge.DrWdWd
import Dodge.EnergyBall
import Dodge.Flame
import Dodge.Flare
import Dodge.Hammer
import Dodge.Inventory
import Dodge.Item.Location
import Dodge.Laser.Update
import Dodge.LightSource.Update
import Dodge.LinearShockwave.Update
import Dodge.Machine.Update
import Dodge.Magnet.Update
import Dodge.Menu
import Dodge.ModificationEffect
import Dodge.PosEvent
import Dodge.PressPlate
import Dodge.Projectile.Update
import Dodge.Prop.Update
import Dodge.RadarBlip
import Dodge.RadarSweep
import Dodge.Shockwave.Update
import Dodge.SoundLogic
import Dodge.Spark
import Dodge.Tesla.Arc
import Dodge.TmTm
import Dodge.TractorBeam.Update
import Dodge.Update.Camera
import Dodge.Update.Cloud
import Dodge.Update.WallDamage
import Dodge.WallCreatureCollisions
import Dodge.WorldEffect
import Dodge.Zoning.Cloud
import Dodge.Zoning.Creature
import Geometry
import qualified IntMapHelp as IM
import LensHelp
--import MaybeHelp
import SDL
import Sound.Data
import StrictHelp
import qualified Data.Text as T
updateWheelEvent :: Int -> World -> World
updateWheelEvent yi w = case w ^. cWorld . hud . hudElement of
updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
DisplayCarte
| rbDown -> w & cWorld . hud . carteZoom %~ min 0.75 . max 0.05 . ((1 + y * 0.1) *)
| otherwise -> w & cWorld . selLocation %~ (`mod` numLocs) . (+ yi)
| rbDown -> w & cWorld . lWorld . hud . carteZoom %~ min 0.75 . max 0.05 . ((1 + y * 0.1) *)
| otherwise -> w & cWorld . lWorld . selLocation %~ (`mod` numLocs) . (+ yi)
DisplayInventory NoSubInventory
-- functions that modify the inventory should be centralised so that
-- this lock can be sensibly applied, perhaps
| _crInvLock (_creatures (_cWorld w) IM.! _yourID (_cWorld w)) -> w
| w ^?! cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInvLock -> w
| rbDown -> case (yourItem w ^? _Just . itUse . heldScroll, _rbOptions w) of
(_, EquipOptions{}) -> scrollRBOption y w
(Nothing, _) -> closeObjScrollDir y w
(Just f, _) -> doHeldScroll f y (you w) w
| lbDown -> w & cWorld . cwCam . cwcZoom +~ y
| lbDown -> w & cWorld . lWorld . cwCam . cwcZoom +~ y
| invKeyDown -> changeSwapInvSel yi w
| otherwise -> stopSoundFrom (CrReloadSound 0) $ changeAugInvSel yi w
DisplayInventory (TweakInventory mi)
@@ -83,15 +41,15 @@ updateWheelEvent yi w = case w ^. cWorld . hud . hudElement of
| otherwise -> w & moveTweakSel yi
DisplayInventory CombineInventory{} ->
w
& cWorld . hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
& cWorld . lWorld . hud . hudElement . subInventory . combineInvSel . _Just %~ ((`mod` numcombs) . subtract yi)
DisplayInventory (DisplayTerminal tmid)
| rbDown && inTermFocus w ->
guardDisconnectedID tmid w $
w
& cWorld . terminals . ix tmid %~ updatetermsubsel
& cWorld . lWorld . terminals . ix tmid %~ updatetermsubsel
| inTermFocus w ->
w
& cWorld . terminals . ix tmid %~ updatetermsel
& cWorld . lWorld . terminals . ix tmid %~ updatetermsel
_ -> w
where
updatetermsel tm = case tm ^? tmInput . tiSel of
@@ -113,7 +71,7 @@ updateWheelEvent yi w = case w ^. cWorld . hud . hudElement of
arg = getArguments' tc tm w' !! j
numcombs = length $ combineItemListYou w
y = fromIntegral yi
numLocs = (fst . IM.findMax $ _seenLocations (_cWorld w)) + 1
numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
rbDown = ButtonRight `M.member` _mouseButtons w
lbDown = ButtonLeft `M.member` _mouseButtons w
invKeyDown = ScancodeCapsLock `S.member` _keys w
@@ -126,7 +84,7 @@ scrollRBOption y w
moveTweakSel :: Int -> World -> World
moveTweakSel i w = case yourItem w ^? _Just . itTweaks . tweakParams of
Just l -> w & cWorld . hud . hudElement . subInventory . tweakInvSel . _Just %~ (`mod` length l) . subtract i
Just l -> w & cWorld . lWorld . hud . hudElement . subInventory . tweakInvSel . _Just %~ (`mod` length l) . subtract i
_ -> w
changeTweakParam :: Maybe Int -> Int -> World -> World
@@ -135,10 +93,11 @@ changeTweakParam mi i w = fromMaybe w $ do
params <- yourItem w ^? _Just . itTweaks . tweakParams . ix paramid
let x = (_tweakVal params + i) `mod` _tweakMax params
return $
w & cWorld . creatures . ix (_yourID (_cWorld w)) . crInv . ix (crSel (you w))
w & cWorld . lWorld . creatures . ix (w ^. cWorld . lWorld . yourID) . crInv . ix (crSel (you w))
%~ ( (itTweaks . tweakParams . ix paramid . tweakVal .~ x)
. doTweak (_tweakType params) x
)
scrollCommands :: Terminal -> [TerminalCommand]
scrollCommands = (nullCommand :) . _tmScrollCommands
+13 -13
View File
@@ -18,7 +18,7 @@ import ListHelp
import SDL
updateUsingInput :: World -> World
updateUsingInput w = case _hudElement $ _hud (_cWorld w) of
updateUsingInput w = case w ^. cWorld . lWorld . hud . hudElement of
DisplayInventory subinv ->
pressedMBEffects subinv (_mouseButtons w) w
DisplayCarte ->
@@ -35,10 +35,10 @@ pressedMBEffects subinv pkeys w = case subinv of
maybeexitcombine (maybe id doCombine mi w) & hammers . ix SubInvHam .~ HammerDown
DisplayTerminal tmid
| pkeys ^? ix ButtonLeft == Just False && inTermFocus w ->
doTerminalEffectLB (w ^?! cWorld . terminals . ix tmid) w
doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w
& hammers . ix SubInvHam .~ HammerDown
| pkeys ^? ix ButtonLeft == Just False ->
w & cWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
& hammers . ix SubInvHam .~ HammerDown
_
| ButtonLeft `M.member` pkeys ->
@@ -47,7 +47,7 @@ pressedMBEffects subinv pkeys w = case subinv of
where
maybeexitcombine
| ButtonRight `M.member` _mouseButtons w = id
| otherwise = cWorld . hud . hudElement .~ DisplayInventory NoSubInventory
| otherwise = cWorld . lWorld . hud . hudElement .~ DisplayInventory NoSubInventory
pressedMBEffectsNoInventory :: M.Map MouseButton Bool -> World -> World
pressedMBEffectsNoInventory pkeys w
@@ -55,17 +55,17 @@ pressedMBEffectsNoInventory pkeys w
useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown
| justPressedDown ButtonLeft && inTopInv
&& w ^?! hammers . ix DoubleMouseHam == HammerUp =
useLeftItem (_yourID (_cWorld w)) w
useLeftItem (w ^. cWorld . lWorld . yourID) w
| isDown ButtonLeft && inTopInv =
w & hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonRight && inTopInv = w
| isDown ButtonMiddle =
w & cWorld . cwCam . cwcRot -~ rotation
w & cWorld . lWorld . cwCam . cwcRot -~ rotation
& clickMousePos .~ _mousePos w
| isDown ButtonLeft = w & hammers . ix DoubleMouseHam .~ HammerDown
| otherwise = w
where
inTopInv = case _hudElement (_hud (_cWorld w)) of
inTopInv = case w ^. cWorld . lWorld . hud . hudElement of
DisplayInventory NoSubInventory -> True
_ -> False
justPressedDown but = (pkeys ^. at but) == Just False
@@ -83,8 +83,8 @@ doCombine i w = case combineItemListYou w ^? ix i of
. createPutItem it
$ foldr (rmInvItem yid) w (sort is)
where
yid = _yourID (_cWorld w)
selectinv (Just i', w') = w' & cWorld . creatures . ix yid . crInvSel .~ InvSel i' NoInvSelAction
yid = w ^. cWorld . lWorld . yourID
selectinv (Just i', w') = w' & cWorld . lWorld . creatures . ix yid . crInvSel .~ InvSel i' NoInvSelAction
selectinv (Nothing, w') = w'
updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World
@@ -92,15 +92,15 @@ updatePressedButtonsCarte pkeys w
| isDown ButtonRight =
w
& clickMousePos .~ _mousePos w
& cWorld . hud . carteCenter %~ (-.- trans)
& cWorld . lWorld . hud . carteCenter %~ (-.- trans)
| isDown ButtonLeft =
w
& clickMousePos .~ _mousePos w
& cWorld . hud . carteRot -~ rot
& cWorld . hud . carteZoom *~ czoom
& cWorld . lWorld . hud . carteRot -~ rot
& cWorld . lWorld . hud . carteZoom *~ czoom
| otherwise = w
where
isDown but = but `M.member` pkeys
rot = angleBetween (_mousePos w) (_clickMousePos w)
czoom = magV (_mousePos w) / magV (_clickMousePos w)
trans = rotateV (_carteRot (_hud (_cWorld w))) $ 1 / _carteZoom (_hud (_cWorld w)) *.* (_mousePos w -.- _clickMousePos w)
trans = rotateV (w ^. cWorld . lWorld . hud . carteRot) $ 1 / (w ^. cWorld . lWorld . hud . carteZoom) *.* (_mousePos w -.- _clickMousePos w)
+3 -3
View File
@@ -10,9 +10,9 @@ import Data.Foldable
updateWallDamages :: World -> World
updateWallDamages w =
w
& cWorld . wallDamages .~ IM.empty
& flip (IM.foldlWithKey' f) (_wallDamages (_cWorld w))
& cWorld . lWorld . wallDamages .~ IM.empty
& flip (IM.foldlWithKey' f) (w ^. cWorld . lWorld . wallDamages)
where
f w' k dams = fromMaybe w' $ do
wl <- w' ^? cWorld . walls . ix k
wl <- w' ^? cWorld . lWorld . walls . ix k
return $ foldl' (flip (`damageWall` wl)) w' dams