| 344 | /* SeqNode */ |
| 345 | |
| 346 | Status SeqNode::tick(Blackboard* board) { |
| 347 | if (_children.empty()) return Status::Success; |
| 348 | int index = 0; |
| 349 | uint32_t key = getId(); |
| 350 | if (auto value = board->get(key)) { |
| 351 | index = value->toVal<int>(); |
| 352 | } else |
| 353 | board->set(key, Value::alloc(index)); |
| 354 | auto status = Status::Running; |
| 355 | do { |
| 356 | status = _children[index]->tick(board); |
| 357 | switch (status) { |
| 358 | case Status::Running: |
| 359 | return Status::Running; |
| 360 | case Status::Success: { |
| 361 | index++; |
| 362 | if (index >= s_cast<int>(_children.size())) { |
| 363 | board->remove(key); |
| 364 | return Status::Success; |
| 365 | } |
| 366 | board->set(key, Value::alloc(index)); |
| 367 | break; |
| 368 | } |
| 369 | case Status::Failure: |
| 370 | board->remove(key); |
| 371 | return Status::Failure; |
| 372 | } |
| 373 | } while (status == Status::Success); |
| 374 | return Status::Running; |
| 375 | } |
| 376 | |
| 377 | /* SelNode */ |
| 378 | |