示例#1
0
        public static bool IsInsideChunkId(Vector3Int worldPos, Vector3Int chunkId, Vector3Int chunkDimensions)
        {
            var chunkLB = chunkId * chunkDimensions;
            var chunkUB = (chunkId + Vector3Int.one) * chunkDimensions;

            return(worldPos.All((a, b) => a >= b, chunkLB) && worldPos.All((a, b) => a < b, chunkUB));
        }
示例#2
0
        public static bool LocalPositionInsideChunkBounds(Vector3Int localPos, Vector3Int chunkDimensions)
        {
            var chunkLB = Vector3Int.zero;
            var chunkUB = chunkDimensions;

            return(localPos.All((a, b) => a >= b, chunkLB) && localPos.All((a, b) => a < b, chunkUB));
        }
示例#3
0
        bool InsideRadius(Vector3Int displacement, Vector3Int Radii)
        {
            Vector3Int absDisplacement = displacement.ElementWise(Mathf.Abs);

            //Inside if all elements of the absolute displacement are less than or equal to the radius
            return(absDisplacement.All((a, b) => a <= b, Radii));
        }
示例#4
0
        private void AddAllDependenciesNecessaryForChunkToGetToStage(Vector3Int chunkId, int targetStage)
        {
            int  terrainRadius        = 0;
            int  structureRadius      = 0;
            int  fullyGeneratedRadius = 0;
            bool includeDiagonals     = pipeline.GenerateStructures;

            if (targetStage > pipeline.TerrainDataStage)
            {
                terrainRadius++;
            }
            if (targetStage > pipeline.OwnStructuresStage)
            {
                if (pipeline.GenerateStructures)
                {
                    terrainRadius++;
                    structureRadius++;
                }
                else if (lighting)
                {
                    //Lighting without structures requires an extra radius of terrain data.
                    terrainRadius++;
                }
            }

            if (targetStage > pipeline.FullyGeneratedStage)
            {
                if (pipeline.GenerateStructures)
                {
                    terrainRadius++;
                    structureRadius++;
                }
                fullyGeneratedRadius++;
            }

            Func <Vector3Int, int, bool> radiusTest = (offset, radius) => offset.All((v) => Math.Abs(v) <= radius);

            if (!includeDiagonals)
            {
                radiusTest = (offset, radius) =>
                {
                    var abs       = offset.ElementWise((_) => Math.Abs(_));
                    var manhattan = abs.x + abs.y + abs.z;
                    return(manhattan <= terrainRadius);
                };
            }

            for (int z = -terrainRadius; z <= terrainRadius; z++)
            {
                for (int y = -terrainRadius; y <= terrainRadius; y++)
                {
                    for (int x = -terrainRadius; x <= terrainRadius; x++)
                    {
                        var offset = new Vector3Int(x, y, z);

                        if (offset.All((v) => v == 0))
                        {
                            continue;//skip center chunk
                        }

                        var id = chunkId + offset;
                        if (radiusTest(offset, fullyGeneratedRadius))
                        {
                            //This chunk should be fully generated including structures
                            AddOrUpdateTarget(id, pipeline.FullyGeneratedStage, true);
                            //Debug.Log($"Set {id} target to FullyGenerated");
                        }
                        else if (radiusTest(offset, structureRadius))
                        {
                            AddOrUpdateTarget(id, pipeline.OwnStructuresStage, true);
                            //Debug.Log($"Set {id} target to OwnStructures");
                        }
                        else if (radiusTest(offset, terrainRadius))
                        {
                            //Request that this chunk should be just terrain data, no structures
                            AddOrUpdateTarget(id, pipeline.TerrainDataStage, true);
                            //Debug.Log($"Set {id} target to TerrainData");
                        }
                    }
                }
            }
        }