Example #1
0
    public override bool Equals(object other)
    {
        PhysicalChunk mesh = other as PhysicalChunk;

        if (other == null)
        {
            return(false);
        }
        return(mesh.Chunk.Position.Equals(Chunk.Position));
    }
Example #2
0
    /// <summary>
    /// Unloads a chunkmesh
    /// </summary>
    /// <param name="chunkMesh"></param>
    public void UnloadChunkMesh(PhysicalChunk chunkMesh)
    {
        lock (_chunkMeshes)
        {
            // check if chunk exists
            if (!_chunkMeshes.Contains(chunkMesh) || chunkMesh == null)
            {
                return;
            }

            Destroy(chunkMesh.gameObject);
            _chunkMeshes.Remove(chunkMesh);
        }
    }
Example #3
0
    private IEnumerator RegenerateChunkCoroutine(PhysicalChunk physicalChunk, ushort sections)
    {
        // wait for an available thread
        while (_regenTasks.Count >= SystemInfo.processorCount)
        {
            yield return(null);
        }

        // generate the mesh on another thread
        var task = Task.Run(() =>
        {
            var finishedRender = physicalChunk.GenerateMesh(sections);

            // add finished mesh data to queue so it can be assigned to the mesh filter
            foreach (var meshData in finishedRender)
            {
                _finishedMeshData.Enqueue(meshData);
            }
        });

        // add task to list of tasks
        _regenTasks.Add(task);

        // wait for task to complete
        while (!task.IsCompleted)
        {
            yield return(null);
        }

        // remove finished task from task list
        _regenTasks.Remove(task);

        if (task.IsFaulted)
        {
            throw task.Exception;
        }
    }
Example #4
0
 /// <summary>
 /// Marks that we need to regenerate the mesh for a chunk
 /// </summary>
 /// <param name="mesh"></param>
 public void MarkChunkForRegeneration(PhysicalChunk mesh, ushort sections)
 {
     StartCoroutine(RegenerateChunkCoroutine(mesh, sections));
 }