Refactor preloading/rendering/update
This commit is contained in:
@@ -48,8 +48,4 @@ applyWorldConfig ::
|
||||
IO PreloadData
|
||||
applyWorldConfig cfig pdata = do
|
||||
setVol cfig
|
||||
pdataResizeUpdate cfig (x `div` divRes) (y `div` divRes) x y pdata
|
||||
where
|
||||
x = round $ _windowX cfig
|
||||
y = round $ _windowY cfig
|
||||
divRes = resFactorNum $ _graphics_world_resolution cfig
|
||||
renderData (pdataResizeUpdate cfig) pdata
|
||||
|
||||
+5
-6
@@ -15,11 +15,12 @@ module Dodge.Event (
|
||||
handleEvent,
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
import qualified Data.Text as T
|
||||
import Dodge.Concurrent
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Event.Input
|
||||
import Dodge.PreloadData
|
||||
import Preload.Update
|
||||
import LensHelp
|
||||
import SDL
|
||||
|
||||
@@ -56,9 +57,7 @@ handleResizeEvent sev u =
|
||||
u
|
||||
& uvConfig . windowX .~ fromIntegral x
|
||||
& uvConfig . windowY .~ fromIntegral y
|
||||
& uvIOEffects %~ sideEffectUpdatePreload divRes x y
|
||||
-- & uvIOEffects %~ sideEffectUpdatePreload
|
||||
& uvIOEffects %~ (updatePreload >=>)
|
||||
where
|
||||
x = fromIntegral x'
|
||||
y = fromIntegral y'
|
||||
V2 x' y' = windowSizeChangedEventSize sev
|
||||
divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
|
||||
V2 x y = windowSizeChangedEventSize sev
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@ import Dodge.Data.Universe
|
||||
import Dodge.Menu.Option
|
||||
import Dodge.Menu.OptionType
|
||||
import Dodge.Menu.PushPop
|
||||
import Dodge.PreloadData
|
||||
import Preload.Update
|
||||
import Dodge.Save
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.StartNewGame
|
||||
@@ -182,11 +182,11 @@ graphicsMenu = titleOptionsMenu "OPTIONS:GRAPHICS" graphicsMenuOptions
|
||||
|
||||
graphicsMenuOptions :: [MenuOption]
|
||||
graphicsMenuOptions =
|
||||
[ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updateFramebufferSize)
|
||||
[ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updatePreload)
|
||||
, makeEnumOption graphics_downsize_resolution "Downsize resolution"
|
||||
(uvIOEffects .~ updateFramebufferSize)
|
||||
(uvIOEffects .~ updatePreload)
|
||||
, makeEnumOption graphics_overlay_resolution "Overlay resolution"
|
||||
(uvIOEffects .~ updateFramebufferSize)
|
||||
(uvIOEffects .~ updatePreload)
|
||||
, makeEnumOption graphics_object_shadows "SHADOW DETAIL" id
|
||||
, makeEnumOption graphics_distortions "ENABLE DISTORTIONS" id
|
||||
, makeEnumOption graphics_bloom "ENABLE BLOOM" id
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
module Dodge.PreloadData where
|
||||
|
||||
import Control.Lens
|
||||
import Dodge.Data.Universe
|
||||
import Preload.Update
|
||||
|
||||
sideEffectUpdatePreload :: Int -> Int -> Int -> (Universe -> IO Universe) -> Universe -> IO Universe
|
||||
sideEffectUpdatePreload divRes x y f u = do
|
||||
-- GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral x) (fromIntegral y))
|
||||
pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
|
||||
f $ u & preloadData .~ pdata
|
||||
|
||||
updatePreload :: Int -> Int -> Int -> Universe -> IO Universe
|
||||
updatePreload divRes x y u = do
|
||||
pdata <- pdataResizeUpdate (u ^. uvConfig) (x `div` divRes) (y `div` divRes) x y (_preloadData u)
|
||||
return $ u & preloadData .~ pdata
|
||||
|
||||
updateFramebufferSize :: Universe -> IO Universe
|
||||
updateFramebufferSize u = updatePreload divRes x y u
|
||||
where
|
||||
(x, y) = (round $ _windowX cfig, round $ _windowY cfig)
|
||||
cfig = _uvConfig u
|
||||
divRes = resFactorNum $ u ^. uvConfig . graphics_world_resolution
|
||||
@@ -51,7 +51,6 @@ doDrawing' win pdata u = do
|
||||
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
|
||||
worldres = resFactorNum $ cfig ^. graphics_world_resolution
|
||||
downres = resFactorNum $ cfig ^. graphics_downsize_resolution
|
||||
overlayres = resFactorNum $ cfig ^. graphics_overlay_resolution
|
||||
(windowPoints, wallSPics, wallsToPoke) = wallsToDraw w
|
||||
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
|
||||
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
|
||||
|
||||
+19
-27
@@ -1,52 +1,39 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Preload.Update (
|
||||
updatePreload,
|
||||
pdataResizeUpdate,
|
||||
) where
|
||||
|
||||
import Dodge.Data.Config
|
||||
import Dodge.Data.Universe
|
||||
import Control.Lens
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Char8 as BSC
|
||||
import Data.Preload
|
||||
import Data.Preload.Render
|
||||
import Framebuffer.Update
|
||||
import Shader.Compile
|
||||
import Shader.Data
|
||||
|
||||
pdataResizeUpdate ::
|
||||
Configuration ->
|
||||
-- | Scaled width
|
||||
Int ->
|
||||
-- | Scaled height
|
||||
Int ->
|
||||
-- | Full width
|
||||
Int ->
|
||||
-- | Full height
|
||||
Int ->
|
||||
PreloadData ->
|
||||
IO PreloadData
|
||||
pdataResizeUpdate cfig xsize ysize xfull yfull pdata = do
|
||||
rd <- renderDataResizeUpdate cfig xsize ysize xfull yfull (_renderData pdata)
|
||||
return (pdata{_renderData = rd})
|
||||
updatePreload :: Universe -> IO Universe
|
||||
updatePreload u = do
|
||||
pdata <- pdataResizeUpdate (u ^. uvConfig) (u ^?! preloadData . renderData)
|
||||
return $ u & preloadData . renderData .~ pdata
|
||||
|
||||
pdataResizeUpdate :: Configuration -> RenderData -> IO RenderData
|
||||
pdataResizeUpdate cfig pdata = do
|
||||
rd <- renderDataResizeUpdate cfig pdata
|
||||
return rd
|
||||
|
||||
renderDataResizeUpdate ::
|
||||
Configuration ->
|
||||
-- | Scaled width
|
||||
Int ->
|
||||
-- | Scaled height
|
||||
Int ->
|
||||
-- | Full width
|
||||
Int ->
|
||||
-- | Full height
|
||||
Int ->
|
||||
RenderData ->
|
||||
IO RenderData
|
||||
renderDataResizeUpdate cfig xsize ysize xfull yfull rdata = do
|
||||
renderDataResizeUpdate cfig rdata = do
|
||||
rdata' <- sizeFBOs cfig rdata
|
||||
bbVert <- BS.readFile "shader/texture/bloomBlur.vert"
|
||||
bbFrag <- BS.readFile "shader/texture/bloomBlur.frag"
|
||||
let (bh, bmid) = BS.breakSubstring "(" bbFrag
|
||||
let (xsize,ysize) = getWindowSize _graphics_downsize_resolution cfig :: (Int,Int)
|
||||
(bh, bmid) = BS.breakSubstring "(" bbFrag
|
||||
(_, btt) = BS.breakSubstring ")" bmid
|
||||
bbFrag' = BS.append bh $ BS.append (BSC.pack $ '(' : show xsize ++ "," ++ show ysize) btt
|
||||
--BSC.putStrLn bbFrag'
|
||||
@@ -57,3 +44,8 @@ renderDataResizeUpdate cfig xsize ysize xfull yfull rdata = do
|
||||
pmTriangleStrip
|
||||
(rdata ^. screenTextureVAO)
|
||||
return (rdata'{_bloomBlurShader = bbShad})
|
||||
|
||||
getWindowSize :: Integral a => (Configuration -> ResFactor) -> Configuration -> (a,a)
|
||||
getWindowSize f cfig = (g _windowX,g _windowY)
|
||||
where
|
||||
g h = fromIntegral $ round (h cfig) `div` resFactorNum (f cfig)
|
||||
|
||||
Reference in New Issue
Block a user