public MyPathfinding() { NextTimestampFunction = GenerateNextTimestamp; m_navmeshCoordinator = new MyNavmeshCoordinator(); m_gridPathfinding = new MyGridPathfinding(m_navmeshCoordinator); m_voxelPathfinding = new MyVoxelPathfinding(m_navmeshCoordinator); }
public void UnloadData() { m_gridPathfinding.UnloadData(); m_voxelPathfinding.UnloadData(); m_gridPathfinding = null; m_voxelPathfinding = null; m_navmeshCoordinator = null; }
public MyPathfinding() : base(0x80, null) { this.NextTimestampFunction = new Func <long>(this.GenerateNextTimestamp); this.m_obstacles = new MyDynamicObstacles(); this.m_navmeshCoordinator = new MyNavmeshCoordinator(this.m_obstacles); this.m_gridPathfinding = new MyGridPathfinding(this.m_navmeshCoordinator); this.m_voxelPathfinding = new MyVoxelPathfinding(this.m_navmeshCoordinator); MyEntities.OnEntityAdd += new Action <MyEntity>(this.MyEntities_OnEntityAdd); }
public void UnloadData() { MyEntities.OnEntityAdd -= new Action <MyEntity>(this.MyEntities_OnEntityAdd); this.m_voxelPathfinding.UnloadData(); this.m_gridPathfinding = null; this.m_voxelPathfinding = null; this.m_navmeshCoordinator = null; this.m_obstacles.Clear(); this.m_obstacles = null; }
public MyPathfinding() { NextTimestampFunction = GenerateNextTimestamp; m_obstacles = new MyDynamicObstacles(); m_navmeshCoordinator = new MyNavmeshCoordinator(m_obstacles); m_gridPathfinding = new MyGridPathfinding(m_navmeshCoordinator); m_voxelPathfinding = new MyVoxelPathfinding(m_navmeshCoordinator); MyEntities.OnEntityAdd += MyEntities_OnEntityAdd; }
public void UnloadData() { MyEntities.OnEntityAdd -= MyEntities_OnEntityAdd; m_voxelPathfinding.UnloadData(); m_gridPathfinding = null; m_voxelPathfinding = null; m_navmeshCoordinator = null; m_obstacles.Clear(); m_obstacles = null; }
public void UpdateVoxelNavmeshCellHighLevelLinks(MyVoxelPathfinding.CellId cellId) { // Make sure links are where they should be List<MyNavigationPrimitive> linkedTriangles = null; if (m_voxelLinkDictionary.TryGetValue(cellId, out linkedTriangles)) { MyNavigationPrimitive hlPrimitive1 = null; MyNavigationPrimitive hlPrimitive2 = null; foreach (var primitive in linkedTriangles) { hlPrimitive1 = primitive.GetHighLevelPrimitive(); List<MyNavigationPrimitive> otherLinkedPrimitives = null; otherLinkedPrimitives = m_links.GetLinks(primitive); if (otherLinkedPrimitives != null) { foreach (var otherPrimitive in otherLinkedPrimitives) { hlPrimitive2 = otherPrimitive.GetHighLevelPrimitive(); m_highLevelLinks.AddLink(hlPrimitive1, hlPrimitive2, onlyIfNotPresent: true); } } } } // CH: TODO: Make sure that links are not where they should not be }
public void SetVoxelPathfinding(MyVoxelPathfinding myVoxelPathfinding) { m_voxelPathfinding = myVoxelPathfinding; }
private void RemoveVoxelLinkFromDictionary(MyVoxelPathfinding.CellId cellId, MyNavigationPrimitive linkedPrimitive) { List<MyNavigationPrimitive> list = null; if (!m_voxelLinkDictionary.TryGetValue(cellId, out list)) { Debug.Assert(false, "Could not find a removed voxel link in the dictionary!"); return; } else { bool retval = list.Remove(linkedPrimitive); Debug.Assert(retval == true, "Couldn't remove a linked triangle from the dictionary!"); if (list.Count == 0) { m_voxelLinkDictionary.Remove(cellId); } } }
private void SaveVoxelLinkToDictionary(MyVoxelPathfinding.CellId cellId, MyNavigationPrimitive linkedPrimitive) { List<MyNavigationPrimitive> list = null; if (!m_voxelLinkDictionary.TryGetValue(cellId, out list)) { // CH:TODO: take these from pre-allocated pools list = new List<MyNavigationPrimitive>(); } else if (list.Contains(linkedPrimitive)) { // Avoid duplicates return; } list.Add(linkedPrimitive); m_voxelLinkDictionary[cellId] = list; }
public void RemoveVoxelNavmeshLinks(MyVoxelPathfinding.CellId cellId) { List<MyNavigationPrimitive> list = null; if (!m_voxelLinkDictionary.TryGetValue(cellId, out list)) { return; } foreach (var primitive in list) { m_links.RemoveAllLinks(primitive); } m_voxelLinkDictionary.Remove(cellId); }
public void TryAddVoxelNavmeshLinks2(MyVoxelPathfinding.CellId cellId, Dictionary<MyGridPathfinding.CubeId, List<MyNavigationPrimitive>> linkCandidates) { ProfilerShort.Begin("TryAddVoxelNavmeshLinks"); foreach (var entry in linkCandidates) { double closestDistSq = double.MaxValue; MyNavigationTriangle closestGridTri = null; MyNavigationPrimitive closestLinkedPrim = null; m_tmpNavTris.Clear(); m_gridPathfinding.GetCubeTriangles(entry.Key, m_tmpNavTris); foreach (var tri in m_tmpNavTris) { Vector3 a, b, c; tri.GetVertices(out a, out b, out c); a = tri.Parent.LocalToGlobal(a); b = tri.Parent.LocalToGlobal(b); c = tri.Parent.LocalToGlobal(c); Vector3D normal = (c - a).Cross(b - a); Vector3D center = (a + b + c) / 3.0f; double lowerY = Math.Min(a.Y, Math.Min(b.Y, c.Y)); double upperY = Math.Max(a.Y, Math.Max(b.Y, c.Y)); lowerY -= 0.25f; upperY += 0.25f; foreach (var primitive in entry.Value) { Vector3D primPos = primitive.WorldPosition; Vector3D offset = primPos - center; double offsetLen = offset.Length(); offset = offset / offsetLen; double dot; Vector3D.Dot(ref offset, ref normal, out dot); if (dot > -0.2f && primPos.Y < upperY && primPos.Y > lowerY) { double dist = offsetLen / (dot + 0.3f); if (dist < closestDistSq) { closestDistSq = dist; closestGridTri = tri; closestLinkedPrim = primitive; } } } } m_tmpNavTris.Clear(); if (closestGridTri != null) { Debug.Assert(closestLinkedPrim.GetHighLevelPrimitive() != null); Debug.Assert(closestGridTri.GetHighLevelPrimitive() != null); m_links.AddLink(closestLinkedPrim, closestGridTri); SaveVoxelLinkToDictionary(cellId, closestLinkedPrim); IncreaseGridLinkCounter(entry.Key); } } ProfilerShort.End(); }
// This is an old version of the function public void TryAddVoxelNavmeshLinks(MyNavigationTriangle addedPrimitive, MyVoxelPathfinding.CellId cellId, List<MyGridPathfinding.CubeId> linkCandidates) { ProfilerShort.Begin("TryAddVoxelNavmeshLinks"); m_tmpNavTris.Clear(); foreach (var candidate in linkCandidates) { // First, find closest navigation triangle from the given candidate cube ProfilerShort.Begin("Find closest grid nav tri"); m_gridPathfinding.GetCubeTriangles(candidate, m_tmpNavTris); double closestDistSq = double.MaxValue; MyNavigationTriangle closestGridTri = null; foreach (var tri in m_tmpNavTris) { Vector3D posDiff = addedPrimitive.WorldPosition - tri.WorldPosition; if (MyPerGameSettings.NavmeshPresumesDownwardGravity) { if (Math.Abs(posDiff.Y) < 0.3) { if (posDiff.LengthSquared() < closestDistSq) { closestDistSq = posDiff.LengthSquared(); closestGridTri = tri; } } } } ProfilerShort.End(); if (closestGridTri != null) { bool createLink = true; var existingLinks = m_links.GetLinks(closestGridTri); List<MyNavigationPrimitive> existingCellLinks = null; m_voxelLinkDictionary.TryGetValue(cellId, out existingCellLinks); if (existingLinks != null) { m_tmpNavPrims.Clear(); CollectClosePrimitives(addedPrimitive, m_tmpNavPrims, 2); for (int i = 0; i < m_tmpNavPrims.Count; ++i) { if (existingLinks.Contains(m_tmpNavPrims[i]) && existingCellLinks != null && existingCellLinks.Contains(m_tmpNavPrims[i])) { double existingDistSq = (m_tmpNavPrims[i].WorldPosition - closestGridTri.WorldPosition).LengthSquared(); if (existingDistSq < closestDistSq) { createLink = false; break; } else { m_links.RemoveLink(closestGridTri, m_tmpNavPrims[i]); if (m_links.GetLinkCount(m_tmpNavPrims[i]) == 0) { RemoveVoxelLinkFromDictionary(cellId, m_tmpNavPrims[i]); } DecreaseGridLinkCounter(candidate); continue; } } } m_tmpNavPrims.Clear(); } if (createLink) { m_links.AddLink(addedPrimitive, closestGridTri); SaveVoxelLinkToDictionary(cellId, addedPrimitive); IncreaseGridLinkCounter(candidate); } } m_tmpNavTris.Clear(); } ProfilerShort.End(); }
public void SetVoxelPathfinding(MyVoxelPathfinding myVoxelPathfinding) { this.m_voxelPathfinding = myVoxelPathfinding; }