Move side effects into world (may be slower)

This commit is contained in:
2021-09-08 18:48:16 +01:00
parent 235e94cecb
commit 04e5b9b39f
6 changed files with 41 additions and 3 deletions
+35 -2
View File
@@ -33,8 +33,8 @@ import Graphics.Rendering.OpenGL hiding (color, rotate, scale, translate)
import qualified SDL
import qualified SDL.Mixer as Mix
main :: IO ()
main = do
main' :: IO ()
main' = do
(sizex,sizey) <- loadConfig
theKeyConfig <- loadKeyConfig
dodgeConfig <- loadDodgeConfig
@@ -47,6 +47,39 @@ main = do
handleEvent
(Just . update)
main :: IO ()
main = do
(sizex,sizey) <- loadConfig
theKeyConfig <- loadKeyConfig
dodgeConfig <- loadDodgeConfig
setupLoop'
(sizex,sizey)
theCleanup
(firstWorldLoad (sizex,sizey) theKeyConfig dodgeConfig)
theUpdateStep
handleEvent
-- (SDL.cursorVisible $= False >> doPreload >>= applyWorldConfig dodgeConfig)
-- (fmap (setWindowSize sizex sizey . (keyConfig .~ theKeyConfig) . (config .~ dodgeConfig)) firstWorld)
-- doSideEffects
theCleanup :: World -> IO ()
theCleanup w = SDL.cursorVisible $= True >> cleanUpPreload (_preloadData w)
--firstWorldLoad :: Configuration -> IO World
firstWorldLoad (sizex,sizey) theKeyConfig theConfig = do
SDL.cursorVisible $= False
pdata <- doPreload >>= applyWorldConfig theConfig
w <- fmap (setWindowSize sizex sizey . (keyConfig .~ theKeyConfig) . (config .~ theConfig)) firstWorld
return $ w & preloadData .~ pdata
theUpdateStep :: World -> IO World
theUpdateStep = applySideEffects . update
applySideEffects :: World -> IO (World)
applySideEffects w = do
newpdata <- doSideEffects (_preloadData w) w
return $ w & preloadData .~ newpdata
doSideEffects :: PreloadData SoundOrigin -> World -> IO (PreloadData SoundOrigin)
doSideEffects preData w = do
--startTicks <- SDL.ticks
+1
View File
@@ -14,5 +14,6 @@ data PreloadData a = PreloadData
, _musicData :: MusicData
, _frameTimer :: Word32
}
| DummyPdata
makeLenses ''PreloadData
+1 -1
View File
@@ -10,7 +10,7 @@ module Dodge.Creature.Picture
import Dodge.Data
--import Dodge.Base
--import Dodge.Creature.Stance.Data
import Dodge.Creature.Perception.Data
--import Dodge.Creature.Perception.Data
import Dodge.Creature.State.Data
import Dodge.Creature.Stance.Data
import Dodge.Creature.Memory.Data
+1
View File
@@ -109,6 +109,7 @@ data World = World
, _lClickHammer :: HammerPosition
, _radDistortion :: [(Point2,Point2,Point2,Float)]
, _gameRooms :: [GameRoom]
, _preloadData :: PreloadData SoundOrigin
}
data OptionScreenFlag = NormalOptions | GameOverOptions
data ScreenLayer
+2
View File
@@ -10,6 +10,7 @@ import Dodge.Item.Data
--import Picture
import Geometry.Data
--import Picture.Texture
import Data.Preload
import System.Random
import qualified Data.IntMap.Strict as IM
@@ -84,6 +85,7 @@ defaultWorld = World
, _foregroundEdgeVerx = []
, _radDistortion = []
, _gameRooms = []
, _preloadData = DummyPdata -- hack TODO remove this
}
defaultDebugFlags :: DebugFlags
defaultDebugFlags = DebugFlags
+1
View File
@@ -8,6 +8,7 @@ This module sets up an SDL window which may be updated using a simple game loop.
module Loop
( setupLoop
, setupMiniLoop
, setupLoop'
) where
import qualified Data.Text as T
import Control.Concurrent