@@ -32,21 +32,28 @@ CompositeAction::~CompositeAction() {
3232}
3333
3434bool CompositeAction::setChild (Action *child) {
35- if (child == nullptr )
35+ if (child == nullptr ) {
36+ LogWarn (" %d:%s[%s], add child %d:%s[%s] fail, child == nullptr" ,
37+ id (), type ().c_str (), label ().c_str ());
38+ return false ;
39+ }
40+
41+ if (!child->setParent (this ))
3642 return false ;
3743
44+ child->setFinishCallback (std::bind (&CompositeAction::onLastChildFinished, this , _1, _2, _3));
45+ child->setBlockCallback (std::bind (&CompositeAction::block, this , _1, _2));
46+
3847 CHECK_DELETE_RESET_OBJ (child_);
3948 child_ = child;
40- child_->setFinishCallback (std::bind (&CompositeAction::onChildFinished, this , _1, _2, _3));
41- child_->setBlockCallback (std::bind (&CompositeAction::onChildBlocked, this , _1, _2));
42- child_->setParent (this );
4349
4450 return true ;
4551}
4652
4753void CompositeAction::toJson (Json &js) const {
54+ SerialAssembleAction::toJson (js);
55+
4856 TBOX_ASSERT (child_ != nullptr );
49- AssembleAction::toJson (js);
5057 child_->toJson (js[" child" ]);
5158}
5259
@@ -59,60 +66,24 @@ bool CompositeAction::isReady() const {
5966}
6067
6168void CompositeAction::onStart () {
62- AssembleAction::onStart ();
63-
64- TBOX_ASSERT (child_ != nullptr );
65- child_->start ();
66- }
69+ SerialAssembleAction::onStart ();
6770
68- void CompositeAction::onStop () {
6971 TBOX_ASSERT (child_ != nullptr );
70- child_->stop ();
71-
72- AssembleAction::onStop ();
73- }
74-
75- void CompositeAction::onPause () {
76- TBOX_ASSERT (child_ != nullptr );
77- child_->pause ();
78-
79- AssembleAction::onPause ();
80- }
81-
82- void CompositeAction::onResume () {
83- AssembleAction::onResume ();
84-
85- TBOX_ASSERT (child_ != nullptr );
86- if (child_->state () == State::kFinished ) {
87- finish (child_->result () == Result::kSuccess );
88- } else {
89- child_->resume ();
90- }
72+ startThisAction (child_);
9173}
9274
9375void CompositeAction::onReset () {
9476 TBOX_ASSERT (child_ != nullptr );
9577 child_->reset ();
9678
97- AssembleAction ::onReset ();
79+ SerialAssembleAction ::onReset ();
9880}
9981
10082void CompositeAction::onFinished (bool is_succ, const Reason &why, const Trace &trace) {
10183 // ! 有可能不是child_自然结束产生的finish
102- TBOX_ASSERT (child_ != nullptr );
103- child_->stop ();
104-
105- AssembleAction::onFinished (is_succ, why, trace);
106- }
107-
108- void CompositeAction::onChildFinished (bool is_succ, const Reason &why, const Trace &trace) {
109- if (state () == State::kRunning )
110- finish (is_succ, why, trace);
111- }
84+ stopCurrAction ();
11285
113- void CompositeAction::onChildBlocked (const Reason &why, const Trace &trace) {
114- if (state () == State::kRunning )
115- block (why, trace);
86+ SerialAssembleAction::onFinished (is_succ, why, trace);
11687}
11788
11889}
0 commit comments