Esempio n. 1
0
        private void SetBlockFaces(BlockType blockType, int bx, int by, int bz, BlockType neighbourType, int nx, int ny, int nz, BlockFaceDirection bFace, BlockFaceDirection nFace)
        {
            if (neighbourType == BlockType.None)
            {
                // Bordering sky make face visible
                if (blockType != BlockType.None)
                {
                    if (blockType == BlockType.Water)
                    {
                        _world.AddWaterFace(bx, by, bz, bFace);
                    }
                    else
                    {
                        _world.AddSolidFace(bx, by, bz, bFace);
                    }
                }
            }
            else
            {
                if (neighbourType == BlockType.Water)
                {
                    if (blockType == BlockType.None)
                    {
                        if (blockType == BlockType.Water)
                        {
                            _world.AddWaterFace(bx, by, bz, bFace);
                        }
                        else
                        {
                            _world.AddSolidFace(bx, by, bz, bFace);
                        }
                    }
                    else if (blockType == BlockType.Water)
                    {
                        // Removed ajoining faces if both blocks are water
                        _world.RemoveWaterFace(bx, by, bz, bFace);
                        _world.RemoveWaterFace(nx, ny, nz, nFace);
                    }
                    else if (BlockInformation.IsModelBlock(blockType))
                    {
                        _world.AddModelFace(bx, by, bz, bFace);
                        _world.AddWaterFace(nx, ny, nz, nFace);
                    }
                    else
                    {
                        // Can always see face through water
                        if (blockType == BlockType.Water)
                        {
                            _world.AddWaterFace(bx, by, bz, bFace);
                        }
                        else
                        {
                            _world.AddSolidFace(bx, by, bz, bFace);
                        }
                        _world.RemoveWaterFace(nx, ny, nz, nFace);
                    }
                }
                else if (BlockInformation.IsModelBlock(neighbourType))
                {
                    if (blockType == BlockType.None)
                    {
                        _world.AddModelFace(nx, ny, nz, nFace);
                    }
                    else if (blockType == BlockType.Water)
                    {
                        // Can see through water
                        _world.AddWaterFace(bx, by, bz, bFace);
                        _world.AddModelFace(nx, ny, nz, nFace);
                    }
                    else if (BlockInformation.IsModelBlock(blockType))
                    {
                        // Can see through transparent
                        _world.AddModelFace(bx, by, bz, bFace);
                        _world.AddModelFace(nx, ny, nz, nFace);
                    }
                    else
                    {
                        // Can see  through transparent and note that neightbour face is occluded
                        _world.AddSolidFace(bx, by, bz, bFace);
                        _world.RemoveModelFace(nx, ny, nz, nFace);
                    }
                }
                else
                {
                    if (blockType == BlockType.None)
                    {
                        _world.AddSolidFace(nx, ny, nz, nFace);
                    }
                    else if (blockType == BlockType.Water)
                    {
                        // We can see it through water
                        if (bFace == BlockFaceDirection.YIncreasing)
                        {
                            _world.AddWaterFace(bx, by, bz, bFace);
                        }
                        else
                        {
                            _world.RemoveWaterFace(bx, by, bz, bFace);
                        }
                        _world.AddSolidFace(nx, ny, nz, nFace);
                    }
                    else if (BlockInformation.IsModelBlock(blockType))
                    {
                        // We can see neighbour face and note that block face is occluded
                        _world.RemoveModelFace(bx, by, bz, bFace);
                        _world.AddSolidFace(nx, ny, nz, nFace);
                    }
                    else
                    {
                        // Both faces hidden

                        _world.RemoveSolidFace(bx, by, bz, bFace);
                        _world.RemoveSolidFace(nx, ny, nz, nFace);
                    }
                }
            }
        }
Esempio n. 2
0
        public void BuildVertexBuffers()
        {
            //_solidVertexList.Clear();
            //_modelVertexList.Clear();
            //_waterVertexList.Clear();
            _solidVertexArray = new VertexPositionTextureShade[_solidFaceCount * 6];
            _modelVertexArray = new VertexPositionTextureShade[_modelFaceCount * 6];
            _waterVertexArray = new VertexPositionTextureShade[_waterFaceCount * 6];
            _solidIndex       = 0;
            _waterIndex       = 0;
            _modelIndex       = 0;
            for (int x = 0; x < WorldSettings.REGIONWIDTH; x++)
            {
                for (int y = 0; y < WorldSettings.REGIONHEIGHT; y++)
                {
                    for (int z = 0; z < WorldSettings.REGIONLENGTH; z++)
                    {
                        BlockType blockType = Blocks[x, y, z];
                        if (blockType != BlockType.None)
                        {
                            byte     faceInfo = _faceInfo[x, y, z];
                            Vector3i position = new Vector3i(_position.x + x, _position.y + y, _position.z + z);
                            if (blockType == BlockType.Water)
                            {
                                BuildBlockVertices(_waterVertexArray, Buffer.Water, blockType, faceInfo, position);
                            }
                            else if (BlockInformation.IsModelBlock(blockType))
                            {
                                BuildBlockVertices(_modelVertexArray, Buffer.Model, blockType, faceInfo, position);
                            }
                            else
                            {
                                BuildBlockVertices(_solidVertexArray, Buffer.Solid, blockType, faceInfo, position);
                            }
                        }
                    }
                }
            }
            if (_waterVertexArray.Length > 0)
            {
                _waterVertexBuffer = new VertexBuffer(_world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _waterVertexArray.Length, BufferUsage.WriteOnly);

                _waterVertexBuffer.SetData(_waterVertexArray);
            }
            else
            {
                _waterVertexBuffer = null;
            }
            if (_modelVertexArray.Length > 0)
            {
                _modelVertexBuffer = new VertexBuffer(_world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _modelVertexArray.Length, BufferUsage.WriteOnly);

                _modelVertexBuffer.SetData(_modelVertexArray);
            }
            else
            {
                _modelVertexBuffer = null;
            }
            if (_solidVertexArray.Length > 0)
            {
                _solidVertexBuffer = new VertexBuffer(
                    _world.Game.GraphicsDevice, typeof(VertexPositionTextureShade), _solidVertexArray.Length, BufferUsage.WriteOnly);

                _solidVertexBuffer.SetData(_solidVertexArray);
            }
            else
            {
                _solidVertexBuffer = null;
            }
        }