From c188512abb176046c8b32e60e376d041ed84965e Mon Sep 17 00:00:00 2001 From: jgk Date: Tue, 23 Feb 2021 15:05:48 +0100 Subject: [PATCH] Separate sound and render io parameters --- app/Main.hs | 11 +++++++---- src/Picture/Preload.hs | 14 +++++++------- src/Picture/Render.hs | 4 ++-- src/Sound/Preload.hs | 8 +++++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 3a11b3e39..90f1dcfe8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -21,6 +21,8 @@ import Picture import Picture.Render import Picture.Preload +import Preload + import Control.Concurrent import Control.Lens @@ -46,15 +48,16 @@ main = do setupLoop "windowName" 800 600 - doPreload' + doPreload cleanUpPreload (initializeWorld $ generateFromTree lev1 $ initWorld) (-- \((bs:fs:ts:_),tes) w -> --do render setparams w egFade \preData w -> --do render setparams w egFade do - renderPicture' preData (_cameraRot w) (_cameraZoom w) - (_cameraPos w) - (_windowX w,_windowY w) + renderPicture' (_renderData preData) + (_cameraRot w) (_cameraZoom w) + (_cameraPos w) + (_windowX w,_windowY w) (wallsForGloom' w) (lightsForGloom' w) (draw blank w) diff --git a/src/Picture/Preload.hs b/src/Picture/Preload.hs index 8bcee22b4..04ba792a0 100644 --- a/src/Picture/Preload.hs +++ b/src/Picture/Preload.hs @@ -16,7 +16,7 @@ import Foreign import Shaders -data PreloadData = PreloadData +data RenderData = RenderData { --_charMap :: Image PixelRGBA8 _textures :: [TextureObject] , _basicShader :: Program @@ -52,7 +52,7 @@ data VAO = VAO , _vaoBufferTargets :: [(BufferObject,Ptr Float,Int)] } -makeLenses ''PreloadData +makeLenses ''RenderData makeLenses ''VAO floatSize = sizeOf (0.5 :: GLfloat) @@ -100,8 +100,8 @@ loadTextures = do bufferOffset :: Integral a => a -> Ptr b bufferOffset = plusPtr nullPtr . fromIntegral -doPreload' :: IO PreloadData -doPreload' = do +preloadRender :: IO RenderData +preloadRender = do -- compile shader programs bs <- makeBasicShader ts <- makeTextureShader @@ -172,7 +172,7 @@ doPreload' = do wallvao <- setupVAO [(posVBO,0,4),(colVBO,1,4)] fadecircvao <- setupVAO [(posVBO,0,4)] - return $ PreloadData + return $ RenderData { -- _charMap = convertRGBA8 cmap _textures = [chartex,dirttex] ,_basicShader = bs @@ -207,8 +207,8 @@ doPreload' = do vaoPointers :: VAO -> [Ptr Float] vaoPointers = (\(_,ps,_) -> ps) . unzip3 . _vaoBufferTargets -cleanUpPreload :: PreloadData -> IO () -cleanUpPreload pd = do +cleanUpRenderPreload :: RenderData -> IO () +cleanUpRenderPreload pd = do mapM_ free $ vaoPointers $ _triVAO pd mapM_ free $ vaoPointers $ _textVAO pd mapM_ free $ vaoPointers $ _circVAO pd diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index cea443c06..34bb01acf 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -247,7 +247,7 @@ threePtrsVAO :: VAO -> (Ptr Float, Ptr Float,Ptr Float) threePtrsVAO vao = case (\(_,ps,_) -> ps) $ unzip3 $ _vaoBufferTargets vao of (a:b:c:_) -> (a,b,c) -renderPicture' :: PreloadData -> Float -> Float -> (Float,Float) -> (Float,Float) -> +renderPicture' :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> [(Point2,Point2,Point2,Point2)] -> [Point4] -> Picture -> IO () renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints pic = do depthFunc $= Just Lequal @@ -349,7 +349,7 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p bufferOffset :: Integral a => a -> Ptr b bufferOffset = plusPtr nullPtr . fromIntegral -renderPicture :: PreloadData -> Float -> Float -> (Float,Float) -> (Float,Float) -> Picture -> IO () +renderPicture :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> Picture -> IO () renderPicture pdata rot zoom (tranx,trany) (winx,winy) pic = do let firstIndex = 0 diff --git a/src/Sound/Preload.hs b/src/Sound/Preload.hs index 4ca47b099..ffcf8f242 100644 --- a/src/Sound/Preload.hs +++ b/src/Sound/Preload.hs @@ -4,4 +4,10 @@ import qualified SDL.Mixer as Mix import qualified Data.IntMap as IM -type LoadedSounds = IM.IntMap Mix.Chunk +type SoundData = IM.IntMap Mix.Chunk + +preloadSound :: IO SoundData +preloadSound = return IM.empty + +cleanUpSoundPreload :: SoundData -> IO () +cleanUpSoundPreload sd = return ()