public Region(TerrainGenerator generator, UInt64 id) { myOrigin = ChunkKey.createWorldLocationFromKey(id); myGenerator = generator; myId = id; Info.print("Creating region {0}", id); }
public Chunk buildChunk(UInt64 key) { Vector3 pos = ChunkKey.createWorldLocationFromKey(key); UInt64 id = regionId(pos); // Region region; // if (myRegionGenerators.TryGetValue(id, out region) == false) // { // region = new Region(this, myTerrainModules, id); // region.world = myWorld; // myRegionGenerators.Add(id, region); // } // // Chunk chunk = region.buildChunk(key); // return chunk; return(null); }
public Chunk buildChunk(UInt64 key) { Vector3 pos = ChunkKey.createWorldLocationFromKey(key); UInt64 id = regionId(pos); Region region; if (myRegionGenerators.TryGetValue(id, out region) == false) { region = new Region(this, id); region.init(myTerrainConfig["terrain"]); region.world = myWorld; myRegionGenerators.Add(id, region); } Chunk chunk = region.buildChunk(key); return(chunk); }
public Chunk buildChunk(UInt64 key) { Vector3 position = ChunkKey.createWorldLocationFromKey(key); UInt32 air = 0; UInt32[] mats = new UInt32[12] { Hash.hash("snow"), //Ice 0 Hash.hash("gravel"), //Tundra 1 Hash.hash("sand"), //Desert 2 Hash.hash("grass"), //Grassland 3 Hash.hash("dirt"), //Savanna 4 Hash.hash("log_spruce"), //TemperateSeasonalForest 5 Hash.hash("log_oak"), //TropicalSeasonalForest 6 Hash.hash("marble"), //Taiga 7 Hash.hash("finished_oak"), //TemperateRainforest 8 Hash.hash("finished_birch"), //TropicalRainforest 9 Hash.hash("sandstone"), //ShallowOcean 10 Hash.hash("bedrock") //DeepOcean 11 }; UInt32 water = Hash.hash("water"); //how big a chunk are we taking int count = WorldParameters.theNodeCount; float stepSize = WorldParameters.theChunkSize / count; //with a count of 32 and the default cube of 102.4m this is a stepsize of 3.2m bool hasSolid = false; bool hasAir = false; float px = position.X / WorldParameters.theWorldSize; float pz = position.Z / WorldParameters.theWorldSize; float elevation = mySampler.get(px, pz, 0) * WorldParameters.theMaxElevation; float biomeFloat = mySampler.get(px, pz, 3); UInt32 biome = BitConverter.ToUInt32(BitConverter.GetBytes(biomeFloat), 0); biome = biome & 0xf; //generate point cloud UInt32[, ,] pc = new UInt32[count, count, count]; for (int x = 0; x < count; x++) { for (int z = 0; z < count; z++) { for (int y = 0; y < count; y++) { double ny = position.Y + (y * stepSize); if (ny < elevation) //underground { hasSolid = true; pc[x, y, z] = mats[biome]; } else { if (ny < (waterLevel * WorldParameters.theMaxElevation)) { pc[x, y, z] = water; hasSolid = true; } else { pc[x, y, z] = air; hasAir = true; } } } } } Chunk chunk = new Chunk(position); chunk.world = world; if (hasSolid == false && hasAir == true) { chunk.myRoot.materialId = air; } else { chunk.fromPointCloud(pc); } Info.print("Built chunk {0}", chunk.chunkKey.myKey); return(chunk); }