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); } } } } }
private void GenerateTerrain(TerrainChunk chunk, int x1, int z1, int x2, int z2) { int num = x2 - x1; int num2 = z2 - z1; Terrain terrain = this.subsystemTerrain.Terrain; int num3 = chunk.Origin.X + x1; int num4 = chunk.Origin.Y + z1; TerrainContentsGenerator.Grid2d grid2d = new TerrainContentsGenerator.Grid2d(num, num2); TerrainContentsGenerator.Grid2d grid2d2 = new TerrainContentsGenerator.Grid2d(num, num2); for (int i = 0; i < num2; i++) { for (int j = 0; j < num; j++) { grid2d.Set(j, i, this.CalculateOceanShoreDistance((float)(j + num3), (float)(i + num4))); grid2d2.Set(j, i, this.CalculateMountainRangeFactor((float)(j + num3), (float)(i + num4))); } } TerrainContentsGenerator.Grid3d grid3d = new TerrainContentsGenerator.Grid3d(num / 4 + 1, 17, num2 / 4 + 1); for (int k = 0; k < grid3d.SizeX; k++) { for (int l = 0; l < grid3d.SizeZ; l++) { int num5 = k * 4 + num3; int num6 = l * 4 + num4; float num7 = this.CalculateHeight((float)num5, (float)num6); float num8 = this.CalculateMountainRangeFactor((float)num5, (float)num6); float num9 = MathUtils.Saturate(0.9f * (num8 - 0.8f) / 0.2f + 0.1f); for (int m = 0; m < grid3d.SizeY; m++) { int num10 = m * 8; float num11 = num7 - this.TGTurbulenceTopOffset; float num12 = MathUtils.Lerp(0f, this.TGTurbulenceStrength * num9, MathUtils.Saturate((num11 - (float)num10) * 0.2f)) * MathUtils.PowSign(2f * SimplexNoise.OctavedNoise((float)num5, (float)(num10 + 1000), (float)num6, 0.008f, 3, 2f, 0.75f) - 1f, this.TGTurbulencePower); float num13 = (float)num10 + num12; float num14 = num7 - num13; num14 += MathUtils.Max(4f * (this.TGDensityBias - (float)num10), 0f); grid3d.Set(k, m, l, num14); } } } int oceanLevel = this.OceanLevel; for (int n = 0; n < grid3d.SizeX - 1; n++) { for (int num15 = 0; num15 < grid3d.SizeZ - 1; num15++) { for (int num16 = 0; num16 < grid3d.SizeY - 1; num16++) { float num17; float num18; float num19; float num20; float num21; float num22; float num23; float num24; grid3d.Get8(n, num16, num15, out num17, out num18, out num19, out num20, out num21, out num22, out num23, out num24); float num25 = (num18 - num17) / 4f; float num26 = (num20 - num19) / 4f; float num27 = (num22 - num21) / 4f; float num28 = (num24 - num23) / 4f; float num29 = num17; float num30 = num19; float num31 = num21; float num32 = num23; for (int num33 = 0; num33 < 4; num33++) { float num34 = (num31 - num29) / 4f; float num35 = (num32 - num30) / 4f; float num36 = num29; float num37 = num30; for (int num38 = 0; num38 < 4; num38++) { float num39 = (num37 - num36) / 8f; float num40 = num36; int num41 = num33 + n * 4; int num42 = num38 + num15 * 4; int x3 = x1 + num41; int z3 = z1 + num42; float x4 = grid2d.Get(num41, num42); float num43 = grid2d2.Get(num41, num42); int temperatureFast = chunk.GetTemperatureFast(x3, z3); int humidityFast = chunk.GetHumidityFast(x3, z3); float f = num43 - 0.01f * (float)humidityFast; float num44 = MathUtils.Lerp(100f, 0f, f); float num45 = MathUtils.Lerp(300f, 30f, f); bool flag = (temperatureFast > 8 && humidityFast < 8 && num43 < 0.95f) || (MathUtils.Abs(x4) < 12f && num43 < 0.9f); int num46 = TerrainChunk.CalculateCellIndex(x3, 0, z3); for (int num47 = 0; num47 < 8; num47++) { int num48 = num47 + num16 * 8; int value = 0; if (num40 < 0f) { if (num48 <= oceanLevel) { value = 18; } } else if (flag) { if (num40 < num44) { value = 4; } else if (num40 < num45) { value = 3; } else { value = 67; } } else if (num40 < num45) { value = 3; } else { value = 67; } chunk.SetCellValueFast(num46 + num48, value); num40 += num39; } num36 += num34; num37 += num35; } num29 += num25; num30 += num26; num31 += num27; num32 += num28; } } } } }