diff --git a/src/Map/Graphics.hs b/src/Map/Graphics.hs index 86bdb96..035b276 100644 --- a/src/Map/Graphics.hs +++ b/src/Map/Graphics.hs @@ -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] diff --git a/src/Map/StaticMaps.hs b/src/Map/StaticMaps.hs index 59316cf..1283981 100644 --- a/src/Map/StaticMaps.hs +++ b/src/Map/StaticMaps.hs @@ -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 diff --git a/src/Map/Types.hs b/src/Map/Types.hs index 0f4ff5d..f55afc1 100644 --- a/src/Map/Types.hs +++ b/src/Map/Types.hs @@ -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)