Пример #1
0
        public static void GenerateChunkVertices(TerrainUpdater updater, TerrainChunk chunk, int x1, int z1, int x2, int z2)
        {
            if (chunk.ThreadState == TerrainChunkState.InvalidVertices1)
            {
                Data.Remove(chunk.Coords);
            }
            Terrain      terrain        = updater.m_terrain;
            TerrainChunk chunkAtCoords  = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y - 1);
            TerrainChunk chunkAtCoords2 = terrain.GetChunkAtCoords(chunk.Coords.X, chunk.Coords.Y - 1);
            TerrainChunk chunkAtCoords3 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y - 1);
            TerrainChunk chunkAtCoords4 = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y);
            TerrainChunk chunkAtCoords5 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y);
            TerrainChunk chunkAtCoords6 = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y + 1);
            TerrainChunk chunkAtCoords7 = terrain.GetChunkAtCoords(chunk.Coords.X, chunk.Coords.Y + 1);
            TerrainChunk chunkAtCoords8 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y + 1);

            if (chunkAtCoords4 == null)
            {
                x1 = MathUtils.Max(x1, 1);
            }
            if (chunkAtCoords2 == null)
            {
                z1 = MathUtils.Max(z1, 1);
            }
            if (chunkAtCoords5 == null)
            {
                x2 = MathUtils.Min(x2, 15);
            }
            if (chunkAtCoords7 == null)
            {
                z2 = MathUtils.Min(z2, 15);
            }
            for (int i = x1; i < x2; i++)
            {
                for (int j = z1; j < z2; j++)
                {
                    switch (i)
                    {
                    case 0:
                        if ((j == 0 && chunkAtCoords == null) || (j == 15 && chunkAtCoords6 == null))
                        {
                            continue;
                        }
                        break;

                    case 15:
                        if ((j == 0 && chunkAtCoords3 == null) || (j == 15 && chunkAtCoords8 == null))
                        {
                            continue;
                        }
                        break;
                    }
                    int num              = i + chunk.Origin.X;
                    int num2             = j + chunk.Origin.Y;
                    int bottomHeightFast = chunk.GetBottomHeightFast(i, j);
                    int bottomHeight     = terrain.GetBottomHeight(num - 1, num2);
                    int bottomHeight2    = terrain.GetBottomHeight(num + 1, num2);
                    int bottomHeight3    = terrain.GetBottomHeight(num, num2 - 1);
                    int bottomHeight4    = terrain.GetBottomHeight(num, num2 + 1);
                    int x3            = MathUtils.Min(bottomHeightFast - 1, MathUtils.Min(bottomHeight, bottomHeight2, bottomHeight3, bottomHeight4));
                    int topHeightFast = chunk.GetTopHeightFast(i, j);
                    int num3          = MathUtils.Max(x3, 1);
                    topHeightFast = MathUtils.Min(topHeightFast, 126);
                    int num4 = TerrainChunk.CalculateCellIndex(i, 0, j);
                    for (int k = num3; k <= topHeightFast; k++)
                    {
                        int cellValueFast = chunk.GetCellValueFast(num4 + k);
                        int num5          = Terrain.ExtractContents(cellValueFast);
                        if (num5 != 0)
                        {
                            BlocksManager.Blocks[num5].GenerateTerrainVertices(updater.m_subsystemTerrain.BlockGeometryGenerator, chunk.Geometry, cellValueFast, num, k, num2);
                            chunk.GeometryMinY = MathUtils.Min(chunk.GeometryMinY, k);
                            chunk.GeometryMaxY = MathUtils.Max(chunk.GeometryMaxY, k);
                        }
                    }
                }
            }
        }