Пример #1
0
    public SubchunkCoord GetSubchunkCoord(Vector3 globalPos)
    {
        ChunkCoord superChunk    = GetChunkCoord(globalPos);
        byte       subchunkIndex = Subchunk.GetSubchunkIndex(Mathf.FloorToInt(globalPos.y));

        return(new SubchunkCoord(superChunk, subchunkIndex));
    }
Пример #2
0
    public List <SubchunkCoord> GetAdjacentSubchunks(int x, int y, int z)
    {
        List <SubchunkCoord> adjacentSubchunks = new List <SubchunkCoord>();
        byte subchunkIndex = Subchunk.GetSubchunkIndex(y);

        if (x == 0)
        {
            ChunkCoord adjacentChunk = new ChunkCoord(coord);
            adjacentChunk.x -= 1;
            if (world.isChunkInWorld(adjacentChunk) && world.GetChunk(adjacentChunk) != null)
            {
                adjacentSubchunks.Add(world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex).coord);
            }
        }
        else if (x == VoxelData.ChunkWidth - 1)
        {
            ChunkCoord adjacentChunk = new ChunkCoord(coord);
            adjacentChunk.x += 1;
            if (world.isChunkInWorld(adjacentChunk) && world.GetChunk(adjacentChunk) != null)
            {
                adjacentSubchunks.Add(world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex).coord);
            }
        }
        if (y % VoxelData.ChunkSubdivisionHeight == 0 && y != 0)
        {
            adjacentSubchunks.Add(new SubchunkCoord(coord, (byte)(subchunkIndex - 1)));
        }
        else if (y % VoxelData.ChunkSubdivisionHeight == (VoxelData.ChunkSubdivisionHeight - 1) && y < VoxelData.ChunkHeight)
        {
            adjacentSubchunks.Add(new SubchunkCoord(coord, (byte)(subchunkIndex + 1)));
        }
        if (z == 0)
        {
            ChunkCoord adjacentChunk = new ChunkCoord(coord);
            adjacentChunk.z -= 1;
            if (world.isChunkInWorld(adjacentChunk) && world.GetChunk(adjacentChunk) != null)
            {
                adjacentSubchunks.Add(world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex).coord);
            }
        }
        else if (z == VoxelData.ChunkWidth - 1)
        {
            ChunkCoord adjacentChunk = new ChunkCoord(coord);
            adjacentChunk.z += 1;
            if (world.isChunkInWorld(adjacentChunk) && world.GetChunk(adjacentChunk) != null)
            {
                if (world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex) == null)
                {
                    Debug.Log(world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex));
                }
                adjacentSubchunks.Add(world.GetChunk(adjacentChunk).GetSubchunk(subchunkIndex).coord);
            }
        }
        return(adjacentSubchunks);
    }
Пример #3
0
    public void _updateChunk()
    {
        isChunkLocked = true;
        bool[] subchunksToUpdate = new bool[VoxelData.ChunkSubdivisions];
        List <SubchunkCoord> adjacentSubchunksToUpdate = new List <SubchunkCoord>();

        lock (voxelModifications) {
            while (voxelModifications.Count > 0)
            {
                Queue <VoxelModification> voxModElement = voxelModifications.Dequeue();
                while (voxModElement.Count > 0)
                {
                    VoxelModification voxMod = voxModElement.Dequeue();
                    voxelMap[voxMod.x, voxMod.y, voxMod.z] = voxMod.newBlockType.blockTypeIndex;
                    subchunksToUpdate[Subchunk.GetSubchunkIndex(voxMod.y)] = true;
                    List <SubchunkCoord> adjacentSubchunks = GetAdjacentSubchunks(voxMod.x, voxMod.y, voxMod.z);
                    foreach (SubchunkCoord adjacentSubchunk in adjacentSubchunks)
                    {
                        if (adjacentSubchunk.superChunkCoord.Equals(coord))
                        {
                            subchunksToUpdate[adjacentSubchunk.subchunkIndex] = true;
                        }
                        else
                        {
                            adjacentSubchunksToUpdate.Add(adjacentSubchunk);
                        }
                    }
                }
            }
        }
        List <SubchunkCoord> updatedAdjacentSubchunks = new List <SubchunkCoord>();

        for (int i = 0; i < subchunksToUpdate.Length; i++)
        {
            if (subchunksToUpdate[i])
            {
                subchunks[i].UpdateSubChunk();
            }
        }
        for (int i = 0; i < adjacentSubchunksToUpdate.Count; i++)
        {
            if (!updatedAdjacentSubchunks.Contains(adjacentSubchunksToUpdate[i]))
            {
                world.GetSubchunk(adjacentSubchunksToUpdate[i]).UpdateSubChunk();
                updatedAdjacentSubchunks.Add(adjacentSubchunksToUpdate[i]);
            }
        }
        isChunkLocked = false;
    }
Пример #4
0
 private void UpdateDebugOverlay()
 {
     if (Input.GetButtonDown("ToggleDebugOverlay"))
     {
         debugOverlayActive = !debugOverlayActive;
         debugOverlay.gameObject.SetActive(debugOverlayActive);
     }
     if (debugOverlayActive)
     {
         Vector3 pos = World.GetFlooredVector3(playerGameObject.transform.position);
         debugOverlay.text = "Block Position: X: " + (int)pos.x + " Y: " + (int)pos.y + " Z: " + (int)pos.z +
                             "\nChunk X: " + world.playerLastChunkCoord.x + " Y: " + Subchunk.GetSubchunkIndex((int)pos.y) + " Z: " + world.playerLastChunkCoord.z +
                             "\nFPS: " + Mathf.FloorToInt(1f / Time.deltaTime);
         if (Mathf.FloorToInt(1f / Time.deltaTime) < 30)
         {
             Debug.Log("FPS Hit: " + Mathf.FloorToInt(1f / Time.deltaTime));
         }
     }
 }