packages feed

spice 0.1.0.1 → 0.1.0.2

raw patch · 4 files changed

+94/−1 lines, 4 files

Files

spice.cabal view
@@ -1,5 +1,5 @@ name:                spice-version:             0.1.0.1+version:             0.1.0.2 synopsis:            An FRP-based game engine written in Haskell. description:         An FRP-based game engine written in Haskell. - See the homepage for more information. homepage:            http://github.com/crockeo/spice@@ -16,6 +16,9 @@   exposed-modules:     FRP.Spice                        FRP.Spice.Config                        FRP.Spice.Engine+                       FRP.Spice.Engine.Driver+                       FRP.Spice.Engine.Network+                       FRP.Spice.Engine.RunInput                        FRP.Spice.Game                        FRP.Spice.Input                        FRP.Spice.Input.Keyboard
+ src/FRP/Spice/Engine/Driver.hs view
@@ -0,0 +1,24 @@+{-|+  This module need not be used directly. Refer to @'FRP.Spice.Engine'@ instead.+-}+module FRP.Spice.Engine.Driver where++--------------------+-- Global Imports --+import Control.Monad++----------+-- Code --++{-|+  Driving a network created with the @'FRP.Spice.Engine.Network.makeNetwork'@+  function and a function such as @'FRP.Spice.Engine.RunInput.runInput'@.+-}+driveNetwork :: (a -> IO (IO ())) -> IO (Maybe a) -> IO ()+driveNetwork network iomdriver = do+  mdriver <- iomdriver++  case mdriver of+    Just driver -> do join $ network driver+                      driveNetwork network iomdriver+    Nothing     -> return ()
+ src/FRP/Spice/Engine/Network.hs view
@@ -0,0 +1,32 @@+{-|+  This module need not be used directly. Refer to+  @'FRP.Spice.Engine.startEngine'@ instead.+-}+module FRP.Spice.Engine.Network where++--------------------+-- Global Imports --+import Control.Applicative+import FRP.Elerea.Param++-------------------+-- Local Imports --+import FRP.Spice.Input+import FRP.Spice.Game++----------+-- Code --++{-|+  Creating a network to be used with the+  @'FRP.Spice.Engine.Driver.driveNetwork'@ function.+-}+makeNetwork :: Game a => Signal Input -> Signal a -> (a -> IO ()) -> IO (Float -> IO (IO ()))+makeNetwork inputSignal gameSignal gameSink =+  start $ memo $ do+    input <- inputSignal+    game  <- gameSignal++    return $ do+      gameSink $ update 0.01 input game+      render game
+ src/FRP/Spice/Engine/RunInput.hs view
@@ -0,0 +1,34 @@+{-|+  This module need not be used directly. Refer to @'FRP.Spice.Engine'@ instead.+-}+module FRP.Spice.Engine.RunInput where++--------------------+-- Global Imports --+import Graphics.Rendering.OpenGL+import Graphics.UI.GLFW as GLFW+import Data.IORef+import GHC.Float++-------------------+-- Local Imports --+import FRP.Spice.Game++----------+-- Code --++{-|+  Given an @'IORef'@ indicating whether or not the program should close, it+  either returns the delta time since the last call, or a @'Nothing'@,+  indicating that the program should close.+-}+runInput :: IORef Bool -> IO (Maybe Float)+runInput closed = do+  c <- readIORef closed++  if c+    then return Nothing+    else do+      dt <- get GLFW.time+      GLFW.time $= 0+      return $ Just $ double2Float (dt / 1000)