Ejemplo n.º 1
0
        /// <summary>
        /// Sets a group of blocks
        /// </summary>
        /// <param name="positions"></param>
        /// <param name="values"></param>
        /// <param name="tags"> </param>
        /// <param name="sourceDynamicId">Id of the entity that is responsible for the change</param>
        public override void SetBlocks(Vector3I[] positions, byte[] values, BlockTag[] tags = null, uint sourceDynamicId = 0)
        {
            lock (_syncRoot)
            {
                if (_blockBytes == null)
                {
                    _blockBytes = new byte[_chunkSize.X * _chunkSize.Y * _chunkSize.Z];
                }

                for (var i = 0; i < positions.Length; i++)
                {
                    _blockBytes[positions[i].X * _chunkSize.Y + positions[i].Y + positions[i].Z * _chunkSize.Y * _chunkSize.X] = values[i];
                    RefreshMetaData(ref positions[i], values[i]);
                }

                if (tags != null)
                {
                    for (var i = 0; i < positions.Length; i++)
                    {
                        SetTag(tags[i], positions[i]);
                    }
                }
            }

            if (_transaction)
            {
                lock (_transactionPositions)
                {
                    _transactionPositions.AddRange(positions);
                    _transactionValues.AddRange(values);
                    if (tags == null)
                    {
                        tags = new BlockTag[positions.Length];
                    }
                    _transactionTags.AddRange(tags);
                }
            }
            else
            {
                // notify everyone about block change
                OnBlockDataChanged(new ChunkDataProviderDataChangedEventArgs
                {
                    Count           = positions.Length,
                    Locations       = positions,
                    Bytes           = values,
                    Tags            = tags,
                    SourceDynamicId = sourceDynamicId
                });
            }
        }
Ejemplo n.º 2
0
 private void SetTag(BlockTag tag, Vector3I inChunkPosition)
 {
     lock (_syncRoot)
     {
         if (tag != null)
         {
             _tags[inChunkPosition] = (BlockTag)tag.Clone();
         }
         else
         {
             _tags.Remove(inChunkPosition);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes specidfied value to the current cursor position
        /// </summary>
        /// <param name="value"></param>
        /// <param name="tag"> </param>
        /// <param name="sourceDynamicId"></param>
        public void Write(byte value, BlockTag tag = null, uint sourceDynamicId = 0)
        {
            if (BeforeWrite != null)
            {
                OnBeforeWrite(new LandscapeCursorBeforeWriteEventArgs {
                    GlobalPosition  = GlobalPosition,
                    Value           = value,
                    BlockTag        = tag,
                    SourceDynamicId = sourceDynamicId == 0 ? OwnerDynamicId : sourceDynamicId
                });
            }

            _currentChunk.BlockData.SetBlock(_internalPosition, value, tag, sourceDynamicId == 0 ? OwnerDynamicId : sourceDynamicId);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets a single block into location specified
        /// </summary>
        /// <param name="inChunkPosition"></param>
        /// <param name="blockValue"></param>
        /// <param name="tag"></param>
        /// <param name="sourceDynamicId">Id of the entity that is responsible for the change</param>
        public override void SetBlock(Vector3I inChunkPosition, byte blockValue, BlockTag tag = null, uint sourceDynamicId = 0)
        {
            int index = ChunkCubes.Index(inChunkPosition.X + DataProviderUser.ChunkPositionBlockUnit.X,
                                         inChunkPosition.Y,
                                         inChunkPosition.Z + DataProviderUser.ChunkPositionBlockUnit.Y);

            ChunkCubes.Cubes[index] = new TerraCube(blockValue);

            SetTag(tag, inChunkPosition);

            RefreshMetaData(BlockHelper.ConvertToGlobal(new Vector3I(DataProviderUser.ChunkPositionBlockUnit.X, 0, DataProviderUser.ChunkPositionBlockUnit.Y), inChunkPosition), blockValue);

            OnBlockDataChanged(new ChunkDataProviderDataChangedEventArgs
            {
                Locations       = new[] { inChunkPosition },
                Bytes           = new[] { blockValue },
                Tags            = tag != null ? new[] { tag } : null,
                SourceDynamicId = sourceDynamicId
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets a single block into location specified
        /// </summary>
        /// <param name="inChunkPosition"></param>
        /// <param name="blockValue"></param>
        /// <param name="tag"></param>
        /// <param name="sourceDynamicId">Id of the entity that is responsible for the change</param>
        public override void SetBlock(Vector3I inChunkPosition, byte blockValue, BlockTag tag = null, uint sourceDynamicId = 0)
        {
            lock (_syncRoot)
            {
                if (_blockBytes == null)
                {
                    _blockBytes = new byte[_chunkSize.X * _chunkSize.Y * _chunkSize.Z];
                }

                _blockBytes[inChunkPosition.X * _chunkSize.Y + inChunkPosition.Y + inChunkPosition.Z * _chunkSize.Y * _chunkSize.X] = blockValue;
                RefreshMetaData(ref inChunkPosition, blockValue);
                SetTag(tag, inChunkPosition);
            }

            if (_transaction)
            {
                lock (_transactionPositions)
                {
                    _transactionPositions.Add(inChunkPosition);
                    _transactionValues.Add(blockValue);
                    _transactionTags.Add(tag);
                }
            }
            else
            {
                // notify everyone about block change
                OnBlockDataChanged(new ChunkDataProviderDataChangedEventArgs
                {
                    Count           = 1,
                    Locations       = new[] { inChunkPosition },
                    Bytes           = new[] { blockValue },
                    Tags            = tag != null ? new[] { tag } : null,
                    SourceDynamicId = sourceDynamicId
                });
            }
        }
Ejemplo n.º 6
0
 public abstract bool Equals(BlockTag tag);
Ejemplo n.º 7
0
 /// <summary>
 /// Sets a single block into location specified
 /// </summary>
 /// <param name="inChunkPosition"></param>
 /// <param name="blockValue"></param>
 /// <param name="tag"></param>
 /// <param name="sourceDynamicId">Id of the entity that is responsible for the change</param>
 public abstract void SetBlock(Vector3I inChunkPosition, byte blockValue, BlockTag tag = null, uint sourceDynamicId = 0);
Ejemplo n.º 8
0
 /// <summary>
 /// Gets a single block with tag (can be null)
 /// </summary>
 /// <param name="inChunkPosition"></param>
 /// <param name="blockValue"></param>
 /// <param name="tag"></param>
 public void GetBlockWithTag(Vector3I inChunkPosition, out byte blockValue, out BlockTag tag)
 {
     blockValue = GetBlock(inChunkPosition);
     tag        = GetTag(inChunkPosition);
 }