affection/src/Affection/Types.hs

88 lines
2.6 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(..)
2022-07-10 02:18:22 +00:00
, AffectionWindow(..)
, AffectionContext(..)
2018-09-25 05:02:33 +00:00
, 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
2022-07-10 02:18:22 +00:00
import Control.Monad.Trans.Resource
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.
data AffectionData = AffectionData
2022-07-10 02:18:22 +00:00
{ drawWindows :: [ AffectionWindow ] -- ^ SDL windows
, glContext :: [ AffectionContext ] -- ^ OpenGL rendering contexts
, elapsedTime :: Double -- ^ Elapsed time in seconds
, deltaTime :: Double -- ^ Elapsed time in seconds since last tick
, sysTime :: TimeSpec -- ^ System time (NOT the time on the clock)
, pausedTime :: Bool -- ^ Should the update loop be executed?
}
-- | Inner 'StateT' monad for the update state
2022-07-10 02:18:22 +00:00
type AffectionStateInner sd m = StateT sd m
-- | Affection's state monad
2020-05-03 23:36:12 +00:00
newtype AffectionState sd m a = AffectionState
{ runState :: AffectionStateInner sd m a }
2022-07-10 02:18:22 +00:00
deriving (Functor, Applicative, Monad, MonadIO, MonadState sd, MonadResource)
2020-05-03 23:36:12 +00:00
instance MP.MonadParallel m => MP.MonadParallel (AffectionState sd m)
2022-07-10 02:18:22 +00:00
type Affection a = AffectionState AffectionData ResIO a
2016-12-08 17:22:29 +00:00
type Angle = Double
2022-07-10 02:18:22 +00:00
data AffectionWindow = AffectionWindow
{ awWindow :: SDL.Window
, awReleaseKey :: ReleaseKey
, awMode :: SDL.WindowMode
}
data AffectionContext = AffectionContext
{ acContext :: SDL.GLContext
, acReleaseKey :: ReleaseKey
}