free-game 1.0.4 → 1.0.5
raw patch · 13 files changed
+178/−11 lines, 13 filesbinary-added
Files
- CHANGELOG.md +48/−0
- FreeGame.hs +2/−0
- FreeGame/Backend/GLFW.hs +5/−1
- FreeGame/Class.hs +1/−0
- FreeGame/Types.hs +1/−5
- FreeGame/UI.hs +18/−2
- FreeGame/Util.hs +3/−2
- examples/VL-PGothic-Regular.ttf too large to diff
- examples/bird.png binary
- examples/demo.hs +86/−0
- examples/helloworld.hs +6/−0
- examples/logo.png binary
- free-game.cabal +8/−1
+ CHANGELOG.md view
@@ -0,0 +1,48 @@+1.0.5 +---------------------------------------------------------------------------------------------------- +* No fundamental changes + +1.0.4 +---------------------------------------------------------------------------------------------------- + +* Fixed some potential bugs that appeared on 7.8.1 RC2 +* Added `getBoundingBox` and `setBoundingBox` which accesses the window size and the region to draw. +* `Resizable`, the new constructor of `WindowMode`, will create a resizable window. +* Demoted the precedence of `thickness` and `blendMode` according to other APIs. + +1.0.3 +---------------------------------------------------------------------------------------------------- +* Added `runGameDefault` as an alternative of classic `runGame def`. +* Removed the duplicate instance of `MonadIO`. +* `free-game` no longer depends on ominous `repa`. +* Reconstructed 'FreeGame.Data.Bitmap'. 'Bitmap' is just an alias of `Codec.Picture.Repa.Image PixelRGBA8` +* Added `bitmapOnce` which does not keep the internal texture to draw. +* Added `forkFrame` analogous to `forkIO`. +* Accelerate text rendering. +* Make the window size solid. + +1.0.2 +---------------------------------------------------------------------------------------------------- +* Supported changing a blend function. `blendMode mode m` changes the blend mode while `m` is running. +* Fixed fatal 'keyPress'-related bugs. +* Special thanks: [@myuon_myon](https://twitter.com/myuon_myon) +* Re-added `keyChar` and `keySpecial`. + +1.0.1 +---------------------------------------------------------------------------------------------------- +* Demoted the precedence of `Affine` APIs to 5. + +1.0 +---------------------------------------------------------------------------------------------------- +* Supported free-4.4. +* Supported GLFW-b-1.3. +* Use `Double` instead of `Float`. +* Made it more efficient. +* `loadBitmaps` takes an expression instead of a `Name`. +* Reorganized typeclasses. +* Rename: `fromBitmap` -> `bitmap` +* Rename: `colored` -> `color` +* New API: `takeScreenshot` +* New API: `getFPS`, `setFPS` +* Now the verbose module prefix `Graphics.UI` is extinct. +* And a bunch of renovations...
FreeGame.hs view
@@ -14,6 +14,7 @@ Game, runGame, runGameDefault, + reGame, WindowMode(..), BoundingBox(..), inBoundingBox, @@ -25,6 +26,7 @@ untickInfinite, -- * Frame Frame, + reFrame, FreeGame(..), -- * Transformations Vec2,
FreeGame/Backend/GLFW.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Rank2Types, BangPatterns, ViewPatterns #-} +{-# LANGUAGE Rank2Types, BangPatterns, ViewPatterns, CPP #-} {-# LANGUAGE ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-orphans #-} ----------------------------------------------------------------------------- @@ -25,7 +25,11 @@ import FreeGame.UI import FreeGame.Types import Linear +#if (MIN_VERSION_containers(0,5,0)) import qualified Data.IntMap.Strict as IM +#else +import qualified Data.IntMap as IM +#endif import qualified Data.Map.Strict as Map import qualified FreeGame.Internal.GLFW as G import qualified Graphics.UI.GLFW as GLFW
FreeGame/Class.hs view
@@ -201,6 +201,7 @@ instance FromFinalizer (FinalizerT IO) where fromFinalizer = id +-- | 'liftIO' variety for 'FromFinalizer'. embedIO :: FromFinalizer m => IO a -> m a embedIO m = fromFinalizer (liftIO m) {-# INLINE embedIO #-}
FreeGame/Types.hs view
@@ -146,11 +146,7 @@ | KeyRightAlt | KeyRightSuper | KeyMenu - deriving (Enum, Eq, Ord, Read, Show, Typeable) - -instance Bounded Key where - minBound = KeyUnknown - maxBound = KeyMenu + deriving (Enum, Eq, Ord, Read, Show, Typeable, Bounded) data BlendMode = Normal | Inverse
FreeGame/UI.hs view
@@ -13,6 +13,8 @@ module FreeGame.UI ( UI(..) , reUI + , reFrame + , reGame , Frame , Game , FreeGame(..) @@ -26,8 +28,9 @@ import FreeGame.Data.Bitmap (Bitmap) import Data.Color import Data.BoundingBox.Dim2 -import Control.Monad.Free.Church -import Control.Monad.Trans.Iter +import Control.Monad.Free.Church (F, iterM) +import Control.Monad.Trans.Iter (IterT, foldM) +import Control.Monad (join) data UI a = Draw (forall m. (Applicative m, Monad m, Picture2D m, Local m) => m a) @@ -53,6 +56,16 @@ type Frame = F UI +-- | Generalize `Game` to any monad based on `FreeGame`. +reGame :: (FreeGame m, Monad m) => Game a -> m a +reGame = Control.Monad.Trans.Iter.foldM (join . reFrame) +{-# RULES "reGame/sameness" reGame = id #-} + +-- | Generalize `Frame` to any monad based on `FreeGame`. +reFrame :: (FreeGame m, Monad m) => Frame a -> m a +reFrame = iterM (join . reUI) +{-# RULES "reFrame/sameness" reFrame = id #-} + reUI :: FreeGame f => UI a -> f a reUI (Draw m) = draw m reUI (PreloadBitmap bmp cont) = cont <$ preloadBitmap bmp @@ -85,11 +98,13 @@ forkFrame :: Frame () -> m () -- | Generate a 'Bitmap' from the front buffer. takeScreenshot :: m Bitmap + -- | Set the goal FPS. setFPS :: Int -> m () setTitle :: String -> m () showCursor :: m () hideCursor :: m () clearColor :: Color -> m () + -- | Get the actual FPS value. getFPS :: m Int getBoundingBox :: m (BoundingBox Double) setBoundingBox :: BoundingBox Double -> m () @@ -150,6 +165,7 @@ instance FromFinalizer UI where fromFinalizer = FromFinalizer + {-# INLINE fromFinalizer #-} instance Keyboard UI where keyStates_ = KeyStates id
FreeGame/Util.hs view
@@ -104,6 +104,7 @@ loadPictureFromFile = embedIO . fmap bitmap . readBitmap -- | The type of the given 'ExpQ' must be @FilePath -> IO FilePath@ +-- FIXME: This may cause name duplication if there are multiple non-alphanumeric file names. loadBitmapsWith :: ExpQ -> FilePath -> Q [Dec] loadBitmapsWith getFullPath path = do loc <- (</>path) <$> takeDirectory <$> loc_filename <$> location @@ -124,9 +125,9 @@ (varE 'readBitmap) -- | Load and define all pictures in the specified directory. --- In GHC >= 7.6, file paths to actually load will be respect to the directory of the executable. Otherwise it will be based on the current directory. +-- On base >= 4.6, file paths to actually load will be respect to the directory of the executable. Otherwise it will be based on the current directory. -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706 +#if (MIN_VERSION_base(4,6,0)) loadBitmaps :: FilePath -> Q [Dec] loadBitmaps path = do
+ examples/VL-PGothic-Regular.ttf view
file too large to diff
+ examples/bird.png view
binary file changed (absent → 330899 bytes)
+ examples/demo.hs view
@@ -0,0 +1,86 @@+-- Pointless demo +{-# LANGUAGE OverloadedStrings #-} +import FreeGame +import Control.Applicative +import Control.Monad +import Control.Monad.State.Strict + +figureTest :: Frame () +figureTest = draw $ do + color cyan -- 'colored' gives a color to the action. + $ line [V2 80 80, V2 160 160] -- 'line' draws line through the given coordinates. + + color green $ polygon [V2 20 0, V2 100 20, V2 90 60, V2 30 70] + + color blue + $ translate (V2 0 200) -- 'translate' moves the action. + $ rotateD 45 -- 'rotateD' rotates the action. (in degrees). + $ scale 2 -- 'scale' resizes the action. You can also specify as (V2 x y). + $ polygonOutline [V2 20 0, V2 100 20, V2 50 60] + + color magenta + $ thickness 3 -- 'thickness' sets the thickness of the lines. + $ translate (V2 100 300) + $ circleOutline 50 + +fontTest :: Font -> Frame () +fontTest font = do + translate (V2 30 300) $ color white $ do + text font 48 "The quick brown fox" + color red $ line [V2 (-100) 0, V2 640 0] + translate (V2 0 80) $ do + text font 48 "jumps over the lazy dog" + color red $ line [V2 (-100) 0, V2 640 0] + translate (V2 0 160) $ do + text font 48 "0123456789" -- Use 'text font size string' to draw a string. + color red $ line [V2 (-100) 0, V2 640 0] + + color red $ line [V2 0 (-600), V2 0 600] + +bitmapTest :: Bitmap -> Frame () +bitmapTest bmp = blendMode Add $ do + + color (Color 1 0 0 1) $ do + translate (V2 300 346) $ bitmap bmp -- 'bitmap' creates an action from the bitmap. + color (Color 0 1 0 1) $ do + translate (V2 310 350) $ bitmap bmp -- 'bitmap' creates an action from the bitmap. + color (Color 0 0 1 1) $ do + translate (V2 293 359) $ bitmap bmp -- 'bitmap' creates an action from the bitmap. + +mouseTest :: Frame () +mouseTest = do + p <- mousePosition + l <- mouseButtonL + r <- mouseButtonR + let col = case (l, r) of + (False, False) -> black + (True, False) -> red + (False, True) -> blue + (True, True) -> blend 0.5 red blue + translate p $ color col $ thickness 4 $ circleOutline 16 + +main = runGame Windowed (BoundingBox 0 0 640 480) $ do + bmp <- readBitmap "bird.png" + bmp' <- readBitmap "logo.png" + font <- loadFont "VL-PGothic-Regular.ttf" + let bmp' = cropBitmap bmp (128, 128) (64, 64) + clearColor black + forkFrame $ preloadBitmap bmp' + foreverFrame $ do + + bitmapTest bmp + figureTest + translate (V2 320 80) $ bitmap bmp' -- You can slice bitmaps using 'cropBitmap'. + + fontTest font + translate (V2 240 240) $ do + mouseTest + + fps <- getFPS + + color black $ text font 15 (show fps) + + whenM (keyDown KeyA) $ translate (V2 300 300) $ color black $ text font 30 "A" + whenM (keyPress KeyA) $ translate (V2 320 300) $ color black $ text font 30 "B" + whenM (keyUp KeyA) $ translate (V2 340 300) $ color black $ text font 30 "C" + whenM (keyDown KeyS) $ takeScreenshot >>= writeBitmap "capture.png"
+ examples/helloworld.hs view
@@ -0,0 +1,6 @@+import FreeGame + +main = runGame Windowed (BoundingBox 0 0 640 480) $ do + hideCursor + font <- loadFont "VL-PGothic-Regular.ttf" + foreverFrame $ translate (V2 80 200) $ color black $ text font 40 "Hello, World"
+ examples/logo.png view
binary file changed (absent → 1893 bytes)
free-game.cabal view
@@ -1,5 +1,5 @@ name: free-game -version: 1.0.4 +version: 1.0.5 synopsis: Create games for free description: free-game defines a monad that integrates features to create 2D games. @@ -20,12 +20,19 @@ stability: experimental cabal-version: >=1.10 +extra-source-files: + CHANGELOG.md + examples/*.hs + examples/*.png + examples/*.ttf + source-repository head type: git location: https://github.com/fumieval/free-game.git library default-language: Haskell2010 + exposed-modules: FreeGame FreeGame.Class