tessellation-factor is now adaptive
- tessellation gets reduced in distance - tess-factor is now adaptive
This commit is contained in:
		
							
								
								
									
										12
									
								
								src/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/Main.hs
									
									
									
									
									
								
							@@ -132,6 +132,7 @@ main =
 | 
			
		||||
                        }
 | 
			
		||||
              , _io                  = IOState
 | 
			
		||||
                        { _clock               = now
 | 
			
		||||
                        , _tessClockFactor     = 0
 | 
			
		||||
                        }
 | 
			
		||||
              , _mouse               = MouseState
 | 
			
		||||
                        { _isDown              = False
 | 
			
		||||
@@ -234,23 +235,24 @@ run = do
 | 
			
		||||
		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
 | 
			
		||||
        let 	sleepAmount = floor ((targetFrametime - double diff)*1000000) :: Int -- get time until next frame in microseconds
 | 
			
		||||
                clockFactor = (state ^. io.tessClockFactor)
 | 
			
		||||
		tessChange
 | 
			
		||||
			| (sleepAmount > (floor $0.1*targetFrametimeμs)) && (state ^. gl.glMap.stateTessellationFactor < 5) = ((+)1 :: Int -> Int) 
 | 
			
		||||
			| (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
 | 
			
		||||
	print targetFrametimeμs
 | 
			
		||||
        return (now,tessChange,sleepAmount)
 | 
			
		||||
    -- set state with new clock-time
 | 
			
		||||
    modify $ (io.clock .~ mt)
 | 
			
		||||
           . (gl.glMap.stateTessellationFactor %~ tc)
 | 
			
		||||
    liftIO $ putStrLn $ concat $ ["TessFactor at: ",show (state ^. gl.glMap.stateTessellationFactor), " - slept for ",show sleepAmount, "μs."]
 | 
			
		||||
           . (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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,7 @@ data CameraState = CameraState
 | 
			
		||||
 | 
			
		||||
data IOState = IOState
 | 
			
		||||
    { _clock               :: !UTCTime
 | 
			
		||||
    , _tessClockFactor     :: !Double
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
data GameState = GameState
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user