diff --git a/src/Main.hs b/src/Main.hs index dc7b2ab..d64e79f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -19,6 +19,7 @@ import Options.Applicative import Control.Monad import Control.Monad.Loops +import Control.Concurrent (threadDelay) import Control.Concurrent.MVar import qualified Data.Text as T @@ -31,6 +32,8 @@ import Data.Maybe import Data.Time.Clock +import Data.Word (Word32(..)) + import System.Exit (exitFailure) import Foreign.C.String @@ -98,13 +101,14 @@ main = do vebo <- initGL program <- GU.simpleShaderProgramBS vertexShader fragmentShader verb opts "Initializing state" - time <- getCurrentTime + time <- SDL.ticks state <- newMVar ( State 1 (optFile opts) (last $ map fst wins) time + time wins program vebo @@ -121,6 +125,12 @@ main = do draw state ident SDL.glSwapWindow window ) wins + st <- readMVar state + now <- SDL.ticks + -- let dt = now - (stLastTime st) + -- verb opts ("dt: " ++ show dt) + -- threadDelay (fromIntegral $ (max 0 ((1000 `div` 30) - dt))) + modifyMVar_ state (\st -> return st { stLastTime = now }) ) verb opts "Deleting context" SDL.glDeleteContext context diff --git a/src/Types.hs b/src/Types.hs index ced0299..a6e3cfc 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -8,6 +8,8 @@ import qualified Graphics.GLUtil as GU import qualified Data.Text as T +import Data.Word (Word32) + import Data.Time.Clock data Options = Options @@ -22,7 +24,8 @@ data State = State { stCurrentPage :: Word , stFilename :: T.Text , stPresentationWindow :: Word - , stStartTime :: UTCTime + , stStartTime :: Word32 + , stLastTime :: Word32 , stWindows :: [(Word, SDL.Window)] , stProgram :: GU.ShaderProgram , stVEBO :: GLvebo