public static float SPEED = 60;//25; //approximated movement speed with 25% move speed bonus public void OnDestinationReached(DestType type, Vec3 dest) { if (dest.Equals(m_Destination)) { m_Destination = Vec3.Empty; } }
// May enter InputLock (read -> write) internal void SetDestination(Vec3 pos, DestType type, float precision) { if (pos == null || pos.IsEmpty) { ClearDestination(type); return; } using (new ReadLock(InputLock, true)) { if ((m_Destination.Equals(pos) && m_DestinationType == type) || (!m_Destination.IsEmpty && m_DestinationType > type)) { return; } using (new WriteLock(InputLock)) { m_Destination = pos; m_DestinationType = type; Precision = precision; } //m_Navmesh.Log("[Nav] Dest changed to " + pos + " [" + type + "] precision " + precision); ResetDestReachFailed(m_CurrentPos); } RequestPathUpdate(); }
// May enter InputLock (read -> write). Do not use ZERO pos to clear destination, use ClearDestination instead! internal void SetDestination(Vec3 pos, DestType type, float precision) { // refactor not longer clearing destination automatically since ZERO is valid position to go to //if (pos == null || pos.IsEmpty) //{ // ClearDestination(type); // return; //} using (new ReadLock(InputLock, true)) { if ((m_Destination.Equals(pos) && m_DestinationType == type) || (!m_Destination.IsZero() && m_DestinationType > type)) { return; } using (new WriteLock(InputLock)) { m_Destination = pos; m_DestinationType = type; Precision = precision; } //m_Navmesh.Log("[Nav] Dest changed to " + pos + " [" + type + "] precision " + precision); ResetDestReachFailed(m_CurrentPos); } RequestPathUpdate(); }
static void doMapping( ) { var source = createSource( ); Console.WriteLine(@"Mapping {0} on thread {1}", source.GetType( ), Thread.CurrentThread.ManagedThreadId); Mapper.CreateMap(source.GetType( ), typeof(DestType)); DestType t2 = (DestType)Mapper.Map(source, source.GetType( ), typeof(DestType)); }
static void doMapping() { var source = createSource(); Console.WriteLine(@"Mapping {0} on thread {1}", source.GetType(), Thread.CurrentThread.ManagedThreadId); var config = new MapperConfiguration(cfg => cfg.CreateMap(source.GetType(), typeof(DestType))); DestType t2 = (DestType)config.CreateMapper().Map(source, source.GetType(), typeof(DestType)); }
/// <summary> /// Remove the current destination if it is of the given type and stop /// moving. /// </summary> /// <param name="type">Destination type to be removed.</param> /// <returns>Whether the destionation has been removed.<returns> public bool Remove(DestType type) { if (Dest != null && Dest.Type == type) { Dest = null; _agent.ResetPath(); return(true); } return(false); }
protected void NotifyOnDestinationReachFailed(DestType type, Vec3 dest) { List <INavigationObserver> observers_copy = null; using (new ReadLock(InputLock)) observers_copy = m_Observers.ToList(); foreach (INavigationObserver observer in observers_copy) { observer.OnDestinationReachFailed(type, dest); } }
public bool TryGetPath(ref List <Vec3> p, ref DestType p_dest_type) { if (PathLock.TryEnterReadLock(0)) { p = new List <Vec3>(m_Path); p_dest_type = m_PathDestType; PathLock.ExitReadLock(); return(true); } return(false); }
protected override void Invoke(object parameter) { if (DestType != null && !string.IsNullOrEmpty(DestMethod)) { MethodInfo mInfo = DestType.GetMethod(DestMethod, BindingFlags.Public | BindingFlags.Static); if (mInfo != null) { if (IsDirect) { object o1 = mInfo.Invoke(DestObject, (object[])DestParas); if (Target != null && TargetProperty != null) { Target.SetValue(TargetProperty, o1); } } else { List <object> l1 = new List <object>(); switch (parameter.GetType().FullName) { case "System.Windows.Controls.CalendarSelectionChangedEventArgs": var c1 = parameter as System.Windows.Controls.SelectionChangedEventArgs; string date = c1.AddedItems.Count > 0 ? ((DateTime)c1.AddedItems[0]).ToString("yyyy-MM-dd") : ""; l1.Add(date); l1.Add(this.ParasObject); l1.Add(this.DestParas); break; case "System.Windows.Controls.SelectionChangedEventArgs": string date2 = this.ParasObject != null ? (DateTime.Parse(this.ParasObject.ToString())).ToString("yyyy-MM-dd") : ""; l1.Add(date2); l1.Add(this.ParasObject); l1.Add(this.DestParas); break; case "System.Windows.RoutedEventArgs": case "System.Windows.Controls.TextChangedEventArgs": l1.Add(this.ParasObject); l1.Add(this.DestParas); break; default: break; } object o1 = mInfo.Invoke(DestObject, l1.ToArray()); if (Target != null && TargetProperty != null) { Target.SetValue(TargetProperty, o1); } } } } }
public void receiveServerChat(Packet p) { NetworkAction action = (NetworkAction)p.readUint8(); DestType dest = (DestType)p.readUint8(); long clientId = p.readUint32(); String message = p.readString(); long data = p.readUint64(); if (OnChat != null) { OnChat(action, dest, clientId, message, data); } }
internal bool IsValid(out string validationMessage) { //validate the url redirect for the ability to be used validationMessage = "Invalid Redirect Id [" + RedirectId.ToString() + "] ;"; int noErrorLength = validationMessage.Length; if (string.IsNullOrEmpty(RedirectUrl)) { validationMessage += "Redirect Url Field is null. Supply a valid Url. ;"; } if (string.IsNullOrEmpty(MatchType)) { validationMessage += "MatchType field is null. Use either 'absolute' or 'relative' ;"; } else { if (MatchType.ToLower() != "absolute" && MatchType.ToLower() != "relative") { validationMessage += "MatchType field of '" + MatchType + "' is invalid. Use either 'absolute' or 'relative' ;"; } } if (string.IsNullOrEmpty(DestType)) { validationMessage += "DestType field is null. Use either 'tab' or 'url' ;"; } else { if (DestType.ToLower() != "tab" && DestType.ToLower() != "url") { validationMessage += "DestType field of '" + DestType + "' is invalid. Use either 'tab' or 'url' ;"; } if (DestType.ToLower() == "tab" && (DestTabId <= 0 && string.IsNullOrEmpty(DestTabPath))) { validationMessage = "Specify either a valid DestTabId value, or a valid DestTabPath ;"; } if (DestType.ToLower() == "url" && string.IsNullOrEmpty(DestUrl)) { validationMessage += "DestUrl must be specified for DestType of 'url' ;"; } } if (validationMessage.Length > noErrorLength) { return(false); } else { return(true); } }
public override bool Equals(object obj) { if (obj is CastParams) { CastParams parms = (CastParams)obj; return(SourceType.Equals(parms.SourceType) && DestType.Equals(parms.DestType) && Reinterpret == parms.Reinterpret); } else { return(false); } }
internal bool IsDestinationReached(DestType type_filter, ref Vec3 destination) { using (new ReadLock(InputLock)) using (new ReadLock(PathLock)) { if ((m_DestinationType & type_filter) == 0) { return(false); } destination = new Vec3(m_Destination); return((m_CurrentPos.IsEmpty || m_Destination.IsEmpty || !m_Destination.Equals(m_PathDestination)) ? false : (m_Path.Count == 0)); } }
public void sendAdminChat(NetworkAction action, DestType type, long dest, String msg, long data) { Packet p = new Packet(getSocket(), enums.PacketType.ADMIN_PACKET_ADMIN_CHAT); p.writeUint8((short)action); p.writeUint8((short)type); p.writeUint32(dest); msg = (msg.Length > 900) ? msg.Substring(0, 900) : msg; p.WriteString(msg); p.writeUint64(data); NetworkOutputThread.append(p); }
public float TryGetPathLength(ref DestType p_dest_type) { float length = 0; if (PathLock.TryEnterReadLock(0)) { for (int i = 0; i < m_Path.Count - 1; ++i) { length += m_Path[i].Distance2D(m_Path[i + 1]); } p_dest_type = m_PathDestType; PathLock.ExitReadLock(); } return(length); }
public void OnDestinationReached(DestType type, Vec3 dest) { if (type != DestType.Explore) { return; } ExploreCell dest_cell = m_ExploreCells.FirstOrDefault(x => x.Position.Equals(dest)); if (dest_cell != null) { OnCellExplored(dest_cell); } m_DestCell = GetDestinationCell(); m_Navigator.SetDestination(GetDestinationCellPosition(), DestType.Explore, ExploreDestPrecision); }
public void OnDestinationReached(DestType type, Vec3 dest) { if (type != DestType.Explore) { return; } ExploreCell dest_cell = m_ExploreCells.Find(x => x.Position.Equals(dest)); if (dest_cell != null) { OnCellExplored(dest_cell); } Vec3 next_dest = GetDestinationCellPosition(); Navmesh.Navigator.SetDestination(next_dest, DestType.Explore); }
// Aquires InputLock (read -> write) internal void ClearDestination(DestType type) { using (new ReadLock(InputLock, true)) { if ((m_DestinationType & type) == 0) { return; } using (new WriteLock(InputLock)) { //m_Navmesh.Log("[Nav] Dest [" + m_DestinationType + "] cleared using [" + type + "] flags!"); m_Destination = Vec3.Empty; m_DestinationType = DestType.None; } } }
public DestAction(XmlDocument xmlDocument, DestType type, string pageId, double left, double right, double top, double bottom, double zoom) : base(xmlDocument, "Dest") { Type = type; PageId = pageId; Left = left; Right = right; Top = top; Bottom = bottom; Zoom = zoom; Element.SetAttribute("Type", type.ToString()); Element.SetAttribute("PageID", pageId); Element.SetAttribute("Left", left.ToString(CultureInfo.InvariantCulture)); Element.SetAttribute("Right", right.ToString(CultureInfo.InvariantCulture)); Element.SetAttribute("Top", top.ToString(CultureInfo.InvariantCulture)); Element.SetAttribute("Bottom", bottom.ToString(CultureInfo.InvariantCulture)); Element.SetAttribute("Zoom", zoom.ToString(CultureInfo.InvariantCulture)); }
protected override void Invoke(object parameter) { if (DestType != null && !string.IsNullOrEmpty(DestMethod)) { MethodInfo mInfo = null; if (ParameterTypes.Count > 0) { var ts = from s1 in this.ParameterTypes select Type.GetType(s1); mInfo = DestType.GetMethod(DestMethod, ts.ToArray()); } else { mInfo = DestType.GetMethod(DestMethod); } if (mInfo != null) { object o1 = mInfo.Invoke(TargetObject, (object[])MethodParameters); } } }
private void UpdateDestReachFailed() { const float MIN_DIST_TO_RESET = 90; const float MIN_TIME_TO_FAIL_DESTINATION_REACH = 20000; if (m_DestReachFailedTestPos.IsEmpty || m_DestReachFailedTestPos.Distance(m_CurrentPos) > MIN_DIST_TO_RESET) { ResetDestReachFailed(); } else if (IsStandingOnPurpose) { m_DestReachFailedTimer.Stop(); } else { m_DestReachFailedTimer.Start(); } if (m_DestReachFailedTimer.ElapsedMilliseconds > MIN_TIME_TO_FAIL_DESTINATION_REACH) { DestType dest_type = DestType.None; Vec3 dest = null; using (new ReadLock(InputLock)) { dest_type = m_DestinationType; dest = m_Destination; } m_Navmesh.Log("[Nav] Dest " + dest + " [" + dest_type + "] reach failed!"); foreach (NavigationObserver listener in m_Listeners) { listener.OnDestinationReachFailed(dest_type, dest); } ResetDestReachFailed(); } }
private void UpdateDestReachFailed() { const float MIN_DIST_TO_RESET = 90; const float MIN_TIME_TO_FAIL_DESTINATION_REACH = 20000; Vec3 curr_pos = CurrentPos; if (m_DestReachFailedTestPos.Distance(curr_pos) > MIN_DIST_TO_RESET) { ResetDestReachFailed(curr_pos); } else if (IsStandingOnPurpose) { m_DestReachFailedTimer.Stop(); } else { m_DestReachFailedTimer.Start(); } if (m_DestReachFailedTimer.ElapsedMilliseconds > MIN_TIME_TO_FAIL_DESTINATION_REACH) { DestType dest_type = DestType.None; Vec3 dest = default(Vec3); using (new ReadLock(InputLock)) { dest_type = m_DestinationType; dest = m_Destination; } //m_Navmesh.Log("[Nav] Destination " + dest + " [" + dest_type + "] reach failed!"); NotifyOnDestinationReachFailed(dest_type, dest); ResetDestReachFailed(curr_pos); } }
/// <summary> /// Automatically map commonly named properties. /// </summary> private void AutomagicallyMap(string[] ignoreSrceProperties) { MapperPropertyAttribute mpa = null; foreach (var sp in SrceType.GetProperties(BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance)) { // Do not auto-map where ignore has been specified. if (ignoreSrceProperties.Contains(sp.Name)) { continue; } if (sp.GetCustomAttributes(typeof(MapperIgnoreAttribute), true).OfType <MapperIgnoreAttribute>().FirstOrDefault() != null) { continue; } // Find corresponding property. mpa = sp.GetCustomAttributes(typeof(MapperPropertyAttribute), true).OfType <MapperPropertyAttribute>().FirstOrDefault(); var dname = mpa == null || string.IsNullOrEmpty(mpa.Name) ? sp.Name : mpa.Name; var dp = DestType.GetProperty(dname, BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance); if (dp == null) { if (mpa != null) { throw new InvalidOperationException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with Name set to '{dname}' which does not exist for destination Type '{DestType.Name}'."); } continue; } // Create the lambda expressions for the property and add to the mapper. var spe = Expression.Parameter(SrceType, "x"); var sex = Expression.Lambda(Expression.Property(spe, sp.Name), spe); var dpe = Expression.Parameter(DestType, "x"); var dex = Expression.Lambda(Expression.Property(dpe, dname), dpe); var pmap = (IPropertyMapper <TSrce, TDest>) typeof(EntityMapper <TSrce, TDest>) .GetMethod("PropertySrceAndDest", BindingFlags.NonPublic | BindingFlags.Instance) .MakeGenericMethod(new Type[] { sp.PropertyType, dp.PropertyType }) .Invoke(this, new object[] { sex, dex }); if (mpa == null) { continue; } // Apply auto-map Property attribute IsUnique configuration. if (mpa.IsUniqueKey) { pmap.SetUniqueKey(mpa.IsUniqueKeyAutoGeneratedOnCreate); } // Apply auto-map Property attribute ConverterType configuration. if (mpa.ConverterType != null) { if (!typeof(IPropertyMapperConverter).IsAssignableFrom(mpa.ConverterType)) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' which does not implement 'IPropertyMapperConverter'."); } IPropertyMapperConverter pmc = null; var pdef = mpa.ConverterType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (pdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' does not have a static 'Default' property or default constructor."); } pmc = (IPropertyMapperConverter)Activator.CreateInstance(mpa.ConverterType); } else { pmc = (IPropertyMapperConverter)pdef.GetValue(null); } pmap.SetConverter(pmc); continue; } // Apply auto-map Property attribute MapperType configuration for complex types. if (pmap.IsSrceComplexType) { IEntityMapperBase em = null; if (mpa.MapperType != null) { if (!typeof(IEntityMapperBase).IsAssignableFrom(mpa.MapperType)) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' which does not implement 'IEntityMapper'."); } var mdef = mpa.MapperType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (mdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' does not have a static 'Default' property or default constructor."); } em = (IEntityMapperBase)Activator.CreateInstance(mpa.MapperType); } else { em = (IEntityMapperBase)mdef.GetValue(null); } } if (em != null) { pmap.SetMapper(em); } } else if (mpa.MapperType != null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.ConverterType.Name}' although the property is not a complex type."); } } }
// May enter InputLock (read -> write) internal void SetDestination(Vec3 pos, DestType type) { if (pos.IsEmpty) { ClearDestination(type); return; } using (new ReadLock(InputLock, true)) { if ((m_Destination.Equals(pos) && m_DestinationType == type) || (!m_Destination.IsEmpty && m_DestinationType > type)) return; using (new WriteLock(InputLock)) { m_Destination = pos; m_DestinationType = type; } m_Navmesh.Log("[Nav] Dest changed to " + pos + " [" + type + "]"); ResetDestReachFailed(); } RequestPathUpdate(); }
internal bool IsDestinationReached(DestType type_filter) { Vec3 temp = Vec3.Empty; return IsDestinationReached(type_filter, ref temp); }
internal bool IsDestinationReached(DestType type_filter, ref Vec3 destination) { using (new ReadLock(InputLock)) using (new ReadLock(PathLock)) { if ((m_DestinationType & type_filter) == 0) return false; destination = new Vec3(m_Destination); return (m_CurrentPos.IsEmpty || m_Destination.IsEmpty || !m_Destination.Equals(m_PathDestination)) ? false : (m_Path.Count == 0); } }
public Destination(Vector3 position, float distance, DestType type) { Position = position; Distance = distance; Type = type; }
//====================================================================== public Destination(Vector3 position, DestType type) : this(position, 0, type) { }
// Everything inside this method is rendered with transformation resulting from ModifyRenderMatrix. protected virtual void OnRenderData(PaintEventArgs e) { try { int cells_count = 0; int grid_cells_count = 0; if (m_RenderGrids || m_RenderCells) { using (m_Navmesh.AcquireReadDataLock()) { var grid_cells = m_Navmesh.dbg_GetGridCells(); if (m_RenderGrids) { foreach (Nav.GridCell grid_cell in grid_cells) { RenderHelper.Render(grid_cell, m_RenderCenter, e, m_RenderConnections, m_RenderIds); } grid_cells_count = grid_cells.Count; } if (m_RenderCells) { float max_move_cost_mult = 1; foreach (Nav.GridCell grid_cell in grid_cells) { foreach (Nav.Cell cell in grid_cell.GetCells()) { RenderHelper.Render(cell, m_RenderCenter, e, m_RenderConnections, m_RenderIds, m_LastMaxMoveCostMult); max_move_cost_mult = Math.Max(max_move_cost_mult, cell.MovementCostMult); } cells_count += grid_cell.GetCellsCount(); } m_LastMaxMoveCostMult = max_move_cost_mult; } } } if (m_RenderExploreCells || m_RenderExploreArea) { using (m_Explorer.AquireReadDataLock()) { var explore_cells = m_Explorer.dbg_GetExploreCells(); foreach (Nav.ExploreCell explore_cell in explore_cells) { RenderHelper.Render(explore_cell, m_Explorer.ExploreDestPrecision, m_RenderCenter, e, m_RenderConnections, m_RenderIds); if (m_RenderExploreArea) { RenderHelper.DrawString(e.Graphics, Brushes.Black, m_RenderCenter, explore_cell.Position, explore_cell.CellsArea().ToString(), 5); } } } } if (m_RenderRegions) { var regions = m_Navmesh.Regions; foreach (var region in regions) { RenderHelper.DrawRectangle(e.Graphics, Pens.Black, m_RenderCenter, region.area.Min, region.area.Max); } //Vec3 safe_point = m_Navigator.GetNearestGridCellOutsideAvoidAreas(); //if (!safe_point.IsEmpty) // RenderHelper.DrawPoint(e.Graphics, Pens.Green, render_center, safe_point); } if (m_RenderAxis) { e.Graphics.DrawString("X", new Font("Arial", 6 / m_RenderScale), Brushes.Black, 25 / m_RenderScale, 0); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, -25 / m_RenderScale, 0, 25 / m_RenderScale, 0); e.Graphics.DrawString("Y", new Font("Arial", 6 / m_RenderScale), Brushes.Black, 0, 25 / m_RenderScale); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, 0, -25 / m_RenderScale, 0, 25 / m_RenderScale); } if (!m_RenderOriginalPath && m_RenderPath) { DestType last_path_dest_type = DestType.None; if (m_Navigator.TryGetPath(ref m_LastPath, ref last_path_dest_type)) { m_LastPath.Insert(0, m_Navigator.CurrentPos); } RenderHelper.DrawLines(e.Graphics, RenderHelper.PATH_PEN, m_RenderCenter, m_LastPath, 1); } if (m_RenderBacktrackPath) { if (m_Navigator.TryGetBackTrackPath(ref m_LastBacktrackPath)) { m_LastBacktrackPath.Insert(0, m_Navigator.CurrentPos); } RenderHelper.DrawLines(e.Graphics, Pens.Blue, m_RenderCenter, m_LastBacktrackPath, 1); } if (m_RenderPositionsHistory) { m_Navigator.TryGetDebugPositionsHistory(ref m_LastPositionsHistory); RenderHelper.DrawLines(e.Graphics, Pens.Green, m_RenderCenter, m_LastPositionsHistory, 1); } if (!m_Navigator.CurrentPos.IsZero()) { RenderHelper.DrawPoint(e.Graphics, Pens.Blue, m_RenderCenter, m_Navigator.CurrentPos); } if (!m_Navigator.Destination.IsZero()) { RenderHelper.DrawPoint(e.Graphics, Pens.LightBlue, m_RenderCenter, m_Navigator.Destination); } { Vec3 curr = m_Navigator.CurrentPos; Vec3 dest = m_Navigator.Destination; if (!curr.IsZero() && !dest.IsZero()) { if (m_RenderOriginalPath) { List <Vec3> path = new List <Vec3>(); m_Navigator.FindPath(curr, dest, MovementFlag.Walk, ref path, -1, false, false, 0, false, 0, false); path.Insert(0, curr); RenderHelper.DrawLines(e.Graphics, Pens.Black, m_RenderCenter, path, 1); } if (m_RenderRayCast) { Vec3 intersection = default(Vec3); RenderHelper.DrawLine(e.Graphics, m_Navmesh.RayCast2D(curr, dest, MovementFlag.Walk, ref intersection) ? Pens.Green : Pens.Red, m_RenderCenter, curr, intersection); } } } var waypoints = m_Navigator.Waypoints; if (waypoints.Count > 0) { RenderHelper.DrawLines(e.Graphics, Pens.Red, m_RenderCenter, waypoints, 1); } if (m_Bot != null) { //if (!m_Bot.Paused && m_CenterOnBot) // m_RenderCenter = new PointF(m_Bot.Position.X, m_Bot.Position.Y); m_Bot.Render(e.Graphics, m_RenderCenter); } } catch (Exception) { } }
public void OnDestinationReachFailed(DestType type, Vec3 dest) { OnDestinationReached(type, dest); }
public void OnDestinationReached(DestType type, Vec3 dest) { if (type != DestType.Explore) return; ExploreCell dest_cell = m_ExploreCells.Find(x => x.Position.Equals(dest)); if (dest_cell != null) OnCellExplored(dest_cell); Vec3 next_dest = GetDestinationCellPosition(); Navmesh.Navigator.SetDestination(next_dest, DestType.Explore); }
public void OnDestinationReachFailed(DestType type, Vec3 dest) { }
public static float SPEED = 60;//25; //approximated movement speed with 25% move speed bonus public void OnDestinationReached(DestType type, Vec3 dest) { if (dest.Equals(m_Destination)) m_Destination = Vec3.Empty; }
// Aquires InputLock (read -> write) internal void ClearDestination(DestType type) { using (new ReadLock(InputLock, true)) { if ((m_DestinationType & type) == 0) return; using (new WriteLock(InputLock)) { m_Navmesh.Log("[Nav] Dest [" + m_DestinationType + "] cleared using [" + type + "] flags!"); m_Destination = Vec3.Empty; m_DestinationType = DestType.None; } } }
internal bool IsDestinationReached(DestType type_filter) { Vec3 temp = Vec3.Empty; return(IsDestinationReached(type_filter, ref temp)); }
private void Render(object sender, PaintEventArgs e) { try { int location = -1; if (engine != null) { LevelArea level_area = Engine.Current.LevelArea; if (level_area != null) { location = level_area.x044_SnoId; } } if (last_location != location) { if (auto_clear_navmesh) { m_Navmesh.Clear(); LoadDebugConfig(); } last_location = location; } Matrix m = new Matrix(); m.Scale(render_scale, render_scale); m.Translate((Width - 16) / (2 * render_scale), (Height - 30) / (2 * render_scale)); // when Diablo is running display navmesh in the same manner as Diablo does if (engine != null) { m.Rotate(135); Matrix flip_x_m = new Matrix(1, 0, 0, -1, 0, 0); m.Multiply(flip_x_m); } e.Graphics.Transform = m; e.Graphics.CompositingQuality = CompositingQuality.GammaCorrected; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int cells_count = 0; int grid_cells_count = 0; if (render_grids || render_cells) { using (m_Navmesh.AquireReadDataLock()) { List <GridCell> grid_cells = m_Navmesh.dbg_GetGridCells(); if (render_grids) { foreach (Nav.GridCell grid_cell in grid_cells) { RenderHelper.Render(grid_cell, render_center, e, render_connections, render_id); } grid_cells_count = grid_cells.Count; } if (render_cells) { float max_move_cost_mult = 1; foreach (Nav.GridCell grid_cell in grid_cells) { foreach (Nav.Cell cell in grid_cell.Cells) { RenderHelper.Render(cell, render_center, e, render_connections, render_id, m_LastMaxMoveCostMult); max_move_cost_mult = Math.Max(max_move_cost_mult, cell.MovementCostMult); } cells_count += grid_cell.Cells.Count; } m_LastMaxMoveCostMult = max_move_cost_mult; } } } if (render_explore_cells || render_explore_dist) { using (m_Navmesh.Explorator.AquireReadDataLock()) { List <ExploreCell> explore_cells = m_Navmesh.Explorator.dbg_GetExploreCells(); if (render_explore_cells) { foreach (Nav.ExploreCell explore_cell in explore_cells) { RenderHelper.Render(explore_cell, m_Navmesh.Navigator.ExploreCellPrecision, render_center, e, render_connections, render_id); } } if (render_explore_dist) { if (explore_cells.Exists(c => c.Id == explore_cell_id_to_render_dists)) { RenderHelper.Render(m_Navmesh, explore_cells.Find(c => c.Id == explore_cell_id_to_render_dists), render_center, e, render_id); } } } } if (render_regions) { var regions = m_Navmesh.Regions; foreach (var region in regions) { RenderHelper.DrawRectangle(e.Graphics, Pens.Black, render_center, region.area.Min, region.area.Max); } //Vec3 safe_point = m_Navmesh.Navigator.GetNearestGridCellOutsideAvoidAreas(); //if (!safe_point.IsEmpty) // RenderHelper.DrawPoint(e.Graphics, Pens.Green, render_center, safe_point); } if (render_axis) { e.Graphics.DrawString("X", new Font("Arial", 6 / render_scale), Brushes.Black, 25 / render_scale, 0); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, -25 / render_scale, 0, 25 / render_scale, 0); e.Graphics.DrawString("Y", new Font("Arial", 6 / render_scale), Brushes.Black, 0, 25 / render_scale); e.Graphics.DrawLine(RenderHelper.AXIS_PEN, 0, -25 / render_scale, 0, 25 / render_scale); } if (render_explore_cells && m_Navmesh.Explorator is Nav.ExploreEngine.TSP) { ((Nav.ExploreEngine.TSP)m_Navmesh.Explorator).TryGetExplorePath(ref last_explore_path); RenderHelper.DrawLines(e.Graphics, RenderHelper.EXPLORE_PATH_PEN, render_center, last_explore_path, 1); } if (!render_original_path && render_path) { DestType last_path_dest_type = DestType.None; if (m_Navmesh.Navigator.TryGetPath(ref last_path, ref last_path_dest_type)) { last_path.Insert(0, m_Navmesh.Navigator.CurrentPos); } RenderHelper.DrawLines(e.Graphics, RenderHelper.PATH_PEN, render_center, last_path, 1); } if (render_backtrack_path) { if (m_Navmesh.Navigator.TryGetBackTrackPath(ref last_back_track_path)) { last_back_track_path.Insert(0, m_Navmesh.Navigator.CurrentPos); } RenderHelper.DrawLines(e.Graphics, Pens.Blue, render_center, last_back_track_path, 1); } if (render_positions_history) { m_Navmesh.Navigator.TryGetDebugPositionsHistory(ref last_positions_history); RenderHelper.DrawLines(e.Graphics, Pens.Green, render_center, last_positions_history, 1); } if (!m_Navmesh.Navigator.CurrentPos.IsEmpty) { RenderHelper.DrawPoint(e.Graphics, Pens.Blue, render_center, m_Navmesh.Navigator.CurrentPos); } if (!m_Navmesh.Navigator.Destination.IsEmpty) { RenderHelper.DrawPoint(e.Graphics, Pens.LightBlue, render_center, m_Navmesh.Navigator.Destination); } { Vec3 curr = m_Navmesh.Navigator.CurrentPos; Vec3 dest = m_Navmesh.Navigator.Destination; if (!curr.IsEmpty && !dest.IsEmpty) { if (render_original_path) { List <Vec3> path = new List <Vec3>(); m_Navmesh.Navigator.FindPath(curr, dest, MovementFlag.Walk, ref path, -1, false, false, 0, false, 0, false); path.Insert(0, curr); RenderHelper.DrawLines(e.Graphics, Pens.Black, render_center, path, 1); } if (render_ray_cast) { RenderHelper.DrawLine(e.Graphics, m_Navmesh.RayCast2D(curr, dest, MovementFlag.Walk) ? Pens.Green : Pens.Red, render_center, curr, dest); } } } if (waypoints_paths.Count > 0) { int waypoint_id = 1; foreach (List <Vec3> p in waypoints_paths) { if (p.Count > 0) { RenderHelper.DrawCircle(e.Graphics, Pens.Black, render_center, p[0], 3); RenderHelper.DrawString(e.Graphics, Brushes.Black, render_center, p[0], waypoint_id.ToString(), 10); } RenderHelper.DrawLines(e.Graphics, Pens.Red, render_center, p, 1); ++waypoint_id; } } if (bot != null) { if (!bot.Paused && center_on_bot) { render_center = new PointF(bot.Position.X, bot.Position.Y); } bot.Render(e.Graphics, render_center); } e.Graphics.ResetTransform(); Font legend_font = new Font("Arial", 8, FontStyle.Bold); Font stats_font = new Font("Arial", 8); TextRenderer.DrawText(e.Graphics, "L: Toggle render legend", legend_font, new Point(10, 10), render_legend ? Color.White : Color.Black, render_legend ? Color.Black : Color.Transparent); if (render_legend) { e.Graphics.DrawString("F1: Reload waypoints", legend_font, Brushes.Black, 10, 25); e.Graphics.DrawString("F2: Reload nav data", legend_font, Brushes.Black, 10, 40); e.Graphics.DrawString("F3: Dump nav data", legend_font, Brushes.Black, 10, 55); e.Graphics.DrawString("F4: Clear nav data", legend_font, Brushes.Black, 10, 70); e.Graphics.DrawString("F5: Serialize nav data", legend_font, Brushes.Black, 10, 85); e.Graphics.DrawString("F6: Deserialize nav data", legend_font, Brushes.Black, 10, 100); e.Graphics.DrawString("F10: Activate some test", legend_font, Brushes.Black, 10, 115); TextRenderer.DrawText(e.Graphics, "1: Toggle render grid cells", legend_font, new Point(10, 130), render_grids ? Color.White : Color.Black, render_grids ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "2: Toggle render cells", legend_font, new Point(10, 145), render_cells ? Color.White : Color.Black, render_cells ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "3: Toggle render explore cells", legend_font, new Point(10, 160), render_explore_cells ? Color.White : Color.Black, render_explore_cells ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "4: Toggle render connections", legend_font, new Point(10, 175), render_connections ? Color.White : Color.Black, render_connections ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "5: Toggle render IDs", legend_font, new Point(10, 190), render_id ? Color.White : Color.Black, render_id ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "6: Toggle render axis", legend_font, new Point(10, 205), render_axis ? Color.White : Color.Black, render_axis ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "7: Toggle render regions", legend_font, new Point(10, 220), render_regions ? Color.White : Color.Black, render_regions ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "8: Toggle render original path", legend_font, new Point(10, 235), render_original_path ? Color.White : Color.Black, render_original_path ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "9: Toggle render ray cast", legend_font, new Point(10, 250), render_ray_cast ? Color.White : Color.Black, render_ray_cast ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "0: Toggle render back track path", legend_font, new Point(10, 265), render_backtrack_path ? Color.White : Color.Black, render_backtrack_path ? Color.Black : Color.Transparent); e.Graphics.DrawString("S: Set current pos", legend_font, Brushes.Black, 10, 280); e.Graphics.DrawString("E: Set destination pos", legend_font, Brushes.Black, 10, 295); e.Graphics.DrawString("B: Run bot", legend_font, Brushes.Black, 10, 310); TextRenderer.DrawText(e.Graphics, "A: Toggle auto clear navmesh", legend_font, new Point(10, 325), auto_clear_navmesh ? Color.White : Color.Black, auto_clear_navmesh ? Color.Black : Color.Transparent); e.Graphics.DrawString("F7: Reload debug.ini", legend_font, Brushes.Black, 10, 340); TextRenderer.DrawText(e.Graphics, "Ctrl+1: Toggle render path", legend_font, new Point(10, 355), render_path ? Color.White : Color.Black, render_path ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+2: Toggle regions", legend_font, new Point(10, 370), m_Navmesh.RegionsEnabled ? Color.White : Color.Black, m_Navmesh.RegionsEnabled ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+3: Toggle danger regions", legend_font, new Point(10, 385), m_Navmesh.DangerRegionsEnabled ? Color.White : Color.Black, m_Navmesh.DangerRegionsEnabled ? Color.Black : Color.Transparent); TextRenderer.DrawText(e.Graphics, "Ctrl+4: Toggle render positions history", legend_font, new Point(10, 400), render_positions_history ? Color.White : Color.Black, render_positions_history ? Color.Black : Color.Transparent); } e.Graphics.DrawString("Cells count: " + cells_count, stats_font, Brushes.Black, 10, Height - 55); } catch (Exception) { } }
private void UpdatePath() { if (!m_Navmesh.IsNavDataAvailable) { return; } Vec3 destination = Vec3.Empty; DestType dest_type = DestType.None; // make sure destination and its type are in sync using (new ReadLock(InputLock)) { destination = m_Destination; dest_type = m_DestinationType; } Vec3 current_pos = CurrentPos; if (current_pos.IsEmpty || destination.IsEmpty) { return; } List <Vec3> new_path = new List <Vec3>(); FindPath(current_pos, destination, MovementFlags, ref new_path, PATH_NODES_MERGE_DISTANCE, true, false, m_PathRandomCoeffOverride > 0 ? m_PathRandomCoeffOverride : PathRandomCoeff, m_PathBounce, PathNodesShiftDist); // verify whenever some point of path was not already passed during its calculation (this may take place when path calculations took long time) // this is done by finding first path segment current position can be casted on and removing all points preceding this segment including segment origin current_pos = CurrentPos; while (new_path.Count > 1) { Vec3 segment = new_path[1] - new_path[0]; Vec3 segment_origin_to_current_pos = current_pos - new_path[0]; float segment_len = segment.Length2D(); float projection_len = segment.Dot2D(segment_origin_to_current_pos) / segment_len; // current position is already 'after' segment origin so remove it from path if (projection_len > 0) { float distance_from_segment = -1; // additionally verify if current pos is close enough to segment if (projection_len > segment_len) { distance_from_segment = current_pos.Distance2D(new_path[1]); } else { distance_from_segment = current_pos.Distance2D(segment.Normalized2D() * projection_len); } if (distance_from_segment < DefaultPrecision) { new_path.RemoveAt(0); } else { break; } } else { break; } } using (new WriteLock(PathLock)) { // reset override when first destination from path changed if (m_Path.Count == 0 || (new_path.Count > 0 && !m_Path[0].Equals(new_path[0]))) { ResetAntiStuckPrecition(current_pos); } m_Path = new_path; m_PathDestination = destination; m_PathDestType = dest_type; } }
public bool TryGetPath(ref List<Vec3> p, ref DestType p_dest_type) { if (PathLock.TryEnterReadLock(0)) { p = new List<Vec3>(m_Path); p_dest_type = m_PathDestType; PathLock.ExitReadLock(); return true; } return false; }