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); } Debug.Log("Loading Thread stopped"); }
/// <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() { //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); } } } //Notify Traversal Thread lock (traversalThread) { Monitor.PulseAll(traversalThread); } }