sdl2-fps (empty) → 0.0.0
raw patch · 7 files changed
+149/−0 lines, 7 filesdep +basedep +sdl2setup-changed
Dependencies added: base, sdl2
Files
- LICENSE +30/−0
- README.md +3/−0
- Setup.hs +2/−0
- library/SDL/FPS.hs +41/−0
- package.yaml +25/−0
- sdl2-fps.cabal +42/−0
- stack.yaml +6/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# sdl2-fps++Run of the mill, frames per second timer implementation
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ library/SDL/FPS.hs view
@@ -0,0 +1,41 @@+module SDL.FPS where++import qualified SDL+import Control.Monad.IO.Class (MonadIO(..))+import Control.Monad (when)+import Data.Word (Word32)++class Monad m => FPS m where+ startFrame :: m Word32+ default startFrame :: MonadIO m => m Word32+ startFrame = liftIO SDL.ticks++ endFrame :: Int -> Word32 -> m ()+ default endFrame :: MonadIO m => Int -> Word32 -> m ()+ endFrame = endFrame'++-- | `endFrame`'s default definition+endFrame' :: MonadIO m => Int -> Word32 -> m ()+endFrame' fps startTicks = liftIO $ do+ endTicks <- SDL.ticks+ let diff = (endTicks - startTicks) * fps'+ when (msps > diff) $ do+ let ms = (msps - diff) `div` fps'+ SDL.delay (fromIntegral ms)+ where+ fps' = fromIntegral fps++-- | Same as default definition and prints fps and delay+endFrameDebug :: MonadIO m => Int -> Word32 -> m ()+endFrameDebug fps startTicks = liftIO $ do+ endTicks <- SDL.ticks+ let diff = (endTicks - startTicks) * fps'+ let ms = (msps - diff) `div` fps'+ when (msps > diff) $ SDL.delay (fromIntegral ms)+ putStrLn $ show fps ++ " fps - delay " ++ show ms ++ " ms"+ where+ fps' = fromIntegral fps++-- | Milliseconds per second+msps :: Word32+msps = 1000
+ package.yaml view
@@ -0,0 +1,25 @@+name: sdl2-fps+version: '0.0.0'+github: jxv/sdl2-fps+license: BSD3+category: Game+synopsis: Run of the mill, frames per second timer implementation+description: Run of the mill, frames per second timer implementation+maintainer: Joe Vargas+copyright: 2018 Joe Vargas+extra-source-files:+- package.yaml+- README.md+- stack.yaml+ghc-options: -Wall+default-extensions:+- LambdaCase+- NamedFieldPuns+- ScopedTypeVariables+- OverloadedStrings+- DefaultSignatures+library:+ dependencies:+ - base >=4.7 && <5+ - sdl2 >= 2.4.0.1 && <2.5+ source-dirs: library
+ sdl2-fps.cabal view
@@ -0,0 +1,42 @@+-- This file has been generated from package.yaml by hpack version 0.20.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: 1b1172145c3bd3f8a5aa9cbf94273f179a01090a90c44ecac7785bd92767a004++name: sdl2-fps+version: 0.0.0+synopsis: Run of the mill, frames per second timer implementation+description: Run of the mill, frames per second timer implementation+category: Game+homepage: https://github.com/jxv/sdl2-fps#readme+bug-reports: https://github.com/jxv/sdl2-fps/issues+maintainer: Joe Vargas+copyright: 2018 Joe Vargas+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ package.yaml+ README.md+ stack.yaml++source-repository head+ type: git+ location: https://github.com/jxv/sdl2-fps++library+ hs-source-dirs:+ library+ default-extensions: LambdaCase NamedFieldPuns ScopedTypeVariables OverloadedStrings DefaultSignatures+ ghc-options: -Wall+ build-depends:+ base >=4.7 && <5+ , sdl2 >=2.4.0.1 && <2.5+ exposed-modules:+ SDL.FPS+ other-modules:+ Paths_sdl2_fps+ default-language: Haskell2010
+ stack.yaml view
@@ -0,0 +1,6 @@+resolver: lts-11.3+packages:+- '.'+extra-deps: []+flags: {}+extra-package-dbs: []