Allow for hard quitting
This commit is contained in:
@@ -12,6 +12,7 @@ conEffects :: Universe -> ConcurrentEffect Universe
|
|||||||
conEffects u = case u ^? uvSideEffects . _head of
|
conEffects u = case u ^? uvSideEffects . _head of
|
||||||
Just NewSideEffect{_ceSideEffect = eff} -> ConcurrentEffect (u & uvSideEffects . _head %~ g)
|
Just NewSideEffect{_ceSideEffect = eff} -> ConcurrentEffect (u & uvSideEffects . _head %~ g)
|
||||||
(dopop eff)
|
(dopop eff)
|
||||||
|
Just HardQuit -> ImmediateEffect (return Nothing)
|
||||||
_ -> NoConcurrentEffect
|
_ -> NoConcurrentEffect
|
||||||
where
|
where
|
||||||
g seff = RunningSideEffect (_ceString seff)
|
g seff = RunningSideEffect (_ceString seff)
|
||||||
@@ -26,7 +27,8 @@ addSideEffect :: IO (Universe -> Maybe Universe) -> String -> Universe -> Univer
|
|||||||
addSideEffect f s = uvSideEffects %~ (|> NewSideEffect f s)
|
addSideEffect f s = uvSideEffects %~ (|> NewSideEffect f s)
|
||||||
|
|
||||||
hardQuit :: Universe -> Universe
|
hardQuit :: Universe -> Universe
|
||||||
hardQuit = addSideEffect (return $ const Nothing) "QUITTING"
|
hardQuit = uvSideEffects %~ (HardQuit <|)
|
||||||
|
--hardQuit = addSideEffect (return $ const Nothing) "QUITTING"
|
||||||
|
|
||||||
--tryConcEffect :: Bool -> String -> IO (Universe -> Maybe Universe) -> Universe -> Universe
|
--tryConcEffect :: Bool -> String -> IO (Universe -> Maybe Universe) -> Universe -> Universe
|
||||||
--tryConcEffect bl str eff u = case u ^. uvConcEffects of
|
--tryConcEffect bl str eff u = case u ^. uvConcEffects of
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ data SideEffect
|
|||||||
, _ceString :: String
|
, _ceString :: String
|
||||||
}
|
}
|
||||||
| RunningSideEffect {_ceString :: String}
|
| RunningSideEffect {_ceString :: String}
|
||||||
|
| HardQuit
|
||||||
|
|
||||||
data OptionScreenFlag = NormalOptions | GameOverOptions | SplashOptions
|
data OptionScreenFlag = NormalOptions | GameOverOptions | SplashOptions
|
||||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|||||||
+10
-10
@@ -131,6 +131,7 @@ setupConLoop spf title winconfig paramCleanup ioStartWorld coneffs sideEffects e
|
|||||||
(doConLoop themvar spf window coneffs sideEffects eventFn)
|
(doConLoop themvar spf window coneffs sideEffects eventFn)
|
||||||
|
|
||||||
-- | The internal loop.
|
-- | The internal loop.
|
||||||
|
-- Note that ImmediateEffect from ConcurrentEffect does not work properly.
|
||||||
doConLoop ::
|
doConLoop ::
|
||||||
-- | The mvar for concurrency
|
-- | The mvar for concurrency
|
||||||
MVar (world -> Maybe world) ->
|
MVar (world -> Maybe world) ->
|
||||||
@@ -156,6 +157,7 @@ doConLoop themvar spf window coneffs worldSideEffects eventFn !startWorld = go s
|
|||||||
let mconeff = coneffs sw
|
let mconeff = coneffs sw
|
||||||
case mconeff of
|
case mconeff of
|
||||||
NoConcurrentEffect -> return ()
|
NoConcurrentEffect -> return ()
|
||||||
|
ImmediateEffect _ -> return ()
|
||||||
ConcurrentEffect _ acc -> do
|
ConcurrentEffect _ acc -> do
|
||||||
_ <- forkIO $ do
|
_ <- forkIO $ do
|
||||||
up <- acc
|
up <- acc
|
||||||
@@ -163,6 +165,7 @@ doConLoop themvar spf window coneffs worldSideEffects eventFn !startWorld = go s
|
|||||||
return ()
|
return ()
|
||||||
let startWorld'' = case mconeff of
|
let startWorld'' = case mconeff of
|
||||||
NoConcurrentEffect -> sw
|
NoConcurrentEffect -> sw
|
||||||
|
ImmediateEffect _ -> sw
|
||||||
ConcurrentEffect immediatef _ -> immediatef
|
ConcurrentEffect immediatef _ -> immediatef
|
||||||
mconupdate <- tryTakeMVar themvar
|
mconupdate <- tryTakeMVar themvar
|
||||||
let mstartWorld' = case mconupdate of
|
let mstartWorld' = case mconupdate of
|
||||||
@@ -239,21 +242,18 @@ doConLoop' themvar spf window coneffs worldSideEffects eventFn !startWorld = go
|
|||||||
go sw = do
|
go sw = do
|
||||||
startTicks <- ticks
|
startTicks <- ticks
|
||||||
es <- pollEvents
|
es <- pollEvents
|
||||||
let mconeff = coneffs sw
|
mworldAfterCon <- case coneffs sw of
|
||||||
case mconeff of
|
NoConcurrentEffect -> return $ Just sw
|
||||||
NoConcurrentEffect -> return ()
|
ImmediateEffect msw -> msw
|
||||||
ConcurrentEffect _ acc -> do
|
ConcurrentEffect sw' acc -> do
|
||||||
_ <- forkIO $ do
|
_ <- forkIO $ do
|
||||||
up <- acc
|
up <- acc
|
||||||
putMVar themvar up
|
putMVar themvar up
|
||||||
return ()
|
return $ Just sw'
|
||||||
let startWorld'' = case mconeff of
|
|
||||||
NoConcurrentEffect -> sw
|
|
||||||
ConcurrentEffect immediatef _ -> immediatef
|
|
||||||
mconupdate <- tryTakeMVar themvar
|
mconupdate <- tryTakeMVar themvar
|
||||||
let mstartWorld' = case mconupdate of
|
let mstartWorld' = case mconupdate of
|
||||||
Just conupdate -> conupdate startWorld''
|
Just conupdate -> conupdate =<< mworldAfterCon
|
||||||
Nothing -> Just startWorld''
|
Nothing -> mworldAfterCon
|
||||||
case mstartWorld' of
|
case mstartWorld' of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just startWorld' -> do
|
Just startWorld' -> do
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ module Loop.Data where
|
|||||||
|
|
||||||
data ConcurrentEffect world
|
data ConcurrentEffect world
|
||||||
= NoConcurrentEffect
|
= NoConcurrentEffect
|
||||||
|
| ImmediateEffect
|
||||||
|
{ _immediateEffect :: IO (Maybe world)
|
||||||
|
}
|
||||||
| ConcurrentEffect
|
| ConcurrentEffect
|
||||||
{ _immediateUpdate :: world
|
{ _immediateUpdate :: world
|
||||||
, _sideEffect :: IO (world -> Maybe world)
|
, _sideEffect :: IO (world -> Maybe world)
|
||||||
|
|||||||
Reference in New Issue
Block a user