@@ -32,21 +32,28 @@ CompositeAction::~CompositeAction() {
32
32
}
33
33
34
34
bool 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 ))
36
42
return false ;
37
43
44
+ child->setFinishCallback (std::bind (&CompositeAction::onLastChildFinished, this , _1, _2, _3));
45
+ child->setBlockCallback (std::bind (&CompositeAction::block, this , _1, _2));
46
+
38
47
CHECK_DELETE_RESET_OBJ (child_);
39
48
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 );
43
49
44
50
return true ;
45
51
}
46
52
47
53
void CompositeAction::toJson (Json &js) const {
54
+ SerialAssembleAction::toJson (js);
55
+
48
56
TBOX_ASSERT (child_ != nullptr );
49
- AssembleAction::toJson (js);
50
57
child_->toJson (js[" child" ]);
51
58
}
52
59
@@ -59,60 +66,24 @@ bool CompositeAction::isReady() const {
59
66
}
60
67
61
68
void CompositeAction::onStart () {
62
- AssembleAction::onStart ();
63
-
64
- TBOX_ASSERT (child_ != nullptr );
65
- child_->start ();
66
- }
69
+ SerialAssembleAction::onStart ();
67
70
68
- void CompositeAction::onStop () {
69
71
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_);
91
73
}
92
74
93
75
void CompositeAction::onReset () {
94
76
TBOX_ASSERT (child_ != nullptr );
95
77
child_->reset ();
96
78
97
- AssembleAction ::onReset ();
79
+ SerialAssembleAction ::onReset ();
98
80
}
99
81
100
82
void CompositeAction::onFinished (bool is_succ, const Reason &why, const Trace &trace) {
101
83
// ! 有可能不是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 ();
112
85
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);
116
87
}
117
88
118
89
}
0 commit comments