Пример #1
0
        void LayoutTree(Module module, Dictionary <Module, ModuleData> map, int row, int startColumn = 0)
        {
            var nc = map[module].Control;

            tableLayoutPanel1.Controls.Add(nc);
            int column = startColumn;

            tableLayoutPanel1.SetCellPosition(nc, new TableLayoutPanelCellPosition(column, row));

            int xSpan = map[module].MaxSources;

            if (xSpan == 0)
            {
                xSpan = 1;
            }

            tableLayoutPanel1.SetColumnSpan(nc, xSpan);

            int totalWidth = tableLayoutPanel1.GetColumnWidths().Skip(startColumn).Take(xSpan).Sum();

            nc.Anchor = AnchorStyles.None;

            foreach (var source in module.SourceModules)
            {
                LayoutTree(source, map, row - 1, startColumn);

                startColumn += map[source].MaxSources;
            }
        }
        public void BuildOutputModules()
        {
            //Create Modules
            outputModules = new List <SharpNoise.Modules.Module>();

            foreach (Data.NodeData nodeData in noiseAsset.terrainOutput)
            {
                SharpNoise.Modules.Module module = NodeManager.Instance.InstantiateGenericModule(nodeData);
                module.SetData(nodeData);
                outputModules.Add(module);
            }

            //Set Source Modules
            foreach (SharpNoise.Modules.Module module in outputModules)
            {
                SharpNoise.Modules.Module[] sourceModules = new SharpNoise.Modules.Module[4];

                foreach (Data.ConnectionData connectionData in noiseAsset.connections)
                {
                    if (connectionData.inputNodeID == module.NodeId)
                    {
                        //Assign to index of connectorID
                        foreach (SharpNoise.Modules.Module sourceModule in outputModules)
                        {
                            if (sourceModule.NodeId == connectionData.outputNodeID)
                            {
                                sourceModules[connectionData.inputConnectorID] = sourceModule;
                            }
                        }
                    }
                }

                module.SetSourceModules(sourceModules);
            }
        }
Пример #3
0
        int WalkTree(Module module, Dictionary <Module, ModuleData> map, int depth = 0)
        {
            int maxChildSources = 0;
            int childDepth      = 0;

            foreach (var source in module.SourceModules)
            {
                int d = WalkTree(source, map, depth + 1);

                if (d > childDepth)
                {
                    childDepth = d;
                }

                maxChildSources += map[source].MaxSources;
            }

            var nc = new NoiseControl()
            {
                Module = module,
            };

            map[module] = new ModuleData()
            {
                MaxSources = Math.Max(maxChildSources, 1),
                Depth      = depth,
                Control    = nc,
            };

            m_controls.Add(nc);

            return(childDepth + 1);
        }
Пример #4
0
        void LayoutTree(Module module, Dictionary<Module, ModuleData> map, int row, int startColumn = 0)
        {
            var nc = map[module].Control;

            tableLayoutPanel1.Controls.Add(nc);
            int column = startColumn;
            tableLayoutPanel1.SetCellPosition(nc, new TableLayoutPanelCellPosition(column, row));

            int xSpan = map[module].MaxSources;
            if (xSpan == 0)
                xSpan = 1;

            tableLayoutPanel1.SetColumnSpan(nc, xSpan);

            int totalWidth = tableLayoutPanel1.GetColumnWidths().Skip(startColumn).Take(xSpan).Sum();

            nc.Anchor = AnchorStyles.None;

            foreach (var source in module.SourceModules)
            {
                LayoutTree(source, map, row - 1, startColumn);

                startColumn += map[source].MaxSources;
            }
        }
Пример #5
0
        public SharpNoise.Modules.Module InstantiateGenericModule(Data.NodeData nodeData)
        {
            //Create instance of selected node type
            SharpNoise.Modules.Module module = (SharpNoise.Modules.Module)Activator.CreateInstance(Type.GetType(nodeData.moduleType));
            module.SetData(nodeData);

            return(module);
        }
        // Start is called before the first frame update
        void Start()
        {
            heightStrength = noiseAsset.globalHeightStrength;

            BuildOutputModules();

            //Find module at end of output chain
            foreach (SharpNoise.Modules.Module module in outputModules)
            {
                if (module.NodeId == noiseAsset.terrainOutputLastID)
                {
                    lastOutputModule = module;
                }
            }

            CreateTerrain();
            SetHeights();
        }
Пример #7
0
            public SharpNoise.Modules.Module[] NullToConstInputModules()
            {
                SharpNoise.Modules.Module[] modules = new SharpNoise.Modules.Module[inputNodes.Length];

                for (int i = 0; i < inputNodes.Length; i++)
                {
                    if (inputNodes[i] == null)
                    {
                        modules[i] = new SharpNoise.Modules.Constant();
                    }

                    else
                    {
                        modules[i] = inputNodes[i].OutputModule;
                    }
                }

                return(modules);
            }
Пример #8
0
        int WalkTree(Module module, Dictionary<Module, ModuleData> map, int depth = 0)
        {
            int maxChildSources = 0;
            int childDepth = 0;

            foreach (var source in module.SourceModules)
            {
                int d = WalkTree(source, map, depth + 1);

                if (d > childDepth)
                    childDepth = d;

                maxChildSources += map[source].MaxSources;
            }

            var nc = new NoiseControl()
            {
                Module = module,
            };

            map[module] = new ModuleData()
            {
                MaxSources = Math.Max(maxChildSources, 1),
                Depth = depth,
                Control = nc,
            };

            m_controls.Add(nc);

            return childDepth + 1;
        }