mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
feat: 自动战斗费用识别缓存, 减少性能消耗 (#12765)
* feat: 自动战斗费用识别缓存 * refactor: 返回值格式 * chore: 改个名字 * chore: rename * fix: 改名改着改着改错了 * fix: var init * perf: 简化返回值 * fix: template * fix: platform
This commit is contained in:
@@ -302,15 +302,17 @@ void asst::BattleProcessTask::notify_action(const battle::copilot::Action& actio
|
||||
|
||||
bool asst::BattleProcessTask::wait_condition(const Action& action)
|
||||
{
|
||||
cv::Mat image;
|
||||
cv::Mat image, image_prev;
|
||||
auto update_image_if_empty = [&]() {
|
||||
if (image.empty()) {
|
||||
image_prev = cv::Mat();
|
||||
image = ctrler()->get_image();
|
||||
check_in_battle(image);
|
||||
}
|
||||
};
|
||||
auto do_strategy_and_update_image = [&]() {
|
||||
do_strategic_action(image);
|
||||
image_prev = std::move(image);
|
||||
image = ctrler()->get_image();
|
||||
};
|
||||
|
||||
@@ -320,7 +322,7 @@ bool asst::BattleProcessTask::wait_condition(const Action& action)
|
||||
int pre_cost = m_cost;
|
||||
|
||||
while (!need_exit()) {
|
||||
update_cost(image);
|
||||
update_cost(image, image_prev);
|
||||
if (action.cost_changes != 0) {
|
||||
if ((pre_cost + action.cost_changes < 0) ? (m_cost <= pre_cost + action.cost_changes)
|
||||
: (m_cost >= pre_cost + action.cost_changes)) {
|
||||
@@ -350,8 +352,9 @@ bool asst::BattleProcessTask::wait_condition(const Action& action)
|
||||
|
||||
if (action.costs) {
|
||||
update_image_if_empty();
|
||||
update_cost(image); // 保证 m_cost 是最新的
|
||||
while (!need_exit()) {
|
||||
update_cost(image);
|
||||
update_cost(image, image_prev);
|
||||
if (m_cost >= action.costs) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user