public void SetUp() { graph = new NavigationGraph(x => { x.ForMenu(FakeKeys.Key1); x.Add += MenuNode.Node(FakeKeys.Key2); x.Add += MenuNode.Node(FakeKeys.Key3); x.Add += MenuNode.Node(FakeKeys.Key4); x.ForMenu(FakeKeys.Key5); x.Add += MenuNode.Node(FakeKeys.Key6); x.Add += MenuNode.Node(FakeKeys.Key7); x.ForMenu(FakeKeys.Key2); x.Add += MenuNode.Node(FakeKeys.Key8); x.Add += MenuNode.Node(FakeKeys.Key9); x.ForMenu(FakeKeys.Key9); x.Add += MenuNode.Node(FakeKeys.Key10); }); graph.Compile(); }
public NavigatorPageViewModel(string navigationGraphName, Guid destinationRegionID, Guid destinationWaypointID, string destinationWaypointName, XMLInformation informationXML) { _firsrDirectionInstructionScaleVale = 1; _destinationID = destinationWaypointID; _destinationWaypointName = destinationWaypointName; CurrentStepImage = "waittingscan.gif"; _instructionLocation = _originalInstructionLocation; _navigationModule = new NavigationModule(navigationGraphName, destinationRegionID, destinationWaypointID); _navigationModule._event._eventHandler += GetNavigationResultEvent; const string resourceId = "IndoorNavigation.Resources.AppResources"; _resourceManager = new ResourceManager(resourceId, typeof(TranslateExtension).GetTypeInfo().Assembly); CurrentWaypointName = _resourceManager.GetString("NULL_STRING", CrossMultilingual.Current.CurrentCultureInfo); CurrentStepLabel = _resourceManager.GetString("NO_SIGNAL_STRING", CrossMultilingual.Current.CurrentCultureInfo); var currentLanguage = CrossMultilingual.Current.CurrentCultureInfo; if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en-US") { _firstDirectionInstruction = NavigraphStorage.LoadFirstDirectionXML(navigationGraphName + "_en-US.xml"); } else if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh-TW") { _firstDirectionInstruction = NavigraphStorage.LoadFirstDirectionXML(navigationGraphName + "_zh.xml"); } _navigationGraph = NavigraphStorage.LoadNavigationGraphXML(navigationGraphName); _xmlInformation = informationXML; }
public static NavigationGraph LoadNavigationGraphXML(string FileName) { Console.WriteLine("FileName : " + FileName); string filePath = Path.Combine(_navigraphFolder, FileName); Console.WriteLine("Reading File Name : " + filePath); if (!File.Exists(filePath)) { throw new FileNotFoundException(); } var xmlString = File.ReadAllText(filePath); if (xmlString == "") { DeleteNavigationGraph(FileName); } StringReader stringReader = new StringReader(xmlString); XmlDocument document = new XmlDocument(); document.Load(filePath); //XMLParser xmlParser = new XMLParser(); //NavigationGraph navigationGraph = xmlParser.GetString(document); NavigationGraph navigationGraph = new NavigationGraph(document); return(navigationGraph); }
public DestinationPickPage(string navigationGraphName, CategoryType category) { InitializeComponent(); const string resourceId = "IndoorNavigation.Resources.AppResources"; _resourceManager = new ResourceManager(resourceId, typeof(TranslateExtension).GetTypeInfo().Assembly); _destinationItems = new ObservableCollection <DestinationItem>(); _navigationGraphName = navigationGraphName; _navigationGraph = NavigraphStorage.LoadNavigationGraphXML(navigationGraphName); if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en-US") { _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_en-US.xml"); } else if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh-TW") { _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_zh.xml"); } NavigationPage.SetBackButtonTitle(this, _resourceManager.GetString("BACK_STRING", CrossMultilingual.Current.CurrentCultureInfo)); foreach (KeyValuePair <Guid, IndoorNavigation.Models.Region> pairRegion in _navigationGraph.GetRegions()) { string floorName = _nameInformation.GiveRegionName(pairRegion.Value._id); if (pairRegion.Value._waypointsByCategory.ContainsKey(category)) { foreach (Waypoint waypoint in pairRegion.Value._waypointsByCategory[category]) { string waypointName = waypoint._name; waypointName = _nameInformation.GiveWaypointName(waypoint._id); if (waypoint._type.ToString() == "terminal" || waypoint._type.ToString() == "landmark") { Console.WriteLine("check type : " + waypoint._type.ToString()); _destinationItems.Add(new DestinationItem { _regionID = pairRegion.Key, _waypointID = waypoint._id, _waypointName = waypointName, _floor = floorName }); } else { Console.WriteLine("Portal, No need to add!!"); } } } } MyListView.ItemsSource = from waypoint in _destinationItems group waypoint by waypoint._floor into waypointGroup orderby waypointGroup.Key select new Grouping <string, DestinationItem>(waypointGroup.Key, waypointGroup); }
private void DebugMap(NavigationGraph map, Vector2Int nodeToReach, List <Vector2Int> coordinatesToTraverse) { Vector2Int botCoordinates = Environment.ConvertGameObjectToCoordinates(gameObject.transform); StringBuilder builder = new StringBuilder(); builder.Append('\n'); for (int y = map.Map[0].Length - 1; y >= 0; y--) { for (int x = 0; x < map.Map.Length; x++) { if (map.Map[x][y].IsObstacle()) { builder.Append("#"); continue; } if (x == botCoordinates.x && y == botCoordinates.y) { builder.Append("@"); continue; } if (x == m_goalCoordinates.x && y == m_goalCoordinates.y) { builder.Append("X"); continue; } if (x == nodeToReach.x && y == nodeToReach.y) { builder.Append("%"); continue; } bool foundInNodes = false; foreach (Vector2Int coordinates in coordinatesToTraverse) { if (x == coordinates.x && y == coordinates.y) { foundInNodes = true; builder.Append("Q"); continue; } } if (map.Map[x][y].Content == Tile.Unknown) { builder.Append("?"); continue; } if (foundInNodes) { continue; } builder.Append("O"); } builder.Append('\n'); } string s = builder.ToString(); Debug.Log(s); }
private void Start() { var pointsList = GenerateNavGridIcosaedron(radius); excludeVolumes = GenerateEnviroment(excludeVolumesCount, 0.5f, 2f); ExcludePathPoins(pointsList, excludeVolumes); points = pointsList.ToArray(); graph = new NavigationGraph(FinalizeGraph(points)); }
private void Application_Startup(object sender, StartupEventArgs e) { MainPage mainPage = new MainPage(); _navigationGraph = new NavigationGraph(_navigationController); mainPage.NavigationGraph = _navigationGraph; this.RootVisual = mainPage; _navigationController.BeginMainPage(mainPage); _navigationGraph.Start(); }
public Planet(float radius = 10f, int resourcePointsCount = 20, List <ExcludeVolume> excludeVolumes = null) { const float gridCellSize = 0.3f; int density = Mathf.CeilToInt((2f * Mathf.PI * radius / 6f) / gridCellSize); Graph = NavigationGridBuilder.Generate(radius, density, excludeVolumes); Radius = radius; Resources = new ResourcePoint[resourcePointsCount]; for (int i = 0; i < Resources.Length; i++) { Resources[i] = new ResourcePoint(GetRandomPosition(), 10); } }
public void add_node_and_parent_does_not_exist() { var graph = new NavigationGraph(); var node = MenuNode.Node(FakeKeys.Key1); graph.AddChildNode(FakeKeys.Key2, node); graph.Compile(); graph.MenuFor(FakeKeys.Key2).Top .ShouldBeTheSameAs(node); }
public void Before() { TestEventQueue = EventQueue.alloc(); ExternalHooks.LogDebug = (string s) => { }; TurnTimeline.alloc(); NavigationEngine.alloc(); NavigationGraph l_navigationGraph = NavigationGraph.alloc(); NavigationGraphContainer.UniqueNavigationGraph = l_navigationGraph; NavigationGraphBuild.CreateGridNavigation(l_navigationGraph, 4, 4); NavigationGraph.takeSnapshot(l_navigationGraph); }
public void configure_if_the_matcher_can_find_something() { var graph = new NavigationGraph(); graph.MenuFor("one"); graph.MenuFor("two"); var theChain = graph.MenuFor("three"); MockFor <IStringTokenMatcher>().Stub(x => x.Matches(theChain.Key)).Return(true); ClassUnderTest.Configure(graph); MockFor <IMenuPlacementStrategy>().AssertWasCalled(x => x.Apply(theChain, theNode)); }
public void After() { foreach (Entity l_entity in EntityContainer.Entities) { Entity.markForDestruction(l_entity); EventQueue.enqueueEvent(TestEventQueue, EntityDestroyEvent.alloc(l_entity)); } EventQueue.iterate(TestEventQueue); EventQueue.clearAll(TestEventQueue); _TurnTimeline.TurnTimeline.free(_TurnTimeline.TurnTimelineContainer.UniqueTurnTimeline); NavigationEngine.free(NavigationEngineContainer.UniqueNavigationEngine); NavigationGraph.free(NavigationGraphContainer.UniqueNavigationGraph); TestEventQueue = null; }
private void ComputeAStarForSteering() { Node npcNode = NavigationGraph.GetClosestNode(NpcManager.transform.position); Node playerNode = NavigationGraph.GetClosestNode(_playerData.LastSeenPosition); List <Node> path = Pathfinding.Astar(npcNode, playerNode); if (path == null || path.Count < 1) { Debug.Log(npcNode); return; } _currentTargetLocation = path[NpcGlobalVariables.NextElementInPath].position; }
private void Update() { if (_agents.Count < 1) { return; } if (_agentReachedNode || !Node.CanSeeNode(NavigationGraph.GetClosestNode(_currentTargetLocation), GetPositionOfClosestAgent())) { ComputeAStarForFlock(); _agentReachedNode = false; } MoveAgents(); }
public void configure_if_the_matcher_cannot_find_something_will_add_a_menu_chain_for_the_parent() { var graph = new NavigationGraph(); graph.MenuFor("one"); graph.MenuFor("two"); MockFor <IStringTokenMatcher>().Stub(x => x.DefaultKey()).Return(new NavigationKey("three")); ClassUnderTest.Configure(graph); var theChain = graph.MenuFor("three"); MockFor <IMenuPlacementStrategy>().AssertWasCalled(x => x.Apply(theChain, theNode)); }
public void add_node_to_another_node() { var graph = new NavigationGraph(); var parentNode = MenuNode.Node(FakeKeys.Key1); graph.AddChildNode(FakeKeys.Key2, parentNode); var childNode = MenuNode.Node(FakeKeys.Key3); graph.AddChildNode(FakeKeys.Key1, childNode); graph.Compile(); parentNode.Children.Top .ShouldBeTheSameAs(childNode); }
public static void CreateGridNavigation(NavigationGraph p_navigationGraph, int XNumber, int ZNumber) { CreateGridNavigationStructure(XNumber, ZNumber, out Dictionary <int, Vector3> l_navigationNodes, out List <GridNavigationLink> l_navigationLinks); List <NavigationNode> l_instancedNavigationNodes = new List <NavigationNode>(l_navigationNodes.Count); for (int i = 0; i < l_navigationNodes.Count; i++) { NavigationNode l_instancedNavigationNode = NavigationGraph.instanciateAndAddNode(p_navigationGraph); l_instancedNavigationNode.LocalPosition = l_navigationNodes[i]; l_instancedNavigationNodes.Add(l_instancedNavigationNode); } foreach (GridNavigationLink l_link in l_navigationLinks) { NavigationGraph.createLinkBetween(p_navigationGraph, l_instancedNavigationNodes[l_link.StartNode], l_instancedNavigationNodes[l_link.EndNode], math.distance(l_instancedNavigationNodes[l_link.StartNode].LocalPosition, l_instancedNavigationNodes[l_link.EndNode].LocalPosition)); } }
async void Handle_ItemTapped(object sender, ItemTappedEventArgs e) { var currentLanguage = CrossMultilingual.Current.CurrentCultureInfo; if (e.Item is Location location) { NavigationGraph navigationGraph = NavigraphStorage.LoadNavigationGraphXML(location.UserNaming); switch (navigationGraph.GetIndustryServer()) { case "hospital": var answser = await DisplayAlert( _resourceManager.GetString("GO_NAVIGATION_HOME_PAGE_STRING", currentLanguage), location.UserNaming, _resourceManager.GetString("OK_STRING", currentLanguage), _resourceManager.GetString("CANCEL_STRING", currentLanguage)); if (answser) { await Navigation.PushAsync(new NavigationHomePage(location.UserNaming)); } break; case "city_hall": var answser_city_hall = await DisplayAlert( _resourceManager.GetString("GO_NAVIGATION_HOME_PAGE_STRING", currentLanguage), location.UserNaming, _resourceManager.GetString("OK_STRING", currentLanguage), _resourceManager.GetString("CANCEL_STRING", currentLanguage)); if (answser_city_hall) { await Navigation.PushAsync(new CityHallHomePage(location.UserNaming)); } break; default: Console.WriteLine("Unknown _industryService"); break; } } }
public void SetUp() { registry = new NavigationRegistry(); _graph = new Lazy <NavigationGraph>(() => { NavigationGraph graph = null; var r = new FubuRegistry(); r.Actions.IncludeType <Controller1>(); r.Policies.Global.Add(registry); r.Import <NavigationRegistryExtension>(); using (var runtime = r.ToRuntime()) { runtime.Get <IMenuResolver>().MenuFor(new NavigationKey("Root")); graph = runtime.Get <NavigationGraph>(); } return(graph); }); }
public IPSModules(NavigationGraph navigationGraph) { _multipleClient = new Dictionary <IPSType, IIPSClient>(); _multipleClient.Add(IPSType.LBeacon, new WaypointClient()); _multipleClient.Add(IPSType.iBeacon, new IBeaconClient()); _haveIPSKind = new Dictionary <IPSType, bool>(); _haveIPSKind.Add(IPSType.LBeacon, false); _haveIPSKind.Add(IPSType.iBeacon, false); _haveIPSKind.Add(IPSType.GPS, false); _event = new NavigationEvent(); _navigationGraph = navigationGraph; _monitorLBeaconGuid = new List <WaypointBeaconsMapping>(); _monitorIBeaconGuid = new List <WaypointBeaconsMapping>(); _lbeacon = new _addInterestedBeacon(ADDLBeacon); _ibeacon = new _addInterestedBeacon(ADDIBeacon); _gps = new _addInterestedBeacon(ADDGPS); }
private void ComputeAStarForFlock() { Node npcNode = NavigationGraph.GetClosestNode(GetPositionOfClosestAgent()); Node playerNode = NavigationGraph.GetClosestNode(_playerData.LastSeenPosition); List <Node> path = Pathfinding.Astar(npcNode, playerNode); pathTest = path; if (path == null) { Debug.Log($"The A* path is null. Last seen player position is {_playerData.LastSeenPosition}"); } if (path.Count < 2) { _currentTargetLocation = _playerData.LastSeenPosition; } else { _currentTargetLocation = path[NpcGlobalVariables.NextElementInPath].position; } }
private void FindNewTarget() { Vector3 npcPosition = NpcManager.transform.position; Vector3 npcVelocity = NpcManager.Rigidbody.velocity; Vector3 circlePosition = npcPosition + Vector3.Normalize(npcVelocity) * NpcGlobalVariables.WanderCircleDistance; Vector3 target = circlePosition + Random.insideUnitSphere * NpcGlobalVariables.WanderCircleRadius; target.y = 0; Node currentNode = NavigationGraph.GetClosestNode(npcPosition); Node targetNode = NavigationGraph.GetClosestNode(target); try { _pathToTarget = new Queue <Node>(Pathfinding.Astar(currentNode, targetNode)); } catch (Exception) { Debug.Log(NpcManager.name + " tried to go on a separated graph. Will stay Idle."); NpcManager.GetComponent <NPCStateMachine>().StartIdle(); } if (_pathToTarget == null || _pathToTarget.Count < 1) { NpcManager.GetComponent <NPCStateMachine>().StartIdle(); return; } _currentTargetNode = _pathToTarget.Dequeue().position; _currentTargetNode.y = 0; _reachedTarget = false; }
// Check for new links inside the cluster public bool CheckNewLinks(List <Node> cluster, bool canCreateNew = true) { bool addedNewNodes = false; foreach (var node in cluster.ToArray()) { // The ToArray is to iterate over a copy of the list, and so we can add new items while iterating Vector3 tmp_dir = (node.position - position); float dist = tmp_dir.magnitude; if (CanSeeNode(node, dist, tmp_dir)) { // If we can see the node, link the 2 nodes together // // Uncoment theses 2 lines to keep the graph simple with big links. // // Will generate faster, but will be less precise for AI movement // AddLink(node, dist); // continue; // if dist > nodesMaxDistance, add in between nodes if (dist > NavigationGraph.maxLinkLength && dist < NavigationGraph.nodesMaxDistance && canCreateNew && false) // Disable this for now { int nb = (int)(dist / NavigationGraph.maxLinkLength); // compute nb of nodes to add Vector3 dir = (node.position - position).normalized; float intermediateDist = dist / (nb + 1); // distance between nodes Node prev = this; // Keep track of the previous node to add in between links while (nb > 0) { Vector3 pos = prev.position + dir * intermediateDist; Node tmp = NavigationGraph.CreateNode(pos, cluster); if (tmp == null) { // If we fail creating an intermediate node, try to use the closest one Node close = NavigationGraph.GetClosestNode(pos); if (close != null && (close.position - pos).magnitude < NavigationGraph.wallOffset) { tmp = close; } else { // if we can't have a close node, just keep a long link and don't bother more prev.AddLink(node); break; } } addedNewNodes = true; // No need to raycast to check the link : we already did one before on a longest distance // (we already know that the fartest nodes can see each other) tmp.AddLink(prev); prev = tmp; nb--; } prev.AddLink(node); // don't forget to link the last node } else if (dist < NavigationGraph.nodesMaxDistance) { AddLink(node, dist); } } } return(addedNewNodes); }
/// <summary> /// Needs to be called before the RunDStarLite-function. /// Generates an empty map for the bot /// </summary> /// <param name="knowMap">Set to true if the algorithm should know the full map</param> private void GenerateNodeMap(bool knowMap) { Map completeMap = m_environment.GetMap(); Map = new NavigationGraph(completeMap, knowMap, m_environment.GetList()); }
private IEnumerator RefreshCluster(float t) { yield return(new WaitForSecondsRealtime(t)); NavigationGraph.ReGenerateClusterLinks(transform.position); }
/// <summary> /// Returns the farthest coordinate the entity can reach from its current position. /// </summary> /// <param name="currentPosition">The current position of the entity.</param> /// <param name="coordinatesToTraverse">A list containing all the coordinates the entity should traverse to reach its goal.</param> /// <param name="map">The map the entity knows so far.</param> /// <param name="entityWidth">The with of the entity.</param> public static Vector2Int FarthestCoordinateToReach(Vector2 currentPosition, List <Vector2Int> coordinatesToTraverse, NavigationGraph map, float entityWidth) { if (coordinatesToTraverse.Count == 0) { return(new Vector2Int()); } int nextNode = 0; int previousNextNode = nextNode; int goalNode = coordinatesToTraverse.Count - 1; bool possibleToMoveHere = true; // When it is possible to move from current position and the new position AND the new position is not the final destination while (possibleToMoveHere && nextNode != goalNode) { // Save current new point for if the next one fails. previousNextNode = nextNode; // Get new point that is closer to the destination. nextNode++; // For if the path does not lead to the goalNode (Goalnode is unreachable) // Take the last node in the list of CoordinatesToTraverse if (coordinatesToTraverse.Count == nextNode) { continue; } // Skip this node if it's on the same row or column as the current position. // In this case we won't have to recalculate if it's possible to move somewhere since the straight paths are already calculated by the D* algorithm. if (coordinatesToTraverse[nextNode].x == currentPosition.x || coordinatesToTraverse[nextNode].y == currentPosition.y) { continue; } // Check if it is possible to move to the next position. possibleToMoveHere = PossibleToMoveBetween(currentPosition, coordinatesToTraverse[nextNode], map, entityWidth, entityWidth); } // If it is not possible to move to the next position. if (!possibleToMoveHere) { // Get back to previousPoint, since that is the last point that is reachable. nextNode = previousNextNode; } return(new Vector2Int(coordinatesToTraverse[nextNode].x, coordinatesToTraverse[nextNode].y)); }
/// <summary> /// Checks if it is possible to travel straight from one note to the other /// </summary> /// <param name="currentPosition">The start-position on the map to check</param> /// <param name="newPosition">The end-position on the map to check</param> /// <param name="map">The map on which to check the positions</param> /// <returns></returns> private static bool PossibleToMoveBetween(Vector2 currentPosition, Vector2 newPosition, NavigationGraph map, float xOffset, float yOffset) { float leftSideFromEntity = -(xOffset / 2); float rightSideFromEntity = +(xOffset / 2); float upperSideFromEntity = +(yOffset / 2); float lowerSideFromEntity = -(yOffset / 2); // If there is an obstacle on this line, return false since it's not possible to move here. if (CheckIfNodeContainsObstacle(Traverse(currentPosition.x, currentPosition.y + upperSideFromEntity, newPosition.x, newPosition.y + upperSideFromEntity), map) || // Top of entity CheckIfNodeContainsObstacle(Traverse(currentPosition.x + leftSideFromEntity, currentPosition.y, newPosition.x + leftSideFromEntity, newPosition.y), map) || // Left of entity CheckIfNodeContainsObstacle(Traverse(currentPosition.x + rightSideFromEntity, currentPosition.y, newPosition.x + rightSideFromEntity, newPosition.y), map) || // Right of entity CheckIfNodeContainsObstacle(Traverse(currentPosition.x, currentPosition.y + lowerSideFromEntity, newPosition.x, newPosition.y + lowerSideFromEntity), map)) // Bottom of entity { return(false); } // No obstacles have been seen. return(true); }
/// <summary> /// Checks if one of the coordinates contains an obstacle /// </summary> private static bool CheckIfNodeContainsObstacle(List <Vector2Int> passingCoordinates, NavigationGraph map) { foreach (Vector2Int coordinate in passingCoordinates) { if (map.GetNode(coordinate).IsObstacle()) { // There is a wall in the colliding line return(true); } } // No wall is found between these coordinates return(false); }
// Check for new links inside the cluster public bool CheckNewLinks(bool canCreateNew = true) { List <Node> cluster = NavigationGraph.GetCluster(position); return(CheckNewLinks(cluster, canCreateNew)); }
public void Apply(NavigationGraph graph) { var node = _finder(graph); node.AllNodes().Where(x => x.BehaviorChain != null).Each(n => _alterations.Each(x => x(n))); }