{-# OPTIONS_HADDOCK hide #-}
{- | This FunGEn module renders the game window.
-}
{- 

FunGEN - Functional Game Engine
http://www.cin.ufpe.br/~haskell/fungen
Copyright (C) 2002  Andre Furtado <awbf@cin.ufpe.br>

This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-}

module Graphics.UI.Fungen.Display (
        display
) where

import Graphics.UI.Fungen.Game
import Graphics.UI.Fungen.Util (when)
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT

-- | Given a fungen Game and IOGame step action, generate a GLUT
-- display callback that steps the game and renders its resulting
-- state. 'Graphics.UI.Fungen.funInit' runs this automatically.
display :: Game t s u v -> IOGame t s u v () -> DisplayCallback
display :: forall t s u v.
Game t s u v -> IOGame t s u v () -> DisplayCallback
display Game t s u v
g IOGame t s u v ()
gameCycle = do 
        [ClearBuffer] -> DisplayCallback
clear [ClearBuffer
ColorBuffer]
        forall t s u v a.
IOGame t s u v a -> Game t s u v -> IO (Game t s u v, a)
runIOGame (forall t s u v. IOGame t s u v () -> IOGame t s u v ()
displayIOGame IOGame t s u v ()
gameCycle) Game t s u v
g
        forall (m :: * -> *). MonadIO m => m ()
swapBuffers
        DisplayCallback
flush

-- | Run one update and display an IOGame.
displayIOGame :: IOGame t s u v () -> IOGame t s u v ()
displayIOGame :: forall t s u v. IOGame t s u v () -> IOGame t s u v ()
displayIOGame IOGame t s u v ()
gameCycle = do
        (Bool
_,Bool
_,Bool
objectsMoving) <- forall t s u v. IOGame t s u v (Bool, Bool, Bool)
getGameFlags
        forall (m :: * -> *). Monad m => Bool -> m () -> m ()
when Bool
objectsMoving forall t s u v. IOGame t s u v ()
moveAllObjects
        IOGame t s u v ()
gameCycle
        (Bool
mapDrawing,Bool
objectsDrawing,Bool
_) <- forall t s u v. IOGame t s u v (Bool, Bool, Bool)
getGameFlags
        forall (m :: * -> *). Monad m => Bool -> m () -> m ()
when Bool
mapDrawing forall t s u v. IOGame t s u v ()
drawMap
        forall (m :: * -> *). Monad m => Bool -> m () -> m ()
when Bool
objectsDrawing forall t s u v. IOGame t s u v ()
drawAllObjects
        forall t s u v. IOGame t s u v ()
printText