public static void AddToQueue(ChunkDrawDataArray chunkDrawData)
 {
     //lock (q)
     //{
     q.Enqueue(chunkDrawData);
     //}
 }
 public static void AddToQueue(ChunkDrawDataArray chunkDrawData)
 {
     //lock (q)
     //{
         q.Enqueue(chunkDrawData);
     //}
 }
    private void checkForMeshes()
    {
        if (!initLoadDone)
        {
            for (ChunkDrawDataArray chunkdrawdata = MeshGenerationQueue.GetFromQueue(); chunkdrawdata != null; chunkdrawdata = MeshGenerationQueue.GetFromQueue())
            {
                //int3 key = new int3(chunkdrawdata.chunkPos.x - offset.x, chunkdrawdata.chunkPos.y - offset.y, chunkdrawdata.chunkPos.z - offset.z);
                chunkdrawdata.chunk.updateMesh(chunkdrawdata.vertexList, chunkdrawdata.UVList, chunkdrawdata.triangleList);
            }
            //checkForDestroys();
            initLoadDone = true;
        }

        if (initLoadDone)
        {
            //DateTime end = DateTime.Now;
            //TimeSpan generationTime = end - startTime;
            //Debug.Log(generationTime);

            /*
             * if(counter < CONST.framesBetweenMeshes)
             * {
             *  counter++;
             *  return;
             * }
             * else
             * {
             *  counter = 0;
             * }
             */

            for (int i = 0; i < meshesPerFrame; i++)
            {
                ChunkDrawDataArray chunkdrawdata = MeshGenerationQueue.GetFromQueue();
                if (chunkdrawdata != null)
                {
                    chunkdrawdata.chunk.updateMesh(chunkdrawdata.vertexList,
                                                   chunkdrawdata.UVList,
                                                   chunkdrawdata.triangleList);
                }
                else
                {
                    break;
                }
            }
            //else
            //{
            //checkForDestroys();
            //}
        }
    }
    public void AddChunkDrawdataToMeshQueue()
    {
        int3 chunkSize = CONST.chunkSize;

        ChunkDrawData chunkDrawData = new ChunkDrawData(new List <Vector3>(), new List <int>(), new List <Vector2>(), this);

        int offset = 0;

        BlockDrawInfo drawData;

        for (int x = 0; x < chunkSize.x; x++)
        {
            for (int y = 0; y < chunkSize.y; y++)
            {
                for (int z = 0; z < chunkSize.z; z++)
                {
                    if (getBlock(x, y, z) != BlockType.Air)
                    {
                        drawData = getBlockDrawData(x, y, z, offset);

                        chunkDrawData.vertexList.AddRange(drawData.blockVertexList);
                        chunkDrawData.UVList.AddRange(drawData.blockUVList);

                        /*
                         * int j = 0;
                         * foreach (int val in drawData.blockTriangleList)
                         * {
                         *  drawData.blockTriangleList[j] = val + offset;
                         *  j++;
                         * }
                         */

                        offset += drawData.triangleCount;

                        chunkDrawData.triangleList.AddRange(drawData.blockTriangleList);
                    }
                }
            }
        }

        ChunkDrawDataArray cdda = new ChunkDrawDataArray(chunkDrawData.vertexList.ToArray(),
                                                         chunkDrawData.triangleList.ToArray(), chunkDrawData.UVList.ToArray(), this);

        MeshGenerationQueue.AddToQueue(cdda);
    }
Esempio n. 5
0
    private void checkForMeshes()
    {
        if (!initLoadDone)
        {
            for (ChunkDrawDataArray chunkdrawdata = MeshGenerationQueue.GetFromQueue(); chunkdrawdata != null; chunkdrawdata = MeshGenerationQueue.GetFromQueue())
            {
                int3 offset = InfiniteWorld.ChunkWorldPositionOffset;
                //int3 key = new int3(chunkdrawdata.chunkPos.x - offset.x, chunkdrawdata.chunkPos.y - offset.y, chunkdrawdata.chunkPos.z - offset.z);
                chunkdrawdata.chunk.updateMesh(chunkdrawdata.vertexList, chunkdrawdata.UVList, chunkdrawdata.triangleList);
            }
            checkForDestroys();
        }

        if (initLoadDone)
        {
            ChunkDrawDataArray chunkdrawdata = MeshGenerationQueue.GetFromQueue();
            if (chunkdrawdata != null)
            {
                /*
                 * int3 offset = ScrollWorldAroundObject.ChunkWorldPositionOffset;
                 * //int3 key = new int3(chunkdrawdata.chunkPos.x, chunkdrawdata.chunkPos.y, chunkdrawdata.chunkPos.z);
                 * int3 key = new int3(chunkdrawdata.chunkPos.x - offset.x, chunkdrawdata.chunkPos.y - offset.y, chunkdrawdata.chunkPos.z - offset.z);
                 *
                 * if (key.x < 0) key.x = 0;
                 * if (key.y < 0) key.y = 0;
                 * if (key.z < 0) key.z = 0;
                 *
                 * if (key.x > CONST.worldChunkCount.x - 1) { key.x = CONST.worldChunkCount.x - 1; }
                 * if (key.y > CONST.worldChunkCount.y - 1) { key.y = CONST.worldChunkCount.y - 1; }
                 * if (key.z > CONST.worldChunkCount.z - 1) { key.z = CONST.worldChunkCount.z - 1; }
                 */
                //lock (WorldGameObject.chunks)
                //{
                //Debug.Log(key.x + " " + key.y + " " + key.z);
                chunkdrawdata.chunk.updateMesh(chunkdrawdata.vertexList,
                                               chunkdrawdata.UVList,
                                               chunkdrawdata.triangleList);
                //}
            }
            else
            {
                checkForDestroys();
            }
        }
    }
    public void AddChunkDrawdataToMeshQueue()
    {
        int3 chunkSize = CONST.chunkSize;

        ChunkDrawData chunkDrawData = new ChunkDrawData(new List<Vector3>(), new List<int>(), new List<Vector2>(),this);

        int offset = 0;

        BlockDrawInfo drawData;
        for (int x = 0; x < chunkSize.x; x++)
        {
            for (int y = 0; y < chunkSize.y; y++)
            {
                for (int z = 0; z < chunkSize.z; z++)
                {
                    if (getBlock(x, y, z) != BlockType.Air)
                    {

                        drawData = getBlockDrawData(x, y, z, offset);

                        chunkDrawData.vertexList.AddRange(drawData.blockVertexList);
                        chunkDrawData.UVList.AddRange(drawData.blockUVList);

                        /*
                        int j = 0;
                        foreach (int val in drawData.blockTriangleList)
                        {
                            drawData.blockTriangleList[j] = val + offset;
                            j++;
                        }
                        */

                        offset += drawData.triangleCount;

                        chunkDrawData.triangleList.AddRange(drawData.blockTriangleList);
                    }
                }
            }
        }

        ChunkDrawDataArray cdda = new ChunkDrawDataArray(chunkDrawData.vertexList.ToArray(),
            chunkDrawData.triangleList.ToArray(), chunkDrawData.UVList.ToArray(), this);

        MeshGenerationQueue.AddToQueue(cdda);
    }