Merge branch 'iqm' into tessallation
Conflicts: src/Render/Render.hs src/Types.hs
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/Main.hs
									
									
									
									
									
								
							@@ -132,6 +132,7 @@ main =
 | 
			
		||||
                        }
 | 
			
		||||
              , _io                  = IOState
 | 
			
		||||
                        { _clock               = now
 | 
			
		||||
                        , _tessClockFactor     = 0
 | 
			
		||||
                        }
 | 
			
		||||
              , _mouse               = MouseState
 | 
			
		||||
                        { _isDown              = False
 | 
			
		||||
@@ -228,17 +229,30 @@ run = do
 | 
			
		||||
      }
 | 
			
		||||
    -}
 | 
			
		||||
 | 
			
		||||
    mt <- liftIO $ do
 | 
			
		||||
        let double = fromRational.toRational :: (Real a) => a -> Double
 | 
			
		||||
    (mt,tc,sleepAmount) <- liftIO $ do
 | 
			
		||||
        let 	double = fromRational.toRational :: (Real a) => a -> Double
 | 
			
		||||
		targetFramerate = 40.0
 | 
			
		||||
		targetFrametime = 1.0/targetFramerate
 | 
			
		||||
		targetFrametimeμs = targetFrametime * 1000000.0
 | 
			
		||||
        now <- getCurrentTime
 | 
			
		||||
        diff <- return $ diffUTCTime now (state ^. io.clock) -- get time-diffs
 | 
			
		||||
        title <- return $ unwords ["Pioneers @ ",show ((round . double $ 1.0/diff)::Int),"fps"]
 | 
			
		||||
        let diff  = diffUTCTime now (state ^. io.clock) -- get time-diffs
 | 
			
		||||
            title = unwords ["Pioneers @ ",show ((round . double $ 1.0/diff)::Int),"fps"]
 | 
			
		||||
        setWindowTitle (env ^. windowObject) title
 | 
			
		||||
        sleepAmount <- return $ floor (max 0 (0.04 - diff))*1000000 -- get time until next frame in microseconds
 | 
			
		||||
        threadDelay sleepAmount
 | 
			
		||||
        return now
 | 
			
		||||
        let 	sleepAmount = floor ((targetFrametime - double diff)*1000000) :: Int -- get time until next frame in microseconds
 | 
			
		||||
                clockFactor = (state ^. io.tessClockFactor)
 | 
			
		||||
		tessChange
 | 
			
		||||
			| (clockFactor > (2*targetFrametimeμs)) && (state ^. gl.glMap.stateTessellationFactor < 5) = ((+)1 :: Int -> Int) 
 | 
			
		||||
									-- > factor < 5 & 10% of frame idle -> increase graphics
 | 
			
		||||
			| sleepAmount < 0 && (state ^. gl.glMap.stateTessellationFactor > 1) = (flip (-) 1 :: Int -> Int)
 | 
			
		||||
									-- frame used up completely -> decrease
 | 
			
		||||
			| otherwise = ((+)0 :: Int -> Int)              -- 0ms > x > 10% -> keep settings
 | 
			
		||||
        when (sleepAmount > 0) $ threadDelay sleepAmount
 | 
			
		||||
        return (now,tessChange,sleepAmount)
 | 
			
		||||
    -- set state with new clock-time
 | 
			
		||||
    modify $ io.clock .~ mt
 | 
			
		||||
    modify $ (io.clock .~ mt)
 | 
			
		||||
           . (gl.glMap.stateTessellationFactor %~ tc)
 | 
			
		||||
           . (io.tessClockFactor %~ (((+) (fromIntegral sleepAmount)).((*) 0.99)))
 | 
			
		||||
    -- liftIO $ putStrLn $ concat $ ["TessFactor at: ",show (state ^. gl.glMap.stateTessellationFactor), " - slept for ",show sleepAmount, "μs."]
 | 
			
		||||
    shouldClose' <- return $ state ^. window.shouldClose
 | 
			
		||||
    unless shouldClose' run
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -288,6 +288,10 @@ renderOverview = do
 | 
			
		||||
        checkError "draw map"
 | 
			
		||||
-}
 | 
			
		||||
 | 
			
		||||
renderObject :: MapObject -> IO ()
 | 
			
		||||
renderObject (MapObject model (L.V3 x y z) _{-state-}) = 
 | 
			
		||||
	undefined
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
render :: Pioneers ()
 | 
			
		||||
render = do
 | 
			
		||||
@@ -384,6 +388,12 @@ render = do
 | 
			
		||||
 | 
			
		||||
        checkError "draw map"
 | 
			
		||||
 | 
			
		||||
	---- RENDER MAPOBJECTS --------------------------------------------
 | 
			
		||||
	
 | 
			
		||||
	currentProgram $= Just (state ^. gl.glMap.objectsProgram)
 | 
			
		||||
 | 
			
		||||
	mapM_ renderObject (state ^. gl.glMap.mapObjects)
 | 
			
		||||
 | 
			
		||||
        -- set sample 1 as target in renderbuffer
 | 
			
		||||
        {-framebufferRenderbuffer
 | 
			
		||||
                DrawFramebuffer              --write-only
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Types.hs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/Types.hs
									
									
									
									
									
								
							@@ -8,6 +8,7 @@ import           Foreign.C                            (CFloat)
 | 
			
		||||
import qualified Data.HashMap.Strict                  as Map
 | 
			
		||||
import           Data.Time                            (UTCTime)
 | 
			
		||||
import Linear.Matrix (M44)
 | 
			
		||||
import Linear (V3)
 | 
			
		||||
import Control.Monad.RWS.Strict (RWST)
 | 
			
		||||
import Control.Lens
 | 
			
		||||
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject)
 | 
			
		||||
@@ -51,6 +52,7 @@ data CameraState = CameraState
 | 
			
		||||
 | 
			
		||||
data IOState = IOState
 | 
			
		||||
    { _clock               :: !UTCTime
 | 
			
		||||
    , _tessClockFactor     :: !Double
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
data GameState = GameState
 | 
			
		||||
@@ -120,6 +122,15 @@ data GLMapState = GLMapState
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
data GLObject = GLObject IQM (Coord3D Double)
 | 
			
		||||
    , _objectsProgram       :: !GL.Program
 | 
			
		||||
    , _mapObjects           :: ![MapObject]
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
data MapObject = MapObject !IQM !MapCoordinates !MapObjectState
 | 
			
		||||
 | 
			
		||||
data MapObjectState = MapObjectState ()
 | 
			
		||||
 | 
			
		||||
type MapCoordinates = V3 CFloat
 | 
			
		||||
 | 
			
		||||
data GLHud = GLHud
 | 
			
		||||
    { _hudTexture               :: !TextureObject       -- ^ HUD-Texture itself
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user