Exemplo n.º 1
0
        public bool GetVoxel(VoxelChunk checkFirst, Vector3 worldLocation, ref Voxel newReference)
        {
            while (true)
            {
                if (checkFirst != null)
                {
                    if (checkFirst.IsWorldLocationValid(worldLocation))
                    {
                        if (!checkFirst.GetVoxelAtWorldLocation(worldLocation, ref newReference))
                        {
                            return(false);
                        }

                        Vector3 grid = checkFirst.WorldToGrid(worldLocation);
                        newReference.Chunk        = checkFirst;
                        newReference.GridPosition = new Vector3((int)grid.X, (int)grid.Y, (int)grid.Z);

                        return(true);
                    }

                    checkFirst = null;
                    continue;
                }

                VoxelChunk chunk = GetVoxelChunkAtWorldLocation(worldLocation);

                if (chunk == null)
                {
                    return(false);
                }


                return(chunk.GetVoxelAtWorldLocation(worldLocation, ref newReference));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// TODO: Get rid of the recursion
        /// Recursive function which gets all the voxels at a position in the world, assuming the voxel is in a given chunk
        /// </summary>
        /// <param Name="checkFirst">The voxel chunk to check first</param>
        /// <param Name="worldLocation">The point in the world to check</param>
        /// <param Name="toReturn">A list of voxels to get</param>
        /// <param Name="depth">The depth of the recursion</param>
        public bool GetNonNullVoxelAtWorldLocationCheckFirst(VoxelChunk checkFirst, Vector3 worldLocation, ref Voxel toReturn)
        {
            if (checkFirst != null)
            {
                if (!checkFirst.IsWorldLocationValid(worldLocation))
                {
                    return(GetNonNullVoxelAtWorldLocation(worldLocation, ref toReturn));
                }

                bool success = checkFirst.GetVoxelAtWorldLocation(worldLocation, ref toReturn);

                if (success && !toReturn.IsEmpty)
                {
                    return(true);
                }
                return(GetNonNullVoxelAtWorldLocation(worldLocation, ref toReturn));
            }

            VoxelChunk chunk = GetVoxelChunkAtWorldLocation(worldLocation);

            if (chunk == null)
            {
                return(false);
            }

            if (!chunk.IsWorldLocationValid(worldLocation))
            {
                return(false);
            }

            if (chunk.GetVoxelAtWorldLocation(worldLocation, ref toReturn) && !toReturn.IsEmpty)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public bool GetVoxel(VoxelChunk checkFirst, Vector3 worldLocation, ref Voxel newReference)
        {
            while(true)
            {
                if(checkFirst != null)
                {
                    if(checkFirst.IsWorldLocationValid(worldLocation))
                    {
                        if(!checkFirst.GetVoxelAtWorldLocation(worldLocation, ref newReference))
                        {
                            return false;
                        }

                        Vector3 grid = checkFirst.WorldToGrid(worldLocation);
                        newReference.Chunk = checkFirst;
                        newReference.GridPosition = new Vector3((int) grid.X, (int) grid.Y, (int) grid.Z);

                        return true;
                    }

                    checkFirst = null;
                    continue;
                }

                VoxelChunk chunk = GetVoxelChunkAtWorldLocation(worldLocation);

                if (chunk == null)
                {
                    return false;
                }

                return chunk.GetVoxelAtWorldLocation(worldLocation, ref newReference);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// TODO: Get rid of the recursion
        /// Recursive function which gets all the voxels at a position in the world, assuming the voxel is in a given chunk
        /// </summary>
        /// <param Name="checkFirst">The voxel chunk to check first</param>
        /// <param Name="worldLocation">The point in the world to check</param>
        /// <param Name="toReturn">A list of voxels to get</param>
        /// <param Name="depth">The depth of the recursion</param>
        public bool GetNonNullVoxelAtWorldLocationCheckFirst(VoxelChunk checkFirst, Vector3 worldLocation, ref Voxel toReturn)
        {
            if(checkFirst != null)
            {
                if(!checkFirst.IsWorldLocationValid(worldLocation))
                {
                    return GetNonNullVoxelAtWorldLocation(worldLocation, ref toReturn);
                }

                bool success = checkFirst.GetVoxelAtWorldLocation(worldLocation, ref toReturn);

                if(success && !toReturn.IsEmpty)
                {
                    return true;
                }
                return GetNonNullVoxelAtWorldLocation(worldLocation, ref toReturn);
            }

            VoxelChunk chunk = GetVoxelChunkAtWorldLocation(worldLocation);

            if(chunk == null)
            {
                return false;
            }

            if(!chunk.IsWorldLocationValid(worldLocation))
            {
                return false;
            }

            if (chunk.GetVoxelAtWorldLocation(worldLocation, ref toReturn) && !toReturn.IsEmpty)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 5
0
        public bool DoesWaterCellExist(Vector3 worldLocation)
        {
            VoxelChunk chunkAtLocation = GetVoxelChunkAtWorldLocation(worldLocation);

            return(chunkAtLocation != null && chunkAtLocation.IsWorldLocationValid(worldLocation));
        }