From 7c9cba9ee1e377269b635a1446fbbd08492aa22a Mon Sep 17 00:00:00 2001 From: jgk Date: Wed, 24 Mar 2021 19:51:10 +0100 Subject: [PATCH] Refactor flame draw --- app/Main.hs | 11 ++++-- src/Dodge/Item/Weapon.hs | 81 +++++++++++----------------------------- src/Picture/Render.hs | 1 + 3 files changed, 30 insertions(+), 63 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 24e8692c3..28591fa8c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -27,6 +27,8 @@ import Preload import Control.Concurrent import Control.Lens + +import Control.Monad (when) import System.Random @@ -44,10 +46,6 @@ main = do (fmap (setWindowSize sizex sizey) firstWorld) ( \preData w -> do startTicks <- SDL.ticks - errs <- errors - if length errs > 0 - then putStrLn $ "GLerror during doLoop: " ++ (unwords $ map show errs) - else return () clear [ColorBuffer,DepthBuffer] (lightTicks,timeSpentPoking) <- renderPicture' (_renderData preData) (_cameraRot w) (_cameraZoom w) @@ -76,6 +74,11 @@ main = do (\w -> Just $ update w) Mix.closeAudio +checkForGlErrors :: IO () +checkForGlErrors = do + errs <- errors + when (length errs > 0) $ putStrLn $ "GLerror during doLoop: " ++ (unwords $ map show errs) + setWindowSize :: Int -> Int -> World -> World setWindowSize x y w = w & windowX .~ fromIntegral x & windowY .~ fromIntegral y diff --git a/src/Dodge/Item/Weapon.hs b/src/Dodge/Item/Weapon.hs index de78461d2..ed94703a3 100644 --- a/src/Dodge/Item/Weapon.hs +++ b/src/Dodge/Item/Weapon.hs @@ -866,8 +866,6 @@ aFlame a cid w cr = (_creatures w IM.! cid) dir = _crDir cr + angle pos = _crPos cr +.+ ((_crRad cr + 2.9) *.* unitVectorAtAngle (_crDir cr)) - pos2 = (0.5 *.* vel) +.+ - _crPos cr +.+ ((_crRad cr + 2.9) *.* unitVectorAtAngle (_crDir cr)) w1 = set randGen g w i = newProjectileKey w1 vel = (_crPos cr -.- _crOldPos cr) +.+ 4 *.* unitVectorAtAngle dir @@ -878,7 +876,7 @@ aFlame a cid w makeFlame :: Point2 -> Point2 -> Maybe Int -> World -> World makeFlame pos vel maycid = over particles' ((:) theFlame) where theFlame = - Pt' { _ptDraw = drawFlame + Pt' { _ptDraw = drawFlame vel , _ptUpdate' = moveFlame vel , _btVel' = vel , _btColor' = red @@ -889,37 +887,30 @@ makeFlame pos vel maycid = over particles' ((:) theFlame) , _btHitEffect' = destroyOnImpact (doFlameDam 1) noEff noEff } -drawFlame :: Particle' -> Picture -drawFlame pt = thePic ep +drawFlame :: Point2 -> Particle' -> Picture +drawFlame rotd pt = thePic where ep = _btPos' pt - rotd = _btVel' pt - thePic p' = pictures $ reverse [ pic p' , piu p' , pi2 p' , glow p' ] - pic p' = setLayer 1 . setDepth 0.2994 $ uncurry translate (prot3 p') - $ rotate (pi * 0.5 + argV rotd) - $ scale scaleChange 1 - $ pictures $ reverse [color white $ circleSolid 4 - ,color (withAlpha 0.5 white) $ circleSolid 5 - ] - piu p' = setLayer 1 . setDepth 0.2998 $ uncurry translate (prot2 p') - $ rotate (pi*0.5 + argV rotd) - $ scale (scaleChange + 1) 2 - $ pictures $ reverse [color red $ circleSolid 4.5 - ,color (withAlpha 0.5 red) $ circleSolid 5 - ] - pi2 p' = setLayer 1 - . setDepth 0.2996 - . uncurry translate (prot p') - $ rotate (pi * 0.5 + argV rotd) - $ scale (scaleChange + 0.5) 1.5 - $ pictures $ reverse [color orange $ circleSolid 4.5 - ,color (withAlpha 0.5 orange) $ circleSolid 5 - ] - glow p' = setLayer 1 $ setDepth 0.3 $ uncurry translate p' + thePic = pictures + [ glow + , aPic prot2 0.2998 (scaleChange + 1,2) red + , aPic prot 0.2996 (scaleChange + 0.5,1.5) orange + , aPic prot3 0.2994 (scaleChange,1) white + ] + aPic :: (Point2 -> Point2) -> Float -> Point2 -> Color -> Picture + aPic offset depth (scalex,scaley) col + = setLayer 1 + . setDepth depth + . uncurry translate (offset ep) + . rotate (pi * 0.5 + argV rotd) + . scale scalex scaley + . color col + $ circleSolid 5 + glow = setLayer 1 $ setDepth 0.3 $ uncurry translate ep $ circleSolidCol (withAlpha 0 orange) (withAlpha 0.02 orange) 50 time = _btTimer' pt scaleChange | time < 80 = 3 | otherwise = 3 - (fromIntegral time - 80) * 0.2 - prot p' = p' +.+ rotateV (fromIntegral time * 1) (0,1) + prot p' = p' +.+ rotateV (fromIntegral time * 1) (0,1) prot2 p' = p' +.+ rotateV (negate $ fromIntegral time * 1) (0,1) prot3 p' = p' +.+ rotateV (2 + fromIntegral time * 0.1) (0,2) @@ -936,10 +927,10 @@ moveFlame rotd w pt sp = _btPos' pt vel = _btVel' pt ep = sp +.+ vel - mvPt = Just $ pt {_btTimer' = time - 1, _btPos' = ep--, _ptDraw = const $ thepic ep + mvPt = Just $ pt {_btTimer' = time - 1, _btPos' = ep , _btPassThrough' = Nothing ,_btVel' = 0.98 *.* vel} - mvPt' = Just $ pt {_btTimer' = time - 1, _btPos' = ep--, _ptDraw = const $ thepic ep + mvPt' = Just $ pt {_btTimer' = time - 1, _btPos' = ep , _btPassThrough' = Nothing ,_btVel' = 0.7 *.* vel} damcrs = foldr ($) w $ map (\cr -> fst . hiteff [(ep,E3x1 cr)]) $ filter closeCrs @@ -949,42 +940,14 @@ moveFlame rotd w pt + 5 * angleCoeff (angleVV (ep -.- _crPos cr) rotd) angleCoeff x = abs $ 1 - (abs $ (x * 2 - pi) / (pi)) hiteff = _btHitEffect' pt pt - thepic p' = pictures $ reverse [ pic p' , piu p' , pi2 p' , glow p' ] - pic p' = setLayer 1 . setDepth 0.2994 $ uncurry translate (prot3 p') - $ rotate (pi * 0.5 + argV rotd) - $ scale scaleChange 1 - $ pictures $ reverse [color white $ circleSolid 4 - ,color (withAlpha 0.5 white) $ circleSolid 5 - ] - pi2 p' = setLayer 1 - . setDepth 0.2996 - . uncurry translate (prot p') - $ rotate (pi * 0.5 + argV rotd) - $ scale (scaleChange + 0.5) 1.5 - $ pictures $ reverse [color orange $ circleSolid 4.5 - ,color (withAlpha 0.5 orange) $ circleSolid 5 - ] - prot p' = p' +.+ rotateV (fromIntegral time * 1) (0,1) - prot2 p' = p' +.+ rotateV (negate $ fromIntegral time * 1) (0,1) - prot3 p' = p' +.+ rotateV (2 + fromIntegral time * 0.1) (0,2) - piu p' = setLayer 1 . setDepth 0.2998 $ uncurry translate (prot2 p') - $ rotate (pi*0.5 + argV rotd) - $ scale (scaleChange + 1) 2 - $ pictures $ reverse [color red $ circleSolid 4.5 - ,color (withAlpha 0.5 red) $ circleSolid 5 - ] rfl wl p = Just $ pt {_btTimer' = time -1, _btPos' = pOut p , _btVel' = reflV wl--, _ptDraw = const $ thepic $ pOut p } - glow p' = setLayer 1 $ setDepth 0.3 $ uncurry translate p' - $ circleSolidCol (withAlpha 0 orange) (withAlpha 0.02 orange) 50 pOut p = p +.+ safeNormalizeV (sp -.- p) reflV wall = (0.3 *.* reflectIn (_wlLine wall !! 1 -.- _wlLine wall !! 0) vel ) +.+ (0.2 *.* vel) - scaleChange | time < 80 = 3 - | otherwise = 3 - (fromIntegral time - 80) * 0.2 smokeGen = makeFlamerSmokeAt ep diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index 37781e6ab..066cfb270 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -38,6 +38,7 @@ renderPicture' pdata rot zoom trans@(tranx,trany) wins@(winx,winy) wallPointsCol viewFroms@(viewFromx,viewFromy) pic = do let wallPoints = map fst wallPointsCol startTicks <- SDL.ticks + setCommonUniforms pdata rot zoom trans wins depthFunc $= Just Less