packages feed

elerea-sdl (empty) → 0.1

raw patch · 5 files changed

+123/−0 lines, 5 filesdep +SDLdep +basedep +elereasetup-changed

Dependencies added: SDL, base, elerea

Files

+ COPYING view
@@ -0,0 +1,13 @@+Copyright © 2011, Stephen Paul Weber <singpolyma.net>++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ FRP/Elerea/SDL.hs view
@@ -0,0 +1,73 @@+module FRP.Elerea.SDL (sdlLoop, Ticks) where++import Data.Word (Word32)+import System.IO.Unsafe+import Control.Concurrent (threadDelay)++import FRP.Elerea.Param+import qualified Graphics.UI.SDL as SDL++-- | SDL Ticks+type Ticks = Word32++-- | Main SDL event loop (with framerate)+--+-- Produces an "infinite" list of network samples+sdlLoop ::+	Ticks+	-- ^ Frame duration / Frame time+	-> (SignalGen Ticks (Signal [SDL.Event]) -> SignalGen Ticks (Signal a))+	-- ^ 'Signal' network, takes event 'SignalGen' as argument+	-> IO [a]+sdlLoop frameTime network = do+	(events, signalEvents) <- externalMulti+	sampleNetwork <- start (network events)+	now <- SDL.getTicks+	sdlLoop' signalEvents sampleNetwork frameTime now++sdlLoop' ::+	(SDL.Event -> IO ()) -- ^ IO action to signal an event+	-> (Ticks -> IO a)   -- ^ IO action to sample the network+	-> Ticks             -- ^ Frame duration / Frame time+	-> Ticks             -- ^ Current SDL time (getTicks)+	-> IO [a]+sdlLoop' signalEvents sampleNetwork frameTime = loop frameTime+	where+	loop timeLeft time = do+		(event, (left, nextTime)) <- waitEventTimeout (timeLeft, time)+		case event of+			(Just e) -> signalEvents e >> loop left nextTime+			Nothing -> do+				x <- sampleNetwork nextTime+				xs <- unsafeInterleaveIO (loop frameTime nextTime)+				return (x : xs)++-- | Turns out, SDL just does poll-and-wait internally anyway+--   This wait can time out, which is useful for drawing+waitEventTimeout :: (Ticks,Ticks) -> IO (Maybe SDL.Event, (Ticks,Ticks))+waitEventTimeout (initialLeft, lastTime) = do+	SDL.pumpEvents+	e <- SDL.pollEvent+	case e of+		SDL.NoEvent -> do+			now <- SDL.getTicks+			loop (initialLeft `sub` (now-lastTime)) now+		_ -> return (Just e, (initialLeft, lastTime))+	where+	loop 0 _ = do+		timeoutNow <- SDL.getTicks+		return (Nothing, (0, timeoutNow))+	loop _ now = do+		SDL.pumpEvents+		e <- SDL.pollEvent+		case e of+			SDL.NoEvent -> do+				threadDelay 10000+				eventNow <- SDL.getTicks+				loop (initialLeft `sub` (eventNow - now)) now+			_ -> do+				eventNow <- SDL.getTicks+				return (Just e, (initialLeft `sub` (eventNow - now), eventNow))+	sub t n+		| t > n = t - n+		| otherwise = 0
+ README view
@@ -0,0 +1,1 @@+This is an FRP wrapper for SDL using Elerea.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ elerea-sdl.cabal view
@@ -0,0 +1,33 @@+name:            elerea-sdl+version:         0.1+cabal-version:   >= 1.8+license:         OtherLicense+license-file:    COPYING+category:        Data+copyright:       © 2011-2012 Stephen Paul Weber+author:          Stephen Paul Weber <singpolyma@singpolyma.net>+maintainer:      Stephen Paul Weber <singpolyma@singpolyma.net>+stability:       experimental+tested-with:     GHC == 7.0.3+synopsis:        Elerea FRP wrapper for SDL+homepage:        http://github.com/singpolyma/elerea-sdl+bug-reports:     http://github.com/singpolyma/elerea-sdl/issues+build-type:      Simple+description:+        This is an FRP wrapper for SDL using Elerea.++extra-source-files:+        README++library+        exposed-modules:+                FRP.Elerea.SDL++        build-depends:+                base == 4.*,+                elerea,+                SDL++source-repository head+        type:     git+        location: git://github.com/singpolyma/elerea-sdl.git