Unify config files, add capability to remember window position
This commit is contained in:
+6
-8
@@ -13,24 +13,23 @@ import Control.Concurrent
|
||||
import Control.Exception
|
||||
import Control.Monad
|
||||
import System.Mem
|
||||
--import Foreign.C
|
||||
import SDL
|
||||
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.
|
||||
-> (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 -> Maybe world)
|
||||
-- ^ SDL Event handling, once per frame. Evaluating 'Nothing' exits the loop.
|
||||
-> IO ()
|
||||
setupLoop spf (xSize,ySize) paramCleanup ioStartWorld sideEffects eventFn = do
|
||||
setupLoop spf (xSize,ySize) (xPos,yPos) paramCleanup ioStartWorld sideEffects eventFn = do
|
||||
initializeAll
|
||||
bracket
|
||||
(createWindow (T.pack "Simple Game Loop") (winConfig xSize ySize))
|
||||
(createWindow (T.pack "Simple Game Loop") (winConfig xSize ySize xPos yPos))
|
||||
destroyWindow
|
||||
$ \window -> bracket
|
||||
(glCreateContext window)
|
||||
@@ -79,14 +78,13 @@ applyEventIO fn mw e = case eventPayload e of
|
||||
-> GL.viewport $= (GL.Position 0 0,GL.Size x y) >> return (mw >>= \w -> fn w e)
|
||||
_ -> return $ mw >>= flip fn e
|
||||
-- | Create an OpenGL SDL window configuration with a given x and y size.
|
||||
winConfig :: Int -> Int -> WindowConfig
|
||||
winConfig x y = defaultWindow
|
||||
winConfig :: Int -> Int -> Int -> Int -> WindowConfig
|
||||
winConfig x y px py = defaultWindow
|
||||
{ windowGraphicsContext = OpenGLContext $ defaultOpenGL
|
||||
{ glProfile = Core Normal 4 3
|
||||
, glColorPrecision = V4 8 8 8 8
|
||||
}
|
||||
, windowPosition = Absolute (P (V2 (fromIntegral px) (fromIntegral py)))
|
||||
, windowInitialSize = V2 (fromIntegral x) (fromIntegral y)
|
||||
, windowResizable =True
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user