packages feed

spice 0.1.2.1 → 0.2.0.0

raw patch · 15 files changed

+178/−63 lines, 15 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- FRP.Spice.Config: WindowConfig :: Int -> Int -> Bool -> Bool -> String -> WindowConfig
- FRP.Spice.Config: data WindowConfig
- FRP.Spice.Config: defaultWindowConfig :: WindowConfig
- FRP.Spice.Config: getWindowFullscreen :: WindowConfig -> Bool
- FRP.Spice.Config: getWindowHeight :: WindowConfig -> Int
- FRP.Spice.Config: getWindowResizable :: WindowConfig -> Bool
- FRP.Spice.Config: getWindowTitle :: WindowConfig -> String
- FRP.Spice.Config: getWindowWidth :: WindowConfig -> Int
- FRP.Spice.Config: instance Default WindowConfig
- FRP.Spice.Config: instance Eq WindowConfig
- FRP.Spice.Config: instance Read WindowConfig
- FRP.Spice.Config: instance Show WindowConfig
- FRP.Spice.Engine: startEngine :: Game a => WindowConfig -> a -> IO ()
- FRP.Spice.Engine.Driver: driveNetwork :: (a -> IO (IO ())) -> IO (Maybe a) -> IO ()
- FRP.Spice.Engine.Network: makeNetwork :: Game a => Signal Input -> Signal a -> (a -> IO ()) -> IO (Float -> IO (IO ()))
- FRP.Spice.Engine.RenderWrapper: renderWrapper :: IO () -> IO ()
- FRP.Spice.Engine.RunInput: runInput :: IORef Bool -> IO (Maybe Float)
- FRP.Spice.Game: class Game a
- FRP.Spice.Game: render :: Game a => a -> IO ()
- FRP.Spice.Game: type DeltaTime = Float
- FRP.Spice.Game: update :: Game a => DeltaTime -> Input -> a -> a
- FRP.Spice.Graphics.Color: Color :: Float -> Float -> Float -> Float -> Color
- FRP.Spice.Graphics.Color: bindColor :: Color -> IO ()
- FRP.Spice.Graphics.Color: black :: Color
- FRP.Spice.Graphics.Color: blue :: Color
- FRP.Spice.Graphics.Color: color3f :: Float -> Float -> Float -> Color
- FRP.Spice.Graphics.Color: color3i :: Int -> Int -> Int -> Color
- FRP.Spice.Graphics.Color: color4f :: Float -> Float -> Float -> Float -> Color
- FRP.Spice.Graphics.Color: color4i :: Int -> Int -> Int -> Int -> Color
- FRP.Spice.Graphics.Color: data Color
- FRP.Spice.Graphics.Color: getAlpha :: Color -> Float
- FRP.Spice.Graphics.Color: getBlue :: Color -> Float
- FRP.Spice.Graphics.Color: getGreen :: Color -> Float
- FRP.Spice.Graphics.Color: getRed :: Color -> Float
- FRP.Spice.Graphics.Color: green :: Color
- FRP.Spice.Graphics.Color: instance Eq Color
- FRP.Spice.Graphics.Color: instance Read Color
- FRP.Spice.Graphics.Color: instance Show Color
- FRP.Spice.Graphics.Color: red :: Color
- FRP.Spice.Graphics.Color: white :: Color
- FRP.Spice.Graphics.Geometry: renderPoint :: Vector Float -> IO ()
- FRP.Spice.Graphics.Geometry: renderRectangle :: Vector Float -> Vector Float -> IO ()
- FRP.Spice.Graphics.Geometry: renderSquare :: Vector Float -> Float -> IO ()
- FRP.Spice.Graphics.Utils: togl :: Float -> GLfloat
- FRP.Spice.Input: Input :: Vector Float -> Map Key Bool -> Map MouseButton Bool -> Input
- FRP.Spice.Input: InputContainer :: Sinks -> Signal Input -> InputContainer
- FRP.Spice.Input: Sinks :: (Vector Float -> IO ()) -> Map Key (Bool -> IO ()) -> Map MouseButton (Bool -> IO ()) -> Sinks
- FRP.Spice.Input: data Input
- FRP.Spice.Input: data InputContainer
- FRP.Spice.Input: data Sinks
- FRP.Spice.Input: getInput :: InputContainer -> Signal Input
- FRP.Spice.Input: getSinks :: InputContainer -> Sinks
- FRP.Spice.Input: keyboard :: Input -> Map Key Bool
- FRP.Spice.Input: keyboardSinks :: Sinks -> Map Key (Bool -> IO ())
- FRP.Spice.Input: makeInputContainer :: IO InputContainer
- FRP.Spice.Input: makeKeyboardCallback :: InputContainer -> KeyCallback
- FRP.Spice.Input: makeMouseCallback :: InputContainer -> MouseButtonCallback
- FRP.Spice.Input: makeMousePositionCallback :: InputContainer -> MousePosCallback
- FRP.Spice.Input: mouse :: Input -> Map MouseButton Bool
- FRP.Spice.Input: mousePosition :: Input -> Vector Float
- FRP.Spice.Input: mousePositionSinks :: Sinks -> Vector Float -> IO ()
- FRP.Spice.Input: mouseSinks :: Sinks -> Map MouseButton (Bool -> IO ())
- FRP.Spice.Input.Keyboard: externals :: IO (Map Key (Signal Bool, Bool -> IO ()))
- FRP.Spice.Input.Keyboard: keys :: [Key]
- FRP.Spice.Input.Keyboard: signals :: Map Key (Signal Bool, Bool -> IO ()) -> Signal (Map Key Bool)
- FRP.Spice.Input.Keyboard: sinks :: Map Key (Signal Bool, Bool -> IO ()) -> Map Key (Bool -> IO ())
- FRP.Spice.Input.Mouse: buttons :: [MouseButton]
- FRP.Spice.Input.Mouse: externals :: IO (Map MouseButton (Signal Bool, Bool -> IO ()))
- FRP.Spice.Input.Mouse: instance Ord MouseButton
- FRP.Spice.Input.Mouse: signals :: Map MouseButton (Signal Bool, Bool -> IO ()) -> Signal (Map MouseButton Bool)
- FRP.Spice.Input.Mouse: sinks :: Map MouseButton (Signal Bool, Bool -> IO ()) -> Map MouseButton (Bool -> IO ())
- FRP.Spice.Input.MousePosition: externals :: IO (Signal (Vector Float), Vector Float -> IO ())
- FRP.Spice.Input.MousePosition: signals :: (Signal (Vector Float), Vector Float -> IO ()) -> Signal (Vector Float)
- FRP.Spice.Input.MousePosition: sinks :: (Signal (Vector Float), Vector Float -> IO ()) -> Vector Float -> IO ()
- FRP.Spice.Math.Vector: Vector :: a -> a -> Vector a
- FRP.Spice.Math.Vector: data Vector a
- FRP.Spice.Math.Vector: instance Default a => Default (Vector a)
- FRP.Spice.Math.Vector: instance Functor Vector
- FRP.Spice.Math.Vector: instance Num a => Num (Vector a)
- FRP.Spice.Math.Vector: instance Show a => Show (Vector a)
+ FRP.Spice: Input :: Vector Float -> Map Key Bool -> Map MouseButton Bool -> Input
+ FRP.Spice: InputContainer :: Sinks -> Signal Input -> InputContainer
+ FRP.Spice: Sinks :: (Vector Float -> IO ()) -> Map Key (Bool -> IO ()) -> Map MouseButton (Bool -> IO ()) -> Sinks
+ FRP.Spice: WindowConfig :: Int -> Int -> Bool -> String -> WindowConfig
+ FRP.Spice: class Game a
+ FRP.Spice: data Input
+ FRP.Spice: data InputContainer
+ FRP.Spice: data Sinks
+ FRP.Spice: data WindowConfig
+ FRP.Spice: defaultWindowConfig :: WindowConfig
+ FRP.Spice: getInput :: InputContainer -> Signal Input
+ FRP.Spice: getSinks :: InputContainer -> Sinks
+ FRP.Spice: getWindowFullscreen :: WindowConfig -> Bool
+ FRP.Spice: getWindowHeight :: WindowConfig -> Int
+ FRP.Spice: getWindowTitle :: WindowConfig -> String
+ FRP.Spice: getWindowWidth :: WindowConfig -> Int
+ FRP.Spice: keyboard :: Input -> Map Key Bool
+ FRP.Spice: keyboardSinks :: Sinks -> Map Key (Bool -> IO ())
+ FRP.Spice: makeInputContainer :: IO InputContainer
+ FRP.Spice: makeKeyboardCallback :: InputContainer -> KeyCallback
+ FRP.Spice: makeMouseCallback :: InputContainer -> MouseButtonCallback
+ FRP.Spice: makeMousePositionCallback :: WindowConfig -> InputContainer -> MousePosCallback
+ FRP.Spice: mouse :: Input -> Map MouseButton Bool
+ FRP.Spice: mousePosition :: Input -> Vector Float
+ FRP.Spice: mousePositionSinks :: Sinks -> Vector Float -> IO ()
+ FRP.Spice: mouseSinks :: Sinks -> Map MouseButton (Bool -> IO ())
+ FRP.Spice: render :: Game a => a -> Scene
+ FRP.Spice: startEngine :: Game a => WindowConfig -> a -> IO ()
+ FRP.Spice: type DeltaTime = Float
+ FRP.Spice: update :: Game a => DeltaTime -> Input -> a -> a
+ FRP.Spice.Graphics: Color :: Float -> Float -> Float -> Float -> Color
+ FRP.Spice.Graphics: Element :: PrimitiveMode -> [Vector Float] -> Element
+ FRP.Spice.Graphics: SceneT :: [Element] -> a -> SceneT a
+ FRP.Spice.Graphics: bindColor :: Color -> IO ()
+ FRP.Spice.Graphics: black :: Color
+ FRP.Spice.Graphics: blue :: Color
+ FRP.Spice.Graphics: color3f :: Float -> Float -> Float -> Color
+ FRP.Spice.Graphics: color3i :: Int -> Int -> Int -> Color
+ FRP.Spice.Graphics: color4f :: Float -> Float -> Float -> Float -> Color
+ FRP.Spice.Graphics: color4i :: Int -> Int -> Int -> Int -> Color
+ FRP.Spice.Graphics: data Color
+ FRP.Spice.Graphics: data Element
+ FRP.Spice.Graphics: data SceneT a
+ FRP.Spice.Graphics: fromElements :: [Element] -> Scene
+ FRP.Spice.Graphics: getAlpha :: Color -> Float
+ FRP.Spice.Graphics: getBlue :: Color -> Float
+ FRP.Spice.Graphics: getGreen :: Color -> Float
+ FRP.Spice.Graphics: getRed :: Color -> Float
+ FRP.Spice.Graphics: green :: Color
+ FRP.Spice.Graphics: red :: Color
+ FRP.Spice.Graphics: renderElement :: Element -> IO ()
+ FRP.Spice.Graphics: renderPoint :: Vector Float -> Scene
+ FRP.Spice.Graphics: renderRectangle :: Vector Float -> Vector Float -> Scene
+ FRP.Spice.Graphics: renderScene :: Scene -> IO ()
+ FRP.Spice.Graphics: renderSquare :: Vector Float -> Float -> Scene
+ FRP.Spice.Graphics: togl :: Float -> GLfloat
+ FRP.Spice.Graphics: type Scene = SceneT ()
+ FRP.Spice.Graphics: white :: Color
+ FRP.Spice.Math: Vector :: a -> a -> Vector a
+ FRP.Spice.Math: data Vector a

Files

spice.cabal view
@@ -1,5 +1,5 @@ name:                spice-version:             0.1.2.1+version:             0.2.0.0 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@@ -13,17 +13,22 @@ cabal-version:       >=1.10  library+  ghc-options:         -Wall -fno-warn-unused-do-bind+   exposed-modules:     FRP.Spice-                       FRP.Spice.Config+                       FRP.Spice.Graphics+                       FRP.Spice.Math++  other-modules:       FRP.Spice.Config                        FRP.Spice.Engine                        FRP.Spice.Engine.Driver                        FRP.Spice.Engine.Network                        FRP.Spice.Engine.RenderWrapper                        FRP.Spice.Engine.RunInput                        FRP.Spice.Game-                       FRP.Spice.Graphics                        FRP.Spice.Graphics.Color                        FRP.Spice.Graphics.Geometry+                       FRP.Spice.Graphics.Scene                        FRP.Spice.Graphics.Utils                        FRP.Spice.Input                        FRP.Spice.Input.Keyboard
src/FRP/Spice/Config.hs view
@@ -17,7 +17,6 @@ data WindowConfig = WindowConfig { getWindowWidth      :: Int                                  , getWindowHeight     :: Int                                  , getWindowFullscreen :: Bool-                                 , getWindowResizable  :: Bool                                  , getWindowTitle      :: String                                  }   deriving (Eq, Show, Read)@@ -35,7 +34,6 @@ defaultWindowConfig = WindowConfig { getWindowWidth      = 640                                    , getWindowHeight     = 480                                    , getWindowFullscreen = False-                                   , getWindowResizable  = False                                    , getWindowTitle      = "Spice Application"                                    } 
src/FRP/Spice/Engine.hs view
@@ -2,7 +2,7 @@   This module handles starting the engine. This is done via the use of the   @'startEngine'@ function. -}-module FRP.Spice.Engine where+module FRP.Spice.Engine (startEngine) where  -------------------- -- Global Imports --@@ -23,6 +23,25 @@ ---------- -- Code -- +-- Containing if the engine has been made before+madeRef :: IO (IORef Bool)+madeRef = newIORef False++-- Making the size from a WindowConfig+makeSize :: WindowConfig -> Size+makeSize wc = Size (fromIntegral $ getWindowWidth wc) (fromIntegral $ getWindowHeight wc)++-- Making the displaybits from a WindowConfig+makeDisplayBits :: [DisplayBits]+makeDisplayBits = [DisplayRGBBits 8 8 8, DisplayAlphaBits 8, DisplayDepthBits 24]++-- Making the window mode from a WindowConfig+makeWindowMode :: WindowConfig -> WindowMode+makeWindowMode wc =+  if getWindowFullscreen wc+    then FullScreen+    else Window+ {-|   Starting the spice engine with the parameters prescribed in the   @'WindowConfig'@. It updates and renders the @'Game'@ automatically so all@@ -31,33 +50,41 @@ -} startEngine :: Game a => WindowConfig -> a -> IO () startEngine wc game = do-  -- Opening the window-  initialize-  openWindow (Size 640 480) [DisplayRGBBits 8 8 8, DisplayAlphaBits 8, DisplayDepthBits 24] Window+  made   <- madeRef+  isMade <- readIORef made+  if isMade+    then error "You cannot run 'startEngine' more than once per program."+    else do+      writeIORef made True -  -- Checking for the window being closed-  closed <- newIORef False-  windowCloseCallback $= do-    writeIORef closed True-    return True+      -- Opening the window+      initialize+      openWindow (makeSize wc) makeDisplayBits (makeWindowMode wc)+      windowTitle $= getWindowTitle wc -  -- Getting an external of the game-  (gameSignal, gameSink) <- external game+      -- Checking for the window being closed+      closed <- newIORef False+      windowCloseCallback $= do+        writeIORef closed True+        return True -  -- Getting the input container-  ic <- makeInputContainer+      -- Getting an external of the game+      (gameSignal, gameSink) <- external game -  -- Updating the input-  mousePosCallback    $= makeMousePositionCallback ic-  keyCallback         $= makeKeyboardCallback ic-  mouseButtonCallback $= makeMouseCallback ic+      -- Getting the input container+      ic <- makeInputContainer -  -- Creating the network-  network <- makeNetwork (getInput ic) gameSignal gameSink+      -- Updating the input+      mousePosCallback    $= makeMousePositionCallback wc ic+      keyCallback         $= makeKeyboardCallback ic+      mouseButtonCallback $= makeMouseCallback ic -  -- Driving the network-  GLFW.time $= 0-  driveNetwork network $ runInput closed+      -- Creating the network+      network <- makeNetwork (getInput ic) gameSignal gameSink -  -- Closing the window, after all is said and done-  closeWindow+      -- Driving the network+      GLFW.time $= 0+      driveNetwork network $ runInput closed++      -- Closing the window, after all is said and done+      closeWindow
src/FRP/Spice/Engine/Network.hs view
@@ -6,7 +6,6 @@  -------------------- -- Global Imports ---import Control.Applicative import FRP.Elerea.Param  -------------------
src/FRP/Spice/Engine/RenderWrapper.hs view
@@ -9,18 +9,23 @@ import Graphics.Rendering.OpenGL import Graphics.UI.GLFW +--------------------+-- Global Imports --+import FRP.Spice.Graphics.Scene+ ---------- -- Code --  {-|   A function to be ran on a @'FRP.Spice.Game.Game'@'s render function to-  provide a bit of a framework around it.+  provide a bit of a framework around it. It runs @'clear'@ before the render+  function, and @'flush'@ / @'swapBuffers'@ afterwards. -}-renderWrapper :: IO () -> IO ()-renderWrapper renderfn = do+renderWrapper :: Scene -> IO ()+renderWrapper scene = do   clear [ColorBuffer] -  renderfn+  renderScene scene    flush   swapBuffers
src/FRP/Spice/Engine/RunInput.hs view
@@ -10,10 +10,6 @@ import Data.IORef import GHC.Float ----------------------- Local Imports ---import FRP.Spice.Game- ---------- -- Code -- 
src/FRP/Spice/Game.hs view
@@ -6,6 +6,7 @@  ------------------- -- Local Imports --+import FRP.Spice.Graphics.Scene import FRP.Spice.Input  ----------@@ -23,4 +24,4 @@ -} class Game a where   update :: DeltaTime -> Input -> a -> a-  render :: a -> IO ()+  render :: a -> Scene
src/FRP/Spice/Graphics.hs view
@@ -3,6 +3,7 @@ -} module FRP.Spice.Graphics ( module FRP.Spice.Graphics.Geometry                           , module FRP.Spice.Graphics.Color+                          , module FRP.Spice.Graphics.Scene                           , module FRP.Spice.Graphics.Utils                           ) where @@ -10,4 +11,5 @@ -- Rexported Imports -- import FRP.Spice.Graphics.Geometry import FRP.Spice.Graphics.Color+import FRP.Spice.Graphics.Scene import FRP.Spice.Graphics.Utils
src/FRP/Spice/Graphics/Color.hs view
@@ -6,7 +6,7 @@  -------------------- -- Global Imports ---import Graphics.Rendering.OpenGL (Color4 (..), GLfloat, color)+import Graphics.Rendering.OpenGL (Color4 (..), color)  ------------------- -- Local Imports --
src/FRP/Spice/Graphics/Geometry.hs view
@@ -10,6 +10,7 @@  ------------------- -- Local Imports --+import FRP.Spice.Graphics.Scene import FRP.Spice.Graphics.Utils import FRP.Spice.Math.Vector @@ -19,24 +20,24 @@ {-|   Rendering a point. -}-renderPoint :: Vector Float -> IO ()-renderPoint (Vector x y) = do-  renderPrimitive Points $-    vertex $ Vertex2 (togl x) (togl y)+renderPoint :: Vector Float -> Scene+renderPoint pos =+  fromElements [Element Points [pos]]  {-|   Rendering a rectangle. -}-renderRectangle :: Vector Float -> Vector Float -> IO ()+renderRectangle :: Vector Float -> Vector Float -> Scene renderRectangle (Vector x y) (Vector w h) = do-  renderPrimitive Quads $ do-    vertex $ Vertex2 (togl (x    )) (togl (y    ))-    vertex $ Vertex2 (togl (x + w)) (togl (y    ))-    vertex $ Vertex2 (togl (x + w)) (togl (y + h))-    vertex $ Vertex2 (togl (x    )) (togl (y + h))+  fromElements [ Element Quads [ Vector (x    ) (y    )+                               , Vector (x + w) (y    )+                               , Vector (x + w) (y + h)+                               , Vector (x    ) (y + h)+                               ]+               ]  {-|   Rendering a square. -}-renderSquare :: Vector Float -> Float -> IO ()+renderSquare :: Vector Float -> Float -> Scene renderSquare pos size = renderRectangle pos $ Vector size size
+ src/FRP/Spice/Graphics/Scene.hs view
@@ -0,0 +1,78 @@+module FRP.Spice.Graphics.Scene where++--------------------+-- Global Imports --+import Graphics.Rendering.OpenGL+import Control.Applicative+import Control.Monad++-------------------+-- Local Imports --+import FRP.Spice.Graphics.Utils+import FRP.Spice.Math.Vector++----------+-- Code --++{-|+  Purely specifying the rendering behavior of a single element. To be composed+  into @'FRP.Spice.Graphics.Scene'@s for a full rendering effect.+-}+data Element = Element PrimitiveMode [Vector Float]++{-|+  For composing a scene out of a set of elements.+-}+data SceneT a = SceneT [Element] a++{-|+  The commonly used instance of SceneT+-}+type Scene = SceneT ()++{-|+  Functor instance to satisfy applicative instance.+-}+instance Functor SceneT where+  fmap fn (SceneT elements v) = SceneT elements $ fn v++{-|+  Applicative instance to satisfy the monad instance. Not advised to use+-}+instance Applicative SceneT where+  pure  = return+  (<*>) = ap++{-|+  Used for being able to compose Scenes in a do-notation. Not very useful+  outside of that.+-}+instance Monad SceneT where+  return a = SceneT [] a+  (SceneT elements v) >>= fn =+    let (SceneT elements' v') = fn v in+      SceneT (elements ++ elements') v'++{-|+  Rendering a single @'Element'@.+-}+renderElement :: Element -> IO ()+renderElement (Element pm vs) =+  renderPrimitive pm $+    forM_ vs $ \(Vector x y) ->+      vertex $ Vertex2 (togl x) (togl y)++{-|+  Constructing a SceneT from a list of elements.+-}+fromElements :: [Element] -> Scene+fromElements elements =+  SceneT elements ()++{-|+  Rendering a whole @'Scene'@ (renders each @'Element'@ from first in list to last in+  list.)+-}+renderScene :: Scene -> IO ()+renderScene (SceneT elements _) =+  forM_ elements renderElement
src/FRP/Spice/Input.hs view
@@ -16,7 +16,6 @@ import Data.Map.Strict hiding (keys, map) import Graphics.Rendering.OpenGL import Graphics.UI.GLFW as GLFW-import Control.Applicative import FRP.Elerea.Param  -------------------@@ -25,6 +24,7 @@ import qualified FRP.Spice.Input.Keyboard as Keyboard import qualified FRP.Spice.Input.Mouse as Mouse import FRP.Spice.Math.Vector+import FRP.Spice.Config  ----------------------- -- Rexported Imports --@@ -91,9 +91,11 @@ {-|   Creating a callback to update the mouse position's state. -}-makeMousePositionCallback :: InputContainer -> MousePosCallback-makeMousePositionCallback ic (Position x y) =-  mousePositionSinks (getSinks ic) $ Vector (fromIntegral x / 320 - 1) ((-fromIntegral y) / 240 - 1)+makeMousePositionCallback :: WindowConfig -> InputContainer -> MousePosCallback+makeMousePositionCallback wc ic (Position x y) =+  mousePositionSinks (getSinks ic) $+    Vector (  fromIntegral x  / ((fromIntegral $ getWindowWidth  wc) / 2) - 1)+           ((-fromIntegral y) / ((fromIntegral $ getWindowHeight wc) / 2) + 1)  {-|   Creating a callback to update the keyboard's states.
src/FRP/Spice/Input/Mouse.hs view
@@ -7,15 +7,9 @@ -- Global Imports -- import qualified Data.Traversable as T (sequence) import Data.Map.Strict hiding (keys, map)-import Graphics.Rendering.OpenGL import Graphics.UI.GLFW as GLFW import FRP.Elerea.Param import Control.Monad-import Data.Default------------------------ Local Imports ---import FRP.Spice.Math.Vector  ---------- -- Code --
src/FRP/Spice/Input/MousePosition.hs view
@@ -5,8 +5,6 @@  -------------------- -- Global Imports ---import Graphics.Rendering.OpenGL-import Graphics.UI.GLFW as GLFW import FRP.Elerea.Param import Data.Default 
+ src/FRP/Spice/Math.hs view
@@ -0,0 +1,9 @@+{-|+  This module re-exports a number of modules having to do with math.+-}+module FRP.Spice.Math ( module FRP.Spice.Math.Vector+                      ) where++-----------------------+-- Rexported Imports --+import FRP.Spice.Math.Vector