public void LoadData() { var watch = System.Diagnostics.Stopwatch.StartNew(); _random = new Random(ChunkPosition.X * (chunkSize * chunkSize) + ChunkPosition.Y * chunkSize + ChunkPosition.Z); _highestBloc = 128; _lowestBloc = 110; for (int z = 0; z < chunkSize; z++) { for (int x = 0; x < chunkSize; x++) { var height = HeightMap.getHeight(x + (ChunkPosition.X * chunkSize), z + (ChunkPosition.Z * chunkSize)); int luminosity = 15; for (int y = chunkHeight - 1; y >= 0; y--) { int artificialLight = 0; int index = positionToIndex(new Point3d(x, y, z)); Blocs[index] = 0; if (y < height) { BlocMaterial material = BlocMaterial.Air; if (height - 1 == y) { if (y < 128) { material = BlocMaterial.Sand; } else { material = BlocMaterial.Earth; } } else if (height > y) { material = BlocMaterial.Stone; } else { material = BlocMaterial.Wood; } luminosity = 0; setOpacity(index, true); setWater(index, false); setMaterial(index, material); _highestBloc = Math.Max(_highestBloc, y); } else { if (y < 128) { setWater(index, true); luminosity -= 3; } else { setWater(index, false); } setOpacity(index, false); } luminosity = (byte)Math.Max((int)luminosity, 0); setSunLuminosity(index, (byte)luminosity); setArtificialLuminosity(index, (byte)artificialLight); } } } createBox(new Point3d(10, 128, 10), new Point3d(30, 134, 30)); int treeCount = _random.Next() % 3; for (int i = 0; i < treeCount; i++) { createTree(new Point3d(_random.Next() % 11 + 2, 0, _random.Next() % 11 + 2)); } addArtificialLights(); addPlants(); var elapsedMs = watch.ElapsedMilliseconds; //Console.WriteLine("Loading computing : " + elapsedMs); IsLoading = false; }
private void setMaterial(int index, BlocMaterial material) { byte[] data = BitConverter.GetBytes((ushort)material); Blocs[index + 1] = data[0]; Blocs[index + 2] = data[1]; }