MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / main

Function main

examples/t17_blackboard_backup.cpp:32–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30// clang-format on
31
32int main()
33{
34 BehaviorTreeFactory factory;
35 factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
36 factory.registerBehaviorTreeFromText(xml_tree);
37
38 auto tree = factory.createTree("MainTree");
39
40 // We want to create a memory of the blackboard in memory.
41 // This is conveninet when we want to reset its state to the
42 // original one.
43 // It is certainly more efficient than destroying and creating the tree again,
44 // in many casess.
45
46 const auto backup_before_tick = BlackboardBackup(tree);
47 tree.tickWhileRunning();
48
49 // Restore the original status of the blackboard
50 BlackboardRestore(backup_before_tick, tree);
51 tree.tickWhileRunning();
52
53 // Alternatively, we may want to save he values of the element in the blackboard
54 // to file, to restore them again. We use JSON serialization for that.
55 nlohmann::json json_after_tick = ExportTreeToJSON(tree);
56
57 // The JSOn object can be saved to file. See https://github.com/nlohmann/json
58 // for details. For the time being, we just print it in the console
59
60 std::cout << "--- blackboard serialized as JSON: ----\n"
61 << json_after_tick.dump(2) << std::endl;
62
63 // We can restore the values of the blackboards using the JSON
64 ImportTreeFromJSON(json_after_tick, tree);
65
66 return 0;
67}

Callers

nothing calls this directly

Calls 8

BlackboardBackupFunction · 0.85
BlackboardRestoreFunction · 0.85
ExportTreeToJSONFunction · 0.85
ImportTreeFromJSONFunction · 0.85
createTreeMethod · 0.80
tickWhileRunningMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected