mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
feat: 完成之前画的饼
1. base 存在相同前缀则不加前缀 2. tasks 个数超过上限的时候返回临时值 我没测试
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
#include <unordered_set>
|
||||
|
||||
#include "Utils/AsstTypes.h"
|
||||
#ifdef ASST_DEBUG
|
||||
#include "Utils/Logger.hpp"
|
||||
#endif
|
||||
|
||||
namespace asst
|
||||
{
|
||||
@@ -33,22 +36,36 @@ namespace asst
|
||||
task_info_ptr = std::make_shared<TaskInfo>(*base_ptr);
|
||||
break;
|
||||
}
|
||||
task_info_ptr->reduce_other_times = {};
|
||||
for (const std::string& reduce_other_times : base_ptr->reduce_other_times) {
|
||||
task_info_ptr->reduce_other_times.emplace_back(task_prefix + reduce_other_times);
|
||||
}
|
||||
task_info_ptr->on_error_next = {};
|
||||
for (const std::string& on_error_next : base_ptr->on_error_next) {
|
||||
task_info_ptr->on_error_next.emplace_back(task_prefix + on_error_next);
|
||||
}
|
||||
task_info_ptr->exceeded_next = {};
|
||||
for (const std::string& exceeded_next : base_ptr->exceeded_next) {
|
||||
task_info_ptr->exceeded_next.emplace_back(task_prefix + exceeded_next);
|
||||
}
|
||||
task_info_ptr->next = {};
|
||||
for (const std::string& next : base_ptr->next) {
|
||||
task_info_ptr->next.emplace_back(task_prefix + next);
|
||||
}
|
||||
using tasklist_t = std::vector<std::string>;
|
||||
auto generate_tasks = [&](tasklist_t& task_list, const tasklist_t& base_task_list) {
|
||||
task_list = {};
|
||||
for (const std::string& base : base_task_list) {
|
||||
std::string_view base_view = base;
|
||||
size_t l = 0;
|
||||
bool has_same_prefix = false;
|
||||
// base 任务里已经存在相同前缀,则不加前缀
|
||||
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/2116#issuecomment-1270115238
|
||||
for (size_t r = base_view.find('@'); r != std::string_view::npos; r = base_view.find('@', l)) {
|
||||
if (task_prefix == base_view.substr(l, r - l)) {
|
||||
has_same_prefix = true;
|
||||
break;
|
||||
}
|
||||
l = r + 1;
|
||||
}
|
||||
if (has_same_prefix) {
|
||||
task_list.emplace_back(base);
|
||||
}
|
||||
else {
|
||||
task_list.emplace_back(task_prefix + base);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
generate_tasks(task_info_ptr->next, base_ptr->next);
|
||||
generate_tasks(task_info_ptr->exceeded_next, base_ptr->exceeded_next);
|
||||
generate_tasks(task_info_ptr->on_error_next, base_ptr->on_error_next);
|
||||
generate_tasks(task_info_ptr->reduce_other_times, base_ptr->reduce_other_times);
|
||||
|
||||
return task_info_ptr;
|
||||
}
|
||||
|
||||
@@ -61,6 +78,7 @@ namespace asst
|
||||
std::same_as<TargetTaskInfoType, TaskInfo>) // Parameter must be a TaskInfo
|
||||
std::shared_ptr<TargetTaskInfoType> get(const std::string& name)
|
||||
{
|
||||
// 普通 task 或已经生成过的 `@` 型 task
|
||||
if (auto it = m_all_tasks_info.find(name); it != m_all_tasks_info.cend()) [[likely]] {
|
||||
if constexpr (std::same_as<TargetTaskInfoType, TaskInfo>) {
|
||||
return it->second;
|
||||
@@ -70,12 +88,14 @@ namespace asst
|
||||
}
|
||||
}
|
||||
|
||||
if (size_t name_split_pos = name.find('@'); name_split_pos == std::string::npos) [[unlikely]] {
|
||||
size_t at_pos = name.find('@');
|
||||
if (at_pos == std::string::npos) [[unlikely]] {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t name_len = name_split_pos + 1;
|
||||
auto base_task_iter = get(name.substr(name_len));
|
||||
// `@` 前面的字符长度
|
||||
size_t name_len = at_pos;
|
||||
auto base_task_iter = get(name.substr(name_len + 1));
|
||||
if (base_task_iter == nullptr) [[unlikely]] {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -86,7 +106,16 @@ namespace asst
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_all_tasks_info.emplace(name, task_info_ptr);
|
||||
// tasks 个数超过上限时不再 emplace,返回临时值
|
||||
constexpr size_t MAX_TASKS_SIZE = 65535;
|
||||
if (m_all_tasks_info.size() < MAX_TASKS_SIZE) {
|
||||
m_all_tasks_info.emplace(name, task_info_ptr);
|
||||
}
|
||||
#ifdef ASST_DEBUG
|
||||
else {
|
||||
Log.debug("Task count has exceeded the upper limit:", MAX_TASKS_SIZE, "current task:", name);
|
||||
}
|
||||
#endif // ASST_DEBUG
|
||||
|
||||
if constexpr (std::same_as<TargetTaskInfoType, TaskInfo>) {
|
||||
return task_info_ptr;
|
||||
|
||||
Reference in New Issue
Block a user