Example #1
0
        public void Refresh()
        {
            //starting blanks
            if (meshRequired && (meshWorker.blank || ambientWorker.blank))
            {
                meshWorker.Start();
                ambientWorker.Start();                 //starting ambient together with chunk
            }
            if (colliderRequired && colliderApplier.blank)
            {
                colliderApplier.Start();                                                        //will wait for mesh to generate
            }
            if (objectsRequired && objectsWorker.blank)
            {
                objectsWorker.Start();
            }

            //stopping meshes if they are out of range
            if (!meshRequired)
            {
                if (!meshWorker.ready)
                {
                    meshWorker.Stop();
                }
                if (!ambientWorker.ready)
                {
                    ambientWorker.Stop();
                }
            }
            if (!objectsRequired && !objectsWorker.ready)
            {
                objectsWorker.Stop();
            }
            if (!colliderRequired && !colliderApplier.ready)
            {
                colliderApplier.Stop(); meshCollider.sharedMesh = null; colliderIndexToCoord = null;
            }
        }
Example #2
0
        public void Rebuild()          //calculating height/typemap and placing object + updating visibility in apply
        {
                        #if WDEBUG
            Profiler.BeginSample("Rebuild");
                        #endif

            //preparing worker
            if (repositionWorker == null)
            {
                repositionWorker            = new ThreadWorker();
                repositionWorker.name       = "Horizon Reposition";
                repositionWorker.Calculate += CalculateReposition;
                repositionWorker.Apply     += ApplyReposition;
                repositionWorker.tag        = "VoxelandHorizon";
                repositionWorker.priority   = 2;                       //prior to everything!
            }

            //placing object
            //transform.localPosition = camCoord.vector3; //moving in apply to prevent while-generate-mismatch
            //transform.localScale = new Vector3(voxeland.chunks.cellSize, 1, voxeland.chunks.cellSize);

            //saving ref variables
            usedAreas.Clear();
            //CoordRect areasRect = new CoordRect(currentCoord, (int)(meshSize*voxeland.chunks.cellSize/2), voxeland.data.areas.cellRes);
            CoordRect areasRect = CoordRect.PickIntersectingCellsByPos(transform.position, voxeland.data.areaSize / 2, cellSize: voxeland.data.areaSize);
            foreach (Data.Area area in voxeland.data.areas.WithinRect(areasRect))
            {
                if (!area.generateWorker.ready)
                {
                    continue;
                }
                usedAreas.Add(area);
            }

            //starting worker
            if (heightmap == null)
            {
                CalculateReposition(); ApplyReposition();
            }
            else
            {
                repositionWorker.Start();
            }

                        #if WDEBUG
            Profiler.EndSample();
                        #endif
        }