Skip to content

Commit

Permalink
refactor: rename APIs to the term
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Dec 18, 2024
1 parent ca9f1bc commit fdc5829
Show file tree
Hide file tree
Showing 42 changed files with 111 additions and 105 deletions.
6 changes: 3 additions & 3 deletions docs/en_us/3.1-PipelineProtocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
```
When we execute a task (passing the task name to the MaaTaskerPostPipeline interface), it will recognize the tasks in the "next" list one by one (based on the recognition settings for each task). Once a match is found, it will exit the recognition of the "next" list and proceed to execute the matched task. It's similar to traversing and comparing, and as soon as a match is found, it will break and execute the found task.
When we execute a task (passing the task name to the MaaTaskerPostTask interface), it will recognize the tasks in the "next" list one by one (based on the recognition settings for each task). Once a match is found, it will exit the recognition of the "next" list and proceed to execute the matched task. It's similar to traversing and comparing, and as soon as a match is found, it will break and execute the found task.
## Example
Expand Down Expand Up @@ -53,7 +53,7 @@ For example, let's say we have a game where different fruits, such as apples, or
}
```
Let's assume there are no apples on the screen, but there are oranges and bananas. In the above JSON, if we execute "StartFruit" (i.e., pass "StartFruit" to the MaaTaskerPostPipeline interface), it will first recognize "Apple." Since there are no apples on the screen, it will continue to recognize "Orange." If it recognizes an orange, it will start executing the "Orange" task, and it won't attempt to recognize "Banana." After executing "Orange" according to its action, it will continue to recognize "Orange's" "next" tasks.
Let's assume there are no apples on the screen, but there are oranges and bananas. In the above JSON, if we execute "StartFruit" (i.e., pass "StartFruit" to the MaaTaskerPostTask interface), it will first recognize "Apple." Since there are no apples on the screen, it will continue to recognize "Orange." If it recognizes an orange, it will start executing the "Orange" task, and it won't attempt to recognize "Banana." After executing "Orange" according to its action, it will continue to recognize "Orange's" "next" tasks.
Within "Orange's" "next," if it recognizes "Cat," it won't continue to recognize "Dog." It will execute the "Cat" action and continue to recognize "Cat's" "next" after the action is completed. If neither "Cat" nor "Dog" is recognized, it will continue to attempt recognition for these two tasks until a timeout occurs.
Expand Down Expand Up @@ -551,7 +551,7 @@ Additional properties for this action:

### `StopTask`

Stops the current task chain (the individual task chain passed to MaaTaskerPostPipeline).
Stops the current task chain (the individual task chain passed to MaaTaskerPostTask).

### `Custom`

Expand Down
2 changes: 1 addition & 1 deletion docs/en_us/NodeJS/J1.1-QuickStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function main() {
console.log(msg, detail)
}
// Load resource
await res.post_path('./resource')
await res.post_bundle('./resource')

// Create tasker
const tskr = new maa.Tasker()
Expand Down
6 changes: 3 additions & 3 deletions docs/zh_cn/3.1-任务流水线协议.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
```
我们执行某个 Task 时( MaaTaskerPostPipeline 接口传入任务名),会对其 next 列表中的 Task **依次** 进行识别(根据每个 Task 的 recognition 相关设置)
我们执行某个 Task 时( MaaTaskerPostTask 接口传入任务名),会对其 next 列表中的 Task **依次** 进行识别(根据每个 Task 的 recognition 相关设置)
且一旦匹配上了,则会退出 next 列表识别,转而去执行匹配上的任务。类似遍历比较,一旦找到了,就直接 break 转而去执行找到的那个 Task 。
## 举例
Expand Down Expand Up @@ -55,7 +55,7 @@
```
假设现在画面中没有 Apple,但有 Orange 和 Banana 。
在上述 JSON 中,若我们执行 "StartFruit"(即 MaaTaskerPostPipeline 接口传入 "StartFruit"),会先识别 Apple,画面中没有,所以继续识别 Orange,这次识别到了,则我们开始执行 Orange,不会再去识别 Banana 了。
在上述 JSON 中,若我们执行 "StartFruit"(即 MaaTaskerPostTask 接口传入 "StartFruit"),会先识别 Apple,画面中没有,所以继续识别 Orange,这次识别到了,则我们开始执行 Orange,不会再去识别 Banana 了。
执行 Orange 就是根据其 action 去进行对应的操作,当执行完成后,我们会再去识别 Orange 的 next 。
Orange 的 next 中,
Expand Down Expand Up @@ -561,7 +561,7 @@ Orange 的 next 中,
### `StopTask`
停止当前任务链(MaaTaskerPostPipeline 传入的单个任务链)。
停止当前任务链(MaaTaskerPostTask 传入的单个任务链)。
### `Custom`
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/NodeJS/J1.1-快速开始.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function main() {
console.log(msg, detail)
}
// 加载资源
await res.post_path('./resource')
await res.post_bundle('./resource')

// 创建实例
const tskr = new maa.Tasker()
Expand Down
4 changes: 2 additions & 2 deletions include/MaaFramework/Instance/MaaContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C"
{
#endif

MAA_FRAMEWORK_API MaaTaskId MaaContextRunPipeline(MaaContext* context, const char* entry, const char* pipeline_override);
MAA_FRAMEWORK_API MaaTaskId MaaContextRunTask(MaaContext* context, const char* entry, const char* pipeline_override);

MAA_FRAMEWORK_API MaaRecoId
MaaContextRunRecognition(MaaContext* context, const char* entry, const char* pipeline_override, const MaaImageBuffer* image);
Expand All @@ -33,7 +33,7 @@ extern "C"

MAA_FRAMEWORK_API MaaBool MaaContextOverridePipeline(MaaContext* context, const char* pipeline_override);

MAA_FRAMEWORK_API MaaBool MaaContextOverrideNext(MaaContext* context, const char* name, const MaaStringListBuffer* next_list);
MAA_FRAMEWORK_API MaaBool MaaContextOverrideNext(MaaContext* context, const char* node_name, const MaaStringListBuffer* next_list);

MAA_FRAMEWORK_API MaaTaskId MaaContextGetTaskId(const MaaContext* context);

Expand Down
2 changes: 1 addition & 1 deletion include/MaaFramework/Instance/MaaResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C"

MAA_FRAMEWORK_API MaaBool MaaResourceClearCustomAction(MaaResource* res);

MAA_FRAMEWORK_API MaaResId MaaResourcePostPath(MaaResource* res, const char* path);
MAA_FRAMEWORK_API MaaResId MaaResourcePostBundle(MaaResource* res, const char* path);

MAA_FRAMEWORK_API MaaBool MaaResourceClear(MaaResource* res);

Expand Down
8 changes: 4 additions & 4 deletions include/MaaFramework/Instance/MaaTasker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C"

MAA_FRAMEWORK_API MaaBool MaaTaskerInited(const MaaTasker* tasker);

MAA_FRAMEWORK_API MaaTaskId MaaTaskerPostPipeline(MaaTasker* tasker, const char* entry, const char* pipeline_override);
MAA_FRAMEWORK_API MaaTaskId MaaTaskerPostTask(MaaTasker* tasker, const char* entry, const char* pipeline_override);

MAA_FRAMEWORK_API MaaStatus MaaTaskerStatus(const MaaTasker* tasker, MaaTaskId id);

Expand All @@ -60,7 +60,7 @@ extern "C"
MAA_FRAMEWORK_API MaaBool MaaTaskerGetRecognitionDetail(
const MaaTasker* tasker,
MaaRecoId reco_id,
/* out */ MaaStringBuffer* name,
/* out */ MaaStringBuffer* node_name,
/* out */ MaaStringBuffer* algorithm,
/* out */ MaaBool* hit,
/* out */ MaaRect* box,
Expand All @@ -76,7 +76,7 @@ extern "C"
MAA_FRAMEWORK_API MaaBool MaaTaskerGetNodeDetail(
const MaaTasker* tasker,
MaaNodeId node_id,
/* out */ MaaStringBuffer* name,
/* out */ MaaStringBuffer* node_name,
/* out */ MaaRecoId* reco_id,
/* out */ MaaBool* completed);

Expand All @@ -98,7 +98,7 @@ extern "C"
*/
MAA_FRAMEWORK_API MaaBool MaaTaskerGetLatestNode(
const MaaTasker* tasker,
const char* task_name,
const char* node_name,
/* out */ MaaNodeId* latest_id);

#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions include/MaaFramework/MaaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ typedef void(MAA_CALL* MaaNotificationCallback)(const char* message, const char*
typedef MaaBool(MAA_CALL* MaaCustomRecognitionCallback)(
MaaContext* context,
MaaTaskId task_id,
const char* current_task_name,
const char* node_name,
const char* custom_recognition_name,
const char* custom_recognition_param,
const MaaImageBuffer* image,
Expand All @@ -295,7 +295,7 @@ typedef MaaBool(MAA_CALL* MaaCustomRecognitionCallback)(
typedef MaaBool(MAA_CALL* MaaCustomActionCallback)(
MaaContext* context,
MaaTaskId task_id,
const char* current_task_name,
const char* node_name,
const char* custom_action_name,
const char* custom_action_param,
MaaRecoId reco_id,
Expand Down
8 changes: 4 additions & 4 deletions sample/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MaaController* create_win32_controller();
MaaBool my_reco(
MaaContext* context,
MaaTaskId task_id,
const char* current_task_name,
const char* node_name,
const char* custom_recognition_name,
const char* custom_recognition_param,
const MaaImageBuffer* image,
Expand All @@ -48,7 +48,7 @@ int main([[maybe_unused]] int argc, char** argv)

auto resource_handle = MaaResourceCreate(nullptr, nullptr);
std::string resource_dir = R"(E:\Code\MaaFramework\sample\resource)";
auto res_id = MaaResourcePostPath(resource_handle, resource_dir.c_str());
auto res_id = MaaResourcePostBundle(resource_handle, resource_dir.c_str());

MaaControllerWait(controller_handle, ctrl_id);
MaaResourceWait(resource_handle, res_id);
Expand All @@ -72,7 +72,7 @@ int main([[maybe_unused]] int argc, char** argv)

MaaResourceRegisterCustomRecognition(resource_handle, "MyReco", my_reco, nullptr);

auto task_id = MaaTaskerPostPipeline(tasker_handle, "MyTask", "{}");
auto task_id = MaaTaskerPostTask(tasker_handle, "MyTask", "{}");
MaaTaskerWait(tasker_handle, task_id);

destroy();
Expand Down Expand Up @@ -159,7 +159,7 @@ MaaController* create_win32_controller()
MaaBool my_reco(
MaaContext* context,
MaaTaskId task_id,
const char* current_task_name,
const char* node_name,
const char* custom_recognition_name,
const char* custom_recognition_param,
const MaaImageBuffer* image,
Expand Down
2 changes: 1 addition & 1 deletion sample/nodejs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function main() {
res.notify = (msg, detail) => {
console.log(msg, detail)
}
await res.post_path('sample/resource').wait()
await res.post_bundle('sample/resource').wait()

const devices = await maa.AdbController.find()
if (!devices || devices.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions sample/python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
Toolkit.init_option(user_path)

resource = Resource()
res_job = resource.post_path("sample/resource")
res_job = resource.post_bundle("sample/resource")
res_job.wait()

adb_devices = Toolkit.find_adb_devices()
Expand Down Expand Up @@ -72,7 +72,7 @@ def analyze(
click_job = context.tasker.controller.post_click(10, 20)
click_job.wait()

context.override_next(argv.current_task_name, ["TaskA", "TaskB"])
context.override_next(argv.node_name, ["TaskA", "TaskB"])

return CustomRecognition.AnalyzeResult(
box=(0, 0, 100, 100), detail="Hello World!"
Expand Down
2 changes: 1 addition & 1 deletion sample/python/pi_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run(

print(f"on MyAction.run, context: {context}, argv: {argv}")

context.override_next(argv.current_task_name, ["TaskA", "TaskB"])
context.override_next(argv.node_name, ["TaskA", "TaskB"])

image = context.tasker.controller.cached_image
context.tasker.controller.post_click(100, 100).wait()
Expand Down
8 changes: 8 additions & 0 deletions sample/resource/command/print.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
import time

print(sys.argv)

print("start sleep")
time.sleep(5)
print("end sleep")
4 changes: 2 additions & 2 deletions source/MaaFramework/API/MaaContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Utils/Buffer/StringBuffer.hpp"
#include "Utils/Logger.h"

MaaTaskId MaaContextRunPipeline(MaaContext* context, const char* entry, const char* pipeline_override)
MaaTaskId MaaContextRunTask(MaaContext* context, const char* entry, const char* pipeline_override)
{
LogFunc << VAR_VOIDP(context) << VAR(entry) << VAR(pipeline_override);

Expand All @@ -24,7 +24,7 @@ MaaTaskId MaaContextRunPipeline(MaaContext* context, const char* entry, const ch
return MaaInvalidId;
}

return context->run_pipeline(entry, ov_opt->as_object());
return context->run_task(entry, ov_opt->as_object());
}

MaaRecoId MaaContextRunRecognition(MaaContext* context, const char* entry, const char* pipeline_override, const MaaImageBuffer* image)
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/API/MaaResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ MaaBool MaaResourceClearCustomAction(MaaResource* res)
return true;
}

MaaResId MaaResourcePostPath(MaaResource* res, const char* path)
MaaResId MaaResourcePostBundle(MaaResource* res, const char* path)
{
LogFunc << VAR_VOIDP(res) << VAR(path);

Expand All @@ -113,7 +113,7 @@ MaaResId MaaResourcePostPath(MaaResource* res, const char* path)
return MaaInvalidId;
}

return res->post_path(MAA_NS::path(path));
return res->post_bundle(MAA_NS::path(path));
}

MaaBool MaaResourceClear(MaaResource* res)
Expand Down
8 changes: 4 additions & 4 deletions source/MaaFramework/API/MaaTasker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ MaaBool MaaTaskerInited(const MaaTasker* tasker)
return tasker->inited();
}

MaaTaskId MaaTaskerPostPipeline(MaaTasker* tasker, const char* entry, const char* pipeline_override)
MaaTaskId MaaTaskerPostTask(MaaTasker* tasker, const char* entry, const char* pipeline_override)
{
LogFunc << VAR_VOIDP(tasker) << VAR(entry) << VAR(pipeline_override);

Expand Down Expand Up @@ -312,16 +312,16 @@ MaaBool MaaTaskerGetTaskDetail(
return true;
}

MaaBool MaaTaskerGetLatestNode(const MaaTasker* tasker, const char* task_name, MaaNodeId* latest_id)
MaaBool MaaTaskerGetLatestNode(const MaaTasker* tasker, const char* node_name, MaaNodeId* latest_id)
{
if (!tasker) {
LogError << "handle is null";
return false;
}

auto result_opt = tasker->get_latest_node(task_name);
auto result_opt = tasker->get_latest_node(node_name);
if (!result_opt) {
LogError << "failed to get_latest_node" << VAR(task_name);
LogError << "failed to get_latest_node" << VAR(node_name);
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions source/MaaFramework/API/MaaTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct MaaResource

virtual bool set_option(MaaResOption key, MaaOptionValue value, MaaOptionValueSize val_size) = 0;

virtual MaaResId post_path(const std::filesystem::path& path) = 0;
virtual MaaResId post_bundle(const std::filesystem::path& path) = 0;

virtual MaaStatus status(MaaResId res_id) const = 0;
virtual MaaStatus wait(MaaResId res_id) const = 0;
Expand Down Expand Up @@ -92,20 +92,20 @@ struct MaaTasker
virtual std::optional<MAA_TASK_NS::TaskDetail> get_task_detail(MaaTaskId task_id) const = 0;
virtual std::optional<MAA_TASK_NS::NodeDetail> get_node_detail(MaaNodeId node_id) const = 0;
virtual std::optional<MAA_TASK_NS::RecoResult> get_reco_result(MaaRecoId reco_id) const = 0;
virtual std::optional<MaaNodeId> get_latest_node(const std::string& task_name) const = 0;
virtual std::optional<MaaNodeId> get_latest_node(const std::string& node_name) const = 0;
};

struct MaaContext
{
public:
virtual ~MaaContext() = default;

virtual MaaTaskId run_pipeline(const std::string& entry, const json::object& pipeline_override) = 0;
virtual MaaTaskId run_task(const std::string& entry, const json::object& pipeline_override) = 0;
virtual MaaRecoId run_recognition(const std::string& entry, const json::object& pipeline_override, const cv::Mat& image) = 0;
virtual MaaNodeId
run_action(const std::string& entry, const json::object& pipeline_override, const cv::Rect& box, const std::string& reco_detail) = 0;
virtual bool override_pipeline(const json::object& pipeline_override) = 0;
virtual bool override_next(const std::string& name, const std::vector<std::string>& next) = 0;
virtual bool override_next(const std::string& node_name, const std::vector<std::string>& next) = 0;

virtual MaaContext* clone() const = 0;

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Resource/ResourceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool ResourceMgr::set_option(MaaResOption key, MaaOptionValue value, MaaOptionVa
}
}

MaaResId ResourceMgr::post_path(const std::filesystem::path& path)
MaaResId ResourceMgr::post_bundle(const std::filesystem::path& path)
{
LogInfo << VAR(path);

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Resource/ResourceMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResourceMgr : public MaaResource
public: // MaaResource
virtual bool set_option(MaaResOption key, MaaOptionValue value, MaaOptionValueSize val_size) override;

virtual MaaResId post_path(const std::filesystem::path& path) override;
virtual MaaResId post_bundle(const std::filesystem::path& path) override;

virtual MaaStatus status(MaaResId res_id) const override;
virtual MaaStatus wait(MaaResId res_id) const override;
Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Task/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Context::Context(const Context& other)
LogDebug << VAR(other.getptr());
}

MaaTaskId Context::run_pipeline(const std::string& entry, const json::object& pipeline_override)
MaaTaskId Context::run_task(const std::string& entry, const json::object& pipeline_override)
{
LogFunc << VAR(getptr()) << VAR(entry) << VAR(pipeline_override);

Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Task/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Context
virtual ~Context() override = default;

public: // from MaaContextAPI
virtual MaaTaskId run_pipeline(const std::string& entry, const json::object& pipeline_override) override;
virtual MaaTaskId run_task(const std::string& entry, const json::object& pipeline_override) override;
virtual MaaRecoId run_recognition(const std::string& entry, const json::object& pipeline_override, const cv::Mat& image) override;
virtual MaaNodeId
run_action(const std::string& entry, const json::object& pipeline_override, const cv::Rect& box, const std::string& reco_detail)
Expand Down
3 changes: 2 additions & 1 deletion source/MaaFramework/Tasker/RuntimeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <map>
#include <optional>
#include <string>
#include <shared_mutex>
#include <string>


#include "Task/TaskResultTypes.h"
#include "Utils/NoWarningCVMat.hpp"
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/Tasker/Tasker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ std::optional<MAA_TASK_NS::RecoResult> Tasker::get_reco_result(MaaRecoId reco_id
return runtime_cache().get_reco_result(reco_id);
}

std::optional<MaaNodeId> Tasker::get_latest_node(const std::string& task_name) const
std::optional<MaaNodeId> Tasker::get_latest_node(const std::string& node_name) const
{
return runtime_cache().get_latest_node(task_name);
return runtime_cache().get_latest_node(node_name);
}

RuntimeCache& Tasker::runtime_cache()
Expand Down
Loading

0 comments on commit fdc5829

Please sign in to comment.