From 5585a49393a05c25b7df7a6a48d1f39db6324b69 Mon Sep 17 00:00:00 2001 From: mtgmonkey Date: Mon, 8 Dec 2025 11:21:14 +0100 Subject: semantics, readability, relicense, initResource argument removal --- src/Game.hs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) (limited to 'src/Game.hs') diff --git a/src/Game.hs b/src/Game.hs index 7aeb2a5..9af35d0 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -9,36 +9,24 @@ -} module Game (main) where -import Game.Internal.LoadShaders import Game.Internal.Types import Game.Internal -import Control.Concurrent (threadDelay) -import Control.Lens ((^.), (+~), (&), (%~)) -import Control.Monad (when) -import Data.Fixed (mod') -import Data.IORef (atomicModifyIORef', IORef, modifyIORef', newIORef, readIORef, writeIORef) -import Data.List (delete) -import Foreign.Marshal.Array (withArray) -import Foreign.Ptr (nullPtr, plusPtr) -import Foreign.Storable (sizeOf, Storable) -import GHC.Float (double2Float, int2Double) +import Control.Lens ((^.)) +import Data.IORef (newIORef) +import GHC.Float (double2Float) import qualified Graphics.UI.GLFW as GLFW import qualified Graphics.Rendering.OpenGL as GL import Graphics.Rendering.OpenGL as GL (($=)) import qualified Linear as L -import Linear ( V3(..) - , _x - , _y - , _z - ) +import Linear ( V3(..), _y ) -- | Main function runs game main :: IO () main = do - GLFW.init + _ <- GLFW.init GLFW.defaultWindowHints -- OpenGL core >=3.3 @@ -61,7 +49,7 @@ main = do GLFW.setCursorInputMode window GLFW.CursorInputMode'Hidden GLFW.setCursorPosCallback window $ Just (cursorPosHandler Nothing) - (objects, program) <- initResources window testVertices + (objects, program) <- initResources testVertices -- init model let @@ -123,8 +111,6 @@ update dt model = updateAcceleration :: Float -> Model -> Model updateAcceleration dt model = let - yaw = (L.rotate (L.axisAngle model.wprop.up model.camera.camYaw) model.camera.camReference) - front = L.normalize $ (V3 1 0 1) * (L.rotate (L.axisAngle (L.cross model.wprop.up yaw) model.camera.camPitch) yaw) zp = if elem GLFW.Key'S model.keys then 1 else 0 zn = if elem GLFW.Key'W model.keys then 1 else 0 xp = if elem GLFW.Key'D model.keys then 1 else 0 @@ -193,12 +179,6 @@ updateCameraAngle dt model = } } --- | updates given a keypress. escape case is probably caught by GLFW in the --- handler function itself -updateKeyPressed :: GLFW.Key -> Model -> Model -updateKeyPressed key model = - model { keys = key:model.keys } - -- | views the model view :: GLFW.Window -> Model -> IO () view window model = do @@ -233,8 +213,8 @@ view window model = do projectionLocation <- GL.get $ GL.uniformLocation model.program "u_projection" GL.uniform projectionLocation $= projectionGLMatrix - -- draw objects - drawObjects model.objects + -- draw objects; returns IO [] + _ <- drawObjects model.objects -- swap to current buffer GLFW.swapBuffers window -- cgit v1.3.1