Added function to convert PlayMap to GraphicsMap

This commit is contained in:
jbetzend 2014-03-05 17:51:13 +01:00
parent 23f75f7ff1
commit e2c0863d65
3 changed files with 16 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import System.Random
import Data.Array.IArray
import Data.Text as T
import Prelude as P
--import Graphics.Rendering.OpenGL.GL
import Graphics.Rendering.OpenGL.GL.BufferObjects
import Graphics.Rendering.OpenGL.GL.ObjectName
@ -30,6 +31,7 @@ import Render.Misc (checkError)
import Linear
import Map.Types
import Map.StaticMaps
type MapEntry = (
Float, -- ^ Height
@ -38,6 +40,14 @@ type MapEntry = (
type GraphicsMap = Array (Int, Int) MapEntry
-- extract graphics information from Playmap
convertToGraphicsMap :: PlayMap -> GraphicsMap
convertToGraphicsMap map = array (bounds map) [(i, graphicsyfy (map!i))| i <- indices map]
where
graphicsyfy :: Node -> MapEntry
graphicsyfy (Minimal _ ) = (0, Grass)
graphicsyfy (Full _ y t _ _ _ _ _ ) = (y, t)
lineHeight :: GLfloat
lineHeight = 0.8660254
@ -66,7 +76,7 @@ fgVertexIndex = (ToFloat, mapVertexArrayDescriptor 3 7) --vertex after normal
getMapBufferObject :: IO (BufferObject, NumArrayIndices)
getMapBufferObject = do
map' <- testmap
map' <- return $ convertToGraphicsMap mapCenterMountain
! map' <- return $ generateTriangles map'
len <- return $ fromIntegral $ P.length map' `div` numComponents
putStrLn $ P.unwords ["num verts in map:",show len]

View File

@ -16,7 +16,7 @@ mnh2D (a,b) (c,d) = abs (a-c) + abs (b-d)
-- entirely empty map, only uses the minimal constructor
mapEmpty :: PlayMap
mapEmpty = array ((0,0), (200,200)) [((a,b), (Minimal (a,b) 0.5)) | a <- [0..200], b <- [0..200]]
mapEmpty = array ((0,0), (200,200)) [((a,b), (Minimal (a,b))) | a <- [0..200], b <- [0..200]]
-- TODO: Stripify
mapCenterMountain :: PlayMap

View File

@ -68,5 +68,5 @@ data TileType = Ocean
-- TODO: Record Syntax
data Node = Full (XCoord, ZCoord) YCoord TileType BuildInfo PlayerInfo PathInfo ResInfo StorInfo
| Minimal (XCoord, ZCoord) YCoord -- defaults to empty green grass node on height 0.5
| Minimal (XCoord, ZCoord) -- defaults to empty green grass node on height 0
deriving (Show)