Allow for events to do io
This commit is contained in:
+9
-5
@@ -23,7 +23,7 @@ setupLoop
|
||||
-> (world -> IO ()) -- ^ Function for cleaning up parameters, applied when exiting loop.
|
||||
-> IO world -- ^ Initial simulation state.
|
||||
-> (world -> IO world) -- ^ update, called once per frame. Allows for side effects such as rendering.
|
||||
-> (world -> Event -> Maybe world)
|
||||
-> (world -> Event -> IO (Maybe world))
|
||||
-- ^ SDL Event handling, once per frame. Evaluating 'Nothing' exits the loop.
|
||||
-> IO ()
|
||||
setupLoop spf (xSize,ySize) winpos paramCleanup ioStartWorld sideEffects eventFn = do
|
||||
@@ -43,7 +43,7 @@ doLoop
|
||||
:: Int -- ^ target msec per frame
|
||||
-> Window -- ^ The SDL window.
|
||||
-> (world -> IO world) -- ^ simulation update.
|
||||
-> (world -> Event -> Maybe world) -- ^ SDL Event handling.
|
||||
-> (world -> Event -> IO (Maybe world)) -- ^ SDL Event handling.
|
||||
-> world -- ^ Current simulation state.
|
||||
-> IO ()
|
||||
doLoop
|
||||
@@ -70,13 +70,17 @@ doLoop
|
||||
Nothing -> return ()
|
||||
-- | Handle quit events in a manner to exit the loop. Other events handled as
|
||||
-- determined by the custom function, although resize events also change the viewport.
|
||||
applyEventIO :: (world -> Event -> Maybe world) -> Maybe world -> Event -> IO (Maybe world)
|
||||
applyEventIO :: (world -> Event -> IO (Maybe world)) -> Maybe world -> Event -> IO (Maybe world)
|
||||
applyEventIO fn mw e = case eventPayload e of
|
||||
QuitEvent -> return Nothing
|
||||
WindowClosedEvent _ -> return Nothing
|
||||
WindowSizeChangedEvent WindowSizeChangedEventData {windowSizeChangedEventSize = V2 x y}
|
||||
-> GL.viewport $= (GL.Position 0 0,GL.Size x y) >> return (mw >>= \w -> fn w e)
|
||||
_ -> return $ mw >>= flip fn e
|
||||
-> (GL.viewport $= (GL.Position 0 0,GL.Size x y)) >> mupdate
|
||||
_ -> mupdate
|
||||
where
|
||||
mupdate = case mw of
|
||||
Nothing -> return Nothing
|
||||
Just w -> fn w e
|
||||
-- | Create an OpenGL SDL window configuration with a given x and y size.
|
||||
winConfig :: Int -> Int -> Maybe (Int, Int) -> WindowConfig
|
||||
winConfig x y winpos = defaultWindow
|
||||
|
||||
Reference in New Issue
Block a user