summaryrefslogtreecommitdiff
path: root/src/Game.hs
diff options
context:
space:
mode:
authormtgmonkey <mtgmonkey@nixos>2025-12-08 11:21:14 +0100
committermtgmonkey <mtgmonkey@nixos>2025-12-08 11:21:14 +0100
commit5585a49393a05c25b7df7a6a48d1f39db6324b69 (patch)
tree9f96a496c4c00da9fd286d2b6742d95eb8ae17e1 /src/Game.hs
parente767a5ee5becd575039ff39db40a7373ccca7eaf (diff)
semantics, readability, relicense, initResource argument removal
Diffstat (limited to 'src/Game.hs')
-rw-r--r--src/Game.hs36
1 files changed, 8 insertions, 28 deletions
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