Exemplo n.º 1
0
            public void WriteReplacementSymbols(
                NativeArray <float> globalParameters,
                NativeArray <float> paramTempMemorySpace,
                SymbolString <float> target,
                LSystemSingleSymbolMatchData matchSingletonData,
                NativeArray <OperatorDefinition> globalOperatorData,
                NativeArray <ReplacementSymbolGenerator.Blittable> replacementSymbolSpace,
                NativeArray <RuleOutcome.Blittable> ruleOutcomeMemorySpace,
                NativeArray <StructExpression> structExpressionSpace)
            {
                var selectedReplacementPattern = matchSingletonData.selectedReplacementPattern;

                var matchedParametersIndexing    = matchSingletonData.tmpParameterMemorySpace;
                var replacementSymbolsIndexing   = matchSingletonData.replacementSymbolIndexing;
                var replacementParameterIndexing = matchSingletonData.replacementParameterIndexing;

                var orderedMatchedParameters = new NativeArray <float>(globalParameters.Length + matchedParametersIndexing.length, Allocator.Temp);

                for (int i = 0; i < globalParameters.Length; i++)
                {
                    orderedMatchedParameters[i] = globalParameters[i];
                }
                for (int i = 0; i < matchedParametersIndexing.length; i++)
                {
                    orderedMatchedParameters[globalParameters.Length + i] = paramTempMemorySpace[matchedParametersIndexing.index + i];
                }
                var outcome = ruleOutcomeMemorySpace[selectedReplacementPattern + possibleOutcomeIndexing.index];

                outcome.WriteReplacement(
                    orderedMatchedParameters,
                    new JaggedIndexing
                {
                    index  = 0,
                    length = (ushort)orderedMatchedParameters.Length
                },
                    globalOperatorData,
                    target,
                    replacementSymbolSpace,
                    structExpressionSpace,
                    replacementSymbolsIndexing.index,
                    replacementParameterIndexing.index);
            }
Exemplo n.º 2
0
            public bool PreMatchCapturedParametersWithoutConditional(
                SymbolStringBranchingCache branchingCache,
                SymbolString <float> source,
                int indexInSymbols,
                NativeArray <float> parameterMemory,
                int startIndexInParameterMemory,
                ref LSystemSingleSymbolMatchData matchSingletonData,
                TmpNativeStack <SymbolStringBranchingCache.BranchEventData> helperStack,
                NativeArray <float> globalParams,
                NativeArray <OperatorDefinition> globalOperatorData,
                ref Unity.Mathematics.Random random,
                NativeArray <RuleOutcome.Blittable> outcomes)
            {
                var target = targetSymbolWithParameters;

                // parameters
                byte matchedParameterNum = 0;

                // context match
                if (contextPrefix.IsValid && contextPrefix.graphNodeMemSpace.length > 0)
                {
                    var backwardsMatchMatches = branchingCache.MatchesBackwards(
                        branchingCache.includeSymbols[ruleGroupIndex],
                        indexInSymbols,
                        contextPrefix,
                        source,
                        startIndexInParameterMemory + matchedParameterNum,
                        parameterMemory,
                        out var copiedParameters
                        );
                    if (!backwardsMatchMatches)
                    {
                        return(false);
                    }
                    matchedParameterNum += copiedParameters;
                }

                var coreParametersIndexing = source.parameters[indexInSymbols];

                if (coreParametersIndexing.length != target.parameterLength)
                {
                    return(false);
                }
                if (coreParametersIndexing.length > 0)
                {
                    for (int i = 0; i < coreParametersIndexing.length; i++)
                    {
                        var paramValue = source.parameters[coreParametersIndexing, i];

                        parameterMemory[startIndexInParameterMemory + matchedParameterNum] = paramValue;
                        matchedParameterNum++;
                    }
                }

                if (contextSuffix.IsCreated && contextSuffix.graphNodeMemSpace.length > 0)
                {
                    var forwardMatch = branchingCache.MatchesForward(
                        branchingCache.includeSymbols[ruleGroupIndex],
                        indexInSymbols,
                        contextSuffix,
                        source,
                        startIndexInParameterMemory + matchedParameterNum,
                        parameterMemory,
                        out var copiedParameters,
                        helperStack);
                    if (!forwardMatch)
                    {
                        return(false);
                    }
                    matchedParameterNum += copiedParameters;
                }

                matchSingletonData.tmpParameterMemorySpace = new JaggedIndexing
                {
                    index  = startIndexInParameterMemory,
                    length = matchedParameterNum
                };
                if (conditional.IsValid)
                {
                    var conditionalMatch = conditional.EvaluateExpression(
                        globalParams,
                        new JaggedIndexing {
                        index = 0, length = (ushort)globalParams.Length
                    },
                        parameterMemory,
                        matchSingletonData.tmpParameterMemorySpace,
                        globalOperatorData) > 0;
                    if (!conditionalMatch)
                    {
                        return(false);
                    }
                }

                matchSingletonData.selectedReplacementPattern = SelectOutcomeIndex(ref random, outcomes, possibleOutcomeIndexing);
                var outcomeObject = outcomes[matchSingletonData.selectedReplacementPattern + possibleOutcomeIndexing.index];


                matchSingletonData.replacementSymbolIndexing    = JaggedIndexing.GetWithOnlyLength(outcomeObject.replacementSymbolSize);
                matchSingletonData.replacementParameterIndexing = JaggedIndexing.GetWithOnlyLength(outcomeObject.replacementParameterCount);


                return(true);
            }