Skip to content

Commit

Permalink
feat: 增加基本的调试信息回调
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 7, 2024
1 parent 35593e6 commit b8327b8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ enum MaaGlobalOptionEnum
///
/// value: bool, eg: true; val_size: sizeof(bool)
MaaGlobalOption_ShowHitDraw = 5,

/// Whether to callback debug message
///
/// value: bool, eg: true; val_size: sizeof(bool)
MaaGlobalOption_DebugMessage = 6,
};

typedef MaaOption MaaResOption;
Expand Down
22 changes: 22 additions & 0 deletions include/MaaFramework/MaaMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,26 @@
#define MaaMsg_Task_Focus_Runout ("Task.Focus.Runout")
#define MaaMsg_Task_Focus_Completed ("Task.Focus.Completed")
/// @}

/**
* @{
* @brief Message for debug.
*
* payload: {
* id: number,
* entry: string,
* name: string,
* uuid: string,
* hash: string,
* recognition: object,
* run_times: number,
* last_time: string,
* status: string
* }
*/
#define MaaMsg_Task_Debug_Hit ("Task.Debug.Hit")
#define MaaMsg_Task_Debug_Runout ("Task.Debug.Runout")
#define MaaMsg_Task_Debug_Completed ("Task.Debug.Completed")
/// @}

/** @} */
20 changes: 19 additions & 1 deletion source/MaaFramework/Option/GlobalOptionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ bool GlobalOptionMgr::set_option(
return set_stdout_level(value, val_size);
case MaaGlobalOption_ShowHitDraw:
return set_show_hit_draw(value, val_size);
case MaaGlobalOption_DebugMessage:
return set_debug_message(value, val_size);
default:
LogError << "Unknown key" << VAR(key) << VAR(value);
return false;
Expand Down Expand Up @@ -109,4 +111,20 @@ bool GlobalOptionMgr::set_stdout_level(MaaOptionValue value, MaaOptionValueSize
return true;
}

MAA_NS_END
bool GlobalOptionMgr::set_debug_message(MaaOptionValue value, MaaOptionValueSize val_size)
{
LogFunc;

if (val_size != sizeof(bool)) {
LogError << "Invalid value size" << VAR(val_size);
return false;
}

debug_message_ = *reinterpret_cast<const bool*>(value);

LogInfo << "Set debug message" << VAR(debug_message_);

return true;
}

MAA_NS_END
3 changes: 3 additions & 0 deletions source/MaaFramework/Option/GlobalOptionMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GlobalOptionMgr : public SingletonHolder<GlobalOptionMgr>
bool save_draw() const { return save_draw_; }
bool show_hit_draw() const { return show_hit_draw_; }
bool recording() const { return recording_; }
bool debug_message() const { return debug_message_; }

private:
GlobalOptionMgr() = default;
Expand All @@ -33,12 +34,14 @@ class GlobalOptionMgr : public SingletonHolder<GlobalOptionMgr>
bool set_show_hit_draw(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_recording(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_stdout_level(MaaOptionValue value, MaaOptionValueSize val_size);
bool set_debug_message(MaaOptionValue value, MaaOptionValueSize val_size);

private:
std::filesystem::path log_dir_;
bool save_draw_ = false;
bool show_hit_draw_ = false;
bool recording_ = false;
bool debug_message_ = false;
};

MAA_NS_END
7 changes: 4 additions & 3 deletions source/MaaFramework/Resource/PipelineResMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class PipelineResMgr : public NonCopyable
Recognition::Param& out_param,
const Recognition::Type& default_type,
const Recognition::Param& default_param);
// static bool parse_direct_hit_param(const json::value& input, MAA_VISION_NS::DirectHitParam&
// output,
// const MAA_VISION_NS::DirectHitParam& default_value);
// static bool parse_direct_hit_param(
// const json::value& input,
// MAA_VISION_NS::DirectHitParam& output,
// const MAA_VISION_NS::DirectHitParam& default_value);
static bool parse_template_matcher_param(
const json::value& input,
MAA_VISION_NS::TemplateMatcherParam& output,
Expand Down
17 changes: 16 additions & 1 deletion source/MaaFramework/Task/PipelineTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Controller/ControllerAgent.h"
#include "Instance/InstanceStatus.h"
#include "MaaFramework/MaaMsg.h"
#include "Option/GlobalOptionMgr.h"
#include "Resource/ResourceMgr.h"
#include "Task/CustomAction.h"
#include "Utils/ImageIo.h"
Expand Down Expand Up @@ -181,6 +182,9 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits)
if (hits.task_data.focus) {
notify(MaaMsg_Task_Focus_Hit, detail);
}
if (debug_mode()) {
notify(MaaMsg_Task_Debug_Hit, detail);
}

if (hits.task_data.times_limit <= run_times) {
LogInfo << "Task runout:" << name;
Expand All @@ -190,6 +194,9 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits)
if (hits.task_data.focus) {
notify(MaaMsg_Task_Focus_Runout, detail);
}
if (debug_mode()) {
notify(MaaMsg_Task_Debug_Runout, detail);
}

return RunningResult::Runout;
}
Expand All @@ -204,8 +211,16 @@ PipelineTask::RunningResult PipelineTask::run_task(const HitResult& hits)
if (hits.task_data.focus) {
notify(MaaMsg_Task_Focus_Completed, detail);
}
if (debug_mode()) {
notify(MaaMsg_Task_Debug_Completed, detail);
}

return ret ? RunningResult::Success : RunningResult::InternalError;
}

MAA_TASK_NS_END
bool PipelineTask::debug_mode() const
{
return GlobalOptionMgr::get_instance().debug_message();
}

MAA_TASK_NS_END
1 change: 1 addition & 0 deletions source/MaaFramework/Task/PipelineTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class PipelineTask : public MaaInstanceSink
}

bool need_to_stop() const { return need_to_stop_; }
bool debug_mode() const;

private:
bool need_to_stop_ = false;
Expand Down

0 comments on commit b8327b8

Please sign in to comment.