semantics, readability, relicense, initResource argument removal

This commit is contained in:
mtgmonkey
2025-12-08 11:21:14 +01:00
parent e767a5ee5b
commit 5585a49393
8 changed files with 200 additions and 133 deletions

View File

@@ -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