feat: 自动战斗费用识别缓存, 减少性能消耗 (#12765)

* feat: 自动战斗费用识别缓存

* refactor: 返回值格式

* chore: 改个名字

* chore: rename

* fix: 改名改着改着改错了

* fix: var init

* perf: 简化返回值

* fix: template

* fix: platform
This commit is contained in:
status102
2025-05-23 09:02:00 +08:00
committed by GitHub
parent bc6059b33c
commit 75012b2252
7 changed files with 75 additions and 32 deletions

View File

@@ -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;
}