Ejemplo n.º 1
0
        void Awake()
        {
            cell = new Cell(new CellPos(0, 0, 0), null, this);

            /*
            var greed = new BinaryGrid(16, 10);

            Debug.Log("greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("greed: " + greed.IsSet(5, 5, 5));

            greed.Set(0, 0, 0);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("greed: " + greed.IsSet(1, 1, 1));

            greed.Set(1, 0, 0);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("greed: " + greed.IsSet(1, 1, 1));

            greed.Set(0, 1, 0);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("greed: " + greed.IsSet(1, 1, 1));

            greed.Set(0, 0, 1);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("greed: " + greed.IsSet(1, 1, 1));

            greed.Set(1, 1, 1);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("_greed: " + greed.IsSet(1, 1, 1));


            greed.Reset(0, 1, 0);

            Debug.Log("_greed: " + greed.IsSet(0, 0, 0));
            Debug.Log("_greed: " + greed.IsSet(1, 0, 0));
            Debug.Log("greed: " + greed.IsSet(0, 1, 0));
            Debug.Log("_greed: " + greed.IsSet(0, 0, 1));
            Debug.Log("_greed: " + greed.IsSet(1, 1, 1));
            */
        }
Ejemplo n.º 2
0
        //protected Greed childrenGreed;


        //public Cell(Pos pos, SortedList<ushort, Cell> neighbors, object owner)
        //        public Cell(Pos pos, SortedList<ushort, Cell> neighbors, Cell parent, object owner)
        public Cell(CellPos pos, Cell parent, object owner)
        {
            this.pos = pos;
            this.parent = parent;

            /*
            if (parent == null)
            {
                neighbors = new SortedList<ushort, Cell>();
                neighborsBinaryGrid = new BinaryGrid((byte)Pos.WIDTH, (byte)Pos.HEIGHT);
            } else
            {
                neighbors = parent.children;
                neighborsBinaryGrid = parent.neighborsBinaryGrid;
            }
            */

            childrenBinaryGrid = new BinaryGrid((byte)Pos.WIDTH, (byte)Pos.HEIGHT);


            this.neighbors = parent == null ? new SortedList<ushort, Cell>() : parent.children;

            this.owner = owner == null ? this : owner;
            children = new SortedList<ushort, Cell>();

            neighbors [pos.index] = this;
//            neighborsBinaryGrid.Set(pos.x, pos.y, pos.z);
            if (parent != null)
                parent.childrenBinaryGrid.Set(pos.x, pos.y, pos.z);

            AddNeighbors();
            AddToNeighbors();
        }
Ejemplo n.º 3
0
        public ChunkCell(CellPos pos, Cell parent, object owner) : base(pos, parent, owner)
        {
            childrenOpacityBinaryGreed = new BinaryGrid((byte)Pos.WIDTH, (byte)Pos.HEIGHT);
            childrenLightsTypes = new Dictionary<byte, LightType>();

            if (neighborsArray == null)
                neighborsArray = new ChunkCell[27];
        }
Ejemplo n.º 4
0
        BChunkData GetBChunkData(Cell cell)
        {
            var chunkData = new BChunkData();
            var bChunk = cell.owner as BChunk;
            var blocks = bChunk.blocks;

            chunkData.index = cell.pos.index;

            var blockIndex = new ushort[blocks.Count];
            var blockType = new ushort[blocks.Count];

            for (int i = 0; i < blocks.Count; i++)
            {
                var block = blocks.Values [i];

                blockIndex [i] = block.pos.index;
                blockType [i] = block.type;
            }

            chunkData.blockType = blockType;
            chunkData.blockIndex = blockIndex;


            return chunkData;
        }
Ejemplo n.º 5
0
        protected virtual void AddNeighbors()
        {
            var x = pos.x;
            var y = pos.y;
            var z = pos.z;

            if (pos.edge)
            {
                if (z == Pos.WIDTH - 1)
                {
                    if (parent != null && parent.back != null)
                        back = parent.back.FindCellInChildren(x, y, 0, pos.indexBack);
                    else
                        back = null;
                } else
                    back = FindCellInNeighbours(x, y, (byte)(z + 1), pos.indexBack);

                if (z == 0)
                {
                    if (parent != null && parent.front != null)
                        front = parent.front.FindCellInChildren(x, y, Pos.WIDTH - 1, pos.indexFront);
                    else
                        front = null;
                } else
                    front = FindCellInNeighbours(x, y, (byte)(z - 1), pos.indexFront); 

                if (y == Pos.HEIGHT - 1)
                {
                    if (parent != null && parent.top != null)
                        top = parent.top.FindCellInChildren(x, 0, z, pos.indexTop);
                    else
                        top = null;
                } else
                    top = FindCellInNeighbours(x, (byte)(y + 1), z, pos.indexTop); 

                if (y == 0)
                {
                    if (parent != null && parent.bottom != null)
                        bottom = parent.bottom.FindCellInChildren(x, Pos.HEIGHT - 1, z, pos.indexBottom);
                    else
                        bottom = null;
                } else
                    bottom = FindCellInNeighbours(x, (byte)(y - 1), z, pos.indexBottom); 

                if (x == 0)
                {
                    if (parent != null && parent.left != null)
                        left = parent.left.FindCellInChildren(Pos.WIDTH - 1, y, z, pos.indexLeft);
                    else
                        left = null;
                } else
                    left = FindCellInNeighbours((byte)(x - 1), y, z, pos.indexLeft); 

                if (x == Pos.WIDTH - 1)
                {
                    if (parent != null && parent.right != null)
                        right = parent.right.FindCellInChildren(0, y, z, pos.indexRight);
                    else
                        right = null;
                } else
                    right = FindCellInNeighbours((byte)(x + 1), y, z, pos.indexRight); 

            } else
            {
                back = FindCellInNeighbours(x, y, (byte)(z + 1), pos.indexBack);
                front = FindCellInNeighbours(x, y, (byte)(z - 1), pos.indexFront); 
                top = FindCellInNeighbours(x, (byte)(y + 1), z, pos.indexTop); 
                bottom = FindCellInNeighbours(x, (byte)(y - 1), z, pos.indexBottom); 
                left = FindCellInNeighbours((byte)(x - 1), y, z, pos.indexLeft); 
                right = FindCellInNeighbours((byte)(x + 1), y, z, pos.indexRight); 
            }
        }