Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9b4e2d34a | ||
|
|
73985e298a | ||
|
|
ffc9d08a2d | ||
| 35bd4c1740 | |||
|
|
20ecde081b | ||
|
|
d87e4ba21a | ||
|
|
9e8bafa6e2 | ||
|
|
5585a49393 | ||
|
|
e767a5ee5b |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
dist-newstyle
|
||||
result
|
||||
74
CHANGELOG.md
74
CHANGELOG.md
@@ -6,36 +6,86 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
## [Eventual]
|
||||
|
||||
### Added
|
||||
|
||||
- test suite for non-IO functions
|
||||
- debug/release outputs of Nix flake
|
||||
- test suite for non-`IO` functions
|
||||
|
||||
### Changed
|
||||
|
||||
- use Rotors rather than Quaternions for rotation; easily extended to 4D
|
||||
- use rotors rather than `Linear.Quaternion` for rotation; easily extended to 4D
|
||||
- move `Player` out of `Camera`
|
||||
- configure with `Properties` objects in the Model
|
||||
- use `Double` rather than `FLoat` for internal calculations
|
||||
- `cursorPos`, `dt` natively `Double` already
|
||||
|
||||
## [0.3.0] - 2025-12-08
|
||||
|
||||
### Added
|
||||
|
||||
- Cabal build system
|
||||
- `.gitignore` against build artifacts
|
||||
|
||||
### Changed
|
||||
|
||||
- versioning using the [PVP standard](https://pvp.haskell.org/), though it will remain SemVer compliant
|
||||
- SemVer version A.B.C will become PVP version A.B.C.0
|
||||
- `README.md` overhauled to reflect new build system
|
||||
|
||||
### Fixed
|
||||
|
||||
- semantic issues
|
||||
- a couple non-impactful typos
|
||||
|
||||
### Removed
|
||||
|
||||
- `Game` module -> moved to `Main`
|
||||
|
||||
## [0.2.1] - 2025-12-08
|
||||
|
||||
### Changed
|
||||
|
||||
- break Git by using it wrong
|
||||
- fix Git (maybe)
|
||||
|
||||
## [0.2.0] - 2025-12-07
|
||||
|
||||
### Added
|
||||
|
||||
- 100% documentation coverage
|
||||
- 4 outputs of Nix flake
|
||||
- `debug`: compiles fast, no docs
|
||||
- `release`: runs fast, no docs
|
||||
- `docs`: only docs
|
||||
- `default`: release binary with docs
|
||||
|
||||
### Changed
|
||||
|
||||
- `initResources` no longer takes a `GLFW.Window` argument
|
||||
- BSD 3-clause license adopted rather than WTFPL
|
||||
- reasoning: More professional, widely recognised, effectively identical
|
||||
- `CHANGELOG.md` has more formatting, namely inline code
|
||||
- clarify a couple entries in the `[0.1.0] - 2025-12-07 Changed` entry
|
||||
|
||||
### Fixed
|
||||
|
||||
- semantic issues; no warnings are thrown
|
||||
|
||||
## [0.1.0] - 2025-12-07
|
||||
|
||||
### Added
|
||||
|
||||
- CHANGELOG.md
|
||||
- layer correctly drawn objects in the view function
|
||||
- added `CHANGELOG.md`
|
||||
- layer correctly drawn objects in `view`
|
||||
|
||||
### Changed
|
||||
|
||||
- 8xMSAA rather than 4xMSAA window hint to improve AA
|
||||
- todo and changelog in CHANGELOG.md rather than README.md
|
||||
- a nubmer fo functions from Game module now in Game.Internal
|
||||
- initResources takes an array of objects to draw rather than hardcoded arrays
|
||||
- square the far plane of the perspective transform
|
||||
- loop function takes delta time
|
||||
- todo and changelog in `CHANGELOG.md` rather than `README.md`
|
||||
- a nubmer fo functions from `Game` now in `Game.Internal`
|
||||
- `initResources` takes an `[V3 GL.GLfloat]` to draw rather than hardcoded arrays
|
||||
- square the distance of the far plane of the perspective transform
|
||||
- `loop` function takes delta time `dt :: Float`
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
11
LICENSE
Normal file
11
LICENSE
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright 2025 Andromeda
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
35
README.md
35
README.md
@@ -1,7 +1,30 @@
|
||||
```bash
|
||||
git clone https://git.mtgmonkey.net/Andromeda/hs-game
|
||||
cd hs-game
|
||||
nix run
|
||||
```
|
||||
see CHANGELOG.md
|
||||
|
||||
todo moved to CHANGELOG.md
|
||||
to run without nix:
|
||||
- get build tools:
|
||||
- with apt: `apt install cabal-install ghc git`
|
||||
- get source code: `git clone https://git.mtgmonkey.net/Andromeda/hs-game --depth 1; cd hs-game`
|
||||
- get dependencies
|
||||
- with apt on x86-64: `apt install g++-x86-64_linux-gnu libgl-dev libx11-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev libglu1-mesa-dev`
|
||||
- run with `cabal run` or build with `cabal build`
|
||||
|
||||
to run with nix:
|
||||
`nix run git+https://git.mtgmonkey.net/Andromeda/hs-game`
|
||||
|
||||
to enter nix development shell:
|
||||
`nix develop git+https://git.mtgmonkey.net/Andromeda/hs-game`
|
||||
|
||||
build tested on
|
||||
- nix
|
||||
- Kubuntu 25.10
|
||||
|
||||
to release:
|
||||
- update CHANGELOG.md with new version
|
||||
- update version in hs-game.cabal
|
||||
- update version in flake.nix
|
||||
- check that it builds
|
||||
- `git add -A`
|
||||
- `git status` make sure there aren't random files
|
||||
- `git status -v` make sure all additions are in CHANGELOG.md
|
||||
- double check that flake, .cabal, and CHANGELOG.md all have the same version
|
||||
- release
|
||||
|
||||
56
flake.nix
56
flake.nix
@@ -2,12 +2,64 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
|
||||
};
|
||||
outputs = {nixpkgs, ...}: let
|
||||
outputs = {
|
||||
nixpkgs,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
versionString = "0.3.0";
|
||||
package = {
|
||||
mkDerivation,
|
||||
base,
|
||||
bytestring,
|
||||
GLFW-b,
|
||||
lens,
|
||||
lib,
|
||||
linear,
|
||||
OpenGL,
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "hs-game";
|
||||
version = versionString;
|
||||
src = ./.;
|
||||
isLibrary = false;
|
||||
isExecutable = true;
|
||||
executableHaskellDepends = [
|
||||
base
|
||||
bytestring
|
||||
GLFW-b
|
||||
lens
|
||||
linear
|
||||
OpenGL
|
||||
];
|
||||
homepage = "https://git.mtgmonkey.net/Andromeda/hs-game";
|
||||
license = lib.licenses.bsd3;
|
||||
mainProgram = "hs-game";
|
||||
};
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
packages.${system} = {
|
||||
default = pkgs.callPackage ./package.nix {};
|
||||
default =
|
||||
pkgs.haskellPackages.callPackage package {};
|
||||
};
|
||||
devShells.${system} = {
|
||||
default = pkgs.mkShell {
|
||||
packages = [
|
||||
pkgs.cabal-install
|
||||
pkgs.libGL
|
||||
pkgs.xorg.libX11
|
||||
pkgs.xorg.libXi
|
||||
pkgs.xorg.libXrandr
|
||||
pkgs.xorg.libXxf86vm
|
||||
pkgs.xorg.libXcursor
|
||||
pkgs.xorg.libXinerama
|
||||
pkgs.libGLU
|
||||
];
|
||||
inputsFrom = [
|
||||
self.packages.${system}.default
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
38
hs-game.cabal
Normal file
38
hs-game.cabal
Normal file
@@ -0,0 +1,38 @@
|
||||
cabal-version: 3.0
|
||||
name: hs-game
|
||||
version: 0.3.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
homepage: https://git.mtgmonkey.net/Andromeda/hs-game
|
||||
license: BSD-3-Clause
|
||||
license-file: LICENSE
|
||||
author: andromeda
|
||||
maintainer: @andromeda:tchncs.de
|
||||
-- copyright:
|
||||
category: Game
|
||||
build-type: Simple
|
||||
extra-doc-files: CHANGELOG.md
|
||||
-- extra-source-files:
|
||||
|
||||
common warnings
|
||||
ghc-options: -Wall
|
||||
|
||||
common optimizations
|
||||
ghc-options: -O2
|
||||
|
||||
executable hs-game
|
||||
import: optimizations
|
||||
main-is: Main.hs
|
||||
other-modules:
|
||||
Game.Internal,
|
||||
Game.Internal.LoadShaders,
|
||||
Game.Internal.Types
|
||||
-- other-extensions:
|
||||
build-depends:
|
||||
base >= 4.18,
|
||||
bytestring >= 0.12,
|
||||
GLFW-b >= 3.3,
|
||||
lens >= 5.3,
|
||||
linear >= 1.23,
|
||||
OpenGL >= 3.0,
|
||||
hs-source-dirs: src
|
||||
65
package.nix
65
package.nix
@@ -1,65 +0,0 @@
|
||||
{
|
||||
haskellPackages,
|
||||
lib,
|
||||
stdenv,
|
||||
...
|
||||
}: let
|
||||
ghcExeOptions = lib.concatStringsSep " " ghcFlags;
|
||||
ghcFlags = [
|
||||
"-O"
|
||||
"-Wall"
|
||||
"-Widentities"
|
||||
"-Wincomplete-record-updates"
|
||||
"-Wincomplete-uni-patterns"
|
||||
# "-Wmissing-export-lists"
|
||||
"-Wmissing-home-modules"
|
||||
"-Wpartial-fields"
|
||||
"-Wredundant-constraints"
|
||||
"-threaded"
|
||||
"-rtsopts"
|
||||
"-with-rtsopts=-N"
|
||||
# src
|
||||
"-i./src"
|
||||
"-main-is Game"
|
||||
];
|
||||
haddockOptions = lib.concatStringsSep " " haddockFlags;
|
||||
haddockFlags = [
|
||||
"--html"
|
||||
"--odir docs"
|
||||
"--optghc=-i./src"
|
||||
"src/Game/Main.hs"
|
||||
];
|
||||
ghcPackages = p: [
|
||||
p.GLFW-b
|
||||
p.linear
|
||||
p.OpenGL
|
||||
];
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "haskengl";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
nativeBuildInputs = [
|
||||
(haskellPackages.ghcWithPackages ghcPackages)
|
||||
];
|
||||
buildInputs = [
|
||||
];
|
||||
configurePhase = ''
|
||||
'';
|
||||
buildPhase = ''
|
||||
ghc ${ghcExeOptions} ./src/Game/Main.hs -o ./Main
|
||||
haddock ${haddockOptions}
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ./Main $out/bin/hs-game
|
||||
cp ./docs $out/docs -r
|
||||
'';
|
||||
|
||||
meta = {
|
||||
homepage = "https://mtgmonkey.net";
|
||||
license = lib.licenses.wtfpl;
|
||||
mainProgram = "hs-game";
|
||||
platforms = ["x86_64-linux"];
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
{-# LANGUAGE DisambiguateRecordFields, NamedFieldPuns, OverloadedRecordDot #-}
|
||||
{- |
|
||||
- Module : Game.Internal
|
||||
- Description : 'hidden' functions
|
||||
- Copyright : Andromeda 2025
|
||||
- License : WTFPL
|
||||
- Description : internal functions
|
||||
- Copyright : 2025 Andromeda
|
||||
- License : BSD 3-clause
|
||||
- Maintainer : Matrix @Andromeda:tchncs.de
|
||||
- Stability : Experimental
|
||||
-}
|
||||
@@ -25,10 +25,8 @@ import Game.Internal.LoadShaders
|
||||
import Game.Internal.Types
|
||||
|
||||
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.IORef (IORef, modifyIORef', readIORef)
|
||||
import Data.List (delete)
|
||||
import Foreign.Marshal.Array (withArray)
|
||||
import Foreign.Ptr (nullPtr, plusPtr)
|
||||
@@ -39,20 +37,15 @@ 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(..))
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Shader creation and object initialisation
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- | loads models, shaders
|
||||
initResources :: GLFW.Window -> [V3 GL.GLfloat] -> IO ([Object], GL.Program)
|
||||
initResources window array = do
|
||||
initResources :: [V3 GL.GLfloat] -> IO ([Object], GL.Program)
|
||||
initResources array = do
|
||||
-- create objects
|
||||
testObject0 <- createObject (map (+(V3 (-1) (-1) (-1))) array) 3 GL.TriangleStrip
|
||||
testObject1 <- createObject (map (+(V3 (1) (1) (1))) array) 3 GL.TriangleStrip
|
||||
@@ -151,7 +144,7 @@ createObject array numComponents primitiveMode = do
|
||||
GL.bindVertexArrayObject $= Just vao
|
||||
|
||||
-- vbo for vertices
|
||||
createVBO array numComponents $ GL.AttribLocation 0
|
||||
_ <- createVBO array numComponents $ GL.AttribLocation 0
|
||||
|
||||
return
|
||||
(Object
|
||||
@@ -187,9 +180,9 @@ loop window dt update view modelRef = do
|
||||
-- end frame timer, wait the difference between expected and actual
|
||||
Just frameEnd <- GLFW.getTime
|
||||
let
|
||||
dt = double2Float $ frameEnd - frameStart
|
||||
drawTime = double2Float $ frameEnd - frameStart
|
||||
target = 1 / 60 :: Float
|
||||
when (dt < target) $ threadDelay $ floor $ (target - dt) * 1000000
|
||||
when (drawTime < target) $ threadDelay $ floor $ (target - drawTime) * 1000000
|
||||
Just frameEnd' <- GLFW.getTime
|
||||
let
|
||||
dt' = double2Float $ frameEnd' - frameStart
|
||||
@@ -215,7 +208,7 @@ applyToTuples f (x, y) (a, b) = (f x a, f y b)
|
||||
updateCursorPos :: Double -> Double -> Model -> Model
|
||||
updateCursorPos x y model =
|
||||
let
|
||||
pyth = (((fst model.cursorPos) - x) ** 2 + ((snd model.cursorPos - y)) ** 2) ** 0.5
|
||||
pyth = (((fst model.cursorPos) - x) ** 2 + ((snd model.cursorPos) - y) ** 2) ** 0.5
|
||||
in
|
||||
if pyth < 16 then
|
||||
model
|
||||
@@ -254,9 +247,9 @@ resizeWindow _ _ _ = return ()
|
||||
keyPressed :: Maybe (IORef Model) -> GLFW.KeyCallback
|
||||
keyPressed _ window GLFW.Key'Escape _ GLFW.KeyState'Pressed _ =
|
||||
shutdownWindow window
|
||||
keyPressed (Just modelRef) window key _ GLFW.KeyState'Pressed _ =
|
||||
keyPressed (Just modelRef) _ key _ GLFW.KeyState'Pressed _ =
|
||||
modifyIORef' modelRef $ updateKeyPressed key
|
||||
keyPressed (Just modelRef) window key _ GLFW.KeyState'Released _ =
|
||||
keyPressed (Just modelRef) _ key _ GLFW.KeyState'Released _ =
|
||||
modifyIORef' modelRef $ updateKeyReleased key
|
||||
keyPressed _ _ _ _ _ _ = return ()
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{-# LANGUAGE NamedFieldPuns, OverloadedRecordDot #-}
|
||||
{- |
|
||||
- Module : Game.Types
|
||||
- Module : Game.Internal.Types
|
||||
- Description :
|
||||
- Copyright : Andromeda 2025
|
||||
- License : WTFPL
|
||||
- Copyright : 2025 Andromeda
|
||||
- License : BSD 3-clause
|
||||
- Maintainer : Matrix @Andromeda:tchncs.de
|
||||
- Stability : Experimental
|
||||
-}
|
||||
@@ -44,18 +44,19 @@ import qualified Graphics.UI.GLFW as GLFW
|
||||
import qualified Graphics.Rendering.OpenGL as GL
|
||||
|
||||
import qualified Linear as L
|
||||
import Linear (Quaternion, V3, V3(..), V4(..))
|
||||
import Linear (V3, V3(..), V4(..))
|
||||
|
||||
-- | represents a single draw call
|
||||
data Object =
|
||||
Object
|
||||
{ vao :: GL.VertexArrayObject
|
||||
, numIndicies :: GL.NumArrayIndices
|
||||
, numComponents :: GL.NumComponents
|
||||
, primitiveMode :: GL.PrimitiveMode
|
||||
{ vao :: GL.VertexArrayObject -- ^ vao of vertex buffer
|
||||
, numIndicies :: GL.NumArrayIndices -- ^ number of vertices
|
||||
, numComponents :: GL.NumComponents -- ^ dimensionallity; vec3, vec4, etc.
|
||||
, primitiveMode :: GL.PrimitiveMode -- ^ primitive mode to be drawn with
|
||||
}
|
||||
deriving Show
|
||||
|
||||
-- | converts M44 to a 16array for OpenGL
|
||||
toGLMatrix :: L.M44 GL.GLfloat -> [GL.GLfloat]
|
||||
toGLMatrix
|
||||
(V4
|
||||
@@ -73,34 +74,49 @@ toGLMatrix
|
||||
data Model =
|
||||
Model
|
||||
{ camera :: Camera
|
||||
, cursorDeltaPos :: (Double, Double)
|
||||
, cursorPos :: (Double, Double)
|
||||
, keys :: [GLFW.Key]
|
||||
, objects :: [Object]
|
||||
, program :: GL.Program
|
||||
, cursorDeltaPos :: (Double, Double) -- ^ frame-on-frame delta mouse position
|
||||
, cursorPos :: (Double, Double) -- ^ current mouse position
|
||||
, keys :: [GLFW.Key] -- ^ currently pressed keys
|
||||
, objects :: [Object] -- ^ draw calls
|
||||
, program :: GL.Program -- ^ shader program
|
||||
, wprop :: WorldProperties
|
||||
}
|
||||
deriving Show
|
||||
|
||||
mkModel :: Camera -> [Object] -> GL.Program -> WorldProperties -> Model
|
||||
mkModel camera objects program wprop = Model camera (0,0) (0,0) [] objects program wprop
|
||||
-- | smart constructor for Model
|
||||
mkModel
|
||||
:: Camera
|
||||
-> [Object]
|
||||
-> GL.Program
|
||||
-> WorldProperties
|
||||
-> Model
|
||||
mkModel camera objects program wprop =
|
||||
Model
|
||||
camera
|
||||
(0,0)
|
||||
(0,0)
|
||||
[]
|
||||
objects
|
||||
program
|
||||
wprop
|
||||
|
||||
-- | camera
|
||||
data Camera =
|
||||
Camera
|
||||
{ camPos :: V3 Float
|
||||
, camPitch :: Float
|
||||
, camYaw :: Float
|
||||
, camReference :: V3 Float
|
||||
, camVel :: V3 Float
|
||||
, mouseSensitivity :: Float
|
||||
, strafeStrength :: Float
|
||||
, jumpStrength :: Float
|
||||
, hasJumped :: Bool
|
||||
, airTime :: Float
|
||||
{ camPos :: V3 Float -- ^ position in world space
|
||||
, camPitch :: Float -- ^ pitch in radians, up positive
|
||||
, camYaw :: Float -- ^ yaw in radians, right positive
|
||||
, camReference :: V3 Float -- ^ reference direction; orientation applied to
|
||||
, camVel :: V3 Float -- ^ velocity in world space
|
||||
, mouseSensitivity :: Float -- ^ scale factor for mouse movement
|
||||
, strafeStrength :: Float -- ^ scale factor for strafe
|
||||
, jumpStrength :: Float -- ^ scale factor for jump initial velocity
|
||||
, hasJumped :: Bool -- ^ whether the camera still has jumping state
|
||||
, airTime :: Float -- ^ time since jumping state entered in seconds
|
||||
}
|
||||
deriving Show
|
||||
|
||||
-- | smart constructor for Camera
|
||||
mkCamera
|
||||
:: V3 Float
|
||||
-> Float
|
||||
@@ -132,14 +148,16 @@ mkCamera
|
||||
False
|
||||
0
|
||||
|
||||
-- | physical properties of the world
|
||||
data WorldProperties =
|
||||
WorldProperties
|
||||
{ g :: Float -- ^ gravity `g`
|
||||
, friction :: Float -- ^ floor friction
|
||||
, up :: V3 Float
|
||||
, friction :: Float -- ^ scale factor for floor friction
|
||||
, up :: V3 Float -- ^ global up vector
|
||||
}
|
||||
deriving Show
|
||||
|
||||
-- | smart constructor for WorldProperties
|
||||
mkWorldProperties :: Float -> Float -> V3 Float-> WorldProperties
|
||||
mkWorldProperties g friction up =
|
||||
WorldProperties g friction (L.normalize up)
|
||||
|
||||
@@ -2,43 +2,31 @@
|
||||
{- |
|
||||
- Module : Game
|
||||
- Description : runs game
|
||||
- Copyright : Andromeda 2025
|
||||
- License : WTFPL
|
||||
- Copyright : 2025 Andromeda
|
||||
- License : BSD 3-clause
|
||||
- Maintainer : Matrix @Andromeda:tchncs.de
|
||||
- Stability : Experimental
|
||||
-}
|
||||
module Game (main) where
|
||||
module Main (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
|
||||
Reference in New Issue
Block a user