From 41d2402f004bd446c6c4975caa5211fd44d302f5 Mon Sep 17 00:00:00 2001 From: Joshua Rahm Date: Mon, 28 Apr 2014 03:23:51 -0600 Subject: renamed and updated kingofhill to goliath. Added "leap" to jump. Added self-correcting frame rate --- Resources.hs | 20 ++++++++++++++------ maps/goliath_height.png | Bin 0 -> 15565 bytes maps/goliath_terrain.png | Bin 0 -> 2849 bytes maps/kingofhill_height.png | Bin 13921 -> 0 bytes maps/kingofhill_terrain.png | Bin 1101 -> 0 bytes 5 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 maps/goliath_height.png create mode 100644 maps/goliath_terrain.png delete mode 100644 maps/kingofhill_height.png delete mode 100644 maps/kingofhill_terrain.png diff --git a/Resources.hs b/Resources.hs index 9f0806f..e5cb528 100644 --- a/Resources.hs +++ b/Resources.hs @@ -94,7 +94,8 @@ data Resources = Resources { dDown :: GLfloat, waterArray :: ArrIO.IOArray (Int,Int) GLfloat, headBob :: GLfloat, - mode :: CameraMode + mode :: CameraMode, + threadDiff :: Double } getSpeed :: Resources -> GLfloat @@ -160,6 +161,7 @@ firstPerson res = in do return $ ((setHeadBob.(+ jitter)) <..> headBob) $ if (newh+0.3 > droph) then + setSpeedFactor 0.03 $ setRPosition (CameraPosition (Vec3 (x,newh+0.2,y)) (th + (asin dx) * speed * 15) (ph - (asin dy) * speed * 15)) $ setDDown 0 res else @@ -245,7 +247,6 @@ eventHandle event res = do let getY (Vec3 (_,y,_)) = y in return $ setPositionUpdate firstPerson $ - setSpeedFactor 0.03 $ setMode FirstPerson $ (setDDown <..> (negate . getY . resourcesVelocity)) res KeyUp (Keysym SDLK_e _ _) -> @@ -266,7 +267,9 @@ eventHandle event res = do return res KeyDown (Keysym SDLK_SPACE _ _) -> do - return $ setDDown (-0.2) res + return $ + setDDown (-0.2) $ + setSpeedFactor 0.05 res KeyDown (Keysym SDLK_LSHIFT _ _) -> do return $ setSpeedMultiplier 4 res @@ -315,13 +318,17 @@ displayHandle resources = do SDL.glSwapBuffers time2 <- getPOSIXTime - let diff = 0.033 - (time2 - time1) + let diff = threadDiff resources - (realToFrac $ time2 - time1) when (diff > 0) (threadDelay $ round $ diff * 1000000) time3 <- getPOSIXTime + let fps = realToFrac $ 1 / (time3 - time1) :: Double - putStr $ printf "FPS: %.2f\r" (realToFrac $ 1/ (time3 - time1) :: Double) + putStr $ printf "FPS: %.2f\r" fps - return resources + return $ + if' (fps < 30) + ((setThreadDiff.(subtract 0.0001)) <..> threadDiff) + ((setThreadDiff.(+0.0001)) <..> threadDiff) resources cameraToEuclidian :: CameraPosition -> Vec3 GLfloat cameraToEuclidian (CameraPosition _ ph th) = V.normalize $ Vec3 $ toEuclidian (1,ph,th) @@ -576,6 +583,7 @@ makeResources surf builder forestB jungleB water arr waterarr = do <*> pure waterarr <*> pure 0 <*> pure Oracle + <*> pure 0.033 printErrors :: String -> IO () printErrors ctx = diff --git a/maps/goliath_height.png b/maps/goliath_height.png new file mode 100644 index 0000000..557922b Binary files /dev/null and b/maps/goliath_height.png differ diff --git a/maps/goliath_terrain.png b/maps/goliath_terrain.png new file mode 100644 index 0000000..e3eb9ab Binary files /dev/null and b/maps/goliath_terrain.png differ diff --git a/maps/kingofhill_height.png b/maps/kingofhill_height.png deleted file mode 100644 index b548cf2..0000000 Binary files a/maps/kingofhill_height.png and /dev/null differ diff --git a/maps/kingofhill_terrain.png b/maps/kingofhill_terrain.png deleted file mode 100644 index 39b6d0e..0000000 Binary files a/maps/kingofhill_terrain.png and /dev/null differ -- cgit