From 7fac2a80c61aab48910b27d07d4ddbb404536dd3 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 3 Jan 2021 14:39:37 +0000 Subject: Format and hlint --- src/Vivant.hs | 66 +++++++++++++++++++++++--------------------------- src/Vivant/Noise.hs | 15 ++++++------ src/Vivant/Renderer.hs | 2 +- src/Vivant/Terrain.hs | 5 ++-- 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/Vivant.hs b/src/Vivant.hs index 21c397e..5335b30 100644 --- a/src/Vivant.hs +++ b/src/Vivant.hs @@ -67,7 +67,7 @@ initialCamera = cameraFront = normalize (V3 0 10 (-10)), cameraSpeed = 0.05, cameraPitch = 0, - cameraYaw = (-90) + cameraYaw = -90 } data Game = Game @@ -182,12 +182,12 @@ parseEvents keys mouse = do . changeIfIn events' mouseWheel (\(k, m) -> (k, m {mouseWheel = 0})) $ changeIfIn events' mouseMoving (\(k, m) -> (k, m {mouseRelative = V2 0 0})) (k, m) where - mouseMoving (SDL.MouseMotionEvent {}) = True + mouseMoving SDL.MouseMotionEvent {} = True mouseMoving _ = False - mouseWheel (SDL.MouseWheelEvent {}) = True + mouseWheel SDL.MouseWheelEvent {} = True mouseWheel _ = False changeIfIn events event modification initial = - if (> 0) . length $ filter event events + if any event events then initial else modification initial @@ -198,36 +198,31 @@ handleEvents :: handleEvents event (k, m) = case event of SDL.KeyboardEvent - ( SDL.KeyboardEventData - { SDL.keyboardEventKeyMotion = e, - SDL.keyboardEventKeysym = k' - } - ) -> + SDL.KeyboardEventData + { SDL.keyboardEventKeyMotion = e, + SDL.keyboardEventKeysym = k' + } -> ((if e == SDL.Released then Set.delete else Set.insert) k' k, m) SDL.MouseMotionEvent - ( SDL.MouseMotionEventData - { SDL.mouseMotionEventPos = pos, - SDL.mouseMotionEventRelMotion = vel - } - ) -> + SDL.MouseMotionEventData + { SDL.mouseMotionEventPos = pos, + SDL.mouseMotionEventRelMotion = vel + } -> (k, MouseInputs pos vel (mousePositionOld m) (mousePressed m) (mouseWheel m)) SDL.MouseButtonEvent - ( SDL.MouseButtonEventData - { SDL.mouseButtonEventMotion = SDL.Pressed - } - ) -> + SDL.MouseButtonEventData + { SDL.mouseButtonEventMotion = SDL.Pressed + } -> (k, m {mousePressed = True}) SDL.MouseButtonEvent - ( SDL.MouseButtonEventData - { SDL.mouseButtonEventMotion = SDL.Released - } - ) -> + SDL.MouseButtonEventData + { SDL.mouseButtonEventMotion = SDL.Released + } -> (k, m {mousePressed = False}) SDL.MouseWheelEvent - ( SDL.MouseWheelEventData - { SDL.mouseWheelEventPos = V2 x y - } - ) -> + SDL.MouseWheelEventData + { SDL.mouseWheelEventPos = V2 x y + } -> (k, m {mouseWheel = y}) SDL.QuitEvent {} -> (Set.insert escapeKey k, m) @@ -262,13 +257,12 @@ updateMouse mouse game = pixelRenderer :: Double -> Int -> Int -> Float pixelRenderer n x y = fromRational . toRational $ - ( ( perlin3 - permutation - ( (fromIntegral x - 32) / 16, - (fromIntegral y - 32) / 16, - n - ) - ) + ( perlin3 + permutation + ( (fromIntegral x - 32) / 16, + (fromIntegral y - 32) / 16, + n + ) + 1 ) @@ -311,13 +305,13 @@ toRadians :: Float -> Float toRadians = (*) (pi / 180) scaledMat :: V4 (V4 Float) -> V4 (V4 Float) -scaledMat n = ((n * identity) & _w . _w .~ 1) +scaledMat n = (n * identity) & _w . _w .~ 1 castV3 :: V3 a -> GL.Vector3 a castV3 (V3 a b c) = GL.Vector3 a b c draw :: Game -> IO () -draw game@(Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t}) = do +draw game@Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t} = do tick <- ticks GL.clearColor $= GL.Color4 0.2 0.2 0.2 1 GL.clear [GL.ColorBuffer, GL.DepthBuffer] @@ -343,7 +337,7 @@ draw game@(Game {gameProgram = Just p, gameVao = Just v, gameTerrain = Just t}) ourColorLoc <- GL.uniformLocation p "light_pos" GL.uniform ourColorLoc - $= (GL.Vector3 (0 :: Float) (128 * sin (fromIntegral tick / 2000)) (64 * (abs $ cos (fromIntegral tick / 2000)))) + $= GL.Vector3 (0 :: Float) (128 * sin (fromIntegral tick / 2000)) (64 * abs (cos $ fromIntegral tick / 2000)) --castV3 (cameraPos (gameCamera game)) render $ terrainRenderer t diff --git a/src/Vivant/Noise.hs b/src/Vivant/Noise.hs index bf2b197..a9a3b47 100644 --- a/src/Vivant/Noise.hs +++ b/src/Vivant/Noise.hs @@ -390,20 +390,19 @@ main = do pixelRenderer, pixelRenderer' :: String -> Int -> Int -> Word8 pixelRenderer !n !x !y = doubleToByte $ - ( ( perlin3 - permutation - ( (fromIntegral x - 32) / 4, - (fromIntegral y - 32) / 4, - read n :: Double - ) - ) + ( perlin3 + permutation + ( (fromIntegral x - 32) / 4, + (fromIntegral y - 32) / 4, + read n :: Double + ) + 1 ) / 2 * 128 pixelRenderer' !n x y = - (\w -> doubleToByte $ ((w + 1) / 2 * 128)) -- w should be in [-1,+1] + (\w -> doubleToByte ((w + 1) / 2 * 128)) -- w should be in [-1,+1] . perlin3 permutation . (\(x, y, z) -> ((x -256) / 32, (y -256) / 32, (z -256) / 32)) $ (fromIntegral x, fromIntegral y, 0 :: Double) diff --git a/src/Vivant/Renderer.hs b/src/Vivant/Renderer.hs index 91a395f..3ad1bf0 100644 --- a/src/Vivant/Renderer.hs +++ b/src/Vivant/Renderer.hs @@ -20,7 +20,7 @@ getUniformLocation :: GL.UniformLocation -> GL.GLint getUniformLocation (GL.UniformLocation i) = i render :: Renderer -> IO () -render r@(Renderer {rendererProgram = Just p}) = do +render r@Renderer {rendererProgram = Just p} = do -- GL.currentProgram $= rendererProgram r GL.bindVertexArrayObject $= rendererVao r diff --git a/src/Vivant/Terrain.hs b/src/Vivant/Terrain.hs index b73469a..c9c517a 100644 --- a/src/Vivant/Terrain.hs +++ b/src/Vivant/Terrain.hs @@ -27,9 +27,8 @@ normal a b c = partition :: (V.Storable a1, Enum a1, Num a1) => [[a1]] -> V.Vector a1 partition r = - V.fromList . concat . concat - . fmap (\(e, y) -> fmap (generateP y) $ zip (zip (uncurry zip e) $ tail (uncurry zip e)) [0 ..]) - $ zip (zip r $ tail r) [0 ..] + V.fromList . concat . concatMap (\(e, y) -> generateP y <$> zip (zip (uncurry zip e) $ tail (uncurry zip e)) [0 ..]) $ + zip (zip r $ tail r) [0 ..] where generateP y (((z1, z2), (z3, z4)), x) = let (n1x, n1y, n1z) = normal (x, y, z1) (x, y + 1, z2) (x + 1, y, z3) -- cgit