Example #1
0
            public static ComponentGraph FromComponents(IEnumerable <string> components, IDictionary <string, string> elements, IDictionary <string, ComponentGraph> modules)
            {
                ComponentGraph graph = new ComponentGraph();
                Dictionary <string, ComponentVertex> vertices = new Dictionary <string, ComponentVertex>();

                foreach (string component in components)
                {
                    IList <string> parts = ComponentGraph.SplitArchitecture(component, NetworkGraphBuilder.Splitter);
                    if (parts.Count >= 2 && parts.All(x => !string.IsNullOrEmpty(x)))
                    {
                        ComponentVertex sourceVertex = null;
                        ComponentGraph  sourceGraph  = null;

                        for (int i = 0, ii = parts.Count; i < ii; i++)
                        {
                            string         key         = parts[i];
                            ComponentGraph targetGraph = null;

                            if (key.First() == NetworkGraphBuilder.StartQualifier && key.Last() == NetworkGraphBuilder.EndQualifier)
                            {
                                targetGraph = NetworkGraphBuilder.ParseArchitecture(key.Substring(1, key.Length - 2), true);
                            }
                            else
                            {
                                ComponentGraph moduleGraph;
                                if (modules.TryGetValue(key, out moduleGraph))
                                {
                                    targetGraph = moduleGraph.Clone(true) as ComponentGraph;
                                }
                            }

                            if (targetGraph != null)
                            {
                                if (i > 0)
                                {
                                    bool result = sourceVertex != null?ComponentGraph.AddEdge(graph, sourceVertex, targetGraph) : ComponentGraph.AddEdge(graph, sourceGraph, targetGraph);

                                    if (!result)
                                    {
                                        throw new ArgumentException(
                                                  string.Format(CultureInfo.InvariantCulture, Properties.Resources.E_InvalidNetArchitecture_DuplicateEdge, parts[i - 1], parts[i]));
                                    }
                                }

                                sourceVertex = null;
                                sourceGraph  = targetGraph;
                            }
                            else
                            {
                                ComponentVertex targetVertex;

                                string arch;
                                if (elements.TryGetValue(key, out arch))
                                {
                                    if (!vertices.TryGetValue(key, out targetVertex))
                                    {
                                        vertices[key] = targetVertex = new ComponentVertex(key, arch);
                                    }
                                }
                                else
                                {
                                    targetVertex = new ComponentVertex(Guid.NewGuid().ToString(), key);
                                }

                                if (i > 0)
                                {
                                    bool result = sourceVertex != null?ComponentGraph.AddEdge(graph, sourceVertex, targetVertex) : ComponentGraph.AddEdge(graph, sourceGraph, targetVertex);

                                    if (!result)
                                    {
                                        throw new ArgumentException(
                                                  string.Format(CultureInfo.InvariantCulture, Properties.Resources.E_InvalidNetArchitecture_DuplicateEdge, parts[i - 1], parts[i]));
                                    }
                                }

                                sourceVertex = targetVertex;
                                sourceGraph  = null;
                            }
                        }
                    }
                    else if (parts.Count == 1 && !string.IsNullOrEmpty(parts[0]))
                    {
                        graph.AddVertex(new ComponentVertex(Guid.NewGuid().ToString(), parts[0]));
                    }
                    else
                    {
                        throw new ArgumentException(
                                  string.Format(CultureInfo.InvariantCulture, Properties.Resources.E_InvalidNetArchitecture, component));
                    }
                }

                // recreate vertices keys, for the embedded graphs to have unique layers
                foreach (ComponentVertex vertex in graph.Vertices)
                {
                    vertex.Key = Guid.NewGuid().ToString();
                }

                return(graph);
            }
Example #2
0
 private static bool AddEdge(ComponentGraph graph, ComponentVertex sourceVertex, ComponentVertex targetVertex)
 {
     return(graph.AddEdge(new Edge <ComponentVertex>(sourceVertex, targetVertex)));
 }
Example #3
0
        public VisHost(Player.Player player)
            : base(
                GameWindowSettings.Default,
                //new GameWindowSettings {
                //    IsMultiThreaded = false,
                //    UpdateFrequency = 120
                //},
                new NativeWindowSettings
        {
            Size       = new Vector2i(1600, 900),
            APIVersion = new Version(4, 5),
            Profile    = ContextProfile.Compatability,
            Flags      = ContextFlags.Default,
            Title      = "NeuralBeat3",
            API        = ContextAPI.OpenGL
        })
        {
            Player = player;


            //TargetRenderFrequency = 144f;
            //this.RenderFrequency = 144.0;
            VSync = VSyncMode.On;

            UpdateFrame += VisHost_UpdateFrame;
            RenderFrame += VisHost_RenderFrame;
            Load        += VisHost_Load;
            Unload      += VisHost_Unload;
            Resize      += VisHost_Resize;
            Closed      += VisHost_Closed;
            Closing     += VisHost_Closing;

            //Keyboard.KeyDown += Keyboard_KeyDown;
            //Keyboard.KeyUp += Keyboard_KeyUp;
            this.KeyDown += Keyboard_KeyDown;
            this.KeyUp   += Keyboard_KeyUp;

            // set default shader loader
            ShaderProgram.DefaultLoader = new OpenTKExtensions.Loaders.MultiPathFileSystemLoader(SHADERPATH);


            // framedata setup
            frameData.GlobalTextures = globalTextures;

            // create components
            //components.Add(font = new Font(@"res\font\calibrib.ttf_sdf.2048.png", @"res\font\calibrib.ttf_sdf.2048.txt"), 1);
            components.Add(font            = new Font(@"res\font\lucon.ttf_sdf.1024.png", @"res\font\lucon.ttf_sdf.1024.txt"), 1);
            components.Add(text            = new TextManager("texmgr", font), 2);
            components.Add(keyboardActions = new KeyboardActionManager()
            {
                KeyboardPriority = int.MaxValue
            }, 1);
            components.Add(globalTextures);
            components.Add(frameCounter = new OpenTKExtensions.Components.FrameCounter(font));
            components.Add(switcher     = new ComponentSwitcher()
            {
                KeyForward = new KeySpec(Keys.Tab), KeyBackward = new KeySpec(Keys.Tab, KeyModifiers.Shift)
            });

            switcher.Add(new Renderers.AnalysisDebugRenderer(font, Player));
            switcher.Add(new Renderers.BasicShaderRenderer());
            switcher.Add(new Renderers.ParticleRenderer());

            var graph = new ComponentGraph();

            graph.Add(new ParticleNode()
            {
                Name = "particles"
            });
            graph.Add(new ScreenOutputNode()
            {
                Name = "output"
            });;
            graph.AddEdge(new NodePortReference()
            {
                Node = "particles", Port = "tex"
            }, new NodePortReference()
            {
                Node = "output", Port = "tex"
            });

            switcher.Add(graph);


            //Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
        }