private void UpdateEdges() { foreach (Tile t in nodes.Keys) { PathNode <Tile> n = nodes [t]; Tile[] neighbours = t.GetNeighbours(true); for (int i = 0; i < neighbours.Length; i++) { if (neighbours [i] != null && neighbours [i].walkable == true) { if (nodes.ContainsKey(neighbours [i])) { if (n.edges == null) { n.edges = new PathEdge <Tile> [8]; } for (int j = 0; j < n.edges.Length; j++) { if (n.edges [j] == null) { PathEdge <Tile> e = new PathEdge <Tile> (); e.cost = 1; e.node = nodes [neighbours [i]]; n.edges [i] = e; } } } } } } }
private void TraverseNextEdge() { if (PathToFollow == null) { return; } ////TODO: probably should add NextEdge method to Path class PathEdge edgeToFollow = PathToFollow.Dequeue(); if (edgeToFollow == null) { return; } if (PathToFollow.IsEmpty) // last edge { edgeTraverser.Traverse( edgeToFollow, BrakeOnFinalApproach, StopOnFinalArrival); } else { edgeTraverser.Traverse( edgeToFollow, BrakeOnEachApproach, StopOnEachArrival); } }
public TraversalCompletedEventPayload( GameObject gameObject, PathEdge edge) { this.gameObject = gameObject; this.edge = edge; }
private void Reduce(int x, int lim) { IList <PathEdge> es = pathGraph[x]; int deg = es.Count; for (int i = 0; i < deg; i++) { PathEdge e1 = es[i]; for (int j = i + 1; j < deg; j++) { PathEdge e2 = es[j]; if (!e1.Intersects(e2)) { PathEdge reduced = Reduce(e1, e2, x); if (BitArrays.Cardinality(reduced.xs) >= lim) { continue; } if (reduced.Loop()) { if (reduced.CheckPiElectrons(ps)) { reduced.Flag(aromatic); } } else { Add(reduced); } } } } pathGraph[x].Clear(); }
private PathEdge Reduce(PathEdge e, PathEdge f, int x) { return(new PathEdge(e.Other(x), f.Other(x), Union(e.xs, f.xs, x), ps[x] + e.ps + f.ps)); }
private void Add(PathEdge e) { int u = e.Either(); int v = e.Other(u); Add(u, v, e); }
/** * 指定されたオブジェクト同士の連結を登録します。長いパスの場合登録しません */ public PathEdge Edge(IRoutable from, IRoutable to, float cost, float payment) { if (from == null || to == null) { throw new ArgumentNullException(); } var res = Edges.Find(e => e.From.Origin == from && e.To.Origin == to); if (res != null) { if (res.Cost >= cost) { res.Cost = cost; res.Payment = payment; return(res); } else { return(null); } } else { var e = new PathEdge(Node(from), Node(to), cost, payment); Edges.Add(e); return(e); } }
public TraversalFailedEventPayload( GameObject gameObject, PathEdge edge) { this.gameObject = gameObject; this.edge = edge; }
public PathTileGraph(World world) { //loop through all tiles, create a node for each tile // dont create nodes for non-floors // dont create tiles for walls _nodes = new Bag <PathNode <Tile> >(); for (int x = 0; x < world.width; x++) { for (int y = 0; y < world.height; y++) { Tile tile = world.get_tile_at(x, y); if (tile.movement_cost > 0) // tiles with movement cost of 0 are unwalkable { PathNode <Tile> node = new PathNode <Tile>(); node.data = tile; _nodes.set(tile.id, node); } } } // create edges for each tile // create edges only for existing neighbors for (int i = 0; i < _nodes.count; i++) { List <PathEdge <Tile> > edges = new List <PathEdge <Tile> > (); //get tile neighbors for a path node //if neighbor is walkable, add an edge pointing to the neighboring node PathNode <Tile> node = _nodes[i]; // ensure we grabbed a good node if (node == null) { continue; } foreach (Tile neighbor in node.data.get_neighbors()) { if (neighbor != null & neighbor.movement_cost > 0) { // neighbor exists and is walkable PathEdge <Tile> edge = new PathEdge <Tile>(); edge.cost = neighbor.movement_cost; //FIXME: may cause issues if node is not in bag edge.node = _nodes[neighbor.id]; edges.Add(edge); } } if (edges.Count > 0) { node.edges = edges.ToArray(); } } }
PathEdge CreatePathEdge(Location start, Location end) { //Move cost for any edge is the average of the movement cost from it's 2 connected tiles. int moveCost = (GetMovementCostForTile(start) + GetMovementCostForTile(end)) / 2; PathEdge edge = new PathEdge(moveCost, GetPathNode(end)); return(edge); }
public Vector3 GetTrapPosition() { float t = connection.GetInterpolationAmount(); PathGraph graph = FindObjectOfType <PathGraph>(); PathEdge edge = graph.tendrilToEdge[tendril]; PathNeuronNode start = connection.node1.GetComponent <PathNeuronNode>(); return(edge.GetPointAlongPath(start, t)); }
void Start() { PathEdge edge = graph.tendrilToEdge[tendril]; node1 = edge.node1.gameObject; node2 = edge.node2.gameObject; InitializeConnection(); }
/// <summary> /// Validates the Path Edge argument /// </summary> /// <param name="PathEdge">The Path Edge object to validate</param> /// <param name="Culture">The culture in which any exception messages should be thrown</param> internal static void ValidatePathEdge(PathEdge PathEdge, CultureInfo Culture) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); if (PathEdge == null) { throw new ArgumentNullException(ExceptionMessageResources.GetString("InvalidPathEdgeArgument", Culture)); } }
public void TraversePath() { PathEdge pathToFollow = availablePaths[pathIndex]; DeselectCurrentPath(); playerMovement.StartFollowingPath(pathToFollow.GetPath(currentNode), pathToFollow.tendril.isDegraded); PathEdge previousPath = availablePaths[pathIndex]; nextNode = pathGraph.GetOtherNode(currentNode, previousPath); }
public PathTileGraph(World world) { //Debug.Log("PathTileGraph"); //loop through all tiles of the world //for each tile, create a node nodes = new Dictionary <Tile, PathNode <Tile> >(); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { Tile tile = world.GetTileAt(x, y); //if(tile.movementCost > 0) //Tiles with movement cost of 0 are unwalkable //{ PathNode <Tile> node = new PathNode <Tile>(); node.data = tile; nodes.Add(tile, node); //} } } //Debug.Log("PathTileGraph created " + nodes.Count + " nodes"); //loop through a second time and create edges for neighbours int edgeCount = 0; foreach (Tile tile in nodes.Keys) { List <PathEdge <Tile> > edges = new List <PathEdge <Tile> >(); PathNode <Tile> node = nodes[tile]; //get a list of neighbours for the tile Tile[] neighbours = tile.GetNeighbours(true); //Note: some of the array spots could be null. //if neighbour is walkable, create an edge to the relevant node. for (int i = 0; i < neighbours.Length; i++) { if (neighbours[i] != null && neighbours[i].movementCost > 0) { //Neighbour exists and is walkable, so create an edge //But make sure we aren't trying to squeeze inapproperiately if (IsClippingCorner(tile, neighbours[i])) { continue; //skip to the next neighbour without building an edge } PathEdge <Tile> edge = new PathEdge <Tile>(); edge.cost = neighbours[i].movementCost; edge.node = nodes[neighbours[i]]; //Add the edge to our temporary and growable list edges.Add(edge); edgeCount++; } } node.edges = edges.ToArray(); } //Debug.Log("PathTileGraph created " + edgeCount + " edges"); }
public PathNeuronNode GetOtherNode(PathNeuronNode node, PathEdge edge) { if (node == edge.node1) { return(edge.node2); } else { return(edge.node1); } }
/// <summary> /// Creates all the path edges from the list of LocationMappers /// </summary> /// <returns></returns> private async Task CreatePathEdgesFromMap(SimulationExtension SimExt) { await Task.Run(() => { //SimSig.SimulationExtension SimExt = new SimulationExtension(this._Simulation.ID, this._SQLConnector); foreach (MapperLocationNode MappedLocNode in this._LocationNodeMapper) { LocationNode FromLocationNode = null; //Check the MappedLocNode has a next location node to create if (string.IsNullOrEmpty(MappedLocNode.NextLocationNode.SimSigCode) == false) { //Get a list of MapperLocationNode objects with a location node created List <MapperLocationNode> MappersWithLocationNodes = this._LocationNodeMapper.Where(y => y.LocationNode != null).ToList(); //Get the From Location Node if (MappedLocNode.LocationNode == null) { //If not already tagged in the MapperLocationNode search through the list to find it FromLocationNode = MappersWithLocationNodes.Find(x => x.LocationNode.SimID == this._Simulation.ID && x.LocationNode.EraID == this._TemplateSimEra.ID && x.LocationNode.Version.ID == this._Version.ID && String.CompareOrdinal(x.LocationNode.LocationSimSigCode, MappedLocNode.SimSigCode) == 0 && String.CompareOrdinal(x.LocationNode.Platform, MappedLocNode.Platform) == 0 && String.CompareOrdinal(x.LocationNode.Path, MappedLocNode.Path) == 0 && String.CompareOrdinal(x.LocationNode.Line, MappedLocNode.Line) == 0).LocationNode; } else { FromLocationNode = MappedLocNode.LocationNode; } //Get the to location node LocationNode ToNodeLocation = MappersWithLocationNodes.FirstOrDefault(x => x.LocationNode.SimID == this._Simulation.ID && x.LocationNode.EraID == this._TemplateSimEra.ID && x.LocationNode.Version.ID == this._Version.ID && String.CompareOrdinal(x.LocationNode.LocationSimSigCode, MappedLocNode.NextLocationNode.SimSigCode) == 0 && String.CompareOrdinal(x.LocationNode.Platform, MappedLocNode.NextLocationNode.Platform) == 0 && String.CompareOrdinal(x.LocationNode.Path, MappedLocNode.NextLocationNode.Path) == 0 && String.CompareOrdinal(x.LocationNode.Line, MappedLocNode.NextLocationNode.Line) == 0).LocationNode; //Create the path edge if (ToNodeLocation != null) { //Build new LocationNode SimSig.PathEdge NewPathEdge = new PathEdge(FromLocationNode, ToNodeLocation, this._SQLConnector); NewPathEdge.SaveToSQLDB(); } } } }).ConfigureAwait(false); }
public int CompareAnglesOfEdges(PathNeuronNode start, PathEdge edge1, PathEdge edge2) { Vector3 next1 = GetOtherNode(start, edge1).transform.position; Vector3 next2 = GetOtherNode(start, edge2).transform.position; Vector3 rel1 = next1 - start.transform.position; Vector3 rel2 = next2 - start.transform.position; float ang1 = GetClockwiseAngle(rel1.z, rel1.x); float ang2 = GetClockwiseAngle(rel2.z, rel2.x); return(ang2.CompareTo(ang1)); }
public bool CanReachFinishIf(PathTendril tendril, bool tentativeState) { PathEdge edgeException = tentativeState ? null : tendrilToEdge[tendril]; if (startNode == null || finishNode == null) { Debug.LogError("Set start and finish nodes"); } bool canReachFinish = DoesPathExist(startNode, finishNode, edgeException, tentativeState); return(canReachFinish); }
public RandomPath GetRandomPath(int targetPathLength) { RandomPath randomPath = new RandomPath(); List <PathEdge> pathEdges = new List <PathEdge>(); List <PathNeuronNode> allNodes = new List <PathNeuronNode>(nodeToEdge.Keys); PathNeuronNode startNode = allNodes[Random.Range(0, allNodes.Count)]; HashSet <PathNeuronNode> closedNodeSet = new HashSet <PathNeuronNode> { startNode }; Dictionary <PathNeuronNode, HashSet <PathEdge> > closedEdgeSet = new Dictionary <PathNeuronNode, HashSet <PathEdge> >(); PathNeuronNode currentNode = startNode; while (pathEdges.Count < targetPathLength) { if (!closedEdgeSet.Keys.Contains(currentNode)) { closedEdgeSet.Add(currentNode, new HashSet <PathEdge>()); } HashSet <PathEdge> availableEdges = new HashSet <PathEdge>( nodeToEdge[currentNode].Where(x => !closedEdgeSet[currentNode].Contains(x) && !closedNodeSet.Contains(GetOtherNode(currentNode, x)) && !pathEdges.Contains(x)).ToList()); // Back-track if we've reached a dead end if (availableEdges.Count == 0) { if (currentNode == startNode) { Debug.LogError("Random Path could not be found for start node: " + startNode.gameObject.name + " with target path length: " + targetPathLength.ToString()); } PathEdge previousPath = pathEdges[pathEdges.Count - 1]; PathNeuronNode previousNode = GetOtherNode(currentNode, previousPath); closedEdgeSet[previousNode].Add(previousPath); pathEdges.Remove(previousPath); currentNode = previousNode; continue; } PathEdge nextEdge = availableEdges.ToList <PathEdge>()[Random.Range(0, availableEdges.Count)]; pathEdges.Add(nextEdge); closedNodeSet.Add(currentNode); currentNode = GetOtherNode(currentNode, nextEdge); } randomPath.startNode = startNode; randomPath.finishNode = currentNode; randomPath.pathEdges = pathEdges; return(randomPath); }
public IMyPathEdge <MyNavigationPrimitive> GetEdge(MyNavigationPrimitive primitive, int index) { List <MyNavigationPrimitive> list = null; this.m_links.TryGetValue(primitive, out list); if (list == null) { return(null); } MyNavigationPrimitive primitive2 = list[index]; return(PathEdge.GetEdge(primitive, primitive2)); }
/// <summary> /// Add a path-edge to the path-graph. Edges are only added to the vertex of /// lowest rank (see. constructor). /// </summary> /// <param name="edge">path edge</param> private void Add(PathEdge edge) { int u = edge.Either(); int v = edge.Other(u); if (rank[u] < rank[v]) { graph[u].Add(edge); } else { graph[v].Add(edge); } }
public IMyPathEdge <MyNavigationPrimitive> GetEdge(MyNavigationPrimitive primitive, int index) { List <MyNavigationPrimitive> links = null; m_links.TryGetValue(primitive, out links); Debug.Assert(links != null); if (links == null) { return(null); } MyNavigationPrimitive otherPrimitive = links[index]; return(PathEdge.GetEdge(primitive, otherPrimitive)); }
public PathTileGraph(World world) { tileToNode = new Dictionary <Tile, PathNode <Tile> >(); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { Tile t = world.GetTileAt(x, y); //if(t.movementCost > 0) { tileToNode.Add(t, new PathNode <Tile>(t)); //} } } Debug.Log("Created " + tileToNode.Count + " nodes"); int edgeCount = 0; foreach (Tile tile in tileToNode.Keys) { PathNode <Tile> n = tileToNode[tile]; List <PathEdge <Tile> > edges = new List <PathEdge <Tile> >(); Tile[] neighbs = tile.GetNeighbours(true); for (int i = 0; i < neighbs.Length; i++) { if (neighbs[i] != null && neighbs[i].movementCost > 0) { //make sure we aren't clipping diag. if (IsClippingCorner(tile, neighbs[i])) { continue; //don't make any edges. } PathEdge <Tile> e = new PathEdge <Tile> { cost = neighbs[i].movementCost, node = tileToNode[neighbs[i]] }; edges.Add(e); edgeCount++; } } n.edges = edges.ToArray(); } Debug.Log("Created " + edgeCount + " edges"); }
public PathInteriorGraph(IBuildingInteriorManager interior) : base() { // Generate graph for navigating interior spaces, such as houses, to avoid walls if (interior == null) { Debug.Log("interior is null"); return; } for (int x = 0; x < interior.Width(); x++) { for (int y = 0; y < interior.Height(); y++) { PathNode node = new PathNode(); node.data = new Vector2(x, y); nodes.Add(new Vector2(x, y), node); } } foreach (Vector2 pos in nodes.Keys) { PathNode node = nodes[pos]; List <PathEdge> edges = new List <PathEdge>(); Vector2[] neighbors = interior.Neighbors((int)pos.x, (int)pos.y); for (int i = 0; i < neighbors.Length; i++) { if (neighbors[i].x != -1 && neighbors[i].y != -1) { PathEdge edge = new PathEdge(); if (interior.IsWall((int)pos.x, (int)pos.y, (int)neighbors[i].x, (int)neighbors[i].y)) { edge.cost = 0; } else { edge.cost = 1; } edge.node = nodes[neighbors[i]]; edges.Add(edge); } } node.edges = edges.ToArray(); } }
/// <summary> /// Pairwise combination of all disjoint <i>edges</i> incident to a vertex <paramref name="x"/>. /// </summary> /// <param name="edges">edges which are currently incident to <paramref name="x"/></param> /// <param name="x">a vertex in the graph</param> /// <returns>reduced edges</returns> private static List <PathEdge> Combine(IReadOnlyList <PathEdge> edges, int x) { int n = edges.Count; var reduced = new List <PathEdge>(); for (int i = 0; i < n; i++) { PathEdge e = edges[i]; for (int j = i + 1; j < n; j++) { PathEdge f = edges[j]; if (e.Disjoint(f)) { reduced.Add(new ReducedEdge(e, f, x)); } } } return(reduced); }
public AllCycles(Graph g, ElectronDonation model, int lim) { this.org = g; this.ps = new int[g.Order]; this.pathGraph = new IList <PathEdge> [g.Order]; this.aromatic = new bool[g.Order]; ElectronDonation.ICycle cycle = new Inner_ElectronDonation_Cycle(); BitArray cyclic = new BiconnectedComponents(g).Cyclic; for (int u = 0; u < g.Order; u++) { ps[u] = model.Contribution(u, g, cycle, cyclic); } for (int u = 0; u < g.Order; u++) { this.pathGraph[u] = new List <PathEdge>(); } // build the path graph foreach (var e in g.Edges) { int u = e.Either(); int v = e.Other(u); if (cyclic[u] && cyclic[v] && ps[u] >= 0 && ps[v] >= 0) { PathEdge f = new PathEdge(u, v, new BitArray(g.Order), 0); Add(u, v, f); } } for (int u = 0; u < g.Order; u++) { if (this.pathGraph[u].Count > MAX_VERTEX_DEGREE) { throw new ArgumentException("too many cycles generated: " + pathGraph[u].Count); } Reduce(u, lim); } }
private Vector3 Clamp(PathEdge edge, Vector3 pos) { Vector3 p00 = edge.P00(); Vector3 p01 = edge.P01(); Vector3 p10 = edge.P10(); Vector3 p11 = edge.P11(); float minx = Mathf.Min(p00.x, p01.x, p10.x, p11.x); float maxx = Mathf.Max(p00.x, p01.x, p10.x, p11.x); float miny = Mathf.Min(p00.y, p01.y, p10.y, p11.y); float maxy = Mathf.Max(p00.y, p01.y, p10.y, p11.y); float minz = Mathf.Min(p00.z, p01.z, p10.z, p11.z); float maxz = Mathf.Max(p00.z, p01.z, p10.z, p11.z); float x = Mathf.Min(maxx, Mathf.Max(minx, pos.x)); float y = Mathf.Min(maxy, Mathf.Max(miny, pos.y)); float z = Mathf.Min(maxz, Mathf.Max(minz, pos.z)); return(new Vector3(x, y, z)); }
public PathCityGraph() : base() { // Generate graph for city based on walkable sidewalks and connections for (int x = 0; x < CityManager.Instance.Width(); x++) { for (int y = 0; y < CityManager.Instance.Height(); y++) { if (CityManager.Instance.IsWalkable(x, y)) { PathNode node = new PathNode(); node.data = new Vector2(x, y); nodes.Add(new Vector2(x, y), node); } } } foreach (Vector2 pos in nodes.Keys) { PathNode node = nodes[pos]; List <PathEdge> edges = new List <PathEdge>(); Vector2[] neighbors = CityManager.Instance.BuildingNeighbors((int)pos.x, (int)pos.y, true); for (int i = 0; i < neighbors.Length; i++) { if (neighbors[i].x != -1 && neighbors[i].y != -1) { PathEdge edge = new PathEdge(); if (CityManager.Instance.IsWalkable((int)neighbors[i].x, (int)neighbors[i].y)) { edge.cost = 1; } else { edge.cost = 100; } edge.node = nodes[neighbors[i]]; edges.Add(edge); } } node.edges = edges.ToArray(); } }
public PathTileGraph(World world) { nodes = new Dictionary <Tile, PathNode <Tile> > (); for (int x = 0; x < world.Width; x++) { for (int y = 0; y < world.Height; y++) { Tile t = world.GetTileAt(x, y); PathNode <Tile> n = new PathNode <Tile> (); n.data = t; nodes.Add(t, n); } } Debug.Log("PathTileGraph: Created " + nodes.Count + " nodes"); foreach (Tile t in nodes.Keys) { PathNode <Tile> n = nodes [t]; List <PathEdge <Tile> > edges = new List <PathEdge <Tile> > (); Tile[] neighbours = t.GetNeighbours(true); for (int i = 0; i < neighbours.Length; i++) { if (neighbours [i] != null && neighbours [i].movementCost > 0 && !IsClippingCorner(t, neighbours [i])) { PathEdge <Tile> e = new PathEdge <Tile> (); e.cost = neighbours [i].movementCost; e.node = nodes [neighbours [i]]; edges.Add(e); } } n.edges = edges.ToArray(); } }
public Vector3 GetNext(PathNeuronNode node, PathEdge edge) { if (node == edge.node1) { if (edge.tendril != null && edge.tendril.GetFirst() != null) { return(edge.tendril.GetFirst().transform.position); } return(edge.node2.transform.position); } else { if (edge.tendril != null && edge.tendril.GetFirst() != null) { return(edge.tendril.GetLast().transform.position); } return(edge.node2.transform.position); } }
/** Handle incoming data on an Edge */ public void HandleData(MemBlock data, ISender retpath, object state) { MemBlock rest_of_data; PType p; if( state == null ) { p = PType.Parse(data, out rest_of_data); } else { //a demux has already happened: p = (PType)state; rest_of_data = data; } if( PType.Protocol.Pathing.Equals(p) ) { /* * We use a special PType to denote this transaction so * we don't confuse it with other RepRep communication */ _rrm.HandleData(rest_of_data, retpath, null); } else if( PType.Protocol.Rpc.Equals(p) ) { /* * Send this to the RpcHandler */ Rpc.HandleData(rest_of_data, retpath, null); } else { /* * This is some other data * It is either: * 1) Time to announce an already created edge. * 2) Assume this is a "default path" edge creation, to be backwards * compatible */ Edge e = null; PathEdge pe = null; try { e = (Edge)retpath; PathEdgeListener pel = null; lock( _sync ) { if( _unannounced.TryGetValue(e, out pe) ) { // _unannounced.Remove(e); pel = _pel_map[pe.LocalPath]; } } if( pe == null ) { /* * This must be a "default path" incoming connection */ pel = _pel_map[Root]; pe = new PathEdge(e, Root, Root); } pel.SendPathEdgeEvent(pe); pe.Subscribe(); pe.ReceivedPacketEvent(data); } catch(Exception x) { if( pe != null ) { //This closes both edges: pe.Close(); } else if( e != null ) { Console.WriteLine("Closing ({0}) due to: {1}", e, x); e.Close(); } } } }
public bool Traverse(PathEdge edgeToFollow, bool brakeOnApproach, bool stopOnArrival) { if ((movingEntity == null || !movingEntity.enabled) && (aiController == null || !aiController.enabled)) { return false; } // Seek must exist and not be active if (seek == null || seek.TargetPosition.HasValue) { return false; } // Arrive must exist and not be active if (arrive == null || arrive.TargetPosition.HasValue) { return false; } seek.enabled = seek.isOn = false; arrive.enabled = arrive.isOn = false; EdgeToFollow = edgeToFollow; if (brakeOnApproach) { if (steering != null) { steering.enabled = steering.isOn = false; } steering = arrive; steering.TargetPosition = (movingEntity != null && movingEntity.enabled) ? movingEntity.PositionAt(EdgeToFollow.Destination) : World.Instance.GroundPositionAt(EdgeToFollow.Destination); steering.enabled = steering.isOn = true; if ((movingEntity == null || !movingEntity.enabled) && aiController != null && aiController.enabled) { aiController.SetSteering(steering); } } else { if (steering != null) { steering.enabled = steering.isOn = false; } steering = seek; steering.TargetPosition = (movingEntity != null && movingEntity.enabled) ? movingEntity.PositionAt(EdgeToFollow.Destination) : World.Instance.GroundPositionAt(EdgeToFollow.Destination); steering.enabled = steering.isOn = true; if ((movingEntity == null || !movingEntity.enabled) && aiController != null && aiController.enabled) { aiController.SetSteering(steering); } } return true; }
//returns the path as a list of PathEdges public override List<PathEdge> GetPathAsPathEdges() { List<PathEdge> path = new List<PathEdge>(); //just return an empty path if no target or no path found if (targetIdx_ < 0) return path; int nd = targetIdx_; PathEdge newPathEdge = null; Vector2 source; Vector2 destination; while ((nd != sourceIdx_) && (shortestPathTree_[nd] != null)) { source = graph_.GetNode(shortestPathTree_[nd].From()).Position(); destination = graph_.GetNode(shortestPathTree_[nd].To()).Position(); // change map position to real position source.x *= GameSettings.GetInstance().TILE_SIZE; source.y *= GameSettings.GetInstance().TILE_SIZE; destination.x *= GameSettings.GetInstance().TILE_SIZE; destination.y *= GameSettings.GetInstance().TILE_SIZE; newPathEdge = new PathEdge ( source, destination ); path.Insert(0, newPathEdge); nd = shortestPathTree_[nd].From(); } return path; }
public void HandleRpc(ISender caller, string meth, IList args, object state) { if( meth == "create" ) { Edge calling_edge = (Edge)((ReqrepManager.ReplyState)caller).ReturnPath; string remote_path = (string)args[0]; string local_path = (string)args[1]; PathEdgeListener el = _pel_map[local_path]; if( el.IsStarted ) { PathEdge npe = new PathEdge(calling_edge, local_path, remote_path); lock( _sync ) { //We don't announce yet, wait till we get some data, which //verifies that the other side has seen it. _unannounced[calling_edge] = npe; } //So the new Edge has been announced. Rpc.SendResult(state, true); } else { throw new Exception( String.Format("PathEdgeListener({0}) not started", local_path)); } } else { throw new AdrException(-32601, "No Handler for method: " + meth); } }
public void HandleEC(bool succ, Edge e, Exception x) { if( succ ) { /* * Got the underlying Edge, now do the path protocol */ Channel results = new Channel(1); results.CloseEvent += delegate(object q, EventArgs args) { try { RpcResult res = (RpcResult)results.Dequeue(); object o = res.Result; if(o is Exception) { Console.WriteLine(o); throw (o as Exception); } //If we get here, everything looks good: PathEdge pe = new PathEdge(e, LocalPath, RemotePath); //Start sending e's packets into pe pe.Subscribe(); ECB(true, pe, null); } catch(Exception cx) { ECB(false, null, cx); } }; //Make sure we hear the packets on this edge: e.Subscribe(_pel._pem, null); //Now make the rpc call: _pel._pem.Rpc.Invoke(e, results, "sys:pathing.create", LocalPath, RemotePath ); } else { ECB(false, null, x); } }
/** try to create a new PathEdge and send the EdgeEvent */ public void SendPathEdgeEvent(PathEdge pe) { if( 1 == _is_started ) { SendEdgeEvent(pe); } else { throw new Exception( String.Format("PathEdgeListener{0} not yet started", _path)); } }