Add file, move buffer swapping into doDrawing
This commit is contained in:
+14
-31
@@ -6,7 +6,7 @@ import Control.Lens
|
||||
import Control.Monad
|
||||
import Control.Parallel
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Preload.Render
|
||||
--import Data.Preload.Render
|
||||
import qualified Data.Text as T
|
||||
import Dodge.Concurrent
|
||||
import Dodge.Config.Load
|
||||
@@ -24,10 +24,10 @@ import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
|
||||
import qualified IntMapHelp as IM
|
||||
import Loop
|
||||
import Music
|
||||
import Picture
|
||||
--import Picture
|
||||
import Preload
|
||||
import Preload.Render
|
||||
import Render
|
||||
--import Render
|
||||
import qualified SDL
|
||||
import qualified SDL.Mixer as Mix
|
||||
import Sound
|
||||
@@ -91,6 +91,8 @@ firstWorldLoad theConfig = do
|
||||
, _uvSideEffects = mempty
|
||||
, _uvCanContinue = cancontinue
|
||||
, _uvMSeed = mseed
|
||||
, _uvLastFrameTicks = 0
|
||||
, _uvFrameTicks = 0
|
||||
}
|
||||
return $
|
||||
Universe
|
||||
@@ -104,15 +106,17 @@ firstWorldLoad theConfig = do
|
||||
, _uvSideEffects = mempty
|
||||
, _uvCanContinue = cancontinue
|
||||
, _uvMSeed = mseed
|
||||
, _uvLastFrameTicks = 0
|
||||
, _uvFrameTicks = 0
|
||||
}
|
||||
|
||||
theUpdateStep :: Universe -> IO Universe
|
||||
theUpdateStep = doSideEffects <=< updateRenderSplit
|
||||
theUpdateStep :: SDL.Window -> Universe -> IO Universe
|
||||
theUpdateStep win = doSideEffects <=< updateRenderSplit win
|
||||
|
||||
updateRenderSplit :: Universe -> IO Universe
|
||||
updateRenderSplit u = do
|
||||
updateRenderSplit :: SDL.Window -> Universe -> IO Universe
|
||||
updateRenderSplit win u = do
|
||||
let preData = _preloadData u
|
||||
updateUniverse u `par` void (doDrawing (_renderData preData) u)
|
||||
updateUniverse u `par` void (doDrawing win (_renderData preData) u)
|
||||
return $! updateUniverse u
|
||||
|
||||
playSoundUnlessRewinding :: Universe -> IO (M.Map SoundOrigin Sound)
|
||||
@@ -124,37 +128,17 @@ playSoundUnlessRewinding u = case w ^. cWorld . timeFlow of
|
||||
|
||||
doSideEffects :: Universe -> IO Universe
|
||||
doSideEffects u = do
|
||||
let preData = _preloadData u
|
||||
newPlayingSounds <- playSoundUnlessRewinding u
|
||||
u' <- _uvIOEffects u u
|
||||
endTicks <- SDL.ticks
|
||||
let lastFrameTicks = _frameTimer preData
|
||||
when (debugOn Show_ms_frame $ _uvConfig u) $
|
||||
void $
|
||||
renderFoldable
|
||||
(_pictureShaders $ _renderData preData)
|
||||
( setDepth (-1)
|
||||
. translate (-0.5) (-0.8)
|
||||
. scale 0.0005 0.0005
|
||||
$ fpsText (endTicks - lastFrameTicks)
|
||||
)
|
||||
return $
|
||||
u'
|
||||
& preloadData . frameTimer .~ endTicks
|
||||
& uvLastFrameTicks .~ (u ^. uvFrameTicks)
|
||||
& uvFrameTicks .~ endTicks
|
||||
& uvWorld . playingSounds .~ newPlayingSounds
|
||||
& uvWorld . toPlaySounds .~ M.empty
|
||||
& uvIOEffects .~ return
|
||||
|
||||
fpsText :: (Show a, Ord a, Num a) => a -> Picture
|
||||
fpsText x = color col $ text $ "ms/frame " ++ show x
|
||||
where
|
||||
col
|
||||
| x < 22 = blue
|
||||
| x < 30 = green
|
||||
| x < 40 = yellow
|
||||
| x < 50 = orange
|
||||
| otherwise = red
|
||||
|
||||
doPreload :: IO PreloadData
|
||||
doPreload = do
|
||||
rData <- preloadRender
|
||||
@@ -166,7 +150,6 @@ doPreload = do
|
||||
{ _renderData = rData
|
||||
, _soundData = SoundData{_loadedChunks = lChunks}
|
||||
, _musicData = MusicData{_loadedMusic = lMusic}
|
||||
, _frameTimer = 0
|
||||
}
|
||||
|
||||
--checkForGlErrors :: IO ()
|
||||
|
||||
Reference in New Issue
Block a user