コード例 #1
0
        /// <summary>
        /// Reads until the given number of matching nodes have been read.
        /// </summary>
        /// <param name="count">The maximum number of elements of the given type/parent to read.</param>
        /// <param name="type">The node type to break at.</param>
        /// <param name="parent">The minimum parent to break at.</param>
        /// <returns>The number of batch elements that have been read.</returns>
        public int StepBatch(int count, NodeType type, int parent = k_IgnoreParent)
        {
            if (m_Data->NodeLength < count)
            {
                UnsafeUtility.Free(m_Data->Nodes, m_Label);

                m_Data->NodeLength = count;
                m_Data->Nodes      = (int *)UnsafeUtility.Malloc(sizeof(int) * m_Data->NodeLength, 4, m_Label);
            }

            var output = new ParseJobOutput();

            new ParseJob
            {
                Output            = &output,
                Tokens            = m_Data->Tokenizer.Tokens,
                TokensLength      = m_Data->Tokenizer.TokenNextIndex,
                TokenNextIndex    = m_Data->TokenNextIndex,
                TokenParentIndex  = m_Data->TokenParentIndex,
                TargetNodeType    = type,
                TargetParentIndex = parent,
                TargetNodeCount   = count,
                Nodes             = m_Data->Nodes
            }
            .Run();

            m_Data->TokenNextIndex   = output.TokenNextIndex;
            m_Data->TokenParentIndex = output.TokenParentIndex;
            m_Data->NodeNextIndex    = output.NodeNextIndex;

            m_Data->NodeType = output.NodeType;

            return(output.NodeNextIndex);
        }
コード例 #2
0
        /// <summary>
        /// Reads until the given number of matching nodes have been read.
        /// </summary>
        /// <param name="count">The maximum number of elements of the given type/parent to read.</param>
        /// <param name="type">The node type to break at.</param>
        /// <param name="parent">The minimum parent to break at.</param>
        /// <returns>The number of batch elements that have been read.</returns>
        public unsafe int StepBatch(int count, NodeType type, int parent = k_IgnoreParent)
        {
            if (m_Nodes.Length < count)
            {
                m_Nodes.Dispose();
                m_Nodes = new NativeArray <int>(count, m_Label, NativeArrayOptions.UninitializedMemory);
            }

            var output = new ParseJobOutput();

            new ParseJob
            {
                Output            = &output,
                Tokens            = (Token *)m_Tokenizer.Tokens.GetUnsafeReadOnlyPtr(),
                TokensLength      = m_Tokenizer.TokenNextIndex,
                TokenNextIndex    = m_TokenNextIndex,
                TokenParentIndex  = m_TokenParentIndex,
                TargetNodeType    = type,
                TargetParentIndex = parent,
                TargetNodeCount   = count,
                Nodes             = (int *)m_Nodes.GetUnsafePtr()
            }
            .Run();

            m_TokenNextIndex   = output.TokenNextIndex;
            m_TokenParentIndex = output.TokenParentIndex;
            m_NodeNextIndex    = output.NodeNextIndex;

            NodeType = output.NodeType;

            return(output.NodeNextIndex);
        }