我正在尝试使用爱德华的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 ())
}
然而,我不确定我是否正确地将这些碎片放在一起。例如,我有Sector a
,我使用a
来识别顶点和材质。但是,在正确的位置使用正确的标识符非常重要!
我希望通过bound
对这个有点受限制的AST进行建模来听取有关我是否朝着正确方向前进的反馈。