我正在尝试使用爱德华的bound库来模拟游戏中的关卡图形 - 至少是在表现形式存储的级别,然后才能实现为OpenGL对象.
一个级别由一堆顶点组成,我们可以在顶点对之间形成一个墙.顶点也用于创建简单的多边形 - 扇区(房间).一个部门拥有墙壁,但也有一些材料属性.顶点,墙壁,扇区和材料之间有很多共享,所以为了利用这种类似图形的特性,我转向了bound库.
到目前为止的代码是,
-- Vertices live alone and aren't influenced by anything else. Perhaps these
-- should still be a functor, but act like Const?
data Vertex = Vertex
{ vertexPos :: V2 CFloat }
-- Textures also live alone, and are simply a wrapper around the path to the
-- texture.
data Texture = Texture
{ texturePath :: FilePath }
-- A Material needs to refer to one (or more) textures.
data Material a = Material
{ materialDiffuseTexture :: a
, materialNormalMap :: Maybe a
}
-- A Sector needs to refer to materials *and* vertices. How do I reference two
-- types of variables?
data Sector a = Sector
{ sectorFloorMaterial :: a
, sectorWallMaterial :: a
, sectorCeilingMaterial :: a
, sectorVertices :: Vector a -- How do we guarantee these aren't material ids?
, sectorFloorLevel :: Double
, sectorCeilingLevel :: Double
}
-- A wall points to the sectors on either side of the wall, but also its start
-- and end vertices. The same problem with 'Sector' appears here too.
data Wall a = Wall
{ wallFront :: a -- This should be a sector
, wallBack :: Maybe a -- This should also be a sector
, wallV1 :: a -- But this is a vertex
, wallV2 :: a -- This is also a vertex
}
-- Level ties this all together, with the various expressions making up the
-- vertices, the walls between them, the sectors, and the materials.
data Level = Level
{ levelVertices :: IntMap.IntMap Vertex
, levelSectors :: Vector (Scope Int Sector ())
, levelWalls :: Vector (Scope Int Wall ())
, levelMaterials :: Vector (Scope Int Material ())
, levelTextures :: Vector (Scope Int Texture ())
}
Run Code Online (Sandbox Code Playgroud)
但是,我不确定我是否正确地将各个部分放在一起.例如,我有Sector a,我a用来识别顶点和材料.但是,在正确的位置使用正确的标识符非常重要!
我很想通过模拟这个有点受限制的AST来听取关于我是否朝着正确方向前进的反馈bound.