Exemplo n.º 1
0
 private void Run()
 {
     try {
         while (running)
         {
             Node n;
             if (loadingQueue.TryDequeue(out n))
             {
                 Monitor.Enter(n);
                 if (!n.HasPointsToRender() && !n.HasGameObjects())
                 {
                     Monitor.Exit(n);
                     CloudLoader.LoadPointsForNode(n);
                     cache.Insert(n);
                 }
                 else
                 {
                     Monitor.Exit(n);
                 }
             }
         }
     } catch (Exception ex) {
         Debug.LogError(ex);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gives the current camera data to the traversal thread and updates the GameObjects. Called from the MainThread. As described in the Bachelor Thesis in chapter 3.1.3 "Main Thread"
        /// </summary>
        public void Update()
        {
            unityThread = Thread.CurrentThread;
            if (paused)
            {
                return;
            }
            //Set new Camera Data
            traversalThread.SetNextCameraData(camera.transform.position, camera.transform.forward, GeometryUtility.CalculateFrustumPlanes(camera), camera.pixelRect.height, camera.fieldOfView);

            //Update GameObjects
            Queue <Node> toRender;
            Queue <Node> toDelete;

            lock (locker) {
                toRender      = this.toRender;
                toDelete      = this.toDelete;
                this.toRender = null;
                this.toDelete = null;
            }
            if (toRender == null)
            {
                return;
            }
            while (toDelete.Count != 0)
            {
                Node n = toDelete.Dequeue();
                lock (n) {
                    if (n.HasGameObjects())
                    {
                        n.RemoveGameObjects(config);
                        cache.Insert(n);
                    }
                }
            }
            while (toRender.Count != 0)
            {
                Node n = toRender.Dequeue();
                lock (n) {
                    if (n.HasPointsToRender() && (n.Parent == null || n.Parent.HasGameObjects()))
                    {
                        n.CreateGameObjects(config);
                    }
                }
            }
            Monitor.Enter(toDeleteExternal);
            while (toDeleteExternal.Count != 0)
            {
                Node rootNode = toDeleteExternal.Dequeue();
                rootNodes.Remove(rootNode);
                Queue <Node> toRemove = new Queue <Node>();
                toRemove.Enqueue(rootNode);
                while (toRemove.Count != 0)
                {
                    Node n = toRemove.Dequeue();
                    cache.Withdraw(n);
                    if (n.HasGameObjects())
                    {
                        n.RemoveGameObjects(config);
                    }
                    if (n.HasPointsToRender())
                    {
                        n.ForgetPoints();
                        foreach (Node child in n)
                        {
                            toRemove.Enqueue(child);
                        }
                    }
                }
            }
            Monitor.Exit(toDeleteExternal);

            //Notify Traversal Thread
            lock (traversalThread) {
                Monitor.PulseAll(traversalThread);
            }
        }