예제 #1
0
        public void AddBlock(VertexWithIndex data, bool bRebuildIfNeeded = false)
        {
            if (BlockCount >= TotalSize)
            {
                throw new InvalidOperationException("Chunk is full.");
            }

            Renderer.AddBlock(data, bRebuildIfNeeded);
        }
예제 #2
0
        public void SetBlockData(int index, VertexWithIndex data)
        {
            if (!Renderer.IsInitialized())
            {
                throw new InvalidOperationException("Renderer must be initialized with <see cref='BuildChunk' /> first.");
            }

            Renderer.SetBlock(data, index);
        }
예제 #3
0
        /// <summary>
        /// 添加一个Block
        /// </summary>
        /// <param name="block"></param>
        /// <param name="rebuildIfNeeded"></param>
        /// <returns></returns>
        public int AddBlock(VertexWithIndex block, bool bRebuildIfNeeded = false)
        {
            if (m_nFreeBlocks == 0)
            {
                if (bRebuildIfNeeded)
                {
                    RebuildInternal(m_nBlockCount + 1);
                }
                else
                {
                    throw new InvalidOperationException("The buffer cannot hold any more blocks, rebuild the buffer");
                }
            }
            var index = m_nBlockCount;

            SetBlock(block, index);
            m_nBlockCount++;

            return(index);
        }
예제 #4
0
        protected override Chunk Read(ContentReader reader, Chunk existingInstance)
        {
            var gds = (IGraphicsDeviceService)reader.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));
            var gd  = gds.GraphicsDevice;

            var sizeX = reader.ReadInt32();
            var sizeY = reader.ReadInt32();
            var sizeZ = reader.ReadInt32();
            var pos   = reader.ReadVector3();

            var count       = reader.ReadInt32();
            var activeCount = reader.ReadInt32();
            var blockData   = new VertexWithIndex[count];

            for (var i = 0; i < count; i++)
            {
                var x     = reader.ReadByte();
                var y     = reader.ReadByte();
                var z     = reader.ReadByte();
                var index = reader.ReadByte();
                blockData[i] = new VertexWithIndex(x, y, z, index);
            }

            var palette = new Vector4[255];

            for (var i = 0; i < 255; i++)
            {
                palette[i] = reader.ReadColor().ToVector4();
            }

            var renderer = new PolygonChunkRenderer(gd, palette);
            var chunk    = new Chunk(renderer, pos, (byte)sizeX, (byte)sizeY, (byte)sizeZ);

            chunk.BuildChunk(blockData, activeCount);
            return(chunk);
        }
예제 #5
0
 public abstract void SetBlock(VertexWithIndex block, int index);
예제 #6
0
 /// <summary>
 /// 比较两个点
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 private bool Equals(VertexWithIndex other)
 {
     return(X == other.X && Y == other.Y && Z == other.Z && Index == other.Index);
 }
 public override void SetBlock(VertexWithIndex block, int index)
 {
     throw new NotImplementedException();
 }
예제 #8
0
 /// <summary>
 /// 移除一个Block
 /// </summary>
 /// <param name="block"></param>
 public void Remove(VertexWithIndex block)
 {
     Remove(block.X, block.Y, block.Z);
 }
예제 #9
0
 /// <summary>
 /// 添加一个Block
 /// </summary>
 /// <param name="block"></param>
 public virtual void Add(VertexWithIndex block)
 {
     Add(block.X, block.Y, block.Z, new BlockData(block.Index));
 }