Exemple #1
0
        //orchestrates
        public int WorkCycle(int procnum)
        {
            //not really sure if this does anything
            int    processor = (int)procnum;
            Thread tr        = Thread.CurrentThread;

            if (Environment.ProcessorCount > 1)
            {
                SetThreadAffinityMask(GetCurrentThread(),
                                      new IntPtr(1 << processor));
            }
            working = true;

            //basic input for demo
            for (int w = blockWidth / 2; w < (blockWidth / 2) + 1; w++)
            {
                for (int h = blockHeight / 2; h < (blockHeight / 2) + 1; h++)
                {
                    //activate nodes on the first layer
                    nodeCube[(w) + blockWidth * ((h) + blockHeight * (0))].Activation = 1;
                    nodeCube[(w) + blockWidth * ((h) + blockHeight * (0))].IsLoaded   = true;
                    //add them to the work queue
                    _fireQueue.Enqueue(nodeCube[(w) + blockWidth * ((h) + blockHeight * (0))]);
                }
            }

            //This does the work. Cycles through the queue.
            //For each node, add connection weight to connection child,
            //return list of lines to be rendered, add them to glmananger queue
            int counter = 0;

            using (var locked = _fireQueue.Lock())
            {
                while (locked.Count != 0)
                {
                    var workNode = locked.Dequeue();
                    //maybe add a threshold to node, and use that instead of 1
                    if (workNode.IsLoaded && workNode.Activation >= 1)
                    {
                        _glmanager.AddQueue(_workGenerator.Generate(workNode));
                        counter++;
                    }
                }
            }

            foreach (Node n in nodeCube)
            {
                foreach (RenderLine l in n.ChildrenLines)
                {
                    //weaken all connections
                    //l.strength *= .985f;
                }
            }
            working = false;
            return(counter);
        }
Exemple #2
0
 public void AddQueue(ThreadSafeQueue <RenderLine> workQueue)
 {
     using (var locked = workQueue.Lock())
     {
         while (locked.Count > 0)
         {
             lineQueue.Enqueue(locked.Dequeue());
         }
     }
 }
Exemple #3
0
        public void openGLCtrl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            if (doRender)
            {
                gl.ClearColor(.25f, .2f, .2f, 1);

                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

                gl.LoadIdentity();
                gl.Translate(-.2f, -.2f, -3.25f + delta);

                gl.Rotate(deltaY, .5f, 0, 0);
                gl.Rotate(deltaX, 0f, .5f, 0);

                try
                {
                    gl.Color(1f, 1f, 1f);

                    gl.Enable(OpenGL.GL_LINE_SMOOTH);
                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                    gl.Hint(OpenGL.GL_LINE_SMOOTH_HINT, OpenGL.GL_DONT_CARE);
                    gl.LineWidth(.25f);

                    //draw the containing box
                    gl.Begin(OpenGL.GL_LINES);

                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 0, 1);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(1, 0, 0);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 1, 0);
                    gl.Vertex(0, 1, 1);
                    gl.Vertex(0, 0, 1);
                    gl.Vertex(0, 1, 1);
                    gl.Vertex(0, 1, 0);
                    gl.Vertex(0, 1, 1);
                    gl.Vertex(1, 1, 1);
                    gl.Vertex(1, 1, 0);
                    gl.Vertex(1, 0, 0);
                    gl.Vertex(1, 1, 0);
                    gl.Vertex(0, 1, 0);
                    gl.Vertex(1, 1, 0);
                    gl.Vertex(1, 1, 1);
                    gl.Vertex(1, 0, 1);
                    gl.Vertex(0, 0, 1);
                    gl.Vertex(1, 0, 1);
                    gl.Vertex(1, 0, 0);
                    gl.Vertex(1, 0, 1);
                    gl.Vertex(1, 1, 1);
                    gl.End();


                    gl.Color(0f, .9f, (float)1);
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 0, 100);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(0, 100, 0);
                    gl.Vertex(0, 0, 0);
                    gl.Vertex(100, 0, 0);
                    gl.End();

                    gl.LineWidth(.15f);

                    gl.Begin(OpenGL.GL_LINES);
                    int renderCounterL = 0;

                    //draw the lines for each firing path
                    RenderLine cq;
                    using (var locked = lineQueue.Lock())
                    {
                        while (locked.Count > 0)
                        {
                            cq = locked.Dequeue();

                            if (cq != null)
                            {
                                bx0 = cq.xS;
                                bx1 = cq.xV;
                                by0 = cq.yS;
                                by1 = cq.yV;
                                bz0 = cq.zS;
                                bz1 = cq.zV;

                                gl.Color(cq.actionR, cq.actionG, cq.actionB);

                                gl.Vertex(bx0, by0, bz0);
                                gl.Vertex(bx1, by1, bz1);
                            }
                            renderCounterL++;
                        }
                        lineQueue.Clear();
                    }
                    gl.End();
                }
                catch { }
                doRender = false;
            }
        }