Put config/targeting pictures in sensible places, tweak main loop
This commit is contained in:
+7
-19
@@ -18,18 +18,20 @@ import qualified Graphics.Rendering.OpenGL as GL
|
||||
-- | Create a game loop with an SDL window.
|
||||
setupLoop
|
||||
:: Int -- ^ Target seconds per frame
|
||||
-> (Int,Int) -- ^ The window size.
|
||||
-> Maybe (Int,Int) -- ^ The window position.
|
||||
-> T.Text -- ^ Window title
|
||||
-> WindowConfig
|
||||
-- -> (Int,Int) -- ^ The window size.
|
||||
-- -> Maybe (Int,Int) -- ^ The window position.
|
||||
-> (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 -> 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
|
||||
setupLoop spf title winconfig paramCleanup ioStartWorld sideEffects eventFn = do
|
||||
initializeAll
|
||||
bracket
|
||||
(createWindow (T.pack "Simple Game Loop") (winConfig xSize ySize winpos))
|
||||
(createWindow title winconfig)
|
||||
destroyWindow
|
||||
$ \window -> bracket
|
||||
(glCreateContext window)
|
||||
@@ -68,6 +70,7 @@ doLoop
|
||||
|
||||
doLoop spf window worldSideEffects eventFn updatedWorld
|
||||
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 -> IO (Maybe world)) -> Maybe world -> Event -> IO (Maybe world)
|
||||
@@ -81,18 +84,3 @@ applyEventIO fn mw e = case eventPayload e of
|
||||
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
|
||||
{ windowGraphicsContext = OpenGLContext $ defaultOpenGL
|
||||
{ glProfile = Core Normal 4 3
|
||||
, glColorPrecision = V4 8 8 8 8
|
||||
}
|
||||
, windowPosition = theWinPos
|
||||
, windowInitialSize = V2 (fromIntegral x) (fromIntegral y)
|
||||
, windowResizable =True
|
||||
}
|
||||
where
|
||||
theWinPos = case winpos of
|
||||
Just (px,py) -> Absolute (P (V2 (fromIntegral px) (fromIntegral py)))
|
||||
Nothing -> Wherever
|
||||
|
||||
Reference in New Issue
Block a user