Beispiel #1
0
        internal override void Generate(Chunk chunk)
        {
            this.chunk = chunk;
            PositionBlock pos;
            chunk.Position.GetGlobalPositionBlock(out pos, 0, 0, 0);
            noise3D = GetScaledNoise(pos, 0.04f);
            PositionBlock pos2 = pos;
            pos2.Y = 0;
            noise2D = GetScaledNoise(pos2, 0.01f);

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y < 16; y++)
                    {
                        float height = pos.Y + y;
                        if (height == 0)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.BedRock.Id);
                        }
                        else if (height <= 60)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.Stone.Id);
                        }
                        else if (height <= 80)
                        {
                            float limit = CalcOffset(height, 60, 80) * 2f - 1f;
                            Magic(height, x, y, z, BlockRepository.Stone.Id, limit);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void ChangeChunk(int x, int y, int z)
 {
     PositionChunk positionChunk = PositionChunk.CreateFrom(new PositionBlock(x,y,z));
     chunkCache = World.Instance.GetCachedChunks();
     chunk = chunkCache.GetChunk(positionChunk);
     chunk.Position.GetMinCornerBlock(out chunkCorner);
 }
        private void RenderChunk(Chunk chunk)
        {
            Counters.Instance.Increment("chunks in view range");
            if (chunk == null || !ChunkRenderer.InsideViewFrustum(chunk)) return;
            Counters.Instance.Increment("chunks rendered");

            // get chunkrenderer for this chunk (create new if it does not exist)
            object key = chunk.Position.Key;
            ChunkRenderer chunkRenderer;
            if (chunkRenderers.ContainsKey(key))
                chunkRenderer = chunkRenderers[key];
            else
            {
                chunkRenderer = new ChunkRenderer(chunk);
                chunkRenderers.Add(key, chunkRenderer);
            }
            forceCachedRendering |= chunkRenderer.Render(forceCachedRendering);
            if(chunkRenderer.HasPass2())
                pass2ChunkRenderers.Add(chunkRenderer);
        }
Beispiel #4
0
 internal void Decorate(Chunk chunk)
 {
     Random rnd = new Random(chunk.Position.X*12345 ^ chunk.Position.Y*23456 ^ chunk.Position.Z*34657);
     PositionBlock chunkCorner;
     chunk.Position.GetMinCornerBlock(out chunkCorner);
     ChunkPointer pointer = ChunkPointer.Create(chunkCorner.X, chunkCorner.Y, chunkCorner.Z);
     tree.Pointer = pointer;
     bush.Pointer = pointer;
     house.Pointer = pointer;
     for (int x = chunkCorner.X; x < chunkCorner.X + 16; x++)
     {
         for (int z = chunkCorner.Z; z < chunkCorner.Z + 16; z++)
         {
             for (int y = Chunk.MaxSizeY - 1; y >= 0; y--)
             {
                 // find top block
                 if (pointer.GetBlock(x, y, z) == BlockRepository.Stone.Id)
                 {
                     pointer.SetBlock(x, y, z, BlockRepository.DirtWithGrass.Id);
                     double propability = rnd.NextDouble();
                     if (propability < 0.02)
                     {
                         tree.Plant(x, y + 1, z, rnd.Next(4, 10));
                     }
                     else if (propability < 0.04)
                     {
                         bush.Plant(x, y + 1, z, rnd.Next(1, 3));
                     }
                     else if (propability < 0.041)
                     {
                         house.Build(x, y + 1, z, rnd.Next(1, 8));
                     }
                     break;
                 }
             }
         }
     }
 }
Beispiel #5
0
        internal override void Generate(Chunk chunk)
        {
            if (disableRecursivecalls)
                return;
            disableRecursivecalls = true;
            PositionBlock positionBlock;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y < 16; y++)
                    {
                        chunk.Position.GetGlobalPositionBlock(out positionBlock, x, y, z);
                        int globalY = positionBlock.Y;

                        if (globalY < 32)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.Stone.Id);
                            continue;
                        }
                        else if (globalY < 64)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.Dirt.Id);
                            continue;
                        }
                        if (globalY == 64)
                        {

                            chunk.SetLocalBlock(x, y, z, BlockRepository.DirtWithGrass.Id);
                            continue;
                        }

                    }
                }
            }
            disableRecursivecalls = false;
        }
Beispiel #6
0
 internal GeneratorBase Generator(Chunk chunk)
 {
     return generator;
 }
Beispiel #7
0
 internal Chunk GetChunk(PositionChunk positionChunk)
 {
     Chunk chunk = storage.GetChunk(positionChunk);
     if (chunk == null)
     {
         chunk = new Chunk();
         chunk.Position = positionChunk;
         storage.AddChunk(chunk);
     }
     return chunk;
 }
Beispiel #8
0
 internal abstract void Generate(Chunk chunk);
Beispiel #9
0
 internal virtual void Decorate(Chunk chunk)
 {
 }
Beispiel #10
0
        internal override void Generate(Chunk chunk)
        {
            if (disableRecursivecalls)
                return;
            disableRecursivecalls = true;
            PositionBlock positionBlock;
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y < 16; y++)
                    {
                        chunk.Position.GetGlobalPositionBlock(out positionBlock, x, y, z);
                        int globalY = positionBlock.Y;

                        if (globalY < 32)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.Stone.Id);
                            continue;
                        }
                        else if (globalY < 64)
                        {
                            chunk.SetLocalBlock(x, y, z, BlockRepository.Dirt.Id);
                            continue;
                        }
                        if (globalY == 64)
                        {
                            if (chunk.Position.X == 1 && chunk.Position.Z == -1 && globalY == 64)
                            {
                                //chunk.SafeSetLocalBlock(x, y, z, BlockRepository.Water.Id);
                            }
                            else
                                chunk.SetLocalBlock(x, y, z, BlockRepository.DirtWithGrass.Id);
                            continue;
                        }

                        // hit me with some artifacts for collision detection:
                        if (chunk.Position.X == -2 && chunk.Position.Z == -2 && globalY == 65)
                        {
                            if (x % 4 + z % 4 == 0)
                            {
                                chunk.SafeSetLocalBlock(x, y, z, BlockRepository.Sand.Id);
                            }
                        }
                        else if (chunk.Position.X == -1 && chunk.Position.Z == -2 && globalY == 65)
                        {
                            chunk.SafeSetLocalBlock(x, y, z, BlockRepository.TallGrass.Id);
                        }
                        else if (chunk.Position.X == -3 && chunk.Position.Z == -3 && globalY < 16-x -  z + 65)
                        {
                            chunk.SafeSetLocalBlock(x, y, z, globalY == 16-x - z + 64 ? BlockRepository.DirtWithGrass.Id : BlockRepository.Dirt.Id);
                        }
                        else if (chunk.Position.X == -1 && chunk.Position.Z == -1 && globalY < 16 - x - z + 65)
                        {
                            chunk.SafeSetLocalBlock(15 - x, y, 15 - z, globalY == 16 - x - z + 64 ? BlockRepository.CobbleStone.Id : BlockRepository.Stone.Id);
                        }

                        else if (chunk.Position.X == -2 && chunk.Position.Z == -3 && globalY > 64 && globalY < 68)
                        {
                            if (x % 2 + z % 2 == 0)
                            {
                                chunk.SafeSetLocalBlock(x, y, z, BlockRepository.Wood.Id);
                            }
                        }
                    }
                }
            }
            disableRecursivecalls = false;
        }
Beispiel #11
0
 private void SetChunkStage(Chunk.ChunkStageEnum newStage)
 {
     ChunkCache cache = World.Instance.GetCachedChunks();
     for (int y = 0; y < Chunk.MaxSizeY / 16f; y++)
     {
         Chunk chunk = cache.GetChunk(new PositionChunk(Position.X, y, Position.Z));
         chunk.Stage = newStage;
     }
 }
Beispiel #12
0
 internal override void Decorate(Chunk chunk)
 {
     DecoratorBiome decorator = new DecoratorBiome();
     decorator.Decorate(chunk);
 }
Beispiel #13
0
 internal void AddChunk(Chunk chunk)
 {
     chunks.Add(chunk.Position.Key, chunk);
 }