Beispiel #1
0
        private void SetChunkAt(GlobalPos pos, BasicChunk newChunk)
        {
            var x        = pos.X >> 8;
            var y        = pos.Y >> 8;
            var oldChunk = _chunks[ChunkIndex(x, y)];

            oldChunk.UpdateNeighbors(newChunk);
            _chunks[ChunkIndex(x, y)] = newChunk;
        }
Beispiel #2
0
        public ArrayChunk(BasicChunk init) : this((byte)init.Width, (byte)init.Height)
        {
            var index = 0;

            for (var y = 0; y < Height; ++y)
            {
                for (var x = 0; x < Width; ++x)
                {
                    _symbols[index++] = init.GetSymbol((byte)x, (byte)y);
                }
            }
            Next = init.Next;
        }
Beispiel #3
0
 public ListChunk(BasicChunk init) : this((byte)init.Width, (byte)init.Height)
 {
     for (var y = 0; y < Height; ++y)
     {
         for (var x = 0; x < Width; ++x)
         {
             var owner = init.GetSymbol((byte)x, (byte)y);
             if (owner != BasicChunk.NoOwner)
             {
                 var pos = new LocalPos((byte)x, (byte)y);
                 _symbols[pos] = owner;
             }
         }
     }
     Next = init.Next;
 }
Beispiel #4
0
        public void UpdateNeighbors(BasicChunk newChunk)
        {
            if (Next.Up == this)
            {
                newChunk.Next.Up = newChunk;
            }
            else if (Next.Up != null)
            {
                Next.Up.Next.Down = newChunk;
            }

            if (Next.Down == this)
            {
                newChunk.Next.Down = newChunk;
            }
            else if (Next.Down != null)
            {
                Next.Down.Next.Up = newChunk;
            }

            if (Next.Left == this)
            {
                newChunk.Next.Left = newChunk;
            }
            else if (Next.Left != null)
            {
                Next.Left.Next.Right = newChunk;
            }

            if (Next.Right == this)
            {
                newChunk.Next.Right = newChunk;
            }
            else if (Next.Right != null)
            {
                Next.Right.Next.Left = newChunk;
            }

            //and detach myself
            Next.Up = Next.Down = Next.Left = Next.Right = null;
        }