예제 #1
0
        private void ProcessGeneratorJobs(NativeList <int3> jobsToRemove)
        {
            NativeKeyValueArrays <int3, ChunkJobData> jobs = generateJobs.GetKeyValueArrays(Allocator.Temp);

            for (int i = 0; i < jobs.Keys.Length; i++)
            {
                ChunkJobData data = jobs.Values[i];

                if (data.urgent || data.job.IsCompleted || data.frameCounter >= maxJobFrames)
                {
                    data.job.Complete();
                    Chunk chunk = chunks[data.position];
                    chunk.CompleteGenerating();

                    if (!chunk.RequestedRemoval && chunk.render)
                    {
                        TryToQueueChunkRender(chunk, data.priority);
                    }

                    jobsToRemove.Add(jobs.Keys[i]);
                }
                else
                {
                    data.frameCounter++;
                    generateJobs[jobs.Keys[i]] = data;
                }
            }

            jobs.Dispose();

            for (int i = 0; i < jobsToRemove.Length; i++)
            {
                generateJobs.Remove(jobsToRemove[i]);
            }
        }
예제 #2
0
        private void ProcessRenderJobs(NativeList <int3> jobsToRemove)
        {
            NativeKeyValueArrays <int3, ChunkJobData> jobs = renderJobs.GetKeyValueArrays(Allocator.Temp);

            for (int i = 0; i < jobs.Keys.Length; i++)
            {
                ChunkJobData data = jobs.Values[i];
                if (data.urgent || data.job.IsCompleted || data.frameCounter >= maxJobFrames)
                {
                    data.job.Complete();
                    Chunk chunk = chunks[data.position];

                    if (useRendererPrefab)
                    {
                        CreateChunkRenderer(data.position, chunk.CompleteMeshUpdate(chunk.mesh));
                    }
                    else
                    {
                        chunk.CompleteMeshUpdate(chunk.mesh);
                    }

                    if (!chunk.RequestedRemoval)
                    {
                        AddToQueue(colliderQueue, data.position, data.priority);
                    }

                    jobsToRemove.Add(jobs.Keys[i]);
                }
                else
                {
                    data.frameCounter++;
                    renderJobs[jobs.Keys[i]] = data;
                }
            }

            jobs.Dispose();

            for (int i = 0; i < jobsToRemove.Length; i++)
            {
                renderJobs.Remove(jobsToRemove[i]);
            }
        }
예제 #3
0
        private void ProcessColliderJobs(NativeList <int3> jobsToRemove)
        {
            NativeKeyValueArrays <int3, ChunkJobData> jobs = colliderJobs.GetKeyValueArrays(Allocator.Temp);

            for (int i = 0; i < jobs.Keys.Length; i++)
            {
                ChunkJobData data = jobs.Values[i];
                if (data.urgent || data.job.IsCompleted || data.frameCounter >= maxJobFrames)
                {
                    data.job.Complete();
                    Chunk chunk = chunks[data.position];

                    if (!chunkColliders.TryGetValue(data.position, out MeshCollider collider))
                    {
                        collider = GetChunkCollider();
                        chunkColliders.Add(data.position, collider);
#if DEBUG
                        collider.gameObject.name = "Collider [" + data.position.x + "," + data.position.y + "," + data.position.z + "]";
#endif
                    }

                    collider.sharedMesh = chunk.CompleteColliderMeshUpdate(collider.sharedMesh);

                    jobsToRemove.Add(jobs.Keys[i]);
                }
                else
                {
                    data.frameCounter++;
                    colliderJobs[jobs.Keys[i]] = data;
                }
            }

            jobs.Dispose();

            for (int i = 0; i < jobsToRemove.Length; i++)
            {
                colliderJobs.Remove(jobsToRemove[i]);
            }
        }