当前位置: 首页>>代码示例>>C#>>正文


C# IDefinitionManager.GetBlockDefinitions方法代码示例

本文整理汇总了C#中IDefinitionManager.GetBlockDefinitions方法的典型用法代码示例。如果您正苦于以下问题:C# IDefinitionManager.GetBlockDefinitions方法的具体用法?C# IDefinitionManager.GetBlockDefinitions怎么用?C# IDefinitionManager.GetBlockDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDefinitionManager的用法示例。


在下文中一共展示了IDefinitionManager.GetBlockDefinitions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize

        /// <summary>
        /// Deserialisiert die Chunksäule aus dem angegebenen Stream.
        /// </summary>
        /// <param name="stream">Quellstream</param>
        /// <param name="definitionManager">Der verwendete DefinitionManager</param>
        /// <param name="columnIndex">Die Position der Säule</param>
        /// <param name="planetId">Der Index des Planeten</param>
        public void Deserialize(Stream stream, IDefinitionManager definitionManager, int planetId, Index2 columnIndex)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                bool longIndex = br.ReadByte() > 0;

                // Phase 1 (Column Meta: Heightmap, populated, chunkcount)
                Chunks = new Chunk[br.ReadByte()]; // Chunk Count
                Planet = planetId;
                Index = columnIndex;

                Populated = br.ReadBoolean(); // Populated
                for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) // Heightmap
                    for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
                        Heights[x, y] = br.ReadUInt16();

                int[] counter = new int[Chunks.Length];
                for (int i = 0; i < Chunks.Length; i++) // ChangeCounter
                    counter[i] = br.ReadInt32();

                // Phase 2 (Block Definitionen)
                List<IBlockDefinition> types = new List<IBlockDefinition>();
                Dictionary<ushort, ushort> map = new Dictionary<ushort, ushort>();

                int typecount = longIndex ? br.ReadUInt16() : br.ReadByte();
                for (int i = 0; i < typecount; i++)
                {
                    string typeName = br.ReadString();
                    IBlockDefinition[] definitions = definitionManager.GetBlockDefinitions().ToArray();
                    var blockDefinition = definitions.FirstOrDefault(d => d.GetType().FullName == typeName);
                    types.Add(blockDefinition);

                    map.Add((ushort)types.Count, (ushort)(Array.IndexOf(definitions, blockDefinition) + 1));
                }

                // Phase 3 (Chunk Infos)
                for (int c = 0; c < Chunks.Length; c++)
                {
                    IChunk chunk = Chunks[c] = new Chunk(new Index3(columnIndex, c), planetId);
                    for (int i = 0; i < chunk.Blocks.Length; i++)
                    {
                        ushort typeIndex = longIndex ? br.ReadUInt16() : br.ReadByte();
                        chunk.MetaData[i] = 0;
                        if (typeIndex > 0)
                        {
                            chunk.Blocks[i] = map[typeIndex];

                            var definition = definitionManager.GetBlockDefinitionByIndex(map[typeIndex]);
                            if (definition.HasMetaData)
                                chunk.MetaData[i] = br.ReadInt32();
                        }
                    }
                    chunk.ChangeCounter = counter[c];
                }
            }
        }
开发者ID:reicheltp,项目名称:octoawesome,代码行数:63,代码来源:ChunkColumn.cs


注:本文中的IDefinitionManager.GetBlockDefinitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。