public Color Lookup(Terrain terrain, int x, int y, int z) { int shaftValue = terrain.GetShaftValue(x, z); int temperature = terrain.GetSeasonalTemperature(shaftValue) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y); int seasonalHumidity = terrain.GetSeasonalHumidity(shaftValue); return(Lookup(temperature, seasonalHumidity)); }
public void GenerateGeometry(MovingBlockSet movingBlockSet) { Point3 point = default(Point3); point.X = ((movingBlockSet.CurrentVelocity.X > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.X)) : (point.X = (int)MathUtils.Ceiling(movingBlockSet.Position.X))); point.Y = ((movingBlockSet.CurrentVelocity.Y > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Y)) : (point.Y = (int)MathUtils.Ceiling(movingBlockSet.Position.Y))); point.Z = ((movingBlockSet.CurrentVelocity.Z > 0f) ? ((int)MathUtils.Floor(movingBlockSet.Position.Z)) : (point.Z = (int)MathUtils.Ceiling(movingBlockSet.Position.Z))); if (!(point != movingBlockSet.GeometryGenerationPosition)) { return; } Point3 p = new Point3(movingBlockSet.Box.Left, movingBlockSet.Box.Top, movingBlockSet.Box.Near); Point3 point2 = new Point3(movingBlockSet.Box.Width, movingBlockSet.Box.Height, movingBlockSet.Box.Depth); point2.Y = MathUtils.Min(point2.Y, 254); if (m_blockGeometryGenerator == null) { int x = 2; x = (int)MathUtils.NextPowerOf2((uint)x); m_blockGeometryGenerator = new BlockGeometryGenerator(new Terrain(), m_subsystemTerrain, null, base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true), null, base.Project.FindSubsystem <SubsystemPalette>(throwOnError: true)); for (int i = 0; i < x; i++) { for (int j = 0; j < x; j++) { m_blockGeometryGenerator.Terrain.AllocateChunk(i, j); } } } Terrain terrain = m_subsystemTerrain.Terrain; for (int k = 0; k < point2.X + 2; k++) { for (int l = 0; l < point2.Z + 2; l++) { int x2 = k + p.X + point.X - 1; int z = l + p.Z + point.Z - 1; int shaftValue = terrain.GetShaftValue(x2, z); m_blockGeometryGenerator.Terrain.SetTemperature(k, l, Terrain.ExtractTemperature(shaftValue)); m_blockGeometryGenerator.Terrain.SetHumidity(k, l, Terrain.ExtractHumidity(shaftValue)); for (int m = 0; m < point2.Y + 2; m++) { int y = m + p.Y + point.Y - 1; int light = Terrain.ExtractLight(terrain.GetCellValue(x2, y, z)); m_blockGeometryGenerator.Terrain.SetCellValueFast(k, m, l, Terrain.MakeBlockValue(0, light, 0)); } } } m_blockGeometryGenerator.Terrain.SeasonTemperature = terrain.SeasonTemperature; m_blockGeometryGenerator.Terrain.SeasonHumidity = terrain.SeasonHumidity; foreach (MovingBlock block in movingBlockSet.Blocks) { int x3 = block.Offset.X - p.X + 1; int y2 = block.Offset.Y - p.Y + 1; int z2 = block.Offset.Z - p.Z + 1; int value = Terrain.ReplaceLight(light: m_blockGeometryGenerator.Terrain.GetCellLightFast(x3, y2, z2), value: block.Value); m_blockGeometryGenerator.Terrain.SetCellValueFast(x3, y2, z2, value); } m_blockGeometryGenerator.ResetCache(); movingBlockSet.Vertices.Clear(); movingBlockSet.Indices.Clear(); for (int n = 1; n < point2.X + 1; n++) { for (int num = 1; num < point2.Y + 1; num++) { for (int num2 = 1; num2 < point2.Z + 1; num2++) { int cellValueFast = m_blockGeometryGenerator.Terrain.GetCellValueFast(n, num, num2); int num3 = Terrain.ExtractContents(cellValueFast); if (num3 != 0) { BlocksManager.Blocks[num3].GenerateTerrainVertices(m_blockGeometryGenerator, movingBlockSet.Geometry, cellValueFast, n, num, num2); } } } } movingBlockSet.GeometryOffset = new Vector3(p) - new Vector3(1f); movingBlockSet.GeometryGenerationPosition = point; }
public void SaveChunkBlocks(TerrainChunk chunk) { _ = Time.RealTime; Terrain terrain = m_subsystemTerrain.Terrain; int num = chunk.Origin.X >> 4; int num2 = chunk.Origin.Y >> 4; try { bool flag = false; if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out int value)) { m_stream.Seek(value, SeekOrigin.Begin); } else { flag = true; value = (int)m_stream.Length; m_stream.Seek(value, SeekOrigin.Begin); } WriteChunkHeader(m_stream, num, num2); int num3 = 0; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { int num4 = TerrainChunk.CalculateCellIndex(i, 0, j); for (int k = 0; k < 256; k++) { int cellValueFast = chunk.GetCellValueFast(num4++); m_buffer[num3++] = (byte)cellValueFast; m_buffer[num3++] = (byte)(cellValueFast >> 8); } } } m_stream.Write(m_buffer, 0, 131072); num3 = 0; for (int l = 0; l < 16; l++) { for (int m = 0; m < 16; m++) { int shaftValue = terrain.GetShaftValue(l + chunk.Origin.X, m + chunk.Origin.Y); m_buffer[num3++] = (byte)shaftValue; m_buffer[num3++] = (byte)(shaftValue >> 8); m_buffer[num3++] = (byte)(shaftValue >> 16); m_buffer[num3++] = (byte)(shaftValue >> 24); } } m_stream.Write(m_buffer, 0, 1024); if (flag) { m_stream.Flush(); int num5 = m_chunkOffsets.Count % 65536 * 3 * 4; m_stream.Seek(num5, SeekOrigin.Begin); WriteInt(m_stream, num); WriteInt(m_stream, num2); WriteInt(m_stream, value); m_chunkOffsets[new Point2(num, num2)] = value; } } catch (Exception e) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e)); } _ = Time.RealTime; }
public unsafe void SaveChunkBlocks(TerrainChunk chunk) { _ = Time.RealTime; int num = chunk.Origin.X >> 4; int num2 = chunk.Origin.Y >> 4; try { bool flag = false; if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out long value)) { m_stream.Seek(value, SeekOrigin.Begin); } else { flag = true; value = m_stream.Length; m_stream.Seek(value, SeekOrigin.Begin); } WriteChunkHeader(m_stream, num, num2); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr2 = (int *)ptr; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { int num3 = TerrainChunk.CalculateCellIndex(i, 0, j); int num4 = 0; while (num4 < 256) { *ptr2 = chunk.GetCellValueFast(num3); num4++; num3++; ptr2++; } } } } } finally { } m_stream.Write(m_buffer, 0, 262144); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr3 = (int *)ptr; for (int k = 0; k < 16; k++) { for (int l = 0; l < 16; l++) { *ptr3 = m_terrain.GetShaftValue(k + chunk.Origin.X, l + chunk.Origin.Y); ptr3++; } } } } finally { } m_stream.Write(m_buffer, 0, 1024); if (flag) { m_stream.Flush(); int num5 = m_chunkOffsets.Count % 65536 * 3 * 4; m_stream.Seek(num5, SeekOrigin.Begin); WriteInt(m_stream, num); WriteInt(m_stream, num2); WriteInt(m_stream, m_chunkOffsets.Count); m_chunkOffsets[new Point2(num, num2)] = value; } m_stream.Flush(); } catch (Exception e) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e)); } _ = Time.RealTime; }