| 30 | // clang-format on |
| 31 | |
| 32 | int 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 | } |
nothing calls this directly
no test coverage detected