Example #1
0
 public DepropNode(VoxelChunk chunk, Coords coords, byte lightLevel)
 {
     Chunk         = chunk;
     Coords        = coords;
     OriginalLight = lightLevel;
 }
Example #2
0
 public IndexedVoxels(VoxelChunk chunk)
 {
     _data  = chunk.VoxelData;
     _index = chunk.Index;
 }
Example #3
0
 public PropNode(VoxelChunk chunk, Coords coords)
 {
     Chunk  = chunk;
     Coords = coords;
 }
Example #4
0
 public void QueueForPropagation(VoxelChunk chunk, Coords c)
 {
     _propQueue.Enqueue(new PropNode(chunk, c));
 }
Example #5
0
 public unsafe void QueueForPropagation(VoxelChunk chunk, Coords c, byte lightLevel)
 {
     *chunk.LightData[Channel][c] = lightLevel;
     QueueForPropagation(chunk, c);
 }
        // protected override void StartGeneration() {
        //     _chunkWorkerGroup.StartTask(Volume);
        // }

        // protected override bool UpdateGeneration() {
        //     bool isDone = _chunkWorkerGroup.UpdateTask();
        //     if (isDone) {
        //         Logger.Info(this, _chunkWorkerGroup.GetCompletionMessage("Generated {0} chunks"));
        //     }
        //     return isDone;
        // }

        unsafe void GenerateChunk(VoxelChunk chunk)
        {
            if (ChunkIsInterior(chunk))
            {
                for (int i = 0; i < VoxelChunk.SIZE; i++)
                {
                    for (int j = 0; j < VoxelChunk.SIZE; j++)
                    {
                        for (int k = 0; k < VoxelChunk.SIZE; k++)
                        {
                            if (IsInCave(chunk.LocalToVolumeCoords(new Coords(i, j, k))))
                            {
                                *chunk.VoxelData[i, j, k] = VoxelData.Empty;
                            }
                            else
                            {
                                *chunk.VoxelData[i, j, k] = _stoneData;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < VoxelChunk.SIZE; i++)
                {
                    for (int j = 0; j < VoxelChunk.SIZE; j++)
                    {
                        for (int k = 0; k < VoxelChunk.SIZE; k++)
                        {
                            var vc = chunk.LocalToVolumeCoords(new Coords(i, j, k));
                            if (IsInCave(vc))
                            {
                                *chunk.VoxelData[i, j, k] = VoxelData.Empty;
                            }
                            else
                            {
                                var vpos    = vc + Vector3.One * 0.5f;
                                var vposMag = new Vector3(
                                    MathF.Abs(vpos.X),
                                    MathF.Abs(vpos.Y),
                                    MathF.Abs(vpos.Z)
                                    );
                                var max = MathF.Max(vposMag.X, MathF.Max(vposMag.Y, vposMag.Z));
                                vpos.Normalize();
                                var noise = Perlin.Noise(vpos * SurfaceLevel * NoiseFrequency);
                                noise = (noise + 1) / 2f;
                                float     height = SurfaceLevel + noise * MaxHeight;
                                int       stack  = (int)MathF.Ceiling(height) - (int)MathF.Ceiling(max);
                                VoxelData data;
                                if (stack < 0)
                                {
                                    data = VoxelData.Empty;
                                }
                                else if (stack == 0)
                                {
                                    data = _grassData;
                                }
                                else if (stack < 3)
                                {
                                    data = _dirtData;
                                }
                                else
                                {
                                    data = _stoneData;
                                }
                                *chunk.VoxelData[i, j, k] = data;
                            }
                        }
                    }
                }
            }
            Produce(chunk);
        }
 public VoxelChunkMesh(VoxelChunk chunk)
 {
     Chunk = chunk;
 }