ansi-terminal-game 0.2.0.0 → 0.2.1.0
raw patch · 4 files changed
+60/−34 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ansi-terminal-game.cabal +1/−1
- changes.txt +7/−0
- src/Terminal/Game.hs +14/−5
- src/Terminal/Game/GameLoop.hs +38/−28
ansi-terminal-game.cabal view
@@ -1,5 +1,5 @@ name: ansi-terminal-game-version: 0.2.0.0+version: 0.2.1.0 synopsis: sdl-like functions for terminal applications, based on ansi-terminal description: Library which aims to replicate standard 2d game
changes.txt view
@@ -1,3 +1,10 @@+0.2.1.0+-------++- Improved haddock documentation a bit.+- Cleanup runs regardless of exception.+- Released on Sun 18 Mar 2018 03:04:07 CET.+ 0.2.0.0 -------
src/Terminal/Game.hs view
@@ -1,7 +1,16 @@----------------------------------------------------------------------------------- Operate the Terminal machinery.--- 2017 Francesco Ariis GPLv3--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+-- |+-- Module : Terminal.Game+-- Copyright : © 2017-2018 Francesco Ariis+-- License : GPLv3 (see LICENSE file)+--+-- Maintainer : Francesco Ariis <fa-ml@ariis.it>+-- Stability : provisional+-- Portability : portable+--+-- Machinery and utilities for 2D terminal games.+--+-------------------------------------------------------------------------------- -- Basic col-on-black ASCII terminal, operations. -- Only module to be imported.@@ -10,7 +19,7 @@ -- todo resize screen corruption [grave] -- add docs [release] -module Terminal.Game ( -- * Game loop+module Terminal.Game ( -- * Game Loop gameLoop, -- * Plane Plane, -- types
src/Terminal/Game/GameLoop.hs view
@@ -18,43 +18,52 @@ import qualified System.Console.ANSI as CA import qualified System.Console.Terminal.Size as TS import qualified System.Clock as SC+import qualified Control.Exception as E +-- todo [release] [study] no full IO for s, but a+-- jailed IO (provided by a datatype), both for I+-- and for O+ -- todo elimina fps ora che li puoi fare on IO --- | Entry point for the game.-gameLoop :: String -- ^title- -> s -- ^initial state- -- todo [release] [study] no full IO for s, but a- -- jailed IO (provided by a datatype), both for I- -- and for O- -> (s -> Maybe Char -> IO s) -- ^logic function- -> (s -> Plane) -- ^draw function- -> (s -> Bool) -- ^quit? function- -> Integer -- ^framerate (in fps)+-- | Entry point for the game, should be called in @main@. The two+-- most important functions are the one dealing with logic and the+-- blitting one. Check @alone-in-a-room@ (you can compiler it with+-- @cabal new-build -f examples@) to see a simple game in action.+gameLoop :: String -- ^Terminal title.+ -> s -- ^Initial state of the game.+ -> (s -> Maybe Char -> IO s) -- ^Logic function.+ -> (s -> Plane) -- ^Draw function.+ -> (s -> Bool) -- ^\"Should I quit?" function.+ -> Integer -- ^Framerate (in fps). -> IO () gameLoop t s lf df qf fps = - -- init- SI.hSetBuffering SI.stdout SI.NoBuffering >>- SI.hSetBuffering SI.stdin SI.NoBuffering >>- SI.hSetEcho SI.stdin False >>-- -- title and initial setup/checks- CA.setTitle t >>- CA.hideCursor >>- blackScreen >>+ E.finally (initPart >> game)+ cleanAndExit -- this will be run regardless+ -- of exception+ where+ initPart :: IO ()+ initPart = -- init+ SI.hSetBuffering SI.stdout SI.NoBuffering >>+ SI.hSetBuffering SI.stdin SI.NoBuffering >>+ SI.hSetEcho SI.stdin False >> - -- mvars & fork- newMVar 1 >>= \frameCounter ->- newMVar Nothing >>= \inputChar ->- forkIO (inputAction inputChar) >>- forkIO (incTimer frameCounter fps) >>+ -- title and initial setup/checks+ CA.setTitle t >>+ CA.hideCursor >>+ blackScreen - logicDraw inputChar frameCounter- s lf df qf Nothing- (initFPSCounter 20) (0,0) >>+ game :: IO ()+ game = -- mvars & fork+ newMVar 1 >>= \frameCounter ->+ newMVar Nothing >>= \inputChar ->+ forkIO (inputAction inputChar) >>+ forkIO (incTimer frameCounter fps) >> - cleanAndExit+ logicDraw inputChar frameCounter+ s lf df qf Nothing+ (initFPSCounter 20) (0,0) ----------------@@ -159,6 +168,7 @@ -- ANCILLARIES -- ----------------- +-- todo [release] catch any exception in IO and execute this cleanAndExit :: IO () cleanAndExit = CA.setSGR [CA.Reset] >> CA.clearScreen >>