From 832232fef62409dab2f58a8c3813d3e65fb05ca6 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 27 Aug 2021 12:45:52 +0100 Subject: [PATCH] Fix remote camera bug --- src/Dodge/Config/KeyConfig.hs | 4 ++++ src/Dodge/Creature.hs | 1 + src/Dodge/Item/Weapon.hs | 32 ++++++++++++++++------------ src/Dodge/Item/Weapon/Laser.hs | 3 +-- src/Dodge/Item/Weapon/TriggerType.hs | 29 +++++++++++++++++++++++++ src/Dodge/Render.hs | 15 +++++++++++-- src/Render.hs | 7 +++--- 7 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/Dodge/Config/KeyConfig.hs b/src/Dodge/Config/KeyConfig.hs index 2b2363ef2..2a1caf761 100644 --- a/src/Dodge/Config/KeyConfig.hs +++ b/src/Dodge/Config/KeyConfig.hs @@ -3,6 +3,7 @@ module Dodge.Config.KeyConfig ( KeyConfigSDL (..) , defaultKeyConfigSDL + , loadKeyConfig ) where --import Data.Aeson @@ -55,3 +56,6 @@ defaultKeyConfigSDL = , newMapKey = SDL.ScancodeN , modifierKey = SDL.ScancodeCapsLock } + +loadKeyConfig :: IO KeyConfigSDL +loadKeyConfig = return defaultKeyConfigSDL diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index 5e6b8da0f..90bf09a32 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -170,6 +170,7 @@ startInventory = IM.fromList (zip [0..20] ,multGun ,boosterGun ,remoteLauncher + ,remoteBomb ,grenade ,spawnGun (lamp 20) ,lasGun diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index 61fffffee..ef1426d39 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -86,6 +86,7 @@ pistol = defaultGun } pistolPic :: Picture pistolPic = color green $ polygon $ rectNESW 5 5 (-5) (-5) + useAmmoParams :: Item -> Creature -> World -> World useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b) where @@ -134,7 +135,10 @@ teslaGun = defaultGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = \_ -> shoot aTeslaArc + , _itUse = \_ -> aTeslaArc + , _itUseModifiers = + [ shootWithSoundForI 25 1 + ] , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer teslaGunPic @@ -162,7 +166,10 @@ lasGun = defaultAutoGun , _wpReloadState = 0 , _itUseRate = 0 , _itUseTime = 0 - , _itUse = \_ -> shoot aLaser + , _itUse = \_ -> aLaser + , _itUseModifiers = + [ shootWithSoundForI 24 1 + ] , _wpSpread = 0.001 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer lasGunPic @@ -246,7 +253,10 @@ remoteLauncher = defaultGun , _wpReloadState = 0 , _itUseRate = 10 , _itUseTime = 0 - , _itUse = \_ -> hammerCheck fireRemoteLauncher + , _itUse = \_ -> fireRemoteLauncher + , _itUseModifiers = + [ hammerCheckI + ] , _wpSpread = 0.02 , _wpRange = 20 , _itFloorPict = onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) @@ -529,14 +539,8 @@ boosterGun = defaultGun } aTeslaArc :: Creature -> World -> World -aTeslaArc cr w = aTeslaArc' cr $ soundFrom (CrWeaponSound cid) 25 1 0 w - where - cid = _crID cr - -aTeslaArc' :: Creature -> World -> World -aTeslaArc' cr w +aTeslaArc cr w = teslaGunFlashAt (pos +.+ 5 *.* unitVectorAtAngle dir) --- $ over projectiles (IM.insert i (makeTeslaArcAt i pos dir)) $ set randGen g w & particles %~ (makeTeslaArcAt pos dir :) where @@ -607,7 +611,7 @@ pointToItem (OnFloor flid) = floorItems . ix flid . flIt retireRemoteRocket :: Int -> Int -> Int -> World -> World retireRemoteRocket itid 0 pjid w = set (pointToItem (_itemPositions w IM.! itid) . itAttachment . _Just . scopePos) (V2 0 0) - $ set (pointToItem (_itemPositions w IM.! itid) . itUse) (\_ -> hammerCheck fireRemoteLauncher) + $ set (pointToItem (_itemPositions w IM.! itid) . itUse) (\_ -> fireRemoteLauncher) (w & projectiles %~ IM.delete pjid) retireRemoteRocket itid t pjid w = setScope w & projectiles . ix pjid . pjUpdate .~ (\_ -> retireRemoteRocket itid (t-1) pjid) @@ -761,13 +765,13 @@ fireRemoteLauncher cr w = setLocation $ resetFire $ resetName $ soundOnce launcherSound - $ over projectiles remRocket w + $ over projectiles addRemRocket w where i = IM.newKey $ _projectiles w cid = _crID cr dir = _crDir cr pos = _crPos cr +.+ rotateV dir (V2 (_crRad cr + 1) 0) - remRocket = IM.insert i $ Shell + addRemRocket = IM.insert i $ Shell { _pjPos = pos , _pjStartPos = pos , _pjVel = rotateV dir (V2 1 0) @@ -784,7 +788,7 @@ fireRemoteLauncher cr w = setLocation newitid = IM.newKey $ _itemPositions w maybeitid = cr ^? crInv . ix j . itID . _Just resetFire = set (creatures . ix cid . crInv . ix j . itUse) - $ \_ -> hammerCheck $ \_ -> explodeRemoteRocket itid i + $ \_ _ -> explodeRemoteRocket itid i resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEROCKET" setLocation :: World -> World setLocation w' = case maybeitid of diff --git a/src/Dodge/Item/Weapon/Laser.hs b/src/Dodge/Item/Weapon/Laser.hs index 0728baaed..987686dc0 100644 --- a/src/Dodge/Item/Weapon/Laser.hs +++ b/src/Dodge/Item/Weapon/Laser.hs @@ -6,7 +6,7 @@ import Dodge.Picture --import Dodge.Picture.Layer import Dodge.Item.Attachment.Data --import Dodge.Base -import Dodge.SoundLogic +--import Dodge.SoundLogic import Dodge.WorldEvent.SpawnParticle import Dodge.WorldEvent.ThingsHit import Dodge.WorldEvent.HelperParticle @@ -25,7 +25,6 @@ import qualified Data.Sequence as Seq aLaser :: Creature -> World -> World aLaser cr w = over particles (makeLaserAt phaseV pos dir : ) - $ soundFrom LasSound 24 1 0 $ laserGunFlashAt (pos +.+ 5 *.* unitVectorAtAngle dir) w where diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index 6da9c0d7c..3b3067792 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -168,6 +168,35 @@ withSidePushAfter maxSide eff cr w = over (creatures . ix cid) push . eff cr $ w push = over crPos (+.+ rotateV (_crDir cr) (V2 0 (pushAmount / _crMass cr))) (pushAmount, _) = randomR (-maxSide,maxSide) $ _randGen w {- | Applies a world effect and sound effect after an ammo check. -} +shootWithSoundForI + :: Int -- ^ Sound identifier + -> Int -- ^ Frames to play + -> (Item -> Creature -> World -> World) + -- ^ underlying effect + -> Item + -> Creature + -> World + -> World +shootWithSoundForI soundid playTime f item cr w + | fireCondition = soundFromPos (CrWeaponSound cid) cpos soundid playTime 0 + $ f item cr + $ w + & pointerToItem %~ + ( ( wpLoadedAmmo -~ 1 ) + . ( itUseTime .~ _itUseRate item) + ) + | reloadCondition = fromMaybe w $ startReloadingWeapon cr w + | otherwise = w + where + cid = _crID cr + cpos = _crPos cr + itRef = _crInvSel cr + pointerToItem = creatures . ix cid . crInv . ix itRef + fireCondition = _wpReloadState item == 0 + && _itUseTime item == 0 + && _wpLoadedAmmo item > 0 + reloadCondition = _wpLoadedAmmo item == 0 +{- | Applies a world effect and sound effect after an ammo check. -} shootWithSoundFor :: Int -- ^ Sound identifier -> Int -- ^ Frames to play diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index db088b8e7..3e5402a7a 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -45,7 +45,8 @@ doDrawing pdata w = do wins = V2 (getWindowX w) (getWindowY w) (wallPointsCol,windowPoints) = wallsAndWindows w lightPoints = lightsForGloom w - viewFroms = _cameraViewFrom w + viewFroms@(V2 vfx vfy) = _cameraViewFrom w + viewFrom3d = Vector3 vfx vfy 20 shadV = _pictureShaders pdata -- bind as much data into vbos as feasible at this point -- poke wall points and colors @@ -72,10 +73,20 @@ doDrawing pdata w = do clear [ColorBuffer,DepthBuffer] depthFunc $= Just Less - -- draw wall occlusions from your point of view + -- draw wall occlusions from the camera's point of view + currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata) + $= viewFrom3d + currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) + $= viewFrom3d + currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata) + uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata) + $= viewFrom3d drawShader (_lightingOccludeShader pdata) nWalls -- this might only work because the uniform has been correctly set -- elsewhere, beware + -- indeed this is the case: this needs fixing if w ^. config . wall_textured then renderTextureWalls pdata nWalls diff --git a/src/Render.hs b/src/Render.hs index 28fc63473..5e4be149e 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -38,11 +38,12 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do clear [ColorBuffer,DepthBuffer] --colorMask $= Color4 Disabled Disabled Disabled Disabled cullFace $= Just Back - -- draw wall surfaces from your point of view in order to set z buffer + -- we assume that the camera position uniforms have been correctly set elsewhere + -- draw wall surfaces from the camera's point of view in order to set z buffer drawShader (_lightingWallShader pdata) nWalls - -- draw foreground elements from your point of view to set z buffer + -- draw foreground elements the camera's your point of view to set z buffer drawShader (_lightingSurfaceShader pdata) nsurfVs - -- draw wall occlusions from your point of view + -- draw wall occlusions from the camera's point of view drawShader (_lightingOccludeShader pdata) nWalls --hypothesis: the above three draw calls only work because the --uniform was set to your position, that being the last light source in the list