Added function to convert PlayMap to GraphicsMap
This commit is contained in:
parent
23f75f7ff1
commit
e2c0863d65
@ -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
|
||||
@ -24,12 +25,13 @@ import Graphics.Rendering.OpenGL.GL.VertexSpec
|
||||
import Graphics.Rendering.OpenGL.Raw.Core31
|
||||
|
||||
import Foreign.Marshal.Array (withArray)
|
||||
import Foreign.Storable (sizeOf)
|
||||
import Foreign.Ptr (Ptr, nullPtr, plusPtr)
|
||||
import Render.Misc (checkError)
|
||||
import Foreign.Storable (sizeOf)
|
||||
import Foreign.Ptr (Ptr, nullPtr, plusPtr)
|
||||
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]
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user