Exemple #1
0
 public ViewSettings(Vector2i viewDistance)
 {
     ViewDistance = new Vector3i(viewDistance.X, viewDistance.Y, viewDistance.X);
     ViewDistanceCache = new Vector3i(viewDistance.X + 1, viewDistance.Y + 1, viewDistance.X + 1);
     Location = new Vector3i();
     PreviousLocation = new Vector3i(int.MinValue, int.MinValue, int.MinValue);
 }
Exemple #2
0
        public static double Distance(Vector3i a, Vector3i b)
        {
            a.X = b.X - a.X;
            a.Y = b.Y - a.Y;
            a.Z = b.Z - a.Z;

            return Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
        }
        private void UpdateAreaBoundaries()
        {
            bool updatedBoundaries = false;

            // Locate the outer boundaries (locations) of all neighbor areas so that we can skip rendering faces which faces out of the furthest areas (cannot be seen anyway)
            AreaLocationMin = new Vector3i(int.MaxValue);
            AreaLocationMax = new Vector3i(int.MinValue);

            // Loop through all sides of the current area
            for (int i = 0; i < 6; i++)
            {
                if (AreaNeighbors[i] != null)
                {
                    updatedBoundaries = true;

                    // X axis
                    if (AreaNeighbors[i].Info.Location.X < AreaLocationMin.X)
                    {
                        AreaLocationMin.X = AreaNeighbors[i].Info.Location.X;
                    }

                    if (AreaNeighbors[i].Info.Location.X > AreaLocationMax.X)
                    {
                        AreaLocationMax.X = AreaNeighbors[i].Info.Location.X;
                    }

                    // Y axis
                    if (AreaNeighbors[i].Info.Location.Y < AreaLocationMin.Y)
                    {
                        AreaLocationMin.Y = AreaNeighbors[i].Info.Location.Y;
                    }

                    if (AreaNeighbors[i].Info.Location.Y > AreaLocationMax.Y)
                    {
                        AreaLocationMax.Y = AreaNeighbors[i].Info.Location.Y;
                    }

                    // Z axis
                    if (AreaNeighbors[i].Info.Location.Z < AreaLocationMin.Z)
                    {
                        AreaLocationMin.Z = AreaNeighbors[i].Info.Location.Z;
                    }

                    if (AreaNeighbors[i].Info.Location.Z > AreaLocationMax.Z)
                    {
                        AreaLocationMax.Z = AreaNeighbors[i].Info.Location.Z;
                    }
                }
            }

            // No neighbors found, so use default boundaries
            if (!updatedBoundaries)
            {
                AreaLocationMin = area.Info.Location;
                AreaLocationMax = area.Info.Location;
            }
        }
Exemple #4
0
 public static void GetAreaRangeWithinViewDistance(Vector3i location, Vector3i viewDistance, ref AreaRange range)
 {
     range.Min.X = location.X - viewDistance.X;
     range.Max.X = location.X + viewDistance.X;
     range.Min.Y = location.Y - viewDistance.Y;
     range.Max.Y = location.Y + viewDistance.Y;
     range.Min.Z = location.Z - viewDistance.Z;
     range.Max.Z = location.Z + viewDistance.Z;
 }
        private void UpdateAreaNeighbors(List<Area> neighbors)
        {
            // Clear any current areas
            for (int i = 0; i < 6; i++)
            {
                AreaNeighbors[i] = null;
            }

            if (neighbors != null && neighbors.Count > 0)
            {
                var sides = new Vector3i[6];
                sides[(int)TileSide.Top] = new Vector3i(area.Info.Location.X, area.Info.Location.Y + 1, area.Info.Location.Z);
                sides[(int)TileSide.Bottom] = new Vector3i(area.Info.Location.X, area.Info.Location.Y - 1, area.Info.Location.Z);
                sides[(int)TileSide.Left] = new Vector3i(area.Info.Location.X - 1, area.Info.Location.Y, area.Info.Location.Z);
                sides[(int)TileSide.Right] = new Vector3i(area.Info.Location.X + 1, area.Info.Location.Y, area.Info.Location.Z);
                sides[(int)TileSide.Front] = new Vector3i(area.Info.Location.X, area.Info.Location.Y, area.Info.Location.Z + 1);
                sides[(int)TileSide.Back] = new Vector3i(area.Info.Location.X, area.Info.Location.Y, area.Info.Location.Z - 1);

                for (int i = 0; i < neighbors.Count; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (neighbors[i].Info.Location.Equals(sides[j]))
                        {
                            AreaNeighbors[j] = neighbors[i];
                            break;
                        }
                    }
                }
            }
        }
        public void RemoveExpiredAreas(Vector3i location, Vector3i viewDistance)
        {
            lock (areaCollection.CollectionLock)
            {
                var expiredAreas = new List<Area>();

                Area area;

                // Loop through all areas to find expired ones
                for (int i = 0; i < areaCollection.Areas.Count; i++)
                {
                    area = areaCollection.Areas[i];

                    if (area.Info.Location.X >= location.X)
                    {
                        if (area.Info.Location.X - location.X > viewDistance.X + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }
                    else
                    {
                        if (location.X - area.Info.Location.X > viewDistance.X + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }

                    if (area.Info.Location.Y >= location.Y)
                    {
                        if (area.Info.Location.Y - location.Y > viewDistance.Y + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }
                    else
                    {
                        if (location.Y - area.Info.Location.Y > viewDistance.Y + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }

                    if (area.Info.Location.Z >= location.Z)
                    {
                        if (area.Info.Location.Z - location.Z > viewDistance.Z + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }
                    else
                    {
                        if (location.Z - area.Info.Location.Z > viewDistance.Z + 2)
                        {
                            expiredAreas.Add(area);
                        }
                    }
                }

                // Remove all expired areas
                RemoveRange(expiredAreas);
            }
        }
 public Area GetAreaAt(Vector3i location)
 {
     return GetAreaAt(location.X, location.Y, location.Z);
 }
        public Vector3 FindSuitableSpawnPoint(BoundingBox bounds)
        {
            var currentBestPosition = new Vector3();

            // Find the area location of the current bounding box coordinates
            var startingArea = new Vector3i();
            AreaHelper.FindAreaLocation(boundingBoxHelper.GetCenter(bounds), ref startingArea);

            // Check the current area for a suitable spawnpoint
            var area = terrainContext.Generator.Generate(startingArea.X, startingArea.Y, startingArea.Z);

            if (CanSpawnInArea(area, bounds))
            {
                // If we are at the bottom of an area, then theres a chance that the area below us is also empty and might cause us to start falling.
                // If so, we try to scan further for a suitable position, otherwise we return right here since we can assume that we are standing on solid ground.
                if (!info.IsAtBottomOfArea)
                {
                    return info.Position;
                }
                else
                {
                    currentBestPosition = info.Position;
                }
            }

            bool skipAbove = currentBestPosition != Vector3.Zero;

            // Perform a scan of 50 areas above and below the starting area for a suitable spawnpoint
            for (int y = 1; y < 50; y++)
            {
                if (!skipAbove)
                {
                    var areaAbove = terrainContext.Generator.Generate(startingArea.X, startingArea.Y + y, startingArea.Z);

                    if (CanSpawnInArea(areaAbove, bounds))
                    {
                        // If we are at the bottom of an area, then theres a chance that the area below us is also empty and might cause us to start falling.
                        // If so, we try to scan further for a suitable position, otherwise we return right here since we can assume that we are standing on solid ground.
                        if (!info.IsAtBottomOfArea)
                        {
                            return info.Position;
                        }

                        currentBestPosition = info.Position;
                    }
                }

                var areaBelow = terrainContext.Generator.Generate(startingArea.X, startingArea.Y - y, startingArea.Z);

                if (CanSpawnInArea(areaBelow, bounds))
                {
                    // If we are at the bottom of an area, then theres a chance that the area below us is also empty and might cause us to start falling.
                    // If so, we try to scan further for a suitable position, otherwise we return right here since we can assume that we are standing on solid ground.
                    if (!info.IsAtBottomOfArea)
                    {
                        return info.Position;
                    }

                    currentBestPosition = info.Position;
                }
            }

            return currentBestPosition;
        }
Exemple #9
0
 /// <summary>
 /// Takes a world position and finds the matching area location for it
 /// </summary>
 /// <param name="position">The world position</param>
 /// <param name="result">The result area location</param>
 public static void FindAreaLocation(Vector3 position, ref Vector3i result)
 {
     result.X = (int)Math.Ceiling(position.X / (Area.Size.X * Tile.Size.X)) - 1;
     result.Y = (int)Math.Ceiling(position.Y / (Area.Size.Y * Tile.Size.Y)) - 1;
     result.Z = (int)Math.Ceiling(position.Z / (Area.Size.Z * Tile.Size.Z)) - 1;
 }
        private TileType GetSurfaceTileType(Vector3i location, int tileX, int tileY, int tileZ)
        {
            byte tileType = noiseManager.AreaResources.Generators[NoiseAreaResourceType.Grainy].GenerateSinglePoint(
                tileX + (location.X * Area.Size.X),
                tileY + (location.Y * Area.Size.Y),
                tileZ + (location.Z * Area.Size.Z));

            if (tileType > 127)
            {
                return TileType.Stone;
            }
            else
            {
                return TileType.Stone2;
            }
        }
 private TileType GetSurfaceTileType(Vector3i location, int tileX, int tileY, int tileZ)
 {
     return TileType.Stone;
 }
Exemple #12
0
 public AreaRange()
 {
     Min = new Vector3i();
     Max = new Vector3i();
 }