packages feed

spice 0.3.2.4 → 0.3.3.2

raw patch · 5 files changed

+109/−47 lines, 5 files

Files

spice.cabal view
@@ -1,5 +1,5 @@ name:                spice-version:             0.3.2.4+version:             0.3.3.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@@ -37,6 +37,7 @@                        FRP.Spice.Input.Mouse                        FRP.Spice.Input.MousePosition                        FRP.Spice.Math.Vector+                       FRP.Spice.Utils.DoList    hs-source-dirs:      src/ 
src/FRP/Spice/Graphics/Element.hs view
@@ -1,3 +1,8 @@+{-|+  This module provides a unified API for specifying every kind of rendering+  datatype and how they get rendered. All of this -- of course -- is only in+  the scope the spice project.+-} module FRP.Spice.Graphics.Element ( Element (..)                                   , renderElement                                   ) where@@ -20,6 +25,7 @@   has been implemented so far.) -} data Element = RenderPrimitive PrimitiveMode [Vector Float]+             | RenderSprite (Vector Float) (Vector Float) Float              | SetColor Float Float Float Float  {-|@@ -30,5 +36,6 @@   renderPrimitive mode $     forM_ vertecies $ \(Vector x y) ->       vertex $ Vertex2 (togl x) (togl y)+renderElement (RenderSprite pos size rot) = return () renderElement (SetColor r g b a) =   color $ Color4 (togl r) (togl g) (togl b) (togl a)
src/FRP/Spice/Graphics/Geometry.hs view
@@ -28,6 +28,16 @@   fromElements [RenderPrimitive Points [pos]]  {-|+  Rendering a line between two points.+-}+renderLine :: Vector Float -> Vector Float -> Scene+renderLine p1 p2 =+  fromElements [ RenderPrimitive Lines [ p1+                                       , p2+                                       ]+               ]++{-|   Rendering a rectangle. -} renderRectangle :: Vector Float -> Vector Float -> Scene@@ -44,3 +54,21 @@ -} renderSquare :: Vector Float -> Float -> Scene renderSquare pos size = renderRectangle pos $ Vector size size++{-|+  Rendering a triangle.+-}+renderTriangle :: Vector Float -> Vector Float -> Vector Float -> Scene+renderTriangle p1 p2 p3 =+  fromElements [ RenderPrimitive Triangles [ p1+                                           , p2+                                           , p3+                                           ]+               ]++{-|+  Rendering a polygon with 1-N vertecies.+-}+renderPolygon :: [Vector Float] -> Scene+renderPolygon l =+  fromElements [RenderPrimitive Polygon l]
src/FRP/Spice/Graphics/Scene.hs view
@@ -1,61 +1,24 @@+{-|+  This module provides an API to compose @'Scene'@s through do-notation.+-} module FRP.Spice.Graphics.Scene where ------------------------ Global Imports ---import Control.Applicative-import Control.Monad- ------------------- -- Local Imports -- import FRP.Spice.Graphics.Element+import FRP.Spice.Utils.DoList  ---------- -- Code --  {-|-  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.+  A DoList to compose a list of @'Element'@s to render using do-notation. -}-instance Monad SceneT where-  return a = SceneT [] a-  (SceneT elements v) >>= fn =-    let (SceneT elements' v') = fn v in-      SceneT (elements ++ elements') v'+type Scene = DoList [Element] -{-|-  Constructing a SceneT from a list of elements.--} fromElements :: [Element] -> Scene-fromElements elements =-  SceneT elements ()+fromElements = fromValues -{-|-  Rendering a whole @'Scene'@ (renders each @'Element'@ from first in list to last in-  list.)--} renderScene :: Scene -> IO ()-renderScene (SceneT elements _) =-  forM_ elements renderElement+renderScene scene =+  mapM_ renderElement $ values scene
+ src/FRP/Spice/Utils/DoList.hs view
@@ -0,0 +1,63 @@+{-|+  This module provides a list that can be composed and concatenated through+  do-notation.+++-}+module FRP.Spice.Utils.DoList where++--------------------+-- Global Imports --+import Control.Applicative+import Data.Monoid++----------+-- Code --++{-|+  The datastructure itself. Almost equivalent to a tuple of length 2 without+  and more context.+-}+data DoListT a b = DoListT a b++{-|+  A more commonly used synonym for DoListT+-}+type DoList a = DoListT a ()++{-|+  Getting the elements from a @'DoListT'@.+-}+values :: DoListT a b -> a+values (DoListT a _) = a++{-|+  Constructing a do-list from a @'Monoid'@.+-}+fromValues :: Monoid a => a -> DoListT a ()+fromValues a = DoListT a ()++{-|+  A functor instance to satisfy @'Applicative'@'s requirements.+-}+instance Functor (DoListT a) where+  fmap fn (DoListT a b) =+    DoListT a $ fn b++{-|+  An applicative instance to satisfy @'Monad'@'s requirements.+-}+instance Monoid a => Applicative (DoListT a) where+  pure b = DoListT mempty b+  (DoListT _ fn) <*> dl = fmap fn dl++{-|+  A monad instance to perform the actual composition of the list. List is a+  loose word seeing as the monad instance simply needs an instance of+  @'Monoid'@.+-}+instance Monoid a => Monad (DoListT a) where+  return = pure+  (DoListT a b) >>= fn =+    let (DoListT a' b') = fn b in+      DoListT (mappend a a') b'