public void Execute(int indexInSymbols) { var matchSingleton = matchSingletonData[indexInSymbols]; var symbol = sourceData.symbols[indexInSymbols]; if (matchSingleton.isTrivial) { var targetIndex = matchSingleton.replacementSymbolIndexing.index; // check for custom rules if (customSymbols.hasDiffusion && !customSymbols.independentDiffusionUpdate) { // let the diffusion library handle these updates. only if diffusion is happening in parallel if (symbol == customSymbols.diffusionNode || symbol == customSymbols.diffusionAmount) { return; } } // match is trivial. just copy the existing symbol and parameters over, nothing else. targetData.symbols[targetIndex] = symbol; var sourceParamIndexer = sourceData.parameters[indexInSymbols]; var targetDataIndexer = new JaggedIndexing { index = matchSingleton.replacementParameterIndexing.index, length = sourceParamIndexer.length }; targetData.parameters[targetIndex] = targetDataIndexer; // when trivial, copy out of the source param array directly. As opposed to reading parameters out of the parameterMatchMemory when evaluating // a non-trivial match for (int i = 0; i < sourceParamIndexer.length; i++) { targetData.parameters[targetDataIndexer, i] = sourceData.parameters[sourceParamIndexer, i]; } return; } if (!blittableRulesByTargetSymbol.TryGetValue(symbol, out var ruleList) || ruleList.length <= 0) { //throw new System.Exception(LSystemMatchErrorCode.TRIVIAL_SYMBOL_NOT_INDICATED_AT_REPLACEMENT_TIME.ToString()); return; } var rule = blittableRulesByTargetSymbol[ruleList, matchSingleton.matchedRuleIndexInPossible]; rule.WriteReplacementSymbols( globalParametersArray, parameterMatchMemory, targetData, matchSingleton, globalOperatorData, replacementSymbolData, outcomeData, structExpressionSpace ); }
private void ExecuteAtIndex( int indexInSymbols, TmpNativeStack <SymbolStringBranchingCache.BranchEventData> helperStack, ref Unity.Mathematics.Random random) { var matchSingleton = matchSingletonData[indexInSymbols]; if (matchSingleton.isTrivial) { // if match is trivial, then no parameters are captured. the rest of the algo will read directly from the source index // and no transformation will take place. return; } var symbol = sourceData.symbols[indexInSymbols]; if (!blittableRulesByTargetSymbol.TryGetValue(symbol, out var ruleIndexing) || ruleIndexing.length <= 0) { matchSingleton.errorCode = LSystemMatchErrorCode.TRIVIAL_SYMBOL_NOT_INDICATED_AT_MATCH_TIME; matchSingletonData[indexInSymbols] = matchSingleton; return; } var anyRuleMatched = false; var currentIndexInParameterMemory = matchSingleton.tmpParameterMemorySpace.index; for (byte i = 0; i < ruleIndexing.length; i++) { var rule = blittableRulesByTargetSymbol[ruleIndexing, i]; var success = rule.PreMatchCapturedParametersWithoutConditional( branchingCache, sourceData, indexInSymbols, tmpParameterMemory, currentIndexInParameterMemory, ref matchSingleton, helperStack, globalParams, globalOperatorData, ref random, outcomes ); if (success) { anyRuleMatched = true; matchSingleton.matchedRuleIndexInPossible = i; break; } } if (anyRuleMatched == false) { matchSingleton.isTrivial = true; } matchSingletonData[indexInSymbols] = matchSingleton; }