Exemplo n.º 1
0
        public BChunk GetChunk(Pos posChunk)
        {
            var cell = this.cell.neighbors.Values [posChunk.index];

            return cell == null ? null : cell.owner as BChunk;

//            return cell.cells [posChunk.index].owner as BChunk;
        }
Exemplo n.º 2
0
 public void AddLight(Light light, Pos pos)
 {
     if (!childrenLightsTypes.ContainsKey(light.type))
     {
         var lightType = new LightType(light.type, light.color32, light.distance);
         lightType.binaryGrid.Set(pos.x, pos.y, pos.z);
         childrenLightsTypes.Add(light.type, lightType);
     } else
     {
         childrenLightsTypes [light.type].binaryGrid.Set(pos.x, pos.y, pos.z);  
     }
 }
Exemplo n.º 3
0
        //       public object MyProperty { get; }

        public Block(Pos pos, ChunkCell parent, ushort type, ushort textureIndex, bool opacity)
        {
            this.pos = pos;
            this.parent = parent;

            this.type = type;
            this.textureIndex = textureIndex;

            this.opacity = opacity;

            parent.childrenBinaryGrid.Set(pos.x, pos.y, pos.z);

            if (opacity)
                parent.childrenOpacityBinaryGreed.Set(pos.x, pos.y, pos.z);
            
            blockFaces = new BlockFaces();
        }
Exemplo n.º 4
0
        //      [SerializeField]
        //        Transform pointLightWhite;

        /*
        public void UpdatePosChunk()
        {
            //          var position = transform.position;

//            posChunk = new PosChunk((int)position.x / SIZE, (int)position.y / SIZE, (int)position.z / SIZE);
            //posChunk = new Pos((int)position.x / WIDTH, (int)position.y / HEIGHT, (int)position.z / WIDTH);

            //chunkNeighbors = new ChunkNeighbors(posChunk, bChunks.bChunksList);
        }
        */
            

        /*
        public void AddBlock(Block block, bool update)
        {
            blocks [block.posBlock.index] = block;

            if (update)
            {
                block.Update();
                //                block.UpdateNeighbors();
                //              block.UpdateFacesCount();
                UpdateMesh(false);
            }
        }
        */

        public Block AddBlock(Pos pos, ushort type, bool update)
        {
            //     Debug.Log("AddBlock");
            //   Debug.Log("pos:" + pos);
            // Debug.Log("type:" + type);




//            return block;
            //cell.cells


            // FOR DEBUG!!! It's not necessary!!!
            if (!blocks.ContainsKey(pos.index))
            {
                var block = GetBlockByType(type, pos, cell);

                blocks.Add(pos.index, block);

                //cell.neighborsBinaryGreed.Set(pos.x, pos.y, pos.z);

                if (update)
                {
//                    block.UpdateNeighbors();
                    //block.AddToNeighbors();
                    //      block.UpdateFacesCount();

                    UpdateMesh();
                }


                return block;
            }

            return null;

            //       Log.Add("AddBlock, blocks [block.posBlock.index]:" + blocks.Count.ToString());
        }
Exemplo n.º 5
0
        Block GetBlockByType(ushort type, Pos pos, ChunkCell parent)//, ushort textureIndex)
        {
            switch (type)
            {
                case 0:
                    return new B0(pos, parent, 0, 0, true);
                case 1:
                    return new B1(pos, parent, 1, 1, false);
                case 2:
                    return new Block(pos, parent, 2, 2, false);
                case 3:
                    return new Block(pos, parent, 3, 3, true);
                case 4:
                    return new Block(pos, parent, 4, 4, false);
                case 5:
                    return new BlockLight(pos, parent, 5, 5, new Light(0, new Color32(14, 14, 14, 255), 3));
                case 6:
                    return new BlockLight(pos, parent, 5, 5, new Light(1, new Color32(24, 0, 0, 255), 3));
            }

            return null;//new Block(pos, parent, type, false);
            
            //Type[] bs = { B0, B1 };

//            return new bs[type](pos, parent, type);
            //          Type t = Type.GetType("B" + type.ToString());
//            return t != null ? Activator.CreateInstance(t, pos, parent, type) as Block : null;

        }
Exemplo n.º 6
0
        void GetNewBChunkAndNewPosBlock(Pos posBlock, Vector3 worldNormal, ref BChunk newBChunk, ref Pos newPosBlock, ref bool isNewChunk)
        {
            /*
            if (posBlock.edge)
            {
                if (worldNormal.x == -1)
                {
                    if (posBlock.x == 0)
                    {
                        newPosBlock = new Pos(BChunk.WIDTH - 1, posBlock.y, posBlock.z);
                        if (chunkNeighbors.left != null)
                            newBChunk = chunkNeighbors.left;
                        else
                        {
                            newBChunk = bChunks.AddChunk(new Pos(posChunk.x - 1, posChunk.y, posChunk.z));
                            isNewChunk = true;
                        }
                        return;
                    } else
                    {
                        newPosBlock = new Pos(posBlock.x - 1, posBlock.y, posBlock.z);
                        return;
                    }
                } else if (worldNormal.x == 1)
                {
                    if (posBlock.x == BChunks.WIDTH - 1)
                    {
                        newPosBlock = new Pos(0, posBlock.y, posBlock.z);

                        if (chunkNeighbors.right != null)
                            newBChunk = chunkNeighbors.right;
                        else
                        {
                            newBChunk = bChunks.AddChunk(new Pos(posChunk.x + 1, posChunk.y, posChunk.z));
                            isNewChunk = true;
                        }
                        return;
                    } else
                    {
                        newPosBlock = new Pos(posBlock.x + 1, posBlock.y, posBlock.z);
                        return;
                    }
                }



                return;
            } else
            {
                newPosBlock = new Pos(posBlock.y + (int)worldNormal.x, posBlock.y + (int)worldNormal.y, posBlock.z + (int)worldNormal.z);
                return;
            }
            */
        }
Exemplo n.º 7
0
        BChunk AddChunk(Pos posChunk)
        {
            // var chunk = new Chink;

            return null;
//            return new BChunk();
        }
Exemplo n.º 8
0
Arquivo: B0.cs Projeto: nauroman/Cells
 public B0(Pos pos, ChunkCell parent, ushort type, ushort textureIndex, bool opacity) : base(pos, parent, type, textureIndex, opacity)
 {
 }
Exemplo n.º 9
0
        public bool IsAnyXSet(Pos pos)
        {
            ushort i = (ushort)(pos.y * width + pos.z);

            return (grid [i]) != 0;
        }
Exemplo n.º 10
0
        /*
        public bool IsAnyYSet(Pos pos)
        {
            ushort i = (ushort)(pos.y * width + pos.z);

            return (grid [i]) != 0;
        }
        */

        public bool IsSet(Pos pos)
        {
            ushort i = (ushort)(pos.y * width + pos.z);

            return (grid [i] & bitSet [pos.x]) != 0;
        }
Exemplo n.º 11
0
        Block AddBlock(BChunk bChunk, Pos pos, ushort type)
        {
            var block = bChunk.AddBlock(pos, type, false);

            return block;
        }
Exemplo n.º 12
0
        public BlockLight(Pos pos, ChunkCell parent, ushort type, ushort textureIndex, Light light) : base(pos, parent, type, textureIndex, false)
        {
            this.light = light;

            parent.AddLight(light, pos);
        }