Skip to content

Commit

Permalink
Make sure newly created nodes get modify() called and replicated ones…
Browse files Browse the repository at this point in the history
… do not.
  • Loading branch information
calvertdw committed Dec 30, 2024
1 parent 3f6b951 commit bd090a5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void renderImGuiWidgets(RDXBehaviorTreeNode<?, ?> relativeNode, BehaviorT
nodeToInsert = new RDXBehaviorTreeRootNode(behaviorTree.getAndIncrementNextID(),
behaviorTree.getCRDTInfo(),
behaviorTree.getSaveFileDirectory());
nodeToInsert.getDefinition().modify();
topologyOperationQueue.queueAppendChildModify(nodeToInsert, loadedNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void renderNodeCreationClickable(RDXBehaviorTreeNode<?, ?> relativeNode,
behaviorTree.getAndIncrementNextID(),
behaviorTree.getCRDTInfo(),
behaviorTree.getSaveFileDirectory());

newNode.getDefinition().modify();
BehaviorTreeNodeInsertionDefinition<RDXBehaviorTreeNode<?, ?>> insertionDefinition
= new BehaviorTreeNodeInsertionDefinition<>(insertionType, newNode, relativeNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ public void renderImGuiWidgets(RDXBehaviorTreeNode<?, ?> node)
ImGui.pushStyleColor(ImGuiCol.Text, ImGuiTools.RED);
if (ImGui.menuItem(labels.get("Delete Node")))
{
topologyOperationQueue.queueDestroySubtreeModify(node);

if (node.isRootNode()) // Root node
{
behaviorTree.setRootNode(null);
behaviorTree.getRootReferenceModification().modify();
}
if (node.isRootNode())
topologyOperationQueue.queueDestroyEntireTreeModify();
else
topologyOperationQueue.queueDestroySubtreeModify(node);
}
ImGui.popStyleColor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public void modifyTreeTopology()

public void deleteRootNode()
{
modifyTreeTopology(topologyOperationQueue -> topologyOperationQueue.queueDestroySubtreeModify(getRootNode()));
setRootNode(null);
rootReferenceModification.modify();
modifyTreeTopology(BehaviorTreeTopologyOperationQueue::queueDestroyEntireTreeModify);
}

public void toMessage(BehaviorTreeStateMessage message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import us.ihmc.avatar.drcRobot.DRCRobotModel;
import us.ihmc.avatar.drcRobot.ROS2SyncedRobotModel;
import us.ihmc.avatar.ros2.ROS2ControllerHelper;
import us.ihmc.behaviors.behaviorTree.topology.BehaviorTreeTopologyOperationQueue;
import us.ihmc.communication.ros2.ROS2ActorDesignation;
import us.ihmc.communication.ros2.sync.ROS2PeerClockOffsetEstimator;
import us.ihmc.log.LogTools;
Expand Down Expand Up @@ -54,10 +55,7 @@ private void update(BehaviorTreeNodeExecutor<?, ?> node)

public void destroy()
{
if (rootNode != null)
{
modifyTreeTopology(topologyOperationQueue -> topologyOperationQueue.queueDestroySubtreeModify(rootNode));
}
modifyTreeTopology(BehaviorTreeTopologyOperationQueue::queueDestroyEntireTreeModify);
}

@Override
Expand Down Expand Up @@ -90,8 +88,9 @@ public void loadBehavior(String jsonFileName)
else if (rootNode == null) // Automatically add a root node if there isn't one
{
BehaviorTreeRootNodeExecutor newRootNode = new BehaviorTreeRootNodeExecutor(getAndIncrementNextID(),
getCRDTInfo(),
getSaveFileDirectory());
getCRDTInfo(),
getSaveFileDirectory());
newRootNode.getDefinition().modify();
topologyOperationQueue.queueAppendChildModify(newRootNode, loadedNode);
topologyOperationQueue.queueSetRootNodeModify(newRootNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private HLT loadFromFile(WorkspaceResourceFile file, JsonNode jsonNode, HLT pare
behaviorTree.getAndIncrementNextID(),
behaviorTree.getCRDTInfo(),
behaviorTree.getSaveFileDirectory());
node.getDefinition().modify();
node.getDefinition().loadFromFile(jsonNode);

// Make sure the node is named the same as the file including subdirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public void queueInsertNodeModify(BehaviorTreeNodeInsertionDefinition<HLT> inser
}
}

public void queueSetRootNode(HLT rootNode)
{
topologyOperationQueue.add(() ->
{
behaviorTree.setRootNode(rootNode);
});
}

public void queueSetRootNodeModify(HLT rootNode)
{
topologyOperationQueue.add(() ->
Expand All @@ -59,6 +67,18 @@ public void queueSetRootNodeModify(HLT rootNode)
});
}

public void queueDestroyEntireTreeModify()
{
topologyOperationQueue.add(() ->
{
HLT rootNode = behaviorTree.getRootNode();
behaviorTree.setRootNode(null);
behaviorTree.getRootReferenceModification().modify();
if (rootNode != null)
BehaviorTreeTopologyOperations.destroySubtreeModify(rootNode);
});
}

public void queueDestroySubtreeModify(HLT subtreeRoot)
{
topologyOperationQueue.add(() -> BehaviorTreeTopologyOperations.destroySubtreeModify(subtreeRoot));
Expand Down

0 comments on commit bd090a5

Please sign in to comment.