2020-02-07 04:50:19 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2020-02-01 15:09:09 +00:00
|
|
|
module Main where
|
|
|
|
|
2020-02-05 06:21:39 +00:00
|
|
|
import Affection
|
|
|
|
|
2020-02-07 04:50:19 +00:00
|
|
|
import SDL (($=))
|
|
|
|
import qualified SDL
|
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
import qualified Graphics.Rendering.OpenGL as GL
|
2020-02-07 04:50:19 +00:00
|
|
|
|
|
|
|
import Codec.Picture
|
|
|
|
|
|
|
|
import Control.Monad (void)
|
2020-02-07 13:57:09 +00:00
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2020-02-07 04:50:19 +00:00
|
|
|
|
|
|
|
import Control.Concurrent.STM
|
|
|
|
|
|
|
|
import qualified Data.Map.Strict as M
|
|
|
|
|
2020-02-05 06:21:39 +00:00
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
2020-02-07 13:57:09 +00:00
|
|
|
import Types.Sprite
|
|
|
|
import Renderer
|
|
|
|
import Classes.Renderable as CR
|
2020-02-05 06:21:39 +00:00
|
|
|
|
2020-02-01 15:09:09 +00:00
|
|
|
main :: IO ()
|
2020-02-07 04:50:19 +00:00
|
|
|
main =
|
|
|
|
withAffection AffectionConfig
|
|
|
|
{ initComponents = All
|
|
|
|
, windowTitle = "canvas"
|
|
|
|
, windowConfigs =
|
|
|
|
[ ( 0
|
2020-02-07 13:57:09 +00:00
|
|
|
, SDL.defaultWindow
|
2020-02-07 04:50:19 +00:00
|
|
|
{ SDL.windowInitialSize = SDL.V2 1600 900
|
2020-02-07 13:57:09 +00:00
|
|
|
, SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
2020-02-07 04:50:19 +00:00
|
|
|
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, initScreenMode = SDL.FullscreenDesktop
|
|
|
|
, preLoop = return ()
|
2020-02-07 13:57:09 +00:00
|
|
|
, eventLoop = mapM_ handle
|
|
|
|
, updateLoop = updateLoopImpl
|
|
|
|
, drawLoop = drawLoopImpl
|
|
|
|
, loadState = loadStateImpl
|
2020-02-07 04:50:19 +00:00
|
|
|
, cleanUp = (\_ -> return ())
|
|
|
|
, canvasSize = Nothing
|
|
|
|
}
|
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
loadStateImpl :: IO UserData
|
|
|
|
loadStateImpl = do
|
2020-02-07 04:50:19 +00:00
|
|
|
void $ SDL.setMouseLocationMode SDL.RelativeLocation
|
|
|
|
GL.depthFunc $= Just GL.Less
|
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
subs <- Subsystems
|
2020-02-07 04:50:19 +00:00
|
|
|
<$> (SubWindow <$> newTVarIO [])
|
|
|
|
<*> (SubMouse <$> newTVarIO [])
|
|
|
|
|
2020-02-07 06:51:31 +00:00
|
|
|
spriteDetails <- loadSprites
|
2020-02-07 04:50:19 +00:00
|
|
|
|
|
|
|
return UserData
|
|
|
|
{ udSubsystems = subs
|
2020-02-07 06:51:31 +00:00
|
|
|
, udRenderAssets = RenderAssets
|
|
|
|
{ assetSprites = spriteDetails
|
|
|
|
}
|
2020-02-07 04:50:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
handle event = return ()
|
2020-02-07 04:50:19 +00:00
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
updateLoopImpl dt = return ()
|
2020-02-07 04:50:19 +00:00
|
|
|
|
2020-02-07 13:57:09 +00:00
|
|
|
drawLoopImpl = do
|
2020-02-07 06:51:31 +00:00
|
|
|
ud@(UserData subs rassets) <- getAffection
|
2020-02-07 13:57:09 +00:00
|
|
|
let (RenderAssets sDetails@(AssetDetails svo sso sdo)) = rassets
|
|
|
|
liftIO $ do
|
|
|
|
CR.init
|
|
|
|
(svo :: VertexObjects Sprite)
|
|
|
|
(sso :: ShaderObjects Sprite)
|
|
|
|
(head $ M.elems sdo)
|
|
|
|
mapM_ (draw (svo :: VertexObjects Sprite) (sso :: ShaderObjects Sprite)) (M.elems sdo)
|
|
|
|
clean (head $ M.elems sdo)
|