some data moving

This commit is contained in:
nek0 2020-02-07 07:51:31 +01:00
parent 5a9fa0300e
commit 96476ac52e
3 changed files with 38 additions and 10 deletions

View file

@ -54,14 +54,13 @@ loadState = do
<$> (SubWindow <$> newTVarIO []) <$> (SubWindow <$> newTVarIO [])
<*> (SubMouse <$> newTVarIO []) <*> (SubMouse <$> newTVarIO [])
rawImg <- readImage "assets/img/lynx.jpg" spriteDetails <- loadSprites
let img = case eRawImg of
Left err -> error err
Right dynImg -> convertRGBA8 dynImg
return UserData return UserData
{ udSubsystems = subs { udSubsystems = subs
, udAssetSprites = M.singleton "lynx" (Sprite (V2 0 0) img) , udRenderAssets = RenderAssets
{ assetSprites = spriteDetails
}
} }
handle = return () handle = return ()
@ -69,5 +68,6 @@ handle = return ()
updateLoop = return () updateLoop = return ()
drawLoop = do drawLoop = do
ud@(UserData subs sprites) <- getAffection ud@(UserData subs rassets) <- getAffection
draw let (RenderAssets sDetails@(svo sso sdo)) = rassets
mapM_ (draw svo sso) (assocs sdo)

View file

@ -68,3 +68,21 @@ initSpriteShaderObjects = do
GL.attachShader shaderProgram fragmentShader GL.attachShader shaderProgram fragmentShader
GL.linkProgram shaderProgram GL.linkProgram shaderProgram
return (SpriteShaderObjects vertexShader fragmentShader shaderProgram)
loadSprites :: IO (AssetDetails SpriteRenderObjects SpriteShaderObjects Sprite)
loadSprites = do
rawImg <- readImage "assets/img/lynx.jpg"
let img = case eRawImg of
Left err -> error err
Right dynImg -> convertRGBA8 dynImg
vertObj <- initSpriteRenderObjects
shadObj <- initSpriteShaderobjects
return AssetDetails
{ adVertObj = vertObj
, adShadObj = shadObj
, adDataObj = M.singleton "lynx" (Sprite (V2 0 0) img)
}

View file

@ -18,10 +18,20 @@ import Types.Sprite
data UserData = UserData data UserData = UserData
{ udSubsystems :: Subsystems { udSubsystems :: Subsystems
, udAssetSprites :: M.Map ImgId Sprite , udRenderAssets :: RenderAssets
} }
type ImgId = String data RenderAssets = RenderAssets
{ assetSprites :: AssetDetails SpriteRenderObjects SpriteShaderObjects Sprite
}
data Renderable dat => AssetDetails vo so dat = AssetDetails
{ adVertObj :: vo
, adShadObj :: so
, adDataObj :: M.Map AssetId dat
}
type AssetId = String
data Subsystems = Subsystems data Subsystems = Subsystems
{ subWindow :: SubWindow { subWindow :: SubWindow