public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates) { // Stopwatch sw = Stopwatch.StartNew(); ChunkColumn chunk = new ChunkColumn { x = chunkCoordinates.X, z = chunkCoordinates.Z }; Decorators.ChunkDecorator[] chunkDecorators = new ChunkDecorator[] { new WaterDecorator(), //new OreDecorator(), new FoliageDecorator(), }; var biomes = CalculateBiomes(chunk.x, chunk.z); foreach (var i in chunkDecorators) { i.SetSeed(Seed); } var heightMap = GenerateHeightMap(biomes, chunk.x, chunk.z); var thresholdMap = GetThresholdMap(chunk.x, chunk.z, biomes); CreateTerrainShape(chunk, heightMap, thresholdMap, biomes); DecorateChunk(chunk, heightMap, thresholdMap, biomes, chunkDecorators); //chunk.isDirty = true; //chunk.NeedSave = true; /*for (int x = 0; x < 16; x++) * { * for (int z = 0; z < 16; z++) * { * for (int y = 0; y < 256; y++) * { * chunk.SetSkyLight(x, y, z, 255); * } * } * }*/ // sw.Stop(); // if (sw.ElapsedMilliseconds > previousTime) //{ // Debug.WriteLine("Chunk gen took " + sw.ElapsedMilliseconds + " ms"); //previousTime = sw.ElapsedMilliseconds; //} return(chunk); }
private async Task <ChunkColumn> GenerateChunk(ChunkCoordinates chunkCoordinates) { ChunkColumn chunk = new ChunkColumn(); chunk.X = chunkCoordinates.X; chunk.Z = chunkCoordinates.Z; Decorators.ChunkDecorator[] chunkDecorators = new ChunkDecorator[] { new WaterDecorator(), //new OreDecorator(), new FoliageDecorator(), }; foreach (var i in chunkDecorators) { i.SetSeed(Seed); } var res = await GenerateNeeded(chunkCoordinates); var heightMap = res.heightMap; var thresholdMap = res.thresholdMap; var biomes = res.biomes; var blocks = await CreateTerrainShape(heightMap, thresholdMap); int[] metadata = new int[16 * 16 * 256]; DecorateChunk(chunk.X, chunk.Z, blocks, metadata, heightMap, thresholdMap, biomes, chunkDecorators); for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { var height = heightMap[(x << 4) + z]; var biome = biomes[(x << 4) + z]; chunk.biomeId[(x << 4) + z] = (byte)biome.Id; chunk.height[(x << 4) + z] = (short)height; for (int y = 0; y < 256; y++) { var idx = GetIndex(x, y, z); chunk.SetBlock(x, y, z, blocks[idx]); // chunk.SetMetadata(x,y,z, (byte) metadata[idx]); } } } return(chunk); }
public WorldBase(int difficulty) { rand = new Random((difficulty + UniverseProperties.seed).GetHashCode() * (difficulty + 5)); this.difficulty = difficulty; //set up the decoration maker/manager decorator = new ChunkDecorator(this); chunks = new Dictionary <Point, Chunk>(); //set up threading for world generation chunksQueuedForWorldGen = new HashSet <Point>(); chunksinWorldGen = new HashSet <Point>(); deQueuedChunk = new List <Chunk>(); //set up threading for physics baking chunksQueuedForPhysicsGen = new HashSet <Point>(); chunksinPhysicsGen = new HashSet <Point>(); deQueuedChunkPhysicsGen = new List <Chunk>(); //set up entity and entity categories entities = new HashSet <Entity>(); addedEntities = new HashSet <Entity>(); removedEntities = new HashSet <Entity>(); itemEntities = new HashSet <Entity>(); useableEntities = new HashSet <Entity>(); particles = new HashSet <Particle>(); addedParticles = new HashSet <Particle>(); removedParticles = new HashSet <Particle>(); delayedRenders = new List <DelayedRenderable>(); removeChunks = new List <Chunk>(); groundColor = Color.Black; worldGenType = WorldGenType.BLANK; currentScreenShakeOffsetTarget = new Vector2(); prevScreenShakeOffsetTarget = new Vector2(); spawnsEnemies = true; queuedEntites = new HashSet <Entity>(); deQueuedEntities = new HashSet <Entity>(); chunksSpawnedEntities = new HashSet <int>(); }