Exemplo n.º 1
0
        public Point GetClosestPointOnTile(Point position, out bool success)
        {
            lock (_threadLocker)
            {
                float[] extents = new Point(20.0f, 2000.0f, 20.0f).ToFloatArray();
                float[] center  = position.ToRecast().ToFloatArray();

                float tx, ty;
                GetTileByLocation(position, out tx, out ty);
                int x = (int)Math.Floor(tx);
                int y = (int)Math.Floor(ty);
                LoadTile(x, y);

                dtPolyRef startRef = _query.FindNearestPolygon(center, extents, Filter);
                if (startRef == 0)
                {
                    success = false;
                    return(new Point());
                }
                float[]      result;
                DetourStatus status = _query.closestPointOnPolyBoundary(startRef, center, out result);
                if (status.HasFailed())
                {
                    success = false;
                    return(new Point());
                }
                success = true;
                return(new Point(result.ToWoW()));
            }
        }
Exemplo n.º 2
0
        public float GetZ(Point position, bool strict = false)
        {
            lock (_threadLocker)
            {
                float[] extents = strict ? new Point(0.5f, 2000.0f, 0.5f).ToFloatArray() : new Point(1.5f, 2000.0f, 1.5f).ToFloatArray();
                float[] center  = position.ToRecast().ToFloatArray();

                float tx, ty;
                GetTileByLocation(position, out tx, out ty);
                int x = (int)Math.Floor(tx);
                int y = (int)Math.Floor(ty);
                LoadTile(x, y);

                dtPolyRef startRef = _query.FindNearestPolygon(center, extents, Filter);
                if (startRef == 0)
                {
                    Logging.WriteDebug("There is no polygon in this location (Tile " + x + "," + y + "), coord: X:" +
                                       position.X + ", Y:" + position.Y);
                    return(0);
                }
                float z = _query.GetPolyHeight(startRef, center);
                if (z == 0 && !strict) // it failed but we are not strict, then search around
                {
                    float[]      result;
                    DetourStatus status = _query.closestPointOnPolyBoundary(startRef, center, out result);
                    z = status.HasFailed() ? 0 : result[1];
                }
                return(z);
            }
        }
Exemplo n.º 3
0
        public bool LoadTile(byte[] data)
        {
            lock (_threadLocker)
            {
                try
                {
                    if (CheckDungeon())
                    {
                        return(false);
                    }

                    MeshTile     tile;
                    DetourStatus ret = _mesh.AddTile(data, out tile);
                    if (ret.IsWrongVersion())
                    {
                        Logging.WriteNavigator("This mesh tile is outdated.");
                        return(false);
                    }
                    if (ret.HasFailed())
                    {
                        Logging.WriteNavigator("This mesh tile is corrupted.");
                        return(false);
                    }
                    AddMemoryPressure(data.LongLength);
                    // HandleConnections(tile);
                    return(true);
                }
                catch (Exception exception)
                {
                    Logging.WriteError("LoadTile(byte[] data): " + exception);
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     try
     {
         Status = status;
     }
     catch (Exception exception)
     {
         Logging.WriteError("NavMeshException(DetourStatus status, string text): " + exception);
     }
 }
Exemplo n.º 5
0
        public Pather(string continent, ConnectionHandlerDelegate connectionHandler)
        {
            lock (_threadLocker)
            {
                try
                {
                    ConnectionHandler = connectionHandler;

                    Continent = continent.Substring(continent.LastIndexOf('\\') + 1);

                    string dir = Application.StartupPath;
                    _meshPath = dir + "\\Meshes"; // + continent;


                    if (!Directory.Exists(_meshPath))
                    {
                        Logging.WriteNavigator(DetourStatus.Failure + " No mesh for " + continent + " (Path: " + _meshPath +
                                               ")");
                    }

                    _mesh        = new NavMesh();
                    _loadedTiles = new Dictionary <Tuple <int, int>, int>();
                    _failedTiles = new Dictionary <Tuple <int, int>, int>();
                    if (_loadTileCheck == null)
                    {
                        _loadTileCheck = new Helpful.Timer(60 * 1000); // 1 min
                    }
                    DetourStatus status;

                    // check if this is a dungeon and initialize our mesh accordingly
                    WoWMap map = WoWMap.FromMPQName(continent);
                    if (map.Record.MapType == WoWMap.MapType.WDTOnlyType || continent == "AllianceGunship")
                    {
                        string dungeonPath = GetDungeonPath();
                        if (!File.Exists(_meshPath + "\\" + dungeonPath))
                        {
                            downloadTile(dungeonPath);
                        }
                        byte[] data = File.ReadAllBytes(_meshPath + "\\" + dungeonPath);
                        status = _mesh.Initialize(data);
                        AddMemoryPressure(data.LongLength);
                        IsDungeon = true;
                    }
                    else //                       20bits 28bits
                    {
                        status = _mesh.Initialize(1048576, 2048 * Division * Division, Utility.Origin, Utility.TileSize / Division, Utility.TileSize / Division);
                    }
                    // maxPolys = 1 << polyBits (20) = 1048576
                    // maxTiles = is 8192 (was 4096), Travel loads tons of tile in quester.
                    // I have logs with over 6000 .tile files loaded.

                    if (status.HasFailed())
                    {
                        Logging.WriteNavigator(status + " Failed to initialize the mesh");
                    }

                    _query = new NavMeshQuery(new PatherCallback(this));
                    DetourStatus t = _query.Initialize(_mesh, 524287); // 20bits - 1
                    //Logging.WriteDebug("NavMeshQuery initialized with status: " + t);
                    Filter = new QueryFilter {
                        IncludeFlags = 0xFFFF, ExcludeFlags = 0x0
                    };
                    // Add the costs
                    Filter.SetAreaCost((int)PolyArea.Water, 4);
                    Filter.SetAreaCost((int)PolyArea.Terrain, 1);
                    Filter.SetAreaCost((int)PolyArea.Road, 1);  // This is the Taxi system, not in tiles yet
                    Filter.SetAreaCost((int)PolyArea.Danger, 25);
                    if (nManagerSetting.DangerousZones.Count > 0)
                    {
                        int addedDangers = ReportDanger(nManagerSetting.DangerousZones, true);
                        if (addedDangers > 0)
                        {
                            Logging.WriteNavigator(addedDangers + " dangers added.");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Logging.WriteError("Pather(string continent, ConnectionHandlerDelegate connectionHandler): " + exception);
                }
            }
        }
Exemplo n.º 6
0
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     Status = status;
 }
Exemplo n.º 7
0
 public NavMeshException(DetourStatus status, string text)
     : base(text + " (" + status + ")")
 {
     Status = status;
 }
Exemplo n.º 8
0
 public static bool HasSucceeded(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.Success));
 }
Exemplo n.º 9
0
 public static bool IsPartialResult(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.PartialResult));
 }
Exemplo n.º 10
0
 public static bool IsInProgress(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.InProgress));
 }
Exemplo n.º 11
0
 public static bool IsWrongVersion(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.WrongVersion));
 }
Exemplo n.º 12
0
 public static bool HasFailed(this DetourStatus status)
 {
     return(status.HasFlag(DetourStatus.Failure));
 }