-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A simple Game Engine using SDL -- -- This package contains Affection, a simple game engine written in -- Haskell using SDL. This Engine is still work in progress and even -- minor version bumps may contain breaking api changes. @package affection @version 0.0.0.9 -- | This module defines the logging capability of Affection, whis is -- derived from Debug.Trace. module Affection.Logging -- | The log level definition data LogLevel -- | Log everything Verbose :: LogLevel -- | Log Debug messages and above Debug :: LogLevel -- | Log only Warnings and errors Warn :: LogLevel -- | Log only errors Error :: LogLevel -- | Pure logging function log :: LogLevel -> String -> a -> a -- | Manadic logging function residing in the IO Monad logIO :: LogLevel -> String -> IO () module Affection.MessageBus.Message.Class -- | Typeclass definition for messages class Message msg -- | return the time when the message was sent msgTime :: Message msg => msg -> Double module Affection.MessageBus.Message.JoystickMessage -- | Datatype for handling all possible joystick events handed over from -- sdl2 data JoystickMessage -- | Movement of a Joystick axis MsgJoystickAxis :: Double -> Int32 -> Word8 -> Int16 -> JoystickMessage -- | Time of event [msgJAWhen] :: JoystickMessage -> Double -- | Joystick identifier [msgJAWhich] :: JoystickMessage -> Int32 -- | Axis identifier [msgJAAxis] :: JoystickMessage -> Word8 -- | Axis value [msgJAValue] :: JoystickMessage -> Int16 -- | Movement of a joystick ball controller MsgJoystickBall :: Double -> Int32 -> Word8 -> V2 Int16 -> JoystickMessage -- | Time of event [msgJBWhen] :: JoystickMessage -> Double -- | Joystick identifier [msgJBWhich] :: JoystickMessage -> Int32 -- | Ball identifier [msgJBBall] :: JoystickMessage -> Word8 -- | Motion relative to previous position [msgJBRelMotion] :: JoystickMessage -> V2 Int16 -- | Movement of joystick hat controller MsgJoystickHat :: Double -> Int32 -> Word8 -> JoyHatPosition -> JoystickMessage -- | Time of event [msgJHWhen] :: JoystickMessage -> Double -- | Joystick identifier [msgJHWhich] :: JoystickMessage -> Int32 -- | Hat identifier [msgJHHat] :: JoystickMessage -> Word8 -- | New hat position [msgJHPosition] :: JoystickMessage -> JoyHatPosition -- | Joystick button event MsgJoystickButton :: Double -> Int32 -> Word8 -> JoyButtonState -> JoystickMessage -- | Time of event [msgJBWhen] :: JoystickMessage -> Double -- | Joystick identifier [msgJBWhich] :: JoystickMessage -> Int32 -- | Button identifier [msgJBButton] :: JoystickMessage -> Word8 -- | New Button state [msgJBState] :: JoystickMessage -> JoyButtonState -- | Joystick device event MsgJoystickDevice :: Double -> Int32 -> JoyDeviceConnection -> JoystickMessage -- | Time of event [msgJDWhen] :: JoystickMessage -> Double -- | Joystick identifier [msgJDWhich] :: JoystickMessage -> Int32 -- | Connection status [msgJDConnection] :: JoystickMessage -> JoyDeviceConnection -- | A 2-dimensional vector -- --
-- >>> pure 1 :: V2 Int -- V2 1 1 ---- --
-- >>> V2 1 2 + V2 3 4 -- V2 4 6 ---- --
-- >>> V2 1 2 * V2 3 4 -- V2 3 8 ---- --
-- >>> sum (V2 1 2) -- 3 --data V2 a -- | Identifies the state of the POV hat on a joystick. data JoyHatPosition -- | Identifies the state of a joystick button. data JoyButtonState -- | Identifies whether a joystick has been connected or disconnected. data JoyDeviceConnection -- | 8-bit unsigned integer type data Word8 -- | 16-bit signed integer type data Int16 -- | 32-bit signed integer type data Int32 instance GHC.Show.Show Affection.MessageBus.Message.JoystickMessage.JoystickMessage instance Affection.MessageBus.Message.Class.Message Affection.MessageBus.Message.JoystickMessage.JoystickMessage module Affection.MessageBus.Message.KeyboardMessage -- | Dataatype for handling all keyboard events haded down from SDL2 data KeyboardMessage -- | Arbitrary Keyboard event MsgKeyboardEvent :: Double -> Maybe Window -> InputMotion -> Bool -> Keysym -> KeyboardMessage -- | Message time [msgKbdWhen] :: KeyboardMessage -> Double -- | Affected Window [msgKbdWindow] :: KeyboardMessage -> Maybe Window -- | Input motion of button (pressed/released) [msgKbdKeyMotion] :: KeyboardMessage -> InputMotion -- | Is this a repeated event? [msgKbdKeyRepeat] :: KeyboardMessage -> Bool -- | The button's Keysym [msgKbdKeysym] :: KeyboardMessage -> Keysym data Window data InputMotion -- | Information about a key press or key release event. data Keysym instance GHC.Show.Show Affection.MessageBus.Message.KeyboardMessage.KeyboardMessage instance Affection.MessageBus.Message.Class.Message Affection.MessageBus.Message.KeyboardMessage.KeyboardMessage module Affection.MessageBus.Message.MouseMessage data MouseMessage -- | Mouse motion event MsgMouseMotion :: Double -> Maybe Window -> MouseDevice -> [MouseButton] -> V2 Int32 -> V2 Int32 -> MouseMessage -- | Message time [msgMMWhen] :: MouseMessage -> Double -- | Focused window (if any) [msgMMWindow] :: MouseMessage -> Maybe Window -- | Mouse device identifier [msgMMWhich] :: MouseMessage -> MouseDevice -- | List of pressed mouse buttons [msgMMState] :: MouseMessage -> [MouseButton] -- | Absolute mouse positiom [msgMMPos] :: MouseMessage -> V2 Int32 -- | Mouse movement relative to previous position [msgMMRelMotion] :: MouseMessage -> V2 Int32 -- | Mouse button event MsgMouseButton :: Double -> Maybe Window -> InputMotion -> MouseDevice -> MouseButton -> Word8 -> V2 Int32 -> MouseMessage -- | Message time [msgMBWhen] :: MouseMessage -> Double -- | Focused window (if any) [msgMBWindow] :: MouseMessage -> Maybe Window -- | Button's input motion [msgMBMotion] :: MouseMessage -> InputMotion -- | Mouse device identifier [msgMBWhich] :: MouseMessage -> MouseDevice -- | Affected mouse button [msgMBButton] :: MouseMessage -> MouseButton -- | Number of clicks [msgMBClicks] :: MouseMessage -> Word8 -- | Absolute mouse position [msgMBPos] :: MouseMessage -> V2 Int32 -- | Mouse wheel event MsgMouseWheel :: Double -> Maybe Window -> MouseDevice -> V2 Int32 -> MouseScrollDirection -> MouseMessage -- | Message time [msgMWWhen] :: MouseMessage -> Double -- | Focused window (if any) [msgMWWhindow] :: MouseMessage -> Maybe Window -- | Mouse device identifier [msgMWWhich] :: MouseMessage -> MouseDevice -- | Absolute mouse position [msgMWPos] :: MouseMessage -> V2 Int32 -- | Scroll direction [msgMWDIrection] :: MouseMessage -> MouseScrollDirection data Window -- | Identifies what kind of mouse-like device this is. data MouseDevice data MouseButton data InputMotion -- | Identifies mouse scroll direction. data MouseScrollDirection instance GHC.Show.Show Affection.MessageBus.Message.MouseMessage.MouseMessage instance Affection.MessageBus.Message.Class.Message Affection.MessageBus.Message.MouseMessage.MouseMessage module Affection.MessageBus.Message.WindowMessage -- | Datatype for handling Window events handed down rom SDL2 data WindowMessage -- | Window show event MsgWindowShow :: Double -> Window -> WindowMessage -- | Message time [msgWSWhen] :: WindowMessage -> Double -- | Window identifier [msgWSWindow] :: WindowMessage -> Window -- | Window hide event MsgWindowHide :: Double -> Window -> WindowMessage -- | Message time [msgWHWhen] :: WindowMessage -> Double -- | Window identifier [msgWHWindow] :: WindowMessage -> Window -- | Window expose event MsgWindowExpose :: Double -> Window -> WindowMessage -- | Message time [msgWEWhen] :: WindowMessage -> Double -- | Window identifier [msgWEWindow] :: WindowMessage -> Window -- | Window move event MsgWindowMove :: Double -> Window -> V2 Int32 -> WindowMessage -- | Message time [msgWMWhen] :: WindowMessage -> Double -- | Window identifier [msgWMWindow] :: WindowMessage -> Window -- | New absolute window position [msgWMNewPos] :: WindowMessage -> V2 Int32 -- | Window resize event MsgWindowResize :: Double -> Window -> V2 Int32 -> WindowMessage -- | Message time [msgWRWhen] :: WindowMessage -> Double -- | Window identifier [msgWRWindow] :: WindowMessage -> Window -- | New absolute window size [msgWRNewSize] :: WindowMessage -> V2 Int32 -- | Window size change event MsgWindowSizeChange :: Double -> Window -> V2 Int32 -> WindowMessage -- | Message time [msgWSCWhen] :: WindowMessage -> Double -- | Window identifier [msgWSCWindow] :: WindowMessage -> Window -- | New absolute window size [msgWSCNewSize] :: WindowMessage -> V2 Int32 -- | Window minimize event MsgWindowMinimize :: Double -> Window -> WindowMessage -- | Message time [msgWMinWhen] :: WindowMessage -> Double -- | Window identifier [msgWMinWindow] :: WindowMessage -> Window -- | Window maximize event MsgWindowMaximize :: Double -> Window -> WindowMessage -- | Message time [msgWMaxWhen] :: WindowMessage -> Double -- | Window identifier [msgWMaxWindow] :: WindowMessage -> Window -- | Window restore event MsgWindowRestore :: Double -> Window -> WindowMessage -- | Message time [msgWRestWhen] :: WindowMessage -> Double -- | Window identifier [msgWRestWindow] :: WindowMessage -> Window -- | Window gain mouse focus event MsgWindowGainMouseFocus :: Double -> Window -> WindowMessage -- | Message Time [msgWGMFWhen] :: WindowMessage -> Double -- | Window identifier [msgWGMFWindow] :: WindowMessage -> Window -- | Window lose mouse focus event MsgWindowLoseMouseFocus :: Double -> Window -> WindowMessage -- | Message Time [msgWLMFWhen] :: WindowMessage -> Double -- | Window identifier [msgWLMFWindow] :: WindowMessage -> Window -- | Window gain keyboard focus event MsgWindowGainKeyboardFocus :: Double -> Window -> WindowMessage -- | Message time [msgWGKFWhen] :: WindowMessage -> Double -- | Window identifier [msgWGKFWindow] :: WindowMessage -> Window -- | Window lose keyboard focus event MsgWindowLoseKeyboardFocus :: Double -> Window -> WindowMessage -- | Message time [msgWLKFWhen] :: WindowMessage -> Double -- | Window identifier [msgWLKFWindow] :: WindowMessage -> Window -- | Window close event MsgWindowClose :: Double -> Window -> WindowMessage -- | Message time [msgWCWhen] :: WindowMessage -> Double -- | Window identifier [msgWCWindow] :: WindowMessage -> Window data Window instance GHC.Show.Show Affection.MessageBus.Message.WindowMessage.WindowMessage instance Affection.MessageBus.Message.Class.Message Affection.MessageBus.Message.WindowMessage.WindowMessage module Affection.MessageBus.Message module Affection.Types type Affection us a = AffectionState (AffectionData us) IO a -- | Configuration for the aplication. needed at startup. data AffectionConfig us AffectionConfig :: InitComponents -> Text -> WindowConfig -> Maybe (Int, Int) -> WindowMode -> IO us -> Affection us () -> [EventPayload] -> Affection us () -> Double -> Affection us () -> Affection us () -> us -> IO () -> AffectionConfig us -- | SDL components to initialize at startup [initComponents] :: AffectionConfig us -> InitComponents -- | Window title [windowTitle] :: AffectionConfig us -> Text -- | Window configuration [windowConfig] :: AffectionConfig us -> WindowConfig -- | size of the texture canvas [canvasSize] :: AffectionConfig us -> Maybe (Int, Int) -- | Window mode to start in [initScreenMode] :: AffectionConfig us -> WindowMode -- | Provide your own load function to create this data. [loadState] :: AffectionConfig us -> IO us -- | Actions to be performed, before loop starts [preLoop] :: AffectionConfig us -> Affection us () -- | Main update function. Takes fractions of a second as input. [eventLoop] :: AffectionConfig us -> [EventPayload] -> Affection us () -- | Main update function. Takes fractions of a second as input. [updateLoop] :: AffectionConfig us -> Double -> Affection us () -- | Function for updating graphics. [drawLoop] :: AffectionConfig us -> Affection us () -- | Provide your own finisher function to clean your data. [cleanUp] :: AffectionConfig us -> us -> IO () -- | Main type for defining the look, feel and action of the whole -- application. data AffectionData us AffectionData :: Bool -> us -> Window -> GLContext -> WindowMode -> (Int, Int) -> Double -> Double -> TimeSpec -> Bool -> AffectionData us -- | Loop breaker. [quitEvent] :: AffectionData us -> Bool -- | State data provided by user [userState] :: AffectionData us -> us -- | SDL window [drawWindow] :: AffectionData us -> Window -- | OpenGL rendering context [glContext] :: AffectionData us -> GLContext -- | current screen mode [screenMode] :: AffectionData us -> WindowMode -- | Dimensions of target surface [drawDimensions] :: AffectionData us -> (Int, Int) -- | Elapsed time in seconds [elapsedTime] :: AffectionData us -> Double -- | Elapsed time in seconds since last tick [deltaTime] :: AffectionData us -> Double -- | System time (NOT the time on the clock) [sysTime] :: AffectionData us -> TimeSpec -- | Should the update loop be executed? [pausedTime] :: AffectionData us -> Bool -- | Inner StateT monad for the update state type AffectionStateInner us a = StateT us a -- | Affection's state monad newtype AffectionState us m a AffectionState :: AffectionStateInner us m a -> AffectionState us m a [runState] :: AffectionState us m a -> AffectionStateInner us m a -- | Components to initialize in SDL. data InitComponents All :: InitComponents Only :: [InitFlag] -> InitComponents type Angle = Double data WindowConfig WindowConfig :: Bool -> Bool -> Bool -> WindowMode -> Maybe OpenGLConfig -> WindowPosition -> Bool -> V2 CInt -> Bool -> WindowConfig -- | Defaults to True. [windowBorder] :: WindowConfig -> Bool -- | Defaults to False. Can not be changed after window creation. [windowHighDPI] :: WindowConfig -> Bool -- | Defaults to False. Whether the mouse shall be confined to the -- window. [windowInputGrabbed] :: WindowConfig -> Bool -- | Defaults to Windowed. [windowMode] :: WindowConfig -> WindowMode -- | Defaults to Nothing. Can not be changed after window creation. [windowOpenGL] :: WindowConfig -> Maybe OpenGLConfig -- | Defaults to Wherever. [windowPosition] :: WindowConfig -> WindowPosition -- | Defaults to False. Whether the window can be resized by the -- user. It is still possible to programatically change the size by -- changing windowSize. [windowResizable] :: WindowConfig -> Bool -- | Defaults to (800, 600). If you set windowHighDPI flag, -- window size in screen coordinates may differ from the size in pixels. -- Use glGetDrawableSize to get size in pixels. [windowInitialSize] :: WindowConfig -> V2 CInt -- | Defaults to True. [windowVisible] :: WindowConfig -> Bool data WindowMode -- | Real fullscreen with a video mode change Fullscreen :: WindowMode -- | Fake fullscreen that takes the size of the desktop FullscreenDesktop :: WindowMode Maximized :: WindowMode Minimized :: WindowMode Windowed :: WindowMode -- | An enumeration of all possible SDL event types. This data type pairs -- up event types with their payload, where possible. data EventPayload WindowShownEvent :: !WindowShownEventData -> EventPayload WindowHiddenEvent :: !WindowHiddenEventData -> EventPayload WindowExposedEvent :: !WindowExposedEventData -> EventPayload WindowMovedEvent :: !WindowMovedEventData -> EventPayload WindowResizedEvent :: !WindowResizedEventData -> EventPayload WindowSizeChangedEvent :: !WindowSizeChangedEventData -> EventPayload WindowMinimizedEvent :: !WindowMinimizedEventData -> EventPayload WindowMaximizedEvent :: !WindowMaximizedEventData -> EventPayload WindowRestoredEvent :: !WindowRestoredEventData -> EventPayload WindowGainedMouseFocusEvent :: !WindowGainedMouseFocusEventData -> EventPayload WindowLostMouseFocusEvent :: !WindowLostMouseFocusEventData -> EventPayload WindowGainedKeyboardFocusEvent :: !WindowGainedKeyboardFocusEventData -> EventPayload WindowLostKeyboardFocusEvent :: !WindowLostKeyboardFocusEventData -> EventPayload WindowClosedEvent :: !WindowClosedEventData -> EventPayload KeyboardEvent :: !KeyboardEventData -> EventPayload TextEditingEvent :: !TextEditingEventData -> EventPayload TextInputEvent :: !TextInputEventData -> EventPayload KeymapChangedEvent :: EventPayload MouseMotionEvent :: !MouseMotionEventData -> EventPayload MouseButtonEvent :: !MouseButtonEventData -> EventPayload MouseWheelEvent :: !MouseWheelEventData -> EventPayload JoyAxisEvent :: !JoyAxisEventData -> EventPayload JoyBallEvent :: !JoyBallEventData -> EventPayload JoyHatEvent :: !JoyHatEventData -> EventPayload JoyButtonEvent :: !JoyButtonEventData -> EventPayload JoyDeviceEvent :: !JoyDeviceEventData -> EventPayload ControllerAxisEvent :: !ControllerAxisEventData -> EventPayload ControllerButtonEvent :: !ControllerButtonEventData -> EventPayload ControllerDeviceEvent :: !ControllerDeviceEventData -> EventPayload AudioDeviceEvent :: !AudioDeviceEventData -> EventPayload QuitEvent :: EventPayload UserEvent :: !UserEventData -> EventPayload SysWMEvent :: !SysWMEventData -> EventPayload TouchFingerEvent :: !TouchFingerEventData -> EventPayload TouchFingerMotionEvent :: !TouchFingerMotionEventData -> EventPayload MultiGestureEvent :: !MultiGestureEventData -> EventPayload DollarGestureEvent :: !DollarGestureEventData -> EventPayload DropEvent :: !DropEventData -> EventPayload ClipboardUpdateEvent :: EventPayload UnknownEvent :: !UnknownEventData -> EventPayload data InitFlag InitTimer :: InitFlag InitAudio :: InitFlag InitVideo :: InitFlag InitJoystick :: InitFlag InitHaptic :: InitFlag InitGameController :: InitFlag InitEvents :: InitFlag data Window -- | A created OpenGL context. data GLContext instance GHC.Base.Monad m => Control.Monad.State.Class.MonadState us (Affection.Types.AffectionState us m) instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Affection.Types.AffectionState us m) instance GHC.Base.Monad m => GHC.Base.Monad (Affection.Types.AffectionState us m) instance GHC.Base.Monad m => GHC.Base.Applicative (Affection.Types.AffectionState us m) instance GHC.Base.Functor m => GHC.Base.Functor (Affection.Types.AffectionState us m) instance Control.Monad.Parallel.MonadParallel m => Control.Monad.Parallel.MonadParallel (Affection.Types.AffectionState us m) module Affection.Subsystems.Class -- | This class denotes a Subsystem to be part of SDL class SDLSubsystem s us -- | Consume the given EventPayloads and return only those not -- recognised consumeSDLEvents :: SDLSubsystem s us => s -> [EventPayload] -> Affection us [EventPayload] module Affection.StateMachine -- | Typeclass for simple scaffolding of a state machine class StateMachine a us -- | State load routine smLoad :: StateMachine a us => a -> Affection us () -- | state update routine smUpdate :: StateMachine a us => a -> Double -> Affection us () -- | State event handler routine smEvent :: StateMachine a us => a -> [EventPayload] -> Affection us () -- | State draw routine smDraw :: StateMachine a us => a -> Affection us () -- | State clean routine smClean :: StateMachine a us => a -> Affection us () module Affection.MessageBus.Class -- | This typeclass defines the behaviour of a participant in the message -- system class (Message (Mesg prt us), Show (Mesg prt us)) => Participant prt us where { type family Mesg prt us :: *; } -- | Function to get the list of subscribers from the participant partSubscribers :: Participant prt us => prt -> Affection us [Mesg prt us -> Affection us ()] -- | Subscribe to the Participant's events partSubscribe :: Participant prt us => prt -> (Mesg prt us -> Affection us ()) -> Affection us UUID -- | Unsubscribe a Subscriber function from Participant partUnSubscribe :: Participant prt us => prt -> UUID -> Affection us () -- | Get the Participant to emit a Message on all of its -- subscribers partEmit :: Participant prt us => prt -> Mesg prt us -> Affection us () -- | Helper function to generate new UUIDs genUUID :: Affection us UUID -- | The UUID type. A Random instance is provided which produces -- version 4 UUIDs as specified in RFC 4122. The Storable and -- Binary instances are compatible with RFC 4122, storing the -- fields in network order as 16 bytes. data UUID module Affection.MessageBus module Affection.Util -- | Prehandle SDL events preHandleEvents :: [Event] -> Affection us [EventPayload] -- | Return the userstate to the user getAffection :: Affection us us -- | Put altered user state back putAffection :: us -> Affection us () -- | block a thread for a specified amount of time delaySec :: Int -> IO () -- | Get time since start but always the same in the current tick. getElapsedTime :: Affection us Double -- | Get delta time (time elapsed from last frame) getDelta :: Affection us Double -- | Quit the engine loop quit :: Affection us () -- | Toggle the Screen mode between Windowed and -- FullscreenDesktop. Pauses the Engine in the process. toggleScreen :: Affection us () -- | Fit the GL Viewport to Window size fitViewport :: Double -> WindowMessage -> Affection us () module Affection.Subsystems.AffectionWindow -- | Helper function that consumes all Window-related EventPayloads -- and emits appropriate WindowMessages. consumeSDLWindowEvents :: forall aw us. (Participant aw us, Mesg aw us ~ WindowMessage) => aw -> [EventPayload] -> Affection us [EventPayload] module Affection.Subsystems.AffectionMouse -- | Helper funtion that consumes all Mouse-related Eventpayloads -- and emits appropriate MouseMessages consumeSDLMouseEvents :: forall am us. (Participant am us, Mesg am us ~ MouseMessage) => am -> [EventPayload] -> Affection us [EventPayload] module Affection.Subsystems.AffectionKeyboard -- | Helper function that consumes all Keyboard-related -- EventPayloads and emits appropriate KeyboardMessages consumeSDLKeyboardEvents :: forall ak us. (Participant ak us, Mesg ak us ~ KeyboardMessage) => ak -> [EventPayload] -> Affection us [EventPayload] module Affection.Subsystems.AffectionJoystick -- | Helper function that consumes all Joystick-related -- EventPayloads and emits appropriate JoystickMessages consumeSDLJoystickEvents :: forall am us. (Participant am us, Mesg am us ~ JoystickMessage) => am -> [EventPayload] -> Affection us [EventPayload] -- | Helper function to automatically connect and open newly attached -- joystick devices joystickAutoConnect :: JoystickMessage -> Affection us (Maybe Joystick) -- | Helper function to automatically close and disconnect freshly detached -- joystick devices joystickAutoDisconnect :: [Joystick] -> JoystickMessage -> Affection us [Joystick] module Affection.Subsystems module Affection -- | Main function which bootstraps everything else. withAffection :: AffectionConfig us -> IO () -- | Return the state from the internals of the monad. get :: MonadState s m => m s -- | Replace the state inside the monad. put :: MonadState s m => s -> m () -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a