Move side effects into world (may be slower)
This commit is contained in:
+35
-2
@@ -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
|
||||
|
||||
@@ -14,5 +14,6 @@ data PreloadData a = PreloadData
|
||||
, _musicData :: MusicData
|
||||
, _frameTimer :: Word32
|
||||
}
|
||||
| DummyPdata
|
||||
|
||||
makeLenses ''PreloadData
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user