void UpdateVertexBuffer()
        {
            if (m_env == null)
            {
                RemoveAndDispose(ref m_vertexBuffer);
                m_vertexList = null;
                return;
            }

            var envContents = m_env.Contents;

            if (m_vertexList != null && envContents.Count > m_vertexList.Count)
            {
                m_vertexList = null;
            }

            if (m_vertexList == null)
            {
                m_vertexList = new VertexList <SceneryVertex>(envContents.Count * 2);
            }

            IntGrid3 viewGrid = m_viewGridProvider.ViewGrid;

            m_vertexList.Clear();

            foreach (var ob in envContents.OfType <ConcreteObject>())
            {
                if (viewGrid.Contains(ob.Location) == false)
                {
                    continue;
                }

                var c = ob.Color;
                if (c == GameColor.None)
                {
                    c = ob.Material.Color;
                }

                m_vertexList.Add(new SceneryVertex(ob.Location.ToVector3(), ToColor(c), (uint)ob.SymbolID));
            }

            if (m_vertexList.Count > 0)
            {
                if (m_vertexBuffer == null || m_vertexBuffer.ElementCount < m_vertexList.Count)
                {
                    RemoveAndDispose(ref m_vertexBuffer);
                    m_vertexBuffer = ToDispose(SharpDX.Toolkit.Graphics.Buffer.Vertex.New <SceneryVertex>(this.GraphicsDevice, m_vertexList.Count));
                }

                m_vertexBuffer.SetData(m_vertexList.Data, 0, m_vertexList.Count);
            }
        }
Beispiel #2
0
        public void GenerateVertices(ref IntGrid3 viewGrid, IntVector3 cameraChunkPos,
                                     VertexList <TerrainVertex> terrainVertexList, VertexList <SceneryVertex> sceneryVertexList)
        {
            terrainVertexList.Clear();
            sceneryVertexList.Clear();

            var diff = cameraChunkPos - this.ChunkPosition;

            Direction visibleChunkFaces = 0;

            if (diff.X >= 0)
            {
                visibleChunkFaces |= Direction.PositiveX;
            }
            if (diff.X <= 0)
            {
                visibleChunkFaces |= Direction.NegativeX;
            }
            if (diff.Y >= 0)
            {
                visibleChunkFaces |= Direction.PositiveY;
            }
            if (diff.Y <= 0)
            {
                visibleChunkFaces |= Direction.NegativeY;
            }
            if (diff.Z >= 0)
            {
                visibleChunkFaces |= Direction.PositiveZ;
            }
            if (diff.Z <= 0)
            {
                visibleChunkFaces |= Direction.NegativeZ;
            }

            GenerateVertices(ref viewGrid, visibleChunkFaces, terrainVertexList, sceneryVertexList);

            this.VertexCount        = terrainVertexList.Count;
            this.SceneryVertexCount = sceneryVertexList.Count;
        }