affection/src/Affection/Types.hs

86 lines
2.7 KiB
Haskell
Raw Normal View History

{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveFunctor #-}
2018-09-25 05:02:33 +00:00
module Affection.Types
2018-09-25 14:10:36 +00:00
( Affection
2018-09-25 05:02:33 +00:00
, AffectionConfig(..)
, AffectionData(..)
2018-09-25 14:10:36 +00:00
, AffectionStateInner
2018-09-25 05:02:33 +00:00
, AffectionState(..)
, InitComponents(..)
2018-09-25 14:10:36 +00:00
, Angle
2018-09-25 05:02:33 +00:00
-- | SDL reexports
, SDL.WindowConfig(..)
, SDL.WindowMode(..)
, SDL.EventPayload(..)
2018-09-25 14:10:36 +00:00
, SDL.InitFlag(..)
, SDL.Window
, SDL.GLContext
2018-09-25 05:02:33 +00:00
) where
2016-03-25 15:58:46 +00:00
import qualified SDL.Init as SDL
import qualified SDL.Video as SDL
2017-02-17 16:15:06 +00:00
import qualified SDL.Event as SDL
import qualified Data.Text as T
2016-12-21 03:28:57 +00:00
import Control.Monad.IO.Class
2018-06-03 00:41:49 +00:00
import Control.Monad.State.Strict
import qualified Control.Monad.Parallel as MP
2017-07-29 00:51:18 +00:00
import System.Clock (TimeSpec)
-- | Configuration for the aplication. needed at startup.
2017-12-10 15:10:09 +00:00
data AffectionConfig us = AffectionConfig
2016-11-04 15:06:16 +00:00
{ initComponents :: InitComponents
-- ^ SDL components to initialize at startup
, windowTitle :: T.Text
-- ^ Window title
2019-01-30 11:00:28 +00:00
, windowConfigs ::
[
2020-05-03 23:36:12 +00:00
( Word -- --^ Window identifier
, SDL.WindowConfig -- --^ Window config for given window
, SDL.WindowMode -- -- ^ Window mode to start in
2019-01-30 11:00:28 +00:00
)
]
-- ^ Window configurations
}
2016-12-21 03:28:57 +00:00
-- | Components to initialize in SDL.
data InitComponents
= All
| Only [SDL.InitFlag]
-- | Main type for defining the look, feel and action of the whole application.
2017-12-12 12:12:06 +00:00
data AffectionData us = AffectionData
2020-05-03 23:36:12 +00:00
{ drawWindows ::
2019-01-30 11:00:28 +00:00
[
2020-05-03 23:36:12 +00:00
( Word -- --^ Window identifier
, SDL.Window -- --^ Window linked with identifier
, SDL.WindowMode -- -- ^ current screen mode
2019-01-30 11:00:28 +00:00
)
] -- ^ SDL windows
, glContext ::
[
2020-05-03 23:36:12 +00:00
( Word -- --^ Window identifier
, SDL.GLContext -- --^ Associated OpenGL context
2019-01-30 11:00:28 +00:00
)
] -- ^ OpenGL rendering contexts
2017-07-29 19:45:40 +00:00
, screenMode :: SDL.WindowMode -- ^ current screen mode
2016-12-25 07:14:51 +00:00
, elapsedTime :: Double -- ^ Elapsed time in seconds
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick
2017-07-29 00:47:26 +00:00
, sysTime :: TimeSpec -- ^ System time (NOT the time on the clock)
2017-07-29 00:40:41 +00:00
, pausedTime :: Bool -- ^ Should the update loop be executed?
}
-- | Inner 'StateT' monad for the update state
2020-05-03 23:36:12 +00:00
type AffectionStateInner sd a = StateT sd a
-- | Affection's state monad
2020-05-03 23:36:12 +00:00
newtype AffectionState sd m a = AffectionState
{ runState :: AffectionStateInner sd m a }
deriving (Functor, Applicative, Monad, MonadIO, MonadState sd)
2020-05-03 23:36:12 +00:00
instance MP.MonadParallel m => MP.MonadParallel (AffectionState sd m)
2017-12-10 15:10:09 +00:00
type Affection us a = AffectionState (AffectionData us) IO a
2016-12-08 17:22:29 +00:00
type Angle = Double