update affection
This commit is contained in:
commit
5cf9a906db
2
extern/affection/.gitignore
vendored
2
extern/affection/.gitignore
vendored
|
@ -16,3 +16,5 @@ cabal.project.local*
|
||||||
dist*/
|
dist*/
|
||||||
report.html
|
report.html
|
||||||
*.bak
|
*.bak
|
||||||
|
.direnv/
|
||||||
|
.envrc
|
||||||
|
|
64
extern/affection/affection.cabal
vendored
64
extern/affection/affection.cabal
vendored
|
@ -102,7 +102,7 @@ library
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
-- Other library packages from which modules are imported.
|
-- Other library packages from which modules are imported.
|
||||||
build-depends: base >=4.9 && < 5
|
build-depends: base >=4.9 && < 5
|
||||||
, sdl2 ^>= 2.5
|
, sdl2 >= 2.5
|
||||||
, linear
|
, linear
|
||||||
, text
|
, text
|
||||||
, mtl
|
, mtl
|
||||||
|
@ -117,6 +117,7 @@ library
|
||||||
, stm
|
, stm
|
||||||
, uuid
|
, uuid
|
||||||
, vector
|
, vector
|
||||||
|
, resourcet
|
||||||
|
|
||||||
-- This example shows the message system. only makes sense when compiling with
|
-- This example shows the message system. only makes sense when compiling with
|
||||||
-- verbose flag.
|
-- verbose flag.
|
||||||
|
@ -126,12 +127,11 @@ executable example00
|
||||||
ghc-options: -threaded -Wall
|
ghc-options: -threaded -Wall
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions: OverloadedStrings
|
default-extensions: OverloadedStrings
|
||||||
if flag(examples)
|
build-depends: base >=4.9 && < 5
|
||||||
build-depends: base >=4.9 && < 5
|
, affection
|
||||||
, affection
|
, sdl2 >= 2.5
|
||||||
, sdl2 ^>= 2.5
|
, stm
|
||||||
, stm
|
if !flag(examples)
|
||||||
else
|
|
||||||
buildable: False
|
buildable: False
|
||||||
|
|
||||||
-- A small game of life implementation
|
-- A small game of life implementation
|
||||||
|
@ -142,19 +142,18 @@ executable example01
|
||||||
ghc-options: -threaded -Wall
|
ghc-options: -threaded -Wall
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions: OverloadedStrings
|
default-extensions: OverloadedStrings
|
||||||
if flag(examples)
|
build-depends: base >=4.9 && < 5
|
||||||
build-depends: base >=4.9 && < 5
|
, affection
|
||||||
, affection
|
, sdl2 >= 2.5
|
||||||
, sdl2 ^>= 2.5
|
, stm
|
||||||
, stm
|
, OpenGL
|
||||||
, OpenGL
|
, random
|
||||||
, random
|
, containers
|
||||||
, containers
|
, linear
|
||||||
, linear
|
, matrix
|
||||||
, matrix
|
, nanovg >= 0.6.0.0
|
||||||
, nanovg >= 0.6.0.0
|
, deepseq
|
||||||
, deepseq
|
if !flag(examples)
|
||||||
else
|
|
||||||
buildable: False
|
buildable: False
|
||||||
|
|
||||||
-- Another small game of life implementation
|
-- Another small game of life implementation
|
||||||
|
@ -165,17 +164,16 @@ executable example02
|
||||||
ghc-options: -threaded -Wall
|
ghc-options: -threaded -Wall
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions: OverloadedStrings
|
default-extensions: OverloadedStrings
|
||||||
if flag(examples)
|
build-depends: base >=4.9 && < 5
|
||||||
build-depends: base >=4.9 && < 5
|
, affection
|
||||||
, affection
|
, sdl2 >= 2.5
|
||||||
, sdl2 ^>= 2.5
|
, stm
|
||||||
, stm
|
, OpenGL
|
||||||
, OpenGL
|
, random
|
||||||
, random
|
, containers
|
||||||
, containers
|
, linear
|
||||||
, linear
|
, matrix
|
||||||
, matrix
|
, nanovg >= 0.6.0.0
|
||||||
, nanovg >= 0.6.0.0
|
, deepseq
|
||||||
, deepseq
|
if !flag(examples)
|
||||||
else
|
|
||||||
buildable: False
|
buildable: False
|
||||||
|
|
126
extern/affection/shell.nix
vendored
126
extern/affection/shell.nix
vendored
|
@ -1,125 +1,7 @@
|
||||||
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
affection = pkgs.haskellPackages.callCabal2nix "affection" (gitignore ./.) {};
|
||||||
inherit (nixpkgs) pkgs;
|
gitignore = dir: pkgs.nix-gitignore.gitignoreSource [] dir;
|
||||||
|
|
||||||
nanovg = with haskellPackages; callPackage (
|
|
||||||
{ mkDerivation, base, bytestring, c2hs, containers, glew
|
|
||||||
, hspec, inline-c, libGL, libGLU, QuickCheck, stdenv, text, vector
|
|
||||||
}:
|
|
||||||
mkDerivation {
|
|
||||||
pname = "nanovg";
|
|
||||||
version = "0.6.0.0";
|
|
||||||
sha256 = "e35a2772f2a2e71916013cab70eeb8eedd6f66b5490ddf7ce237c8c76895d496";
|
|
||||||
revision = "1";
|
|
||||||
editedCabalFile = "1lhfsq50r9bdby7mfscw8ih3wsz2m19lr2a2z9b6diaf5kz76vij";
|
|
||||||
isLibrary = true;
|
|
||||||
isExecutable = true;
|
|
||||||
doCheck = false;
|
|
||||||
libraryHaskellDepends = [ base bytestring containers text vector ];
|
|
||||||
librarySystemDepends = [ glew libGL libGLU ];
|
|
||||||
libraryPkgconfigDepends = [ glew ];
|
|
||||||
libraryToolDepends = [ c2hs ];
|
|
||||||
testHaskellDepends = [ base containers hspec inline-c QuickCheck ];
|
|
||||||
homepage = "https://github.com/cocreature/nanovg-hs";
|
|
||||||
description = "Haskell bindings for nanovg";
|
|
||||||
license = stdenv.lib.licenses.isc;
|
|
||||||
}) {};
|
|
||||||
|
|
||||||
glib = with haskellPackages; callPackage(
|
|
||||||
{ mkDerivation, base, bytestring, Cabal, containers, glib
|
|
||||||
, stdenv, text, utf8-string, gtk2hs-buildtools
|
|
||||||
}:
|
|
||||||
mkDerivation {
|
|
||||||
pname = "glib";
|
|
||||||
version = "0.13.8.0";
|
|
||||||
sha256 = "9cce6fb44e3c30de2bd330a6902955e3a5fce7b6e9ce41a4afb70e3a7d6e61a2";
|
|
||||||
setupHaskellDepends = [ base Cabal gtk2hs-buildtools ];
|
|
||||||
libraryHaskellDepends = [
|
|
||||||
base bytestring containers text utf8-string
|
|
||||||
];
|
|
||||||
libraryPkgconfigDepends = [ pkgs.glib ];
|
|
||||||
homepage = "http://projects.haskell.org/gtk2hs/";
|
|
||||||
description = "Binding to the GLIB library for Gtk2Hs";
|
|
||||||
license = stdenv.lib.licenses.lgpl21;
|
|
||||||
}) {};
|
|
||||||
|
|
||||||
#gtk2hs-buildtools = with haskellPackages; callPackage(
|
|
||||||
# { mkDerivation, alex, array, base, Cabal, containers, directory
|
|
||||||
# , filepath, happy, hashtables, pretty, process, random, stdenv
|
|
||||||
# }:
|
|
||||||
# mkDerivation {
|
|
||||||
# pname = "gtk2hs-buildtools";
|
|
||||||
# version = "0.13.4.0";
|
|
||||||
# src = ../gtk2hs/tools;
|
|
||||||
# isLibrary = true;
|
|
||||||
# isExecutable = true;
|
|
||||||
# enableSeparateDataOutput = true;
|
|
||||||
# libraryHaskellDepends = [
|
|
||||||
# array base Cabal containers directory filepath hashtables pretty
|
|
||||||
# process random
|
|
||||||
# ];
|
|
||||||
# libraryToolDepends = [ alex happy ];
|
|
||||||
# executableHaskellDepends = [ base ];
|
|
||||||
# homepage = "http://projects.haskell.org/gtk2hs/";
|
|
||||||
# description = "Tools to build the Gtk2Hs suite of User Interface libraries";
|
|
||||||
# license = stdenv.lib.licenses.gpl2;
|
|
||||||
# }) {};
|
|
||||||
|
|
||||||
sdl2 = with haskellPackages; callPackage(
|
|
||||||
{ mkDerivation, base, bytestring, deepseq, exceptions, linear, SDL2
|
|
||||||
, StateVar, stdenv, text, transformers, vector, weigh
|
|
||||||
}:
|
|
||||||
mkDerivation {
|
|
||||||
pname = "sdl2";
|
|
||||||
version = "2.5.1.0";
|
|
||||||
sha256 = "fc1d3d4276b2c4f835a5311075abb240385aae7edad8760f6bda55ed8271ed20";
|
|
||||||
isLibrary = true;
|
|
||||||
isExecutable = true;
|
|
||||||
enableSeparateDataOutput = true;
|
|
||||||
libraryHaskellDepends = [
|
|
||||||
base bytestring exceptions linear StateVar text transformers vector
|
|
||||||
];
|
|
||||||
librarySystemDepends = [ SDL2 ];
|
|
||||||
libraryPkgconfigDepends = [ SDL2 ];
|
|
||||||
testHaskellDepends = [ base deepseq linear vector weigh ];
|
|
||||||
description = "Both high- and low-level bindings to the SDL library (version 2.0.6+).";
|
|
||||||
license = stdenv.lib.licenses.bsd3;
|
|
||||||
doCheck = false;
|
|
||||||
}) {};
|
|
||||||
|
|
||||||
f = { mkDerivation, base, bytestring, clock, containers, deepseq
|
|
||||||
, linear, matrix, monad-loops, monad-parallel, mtl
|
|
||||||
, OpenGL, OpenGLRaw, random, stdenv, stm, text, uuid, vector
|
|
||||||
}:
|
|
||||||
mkDerivation {
|
|
||||||
pname = "affection";
|
|
||||||
version = "0.0.0.9";
|
|
||||||
src = ./.;
|
|
||||||
configureFlags = [ "-fexamples" ];
|
|
||||||
isLibrary = true;
|
|
||||||
isExecutable = true;
|
|
||||||
libraryHaskellDepends = [
|
|
||||||
base bytestring clock containers glib linear monad-loops
|
|
||||||
monad-parallel mtl OpenGL OpenGLRaw sdl2 stm text uuid vector
|
|
||||||
];
|
|
||||||
executableHaskellDepends = [
|
|
||||||
base containers deepseq linear matrix nanovg OpenGL random sdl2 stm
|
|
||||||
];
|
|
||||||
homepage = "https://github.com/nek0/affection#readme";
|
|
||||||
description = "A simple Game Engine using SDL";
|
|
||||||
license = stdenv.lib.licenses.lgpl3;
|
|
||||||
};
|
|
||||||
|
|
||||||
haskellPackages = if compiler == "default"
|
|
||||||
then pkgs.haskellPackages
|
|
||||||
else pkgs.haskell.packages.${compiler};
|
|
||||||
|
|
||||||
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
|
|
||||||
|
|
||||||
drv = variant (haskellPackages.callPackage f {});
|
|
||||||
|
|
||||||
in
|
in
|
||||||
|
affection.env
|
||||||
if pkgs.lib.inNixShell then drv.env else drv
|
|
||||||
|
|
112
extern/affection/src/Affection.hs
vendored
112
extern/affection/src/Affection.hs
vendored
|
@ -1,6 +1,5 @@
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE Strict #-}
|
{-# LANGUAGE Strict #-}
|
||||||
{-# LANGUAGE ExplicitForAll #-}
|
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
{-# LANGUAGE TypeApplications #-}
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
@ -23,12 +22,16 @@ import qualified Graphics.GL as GLRaw
|
||||||
import Foreign.Marshal.Array
|
import Foreign.Marshal.Array
|
||||||
|
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Char8 as B8
|
|
||||||
|
import Data.String (fromString)
|
||||||
|
|
||||||
import System.Clock
|
import System.Clock
|
||||||
|
|
||||||
import Control.Monad.Loops
|
import Control.Monad.Loops
|
||||||
import Control.Monad.State.Strict
|
import Control.Monad.State.Strict
|
||||||
|
import Control.Monad.Trans.Resource
|
||||||
|
|
||||||
|
-- internal imports
|
||||||
|
|
||||||
-- internal imports
|
-- internal imports
|
||||||
|
|
||||||
|
@ -46,46 +49,83 @@ withAffection
|
||||||
:: forall us. (Affectionate us)
|
:: forall us. (Affectionate us)
|
||||||
=> AffectionConfig us -- ^ Configuration of the Game and its engine.
|
=> AffectionConfig us -- ^ Configuration of the Game and its engine.
|
||||||
-> IO ()
|
-> IO ()
|
||||||
withAffection AffectionConfig{..} = do
|
withAffection AffectionConfig{..} = runResourceT $ do
|
||||||
liftIO $ logIO Debug "Affection starting"
|
liftIO $ logIO Debug "Affection starting"
|
||||||
liftIO $ logIO Debug "Initializing SDL"
|
liftIO $ logIO Debug "Initializing SDL"
|
||||||
|
|
||||||
-- intialiaze SDL
|
-- intialiaze SDL
|
||||||
case initComponents of
|
case initComponents of
|
||||||
All ->
|
All ->
|
||||||
SDL.initializeAll
|
SDL.initializeAll
|
||||||
Only is ->
|
Only is ->
|
||||||
SDL.initialize is
|
SDL.initialize is
|
||||||
|
|
||||||
-- give SDL render quality
|
-- give SDL render quality
|
||||||
SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear
|
SDL.HintRenderScaleQuality SDL.$= SDL.ScaleLinear
|
||||||
|
|
||||||
-- just checking…
|
-- just checking…
|
||||||
do
|
renderQuality <- SDL.get SDL.HintRenderScaleQuality
|
||||||
renderQuality <- SDL.get SDL.HintRenderScaleQuality
|
when (renderQuality /= SDL.ScaleLinear) $
|
||||||
when (renderQuality /= SDL.ScaleLinear) $
|
liftIO $ logIO Warn "Linear texture filtering not enabled!"
|
||||||
logIO Warn "Linear texture filtering not enabled!"
|
void $ liftIO (logIO Debug . fromString . show <$> (SDL.version :: IO (Integer, Integer, Integer)))
|
||||||
|
|
||||||
-- construct window
|
-- construct window
|
||||||
liftIO $ logIO Debug "Creating Window(s)"
|
liftIO $ logIO Debug "Creating Window(s)"
|
||||||
windows <- zip3 (map (\(x,_,_) -> x) windowConfigs) <$>
|
windows <-
|
||||||
mapM
|
mapM
|
||||||
(\wc -> SDL.createWindow windowTitle ((\(_,y,_) -> y) wc))
|
(\(_, sdlWindowConfig, mode) -> do
|
||||||
windowConfigs <*>
|
(windowKey, window) <-
|
||||||
pure (map (\(_,_,z) -> z) windowConfigs)
|
allocate
|
||||||
|
(SDL.createWindow windowTitle sdlWindowConfig)
|
||||||
|
(\window -> do
|
||||||
|
logIO Debug "Destroying Window"
|
||||||
|
SDL.destroyWindow window
|
||||||
|
)
|
||||||
|
return $ AffectionWindow window windowKey mode
|
||||||
|
)
|
||||||
|
windowConfigs
|
||||||
|
|
||||||
|
-- Show windows
|
||||||
|
mapM_ (SDL.showWindow . awWindow) windows
|
||||||
|
|
||||||
|
-- set modes of windows
|
||||||
|
mapM_ (\(AffectionWindow window _ mode) -> SDL.setWindowMode window mode) windows
|
||||||
|
|
||||||
|
-- Make GL context shareable
|
||||||
|
void $ SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1
|
||||||
|
|
||||||
|
-- Create OpenGL contexts
|
||||||
|
contexts <-
|
||||||
|
mapM
|
||||||
|
(\(AffectionWindow window _ _) -> do
|
||||||
|
(contextKey, context) <-
|
||||||
|
allocate
|
||||||
|
(SDL.glCreateContext window)
|
||||||
|
(\context -> do
|
||||||
|
logIO Debug "Destroying context"
|
||||||
|
SDL.glDeleteContext context
|
||||||
|
)
|
||||||
|
return $ AffectionContext context contextKey
|
||||||
|
)
|
||||||
|
windows
|
||||||
|
|
||||||
mapM_ (SDL.showWindow . (\(_,y,_) -> y)) windows
|
|
||||||
_ <- SDL.glSetAttribute SDL.SDL_GL_SHARE_WITH_CURRENT_CONTEXT 1
|
|
||||||
contexts <- zip (map (\(x,_,_) -> x) windows) <$>
|
|
||||||
mapM (SDL.glCreateContext . (\(_,y,_) -> y)) windows
|
|
||||||
mapM_ (\w -> flip SDL.setWindowMode ((\(_,_,z) -> z) w) ((\(_,y,_) -> y) w)) windows
|
|
||||||
-- sync updates with monitor
|
-- sync updates with monitor
|
||||||
-- SDL.swapInterval $= SDL.SynchronizedUpdates -- <- causes Problems with windows
|
-- SDL.swapInterval $= SDL.SynchronizedUpdates -- <- causes Problems with windows
|
||||||
liftIO $ logIO Debug "Getting Time"
|
|
||||||
-- print current used GL Version
|
-- print current used GL Version
|
||||||
version <- peekArray0 (0 :: Word8) =<< GLRaw.glGetString GLRaw.GL_VERSION
|
version <- liftIO $ peekArray0 (0 :: Word8) =<< GLRaw.glGetString GLRaw.GL_VERSION
|
||||||
print (B.pack version)
|
liftIO $ print (B.pack version)
|
||||||
|
|
||||||
-- get current time
|
-- get current time
|
||||||
execTime <- getTime Monotonic
|
liftIO $ logIO Debug "Getting Time"
|
||||||
|
execTime <- liftIO $ getTime Monotonic
|
||||||
liftIO $ logIO Debug "Loading initial data container"
|
liftIO $ logIO Debug "Loading initial data container"
|
||||||
|
|
||||||
-- construct game data object from provided Affectionate instance
|
-- construct game data object from provided Affectionate instance
|
||||||
gameData <- loadState @us
|
(gameDataKey, gameData) <-
|
||||||
|
allocate
|
||||||
|
(liftIO $ loadState @us)
|
||||||
|
(liftIO . cleanUp)
|
||||||
-- build state container
|
-- build state container
|
||||||
let initContainer = AffectionData
|
let initContainer = AffectionData
|
||||||
{ drawWindows = windows
|
{ drawWindows = windows
|
||||||
|
@ -95,9 +135,9 @@ withAffection AffectionConfig{..} = do
|
||||||
, sysTime = execTime
|
, sysTime = execTime
|
||||||
, pausedTime = False
|
, pausedTime = False
|
||||||
}
|
}
|
||||||
|
|
||||||
-- initialize and run state
|
-- initialize and run state
|
||||||
(_, _) <- runStateT
|
void $ liftIO $ runAffection initContainer
|
||||||
(A.runState
|
|
||||||
(do
|
(do
|
||||||
liftIO $ logIO Debug "Running Pre-Loop stage"
|
liftIO $ logIO Debug "Running Pre-Loop stage"
|
||||||
-- run preLoop function from Affectionate
|
-- run preLoop function from Affectionate
|
||||||
|
@ -107,9 +147,11 @@ withAffection AffectionConfig{..} = do
|
||||||
(do
|
(do
|
||||||
-- get state
|
-- get state
|
||||||
ad <- get
|
ad <- get
|
||||||
|
|
||||||
-- Measure time difference form last run
|
-- Measure time difference form last run
|
||||||
now <- liftIO $ getTime Monotonic
|
now <- liftIO $ getTime Monotonic
|
||||||
let lastTime = sysTime ad
|
let lastTime = sysTime ad
|
||||||
|
|
||||||
-- compute dt and update elapsedTime
|
-- compute dt and update elapsedTime
|
||||||
let dt = fromIntegral
|
let dt = fromIntegral
|
||||||
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
(toNanoSecs $ diffTimeSpec lastTime now) / (10 ^ (9 :: Int))
|
||||||
|
@ -119,18 +161,25 @@ withAffection AffectionConfig{..} = do
|
||||||
{ elapsedTime = ne
|
{ elapsedTime = ne
|
||||||
, deltaTime = dt
|
, deltaTime = dt
|
||||||
}
|
}
|
||||||
|
|
||||||
-- poll events
|
-- poll events
|
||||||
|
liftIO SDL.pumpEvents
|
||||||
evs <- preHandleEvents =<< liftIO SDL.pollEvents
|
evs <- preHandleEvents =<< liftIO SDL.pollEvents
|
||||||
|
|
||||||
-- handle events
|
-- handle events
|
||||||
handleEvents gameData evs
|
handleEvents gameData evs
|
||||||
|
|
||||||
-- execute user defined update loop
|
-- execute user defined update loop
|
||||||
unless (pausedTime ad) (update gameData dt)
|
unless (pausedTime ad) (update gameData dt)
|
||||||
|
|
||||||
-- clear GL buffer >> execute user defined draw loop >> flush GL buffer
|
-- clear GL buffer >> execute user defined draw loop >> flush GL buffer
|
||||||
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
liftIO $ GL.clear [GL.ColorBuffer, GL.DepthBuffer, GL.StencilBuffer]
|
||||||
draw gameData
|
draw gameData
|
||||||
liftIO GL.flush
|
liftIO GL.flush
|
||||||
|
|
||||||
-- actual displaying of newly drawn frame
|
-- actual displaying of newly drawn frame
|
||||||
mapM_ (SDL.glSwapWindow . (\(_,y,_) -> y)) windows
|
mapM_ (SDL.glSwapWindow . awWindow) windows
|
||||||
|
|
||||||
-- save new time
|
-- save new time
|
||||||
ad3 <- get
|
ad3 <- get
|
||||||
when (sysTime ad == sysTime ad3) (
|
when (sysTime ad == sysTime ad3) (
|
||||||
|
@ -140,11 +189,16 @@ withAffection AffectionConfig{..} = do
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) initContainer
|
-- Cleanup works
|
||||||
liftIO $ logIO Debug "Loop ended. Cleaning"
|
liftIO $ logIO Debug "Loop ended. Cleaning"
|
||||||
cleanUp gameData
|
release gameDataKey
|
||||||
liftIO $ logIO Debug "Destroying Window"
|
-- mapM_ (SDL.glDeleteContext . snd) contexts
|
||||||
mapM_ (SDL.glDeleteContext . snd) contexts
|
-- mapM_ (SDL.destroyWindow . (\(_,y,_) -> y)) windows
|
||||||
mapM_ (SDL.destroyWindow . (\(_,y,_) -> y)) windows
|
|
||||||
-- SDL.quit -- <- This causes segfaults depending on hardware
|
-- SDL.quit -- <- This causes segfaults depending on hardware
|
||||||
liftIO $ logIO Debug "This is the end"
|
liftIO $ logIO Debug "This is the end"
|
||||||
|
|
||||||
|
runAffection
|
||||||
|
:: AffectionData
|
||||||
|
-> AffectionState AffectionData ResIO a
|
||||||
|
-> IO (a, AffectionData)
|
||||||
|
runAffection initialState a = runResourceT $ runStateT (A.runState a) initialState
|
||||||
|
|
43
extern/affection/src/Affection/Types.hs
vendored
43
extern/affection/src/Affection/Types.hs
vendored
|
@ -5,6 +5,8 @@ module Affection.Types
|
||||||
, AffectionData(..)
|
, AffectionData(..)
|
||||||
, AffectionStateInner
|
, AffectionStateInner
|
||||||
, AffectionState(..)
|
, AffectionState(..)
|
||||||
|
, AffectionWindow(..)
|
||||||
|
, AffectionContext(..)
|
||||||
, InitComponents(..)
|
, InitComponents(..)
|
||||||
, Angle
|
, Angle
|
||||||
-- | SDL reexports
|
-- | SDL reexports
|
||||||
|
@ -23,6 +25,7 @@ import qualified Data.Text as T
|
||||||
|
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.State.Strict
|
import Control.Monad.State.Strict
|
||||||
|
import Control.Monad.Trans.Resource
|
||||||
import qualified Control.Monad.Parallel as MP
|
import qualified Control.Monad.Parallel as MP
|
||||||
|
|
||||||
import System.Clock (TimeSpec)
|
import System.Clock (TimeSpec)
|
||||||
|
@ -50,35 +53,35 @@ data InitComponents
|
||||||
|
|
||||||
-- | Main type for defining the look, feel and action of the whole application.
|
-- | Main type for defining the look, feel and action of the whole application.
|
||||||
data AffectionData = AffectionData
|
data AffectionData = AffectionData
|
||||||
{ drawWindows ::
|
{ drawWindows :: [ AffectionWindow ] -- ^ SDL windows
|
||||||
[
|
, glContext :: [ AffectionContext ] -- ^ OpenGL rendering contexts
|
||||||
( Word -- --^ Window identifier
|
, elapsedTime :: Double -- ^ Elapsed time in seconds
|
||||||
, SDL.Window -- --^ Window linked with identifier
|
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick
|
||||||
, SDL.WindowMode -- -- ^ current screen mode
|
, sysTime :: TimeSpec -- ^ System time (NOT the time on the clock)
|
||||||
)
|
, pausedTime :: Bool -- ^ Should the update loop be executed?
|
||||||
] -- ^ SDL windows
|
|
||||||
, glContext ::
|
|
||||||
[
|
|
||||||
( Word -- --^ Window identifier
|
|
||||||
, SDL.GLContext -- --^ Associated OpenGL context
|
|
||||||
)
|
|
||||||
] -- ^ OpenGL rendering contexts
|
|
||||||
, elapsedTime :: Double -- ^ Elapsed time in seconds
|
|
||||||
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick
|
|
||||||
, sysTime :: TimeSpec -- ^ System time (NOT the time on the clock)
|
|
||||||
, pausedTime :: Bool -- ^ Should the update loop be executed?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Inner 'StateT' monad for the update state
|
-- | Inner 'StateT' monad for the update state
|
||||||
type AffectionStateInner sd a = StateT sd a
|
type AffectionStateInner sd m = StateT sd m
|
||||||
|
|
||||||
-- | Affection's state monad
|
-- | Affection's state monad
|
||||||
newtype AffectionState sd m a = AffectionState
|
newtype AffectionState sd m a = AffectionState
|
||||||
{ runState :: AffectionStateInner sd m a }
|
{ runState :: AffectionStateInner sd m a }
|
||||||
deriving (Functor, Applicative, Monad, MonadIO, MonadState sd)
|
deriving (Functor, Applicative, Monad, MonadIO, MonadState sd, MonadResource)
|
||||||
|
|
||||||
instance MP.MonadParallel m => MP.MonadParallel (AffectionState sd m)
|
instance MP.MonadParallel m => MP.MonadParallel (AffectionState sd m)
|
||||||
|
|
||||||
type Affection a = AffectionState AffectionData IO a
|
type Affection a = AffectionState AffectionData ResIO a
|
||||||
|
|
||||||
type Angle = Double
|
type Angle = Double
|
||||||
|
|
||||||
|
data AffectionWindow = AffectionWindow
|
||||||
|
{ awWindow :: SDL.Window
|
||||||
|
, awReleaseKey :: ReleaseKey
|
||||||
|
, awMode :: SDL.WindowMode
|
||||||
|
}
|
||||||
|
|
||||||
|
data AffectionContext = AffectionContext
|
||||||
|
{ acContext :: SDL.GLContext
|
||||||
|
, acReleaseKey :: ReleaseKey
|
||||||
|
}
|
||||||
|
|
55
extern/affection/src/Affection/Util.hs
vendored
55
extern/affection/src/Affection/Util.hs
vendored
|
@ -39,32 +39,35 @@ getDelta = gets deltaTime
|
||||||
toggleScreen :: Word -> Affection ()
|
toggleScreen :: Word -> Affection ()
|
||||||
toggleScreen windowIdent = do
|
toggleScreen windowIdent = do
|
||||||
ad <- get
|
ad <- get
|
||||||
let mwindow = find (\(ident, _, _) -> ident == windowIdent) (drawWindows ad)
|
(stop, alteredWindowList) <- foldM
|
||||||
case mwindow of
|
(\(stop, resWindows) (num, aw@(AffectionWindow window _ mode)) -> do
|
||||||
Just (ident, window, mode) -> do
|
if stop || num == windowIdent
|
||||||
newMode <- case mode of
|
then do
|
||||||
SDL.FullscreenDesktop -> do
|
newMode <- case mode of
|
||||||
SDL.setWindowMode window SDL.Windowed
|
SDL.FullscreenDesktop -> do
|
||||||
return SDL.Windowed
|
liftIO $ SDL.setWindowMode window SDL.Windowed
|
||||||
SDL.Windowed -> do
|
return SDL.Windowed
|
||||||
SDL.setWindowMode window SDL.FullscreenDesktop
|
SDL.Windowed -> do
|
||||||
return SDL.FullscreenDesktop
|
liftIO $ SDL.setWindowMode window SDL.FullscreenDesktop
|
||||||
x -> do
|
return SDL.FullscreenDesktop
|
||||||
liftIO $ logIO Warn ("Unexpected window mode: " <> fromString (show x))
|
x -> do
|
||||||
return x
|
liftIO $ logIO Warn ("Unexpected window mode: " <> fromString (show x))
|
||||||
now <- liftIO $ getTime Monotonic
|
return x
|
||||||
put ad
|
return (True, resWindows ++ [aw { awMode = newMode }])
|
||||||
{ sysTime = now
|
else
|
||||||
, drawWindows = map
|
return (stop, resWindows ++ [aw])
|
||||||
(\e@(lid, win, _) ->
|
)
|
||||||
if lid == ident
|
(False, [])
|
||||||
then (lid, win, newMode)
|
(zip [0..] (drawWindows ad))
|
||||||
else e
|
if stop
|
||||||
)
|
then do
|
||||||
(drawWindows ad)
|
now <- liftIO $ getTime Monotonic
|
||||||
}
|
put ad
|
||||||
Nothing -> do
|
{ sysTime = now
|
||||||
liftIO $ logIO Warn ("No window found with ident " <> fromString (show windowIdent))
|
, drawWindows = alteredWindowList
|
||||||
|
}
|
||||||
|
else
|
||||||
|
liftIO $ logIO Warn ("No window found with ident " <> fromString (show windowIdent))
|
||||||
|
|
||||||
-- | Fit the GL Viewport to Window size
|
-- | Fit the GL Viewport to Window size
|
||||||
fitViewport
|
fitViewport
|
||||||
|
|
42
extern/flake.lock
vendored
Normal file
42
extern/flake.lock
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1667395993,
|
||||||
|
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1669901374,
|
||||||
|
"narHash": "sha256-lObvfluyiZ9cgCMgKSrUOjzbx9Oap9949jlnNRPPYqg=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "1c5443f6cdce419174f198141bd76a3fd9502950",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
61
extern/flake.nix
vendored
Normal file
61
extern/flake.nix
vendored
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
description = "A game stub written in Haskell";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
|
haskellPackages = pkgs.haskellPackages;
|
||||||
|
|
||||||
|
jailbreakUnbreak = pkg:
|
||||||
|
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
|
||||||
|
|
||||||
|
packageName = "affection";
|
||||||
|
in rec {
|
||||||
|
packages.${packageName} = # (ref:haskell-package-def)
|
||||||
|
haskellPackages.callCabal2nixWithOptions packageName self "--flag examples" {
|
||||||
|
# Dependency overrides go here
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultPackage = self.packages.${system}.${packageName};
|
||||||
|
|
||||||
|
apps = {
|
||||||
|
example00 = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.${packageName}}/bin/example00";
|
||||||
|
};
|
||||||
|
example01 = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.${packageName}}/bin/example01";
|
||||||
|
};
|
||||||
|
example02 = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.packages.${system}.${packageName}}/bin/example02";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#devShell = packages.${packageName}.env;
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
buildInputs = with haskellPackages; [
|
||||||
|
haskell-language-server
|
||||||
|
ghcid
|
||||||
|
cabal-install
|
||||||
|
];
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
pkg-config
|
||||||
|
glib
|
||||||
|
SDL2
|
||||||
|
freetype
|
||||||
|
glew
|
||||||
|
];
|
||||||
|
inputsFrom = builtins.attrValues self.packages.${system};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue