Example #1
0
        public void UpdateChunk()
        {
            while (modifications.Count > 0)
            {
                BlockMod b   = modifications.Dequeue();
                Vector3  pos = b.position -= position;

                blockMap[(int)pos.x, (int)pos.y, (int)pos.z].id = b.id;
            }
            ClearMeshData();
            CalculateLight();
            for (int x = 0; x < chunkSize; x++)
            {
                for (int y = 0; y < chunkSize; y++)
                {
                    for (int z = 0; z < chunkSize; z++)
                    {
                        if (world.blockType[blockMap[x, y, z].id].isSolid)
                        {
                            UpdateMeshData(new Vector3(x, y, z));
                        }
                    }
                }
            }
            world.chunksToDraw.Enqueue(this);
        }
Example #2
0
        void ApplyModifications()
        {
            applyingModifications = true;
            //if (modifications.Count <= 0)
            //{
            //    Debug.Log(modifications.Count);
            //}
            while (modifications.Count > 0)
            {
                Queue <BlockMod> queue = modifications.Dequeue();

                //if (queue.Count <= 0)
                //{
                //    Debug.Log(queue.Count);
                //}
                while (queue.Count > 0)
                {
                    BlockMod b = queue.Dequeue();
                    if (!IsBlockInWorld(b.position))
                    {
                        return;
                    }
                    ChunkCoord c = GetChunkCoordFromVector3(b.position);
                    Chunk      modificationChunk = DictionaryChunkFinder(c.x, c.y, c.z);
                    if (modificationChunk == null)
                    {
                        chunksToCreate.Add(c);
                    }
                    //UnityEngine.Debug.Log( "BlockState "+ " x " + b.position.x + " y " + b.position.y + " z " + b.position.z);
                    modificationChunk.modifications.Enqueue(b);
                }
            }
            applyingModifications = false;
        }