public LSystemStructureTreeElement(
            LinkedFileSet sourceFileSet,
            SymbolString <float> symbols,
            int indexInSymbols,
            int branchSymbolIndex = -1)
        {
            symbol     = symbols[indexInSymbols];
            parameters = symbols.parameters.AsArray(indexInSymbols);


            var symbolDefinition = sourceFileSet.GetLeafMostSymbolDefinition(symbol);

            var builder = new StringBuilder();

            builder.Append(symbolDefinition.characterInSourceFile);
            if (!"[]".Contains(symbolDefinition.characterInSourceFile))
            {
                symbols.WriteParamString(indexInSymbols, builder);
                builder.Append(" : ");
                builder.Append(Path.GetFileName(symbolDefinition.sourceFileDefinition));
            }
            displayName = builder.ToString();

            if (branchSymbolIndex != -1)
            {
                id = -branchSymbolIndex - 1;
            }
            else
            {
                id = indexInSymbols;
            }
        }
示例#2
0
        public void LoadFromFilePath(string filePath)
        {
            if (!string.IsNullOrWhiteSpace(filePath))
            {
                var linker = new FileLinker(new FileSystemFileProvider());
                linkedFiles = linker.LinkFiles(filePath);

                // compile the system right away and throw it out to catch any compile-time errors
                this.CompileToCached();
                compiledSystem?.Dispose();
                compiledSystem = null;
            }
        }
        public TurtleInterpretor(
            List <TurtleOperationSet> operationSets,
            TurtleState defaultState,
            LinkedFileSet linkedFiles,
            CustomRuleSymbols customSymbols,
            OrganVolumetricWorld volumetricWorld,
            VoxelCapReachedTimestampEffect damageCapFlags,
            char startChar = '[', char endChar = ']')
        {
            foreach (var operationSet in operationSets)
            {
                operationSet.InternalCacheOperations();
            }

            var totalRequirements = operationSets.Select(x => x.DataReqs).Aggregate(new TurtleDataRequirements(), (agg, req) => agg + req);
            var nativeData        = new NativeTurtleData(totalRequirements);
            var nativeWriter      = new TurtleNativeDataWriter();

            foreach (var operationSet in operationSets)
            {
                operationSet.WriteIntoNativeData(nativeData, nativeWriter);
            }

            submeshMaterials = nativeWriter.materialsInOrder.ToArray();

            nativeData.operationsByKey = new NativeHashMap <int, TurtleOperation>(nativeWriter.operators.Count(), Allocator.Persistent);
            foreach (var ops in nativeWriter.operators)
            {
                var realSymbol = linkedFiles.GetSymbolFromRoot(ops.characterInRootFile);
                nativeData.operationsByKey[realSymbol] = ops.operation;
            }

            branchStartChar    = linkedFiles.GetSymbolFromRoot(startChar);
            branchEndChar      = linkedFiles.GetSymbolFromRoot(endChar);
            this.customSymbols = customSymbols;


            nativeDataTracker = new DependencyTracker <NativeTurtleData>(nativeData);
            this.defaultState = defaultState;

            this.volumetricWorld = volumetricWorld;
            this.damageCapFlags  = damageCapFlags;
            RefreshVolumetricWriters();
        }
        public static TreeViewItem ConstructTreeFromString(
            LinkedFileSet sourceFileSet,
            SymbolString <float> systemState,
            ISet <int> includeSymbols,
            int branchStartChar,
            int branchEndChar,
            int branchSymbolMaxBranchingFactorAsPowerOf2 = 4)
        {
            var root = new TreeViewItem {
                id = -1, depth = -1, displayName = "Root"
            };

            int indexInString = 0;

            for (;
                 indexInString < systemState.Length && !includeSymbols.Contains(systemState[indexInString]);
                 indexInString++)
            {
            }
            if (indexInString >= systemState.Length)
            {
                return(null);
            }


            var currentState = new TreeConstructingState
            {
                indexInString    = indexInString,
                currentParent    = root,
                branchingIndexer = 0,
            };
            var stateStack = new Stack <TreeConstructingState>();


            for (;
                 indexInString < systemState.Length;
                 indexInString++)
            {
                var symbol = systemState[indexInString];
                if (!includeSymbols.Contains(symbol))
                {
                    continue;
                }
                if (symbol == branchStartChar)
                {
                    var branchBitDepth = stateStack.Count * branchSymbolMaxBranchingFactorAsPowerOf2;
                    var nextBranchAdd  = 1 << branchBitDepth;
                    currentState.branchingIndexer += nextBranchAdd;

                    var newBranchState = new TreeConstructingState
                    {
                        indexInString = indexInString,
                        treeElement   = new LSystemStructureTreeElement(
                            sourceFileSet,
                            systemState,
                            indexInString,
                            currentState.branchingIndexer),
                        currentParent    = currentState.currentParent,
                        branchingIndexer = currentState.branchingIndexer
                    };
                    currentState.currentParent.AddChild(newBranchState.treeElement);
                    currentState = newBranchState;

                    stateStack.Push(currentState);
                    currentState.currentParent = currentState.treeElement;
                    continue;
                }
                if (symbol == branchEndChar)
                {
                    if (stateStack.Count <= 0)
                    {
                        Debug.LogWarning($"Too many branch end characters. aborting debug at index {indexInString}");
                        Debug.Log(systemState);
                        break;
                    }
                    currentState = stateStack.Pop();
                    continue;
                }
                var newState = new TreeConstructingState
                {
                    indexInString = indexInString,
                    treeElement   = new LSystemStructureTreeElement(
                        sourceFileSet,
                        systemState,
                        indexInString),
                    currentParent    = currentState.currentParent,
                    branchingIndexer = currentState.branchingIndexer
                };
                currentState.currentParent.AddChild(newState.treeElement);
                currentState = newState;
            }

            RemoveEmptyBranches(root, branchStartChar);

            return(root);
        }