@@ -41,7 +41,7 @@ bool PipelineTask::run()
4141 PipelineData::NextList list = std::move (next);
4242 list.insert (list.end (), std::make_move_iterator (interrupt.begin ()), std::make_move_iterator (interrupt.end ()));
4343
44- auto node_detail = run_reco_and_action (list, node);
44+ auto node_detail = run_next (list, node);
4545
4646 if (context_->need_to_stop ()) {
4747 LogWarn << " need_to_stop" << VAR (node.name );
@@ -119,7 +119,7 @@ void PipelineTask::post_stop()
119119 context_->need_to_stop () = true ;
120120}
121121
122- NodeDetail PipelineTask::run_reco_and_action (const PipelineData::NextList& list, const PipelineData& pretask)
122+ NodeDetail PipelineTask::run_next (const PipelineData::NextList& list, const PipelineData& pretask)
123123{
124124 if (!tasker_) {
125125 LogError << " tasker is null" ;
@@ -148,7 +148,7 @@ NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list,
148148 current_clock = std::chrono::steady_clock::now ();
149149 cv::Mat image = screencap ();
150150
151- reco = run_recognition (image, list);
151+ reco = recognize_list (image, list);
152152 if (reco.box ) { // hit
153153 break ;
154154 }
@@ -167,8 +167,85 @@ NodeDetail PipelineTask::run_reco_and_action(const PipelineData::NextList& list,
167167 std::this_thread::sleep_until (current_clock + pretask.rate_limit );
168168 }
169169
170- auto node_detail = run_action (reco);
171- return node_detail;
170+ auto hit_opt = context_->get_pipeline_data (reco.name );
171+ if (!hit_opt) {
172+ LogError << " get_pipeline_data failed, node not exist" << VAR (reco.name );
173+ return {};
174+ }
175+
176+ auto act = run_action (reco, *hit_opt);
177+
178+ NodeDetail result {
179+ .node_id = generate_node_id (),
180+ .name = hit_opt->name ,
181+ .reco_id = reco.reco_id ,
182+ .action_id = act.action_id ,
183+ .completed = act.success ,
184+ };
185+ set_node_detail (result.node_id , result);
186+
187+ return result;
188+ }
189+
190+ RecoResult PipelineTask::recognize_list (const cv::Mat& image, const PipelineData::NextList& list)
191+ {
192+ LogFunc << VAR (cur_node_) << VAR (list);
193+
194+ if (!context_) {
195+ LogError << " context is null" ;
196+ return {};
197+ }
198+
199+ if (image.empty ()) {
200+ LogError << " Image is empty" ;
201+ return {};
202+ }
203+
204+ auto cur_opt = context_->get_pipeline_data (cur_node_);
205+ if (!cur_opt) {
206+ LogError << " get_pipeline_data failed, node not exist" << VAR (cur_node_);
207+ return {};
208+ }
209+
210+ const auto & cur_node = *cur_opt;
211+
212+ const json::value reco_list_cb_detail {
213+ { " task_id" , task_id () },
214+ { " name" , cur_node_ },
215+ { " list" , json::array (list) },
216+ { " focus" , cur_node.focus },
217+ };
218+
219+ if (debug_mode () || !cur_node.focus .is_null ()) {
220+ notify (MaaMsg_Node_NextList_Starting, reco_list_cb_detail);
221+ }
222+
223+ for (const auto & node : list) {
224+ auto node_opt = context_->get_pipeline_data (node);
225+ if (!node_opt) {
226+ LogError << " get_pipeline_data failed, node not exist" << VAR (node);
227+ continue ;
228+ }
229+ const auto & pipeline_data = *node_opt;
230+
231+ RecoResult result = run_recognition (image, pipeline_data);
232+
233+ if (!result.box ) {
234+ continue ;
235+ }
236+
237+ if (debug_mode () || !cur_node.focus .is_null ()) {
238+ notify (MaaMsg_Node_NextList_Succeeded, reco_list_cb_detail);
239+ }
240+
241+ return result;
242+ }
243+
244+ if (debug_mode () || !cur_node.focus .is_null ()) {
245+ notify (MaaMsg_Node_NextList_Failed, reco_list_cb_detail);
246+ }
247+
248+ return {};
172249}
173250
174251MAA_TASK_NS_END
0 commit comments