public JobHandle ScheduleChunkGenerationJob(WorldChunkPos_t cpos, PinnedChunkData_t chunk) { return(new ProcWorldStreaming_V1_Job_t() { cpos = cpos, chunk = chunk }.Schedule()); }
public static WorldVoxelPos_t ChunkToWorld(WorldChunkPos_t p) { return(new WorldVoxelPos_t { vx = ChunkToWorld(p.cx, VOXEL_CHUNK_SIZE_XZ), vy = ChunkToWorld(p.cy, VOXEL_CHUNK_SIZE_Y), vz = ChunkToWorld(p.cz, VOXEL_CHUNK_SIZE_XZ) }); }
static PinnedChunkData_t GenerateVoxelsSinWave(WorldChunkPos_t cpos, PinnedChunkData_t chunk) { var Y_OFS = (VOXEL_CHUNK_SIZE_Y * MaxVoxelChunkLine(VOXEL_CHUNK_VIS_MAX_Y)) / 8; bool solid = false; bool air = false; chunk.flags = EChunkFlags.LAYER_DEFAULT; WorldVoxelPos_t pos = ChunkToWorld(cpos); Vector3 v3 = WorldToVec3(pos); for (int x = 0; x < VOXEL_CHUNK_SIZE_XZ; ++x) { for (int z = 0; z < VOXEL_CHUNK_SIZE_XZ; ++z) { var cs = Mathf.Cos((v3.x + x) / 64); var ss = Mathf.Sin((v3.z + z) / 64); for (int y = 0; y < VOXEL_CHUNK_SIZE_Y; ++y) { var ofs = x + (z * VOXEL_CHUNK_SIZE_XZ) + (y * VOXEL_CHUNK_SIZE_XZ * VOXEL_CHUNK_SIZE_XZ); var ypos = v3.y + y; if (ypos < ((cs + ss) * (Y_OFS / 2))) { chunk.voxeldata[ofs] = EVoxelBlockType.Dirt; solid = true; } else { air = true; chunk.voxeldata[ofs] = EVoxelBlockType.Air; } } } } if (solid) { chunk.flags |= EChunkFlags.SOLID; } if (air) { chunk.flags |= EChunkFlags.AIR; } chunk.flags |= EChunkFlags.LAYER_DEFAULT; return(chunk); }
protected override JobHandle CreateGenVoxelsJob(WorldChunkPos_t pos, PinnedChunkData_t chunk) { return(_gameMode.worldStreaming.ScheduleChunkGenerationJob(pos, chunk)); }
static PinnedChunkData_t GenerateVoxels(WorldChunkPos_t cpos, PinnedChunkData_t chunk) { FastNoise_t noise = FastNoise_t.New(); chunk.flags = EChunkFlags.ALL_LAYERS_FLAGS; bool solid = false; bool air = true; bool fullVoxel = false; var wpos = ChunkToWorld(cpos); var v3 = WorldToVec3(wpos); for (int x = 0; x < VOXEL_CHUNK_SIZE_XZ; ++x) { for (int z = 0; z < VOXEL_CHUNK_SIZE_XZ; ++z) { var xpos = (int)v3.x + x; var zpos = (int)v3.z + z; bool isEmptyAtBottom = false; var lowerGroundHeight = GetLowerGroundHeight(ref noise, xpos, zpos); var upperGroundHeight = GetUpperGroundHeight(ref noise, xpos, zpos, lowerGroundHeight); float waterDepth = CalculateRiver(ref noise, xpos, zpos, lowerGroundHeight, 0, 0, ref upperGroundHeight); bool isRoad = CalculateRoad(ref noise, xpos, zpos, lowerGroundHeight, 0, 0, ref upperGroundHeight); for (int y = 0; y < VOXEL_CHUNK_SIZE_Y; ++y) { var ofs = x + (z * VOXEL_CHUNK_SIZE_XZ) + (y * VOXEL_CHUNK_SIZE_XZ * VOXEL_CHUNK_SIZE_XZ); var ypos = v3.y + y; EVoxelBlockType bt; bool isCave = false; if (ypos > lowerGroundHeight && ypos <= upperGroundHeight) { // Let's see about some caves er valleys! float caveNoise = GetPerlinValue(ref noise, xpos, ypos, zpos, 0.001f) * (0.015f * ypos) + 0.1f; caveNoise += GetPerlinValue(ref noise, xpos, ypos, zpos, 0.01f) * 0.06f + 0.1f; caveNoise += GetPerlinValue(ref noise, xpos, ypos, zpos, 0.02f) * 0.02f + 0.01f; isCave = caveNoise > GetPerlinNormal(ref noise, xpos, ypos, zpos, 0.01f) * 0.3f + 0.4f; } if (ypos <= upperGroundHeight && !isCave) { bt = GetBlockType(ref noise, xpos, (int)ypos, zpos, (int)upperGroundHeight, isRoad, false, out fullVoxel); } else { if (ypos < waterLevel) { float temperature = GetTemperature(ref noise, (int)xpos, (int)ypos, zpos); if (IsFrozen(temperature, GetHumidity(ref noise, xpos, zpos))) { bt = EVoxelBlockType.Ice; } else { bt = EVoxelBlockType.Water; } } else { bt = EVoxelBlockType.Air; } } if (bt == EVoxelBlockType.Air) { if (y == 0) { isEmptyAtBottom = true; } if (waterDepth > 0 && !isEmptyAtBottom) { float temperature = GetTemperature(ref noise, xpos, (int)ypos, zpos); if (IsFrozen(temperature, GetHumidity(ref noise, xpos, zpos))) { bt = EVoxelBlockType.Ice; } else { bt = EVoxelBlockType.Water; } waterDepth--; solid = true; } else { air = true; } } else { solid = true; } if (fullVoxel) { chunk.voxeldata[ofs] = bt.WithFlags(EVoxelBlockFlags.FullVoxel); } else { chunk.voxeldata[ofs] = bt; } } } } if (solid) { chunk.flags |= EChunkFlags.SOLID; } if (air) { chunk.flags |= EChunkFlags.AIR; } if (solid && air) { for (int x = 0; x < VOXEL_CHUNK_SIZE_XZ; ++x) { for (int z = 0; z < VOXEL_CHUNK_SIZE_XZ; ++z) { var xpos = (int)v3.x + x; var zpos = (int)v3.z + z; for (int y = VOXEL_CHUNK_SIZE_Y - 1; y >= 0; --y) { var ofs = x + (z * VOXEL_CHUNK_SIZE_XZ) + (y * VOXEL_CHUNK_SIZE_XZ * VOXEL_CHUNK_SIZE_XZ); var ypos = (int)v3.y + y; var bt = chunk.voxeldata[ofs].type; if (bt != EVoxelBlockType.Air) { if (bt == EVoxelBlockType.Water || bt == EVoxelBlockType.Leaves || bt == EVoxelBlockType.Needles || bt == EVoxelBlockType.Wood) { break; } float rock = GetRock(ref noise, xpos, ypos, zpos); float rockCutoff = 0.35f; if (rock > rockCutoff) { float rockLimit = (1.0f - Mathf.Pow((rock - rockCutoff) / (1.0f - rockCutoff), 0.5f)) * 100 + 1; if (GetWhiteNoise(ref noise, xpos, ypos, zpos) < 1.0f / rockLimit) { BuildRock(ref noise, x, y, z, chunk); } } if (bt == EVoxelBlockType.Ice || bt == EVoxelBlockType.Sand) { break; } float humidity = GetHumidity(ref noise, xpos, zpos); float forestPower = (1.0f - (GetPerlinNormal(ref noise, xpos, zpos, NoiseFloatScale._01) * GetPerlinNormal(ref noise, xpos + 64325, zpos + 6543, NoiseFloatScale._005))) * Mathf.Pow(humidity, 2) * (1.0f - Mathf.Pow(rock, 4)); float cutoff = 0.05f; if (forestPower > cutoff) { float forestLimit = Mathf.Pow(1.0f - (forestPower - cutoff) / (1.0f - cutoff), 8) * 100 + 4; if (GetWhiteNoise(ref noise, xpos, ypos, zpos) < 1.0f / forestLimit) { float temperature = GetTemperature(ref noise, xpos, ypos, zpos); int treeType; // dead if (humidity + temperature / 100.0f + GetPerlinNormal(ref noise, xpos, zpos, NoiseFloatScale._1) * 1.5f < 1.5f) { if (temperature + 30 * GetPerlinNormal(ref noise, xpos + 422, zpos + 5357, NoiseFloatScale._1) > 60) { treeType = 3; } else { treeType = 2; // pine } } else if (IsFrozen(temperature, humidity)) { treeType = 0; } else { treeType = 1; } BuildTree(ref noise, x, y, z, treeType, chunk); break; } } if (bt == EVoxelBlockType.Grass || bt == EVoxelBlockType.Dirt) { if (y < VOXEL_CHUNK_SIZE_Y - 1) { float flowerPower1 = 0.3f * GetPerlinNormal(ref noise, xpos, zpos, NoiseFloatScale._5) + 0.2f * GetPerlinNormal(ref noise, xpos + 67435, zpos + 653, NoiseFloatScale._01) + 0.5f * GetPerlinNormal(ref noise, xpos + 6435, zpos + 65453, NoiseFloatScale._005); float flowerPower2 = 0.4f * GetPerlinNormal(ref noise, xpos + 256, zpos + 54764, NoiseFloatScale._5) + 0.3f * GetPerlinNormal(ref noise, xpos + 6746435, zpos + 63, NoiseFloatScale._01) + 0.3f * GetPerlinNormal(ref noise, xpos + 649835, zpos + 6543, NoiseFloatScale._005); float flowerPower3 = 0.2f * GetPerlinNormal(ref noise, xpos + 7657376, zpos + 5421, NoiseFloatScale._5) + 0.3f * GetPerlinNormal(ref noise, xpos + 67435, zpos + 658963, NoiseFloatScale._01) + 0.5f * GetPerlinNormal(ref noise, xpos + 64935, zpos + 695453, NoiseFloatScale._005); float flowerPower4 = 0.3f * GetPerlinNormal(ref noise, xpos + 15, zpos + 6532, NoiseFloatScale._5) + 0.1f * GetPerlinNormal(ref noise, xpos + 6735, zpos + 63, NoiseFloatScale._01) + 0.6f * GetPerlinNormal(ref noise, xpos + 645, zpos + 6553, NoiseFloatScale._005); cutoff = 0.75f; int flowerType = 0; float flowerPower = 0; if (flowerPower1 > flowerPower) { flowerPower = flowerPower1; flowerType = 0; } if (flowerPower2 > flowerPower) { flowerPower = flowerPower2; flowerType = 1; } if (flowerPower3 > flowerPower) { flowerPower = flowerPower3; flowerType = 2; } if (flowerPower4 > flowerPower) { flowerPower = flowerPower4; flowerType = 3; } if (flowerPower > cutoff) { var ofs2 = x + (z * VOXEL_CHUNK_SIZE_XZ) + ((y + 1) * VOXEL_CHUNK_SIZE_XZ * VOXEL_CHUNK_SIZE_XZ); chunk.voxeldata[ofs2] = (EVoxelBlockType)((int)EVoxelBlockType.Flowers1 + flowerType); } } } //else if (blockType == BlockType.Grass && r.Next((int)(1000 * forestPower) + 10) == 0) //{ // chunk.setBlock(x, (byte)y, z, new Block(BlockType.RedFlower)); //} //else if (blockType == BlockType.Grass && r.Next((int)(50 * forestPower) + 1) == 1) //{ // chunk.setBlock(x, (byte)y, z, new Block(BlockType.LongGrass)); //} break; } } } } if (noise.GetWhiteNoise(cpos.cx, cpos.cy, cpos.cz) > 0.98f) { ConstructTower(16, 0, 16, chunk); } } return(chunk); }
public bool Equals(WorldChunkPos_t pos) { return(pos == this); }
JobHandle CreateGenVoxelsJob(WorldChunkPos_t pos, World.PinnedChunkData_t chunk) { return(_chunkStreaming.ScheduleChunkGenerationJob(pos, chunk)); }
protected abstract Unity.Jobs.JobHandle CreateGenVoxelsJob(WorldChunkPos_t pos, PinnedChunkData_t chunk);