/// <summary> /// Updates the graph during runtime removing the approach waypoints (marking them as unwalkable) for this starbase, /// and makes any waypoints walkable that were previously made unwalkable when the base was added, then reconnects. /// </summary> /// <param name="baseCmd">The Starbase command.</param> public void RemoveFromGraph(StarbaseCmdItem baseCmd) { D.Log("{0}.RemoveFromGraph({1}) called.", GetType().Name, baseCmd.DebugName); // Note: active.IsAnyGraphUpdatesQueued is never true except when using UpdateGraphs(). // I've replaced UpdateGraphs(GUO) with WorkItems // forceCompletion is set by AstarPath internally var makeApproachNodesUnwalkable = new AstarPath.AstarWorkItem(update: (forceCompletion) => { active.QueueWorkItemFloodFill(); MakeStarbaseApproachNodesUnwalkable(baseCmd); return true; }); active.AddWorkItem(makeApproachNodesUnwalkable); // restore any nodes made unwalkable when this starbase was added // Note: cannot precede makeApproachNodesUnwalkable as the above also makes all nodes INSIDE the approach nodes unwalkable var restoreNodesInsideApproachNodesWorkItem = new AstarPath.AstarWorkItem(update: (forceCompletion) => { ChangeWalkabilityOfNodesInsideApproachNodes(baseCmd, isWalkable: true); return true; }); active.AddWorkItem(restoreNodesInsideApproachNodesWorkItem); // Note: 8.17.16 no current way to remove a work item once added. Otherwise, if I got another call to this // method with IsAnyGraphUpdatesQueued = true, I'd remove the previous queued MakeConnections and replace // with a new one at the end. Currently, if I get another call while queued, MakeConnections will run twice. var makeConnectionsWorkItem = new AstarPath.AstarWorkItem(update: (forceCompletion) => { MakeConnections(); return true; }); active.AddWorkItem(makeConnectionsWorkItem); }
/// <summary> /// Updates the graph during runtime adding approach waypoints for this starbase, /// and makes any waypoints located inside the new approach waypoints unwalkable, then reconnects. /// </summary> /// <param name="baseCmd">The Starbase command.</param> public void AddToGraph(StarbaseCmdItem baseCmd) { //D.Log("{0}.AddToGraph({1}) called.", GetType().Name, baseCmd.DebugName); // Note: active.IsAnyGraphUpdatesQueued is never true except when using UpdateGraphs(). I've replaced UpdateGraphs(GUO) with WorkItems // forceCompletion is set by AstarPath internally var makeNodesInsideApproachNodesUnwalkableWorkItem = new AstarPath.AstarWorkItem(update: (forceCompletion) => { active.QueueWorkItemFloodFill(); ChangeWalkabilityOfNodesInsideApproachNodes(baseCmd, isWalkable: false); return true; }); active.AddWorkItem(makeNodesInsideApproachNodesUnwalkableWorkItem); var addApproachNodesWorkItem = new AstarPath.AstarWorkItem(update: (forceCompletion) => { AddStarbaseApproachNodes(baseCmd); return true; }); active.AddWorkItem(addApproachNodesWorkItem); // Note: 8.17.16 no current way to remove a work item once added. Otherwise, if I got another call to this // method with IsAnyGraphUpdatesQueued = true, I'd remove the previous queued MakeConnections and replace // with a new one at the end. Currently, if I get another call while queued, MakeConnections will run twice. var makeConnectionsWorkItem = new AstarPath.AstarWorkItem(update: (forceCompletion) => { MakeConnections(); return true; }); active.AddWorkItem(makeConnectionsWorkItem); }