审查修复: 任务配置恢复、执行器容错与续局状态、识别性能

Browse Source
正确性
- stop_task 强杀后 run_task 的临时次数会残留在 config.yaml (AALC 中途整份存盘);
  任务启动时先落盘原值, 强停/异常退出后由 TaskRunner 用 --restore 写回,
  写回失败时拒绝启动新任务并在 task_status 显示 pending_restore
- Jev 执行器: 工具失败不再抛异常导致整局退出 (Session raise_on_error=False),
  原有的"截图暂不可用"等降级分支终于生效; 刷新计数/开战标记只在动作成功后更新
- 一局完成后归档 jev_shop_context.json, 否则 claim_requested 让下一局一启动就判定完成
- 通用按钮直接点已核对的坐标, 不再 click_text 重新搜索 (可能点到背景同名按钮)
- 认证行按字节比较, 非 ASCII 输入不再让 compare_digest 抛 TypeError
- 单实例互斥改用 use_last_error 读取 ERROR_ALREADY_EXISTS

性能
- find_image 只在窗口尺寸变化时清模板缓存 (原来每次两次全量 gc); 模板列表只扫描一次
- 截图 PNG 压缩级别 1: 1080p 存图 0.66s -> 0.19s
- 执行器每帧截图只解码一次 (button_enabled 75ms -> 0.3ms); 地图模板与 ORB 描述子按比例缓存
- 箭头模板用 imdecode 读取, 支持中文路径 (输出与 imread 逐像素一致)

测试 73 -> 84, 修改前的识别输出与修改后逐项比对一致。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-10-03 00:31:21 +00:00
co-authored by Claude Opus 5.5
parent 5ab5fd9508
commit 030527f5de
9 changed files with 444 additions and 105 deletions
+20 -10
View File
@@ -57,6 +57,9 @@ def prune(directory, pattern, keep):
class AalcEngine(Engine): class AalcEngine(Engine):
_templates = None # 模板相对路径集合; assets 运行中不变, 只扫描一次磁盘
_template_size = None # 当前 AALC 模板缓存对应的缩放尺寸
def __init__(self, shot_dir, keep_shots=30): def __init__(self, shot_dir, keep_shots=30):
self.shot_dir = os.path.abspath(shot_dir) self.shot_dir = os.path.abspath(shot_dir)
os.makedirs(self.shot_dir, exist_ok=True) os.makedirs(self.shot_dir, exist_ok=True)
@@ -90,7 +93,8 @@ class AalcEngine(Engine):
def _save(self, img): def _save(self, img):
stamp = time.strftime('%Y%m%d_%H%M%S') + '_%03d' % (int(time.time() * 1000) % 1000) stamp = time.strftime('%Y%m%d_%H%M%S') + '_%03d' % (int(time.time() * 1000) % 1000)
path = os.path.join(self.shot_dir, 'shot_%s.png' % stamp) path = os.path.join(self.shot_dir, 'shot_%s.png' % stamp)
img.save(path) # 每次 get_state 都存图: 1080p 下默认压缩级别 6 约 0.66s, 级别 1 约 0.19s, 文件只大 ~17%
img.save(path, compress_level=1)
prune(self.shot_dir, 'shot_*.png', self.keep_shots) prune(self.shot_dir, 'shot_*.png', self.keep_shots)
return {'path': path.replace('\\', '/'), 'w': img.width, 'h': img.height} return {'path': path.replace('\\', '/'), 'w': img.width, 'h': img.height}
@@ -114,13 +118,15 @@ class AalcEngine(Engine):
return shot, items return shot, items
def list_images(self, prefix=''): def list_images(self, prefix=''):
names = set() if self._templates is None:
for theme in ('dark', 'default'): names = set()
for lang in ('zh_cn', 'en', 'share'): for theme in ('dark', 'default'):
base = os.path.join(self.images_root, theme, lang) for lang in ('zh_cn', 'en', 'share'):
for p in glob.glob(os.path.join(base, '**', '*.png'), recursive=True): base = os.path.join(self.images_root, theme, lang)
names.add(os.path.relpath(p, base).replace('\\', '/')) for p in glob.glob(os.path.join(base, '**', '*.png'), recursive=True):
return sorted(n for n in names if n.startswith(prefix)) names.add(os.path.relpath(p, base).replace('\\', '/'))
self._templates = frozenset(names)
return sorted(n for n in self._templates if n.startswith(prefix))
def find_image(self, name, threshold=0.8, model='normal'): def find_image(self, name, threshold=0.8, model='normal'):
if name not in self.list_images(name): if name not in self.list_images(name):
@@ -132,16 +138,20 @@ class AalcEngine(Engine):
# 保留亚像素比例:例如 1278 宽对应 718.875 高,取整会改变 # 保留亚像素比例:例如 1278 宽对应 718.875 高,取整会改变
# 缩放采样,使小图标的匹配置信度明显下降。 # 缩放采样,使小图标的匹配置信度明显下降。
match_size = max(1, min(img.height, img.width * 9 / 16)) match_size = max(1, min(img.height, img.width * 9 / 16))
# AALC 的模板缓存按加载时的 set_win_size 缩放, 键里不含尺寸; 尺寸变了才清空。
# 本进程只有这里用模板, 缓存可以一直保持当前客户区的比例
# (clear_img_cache 每次都会全量 gc, 不能每次调用都清)。
if match_size != self._template_size:
self.auto.clear_img_cache()
self._template_size = match_size
changed = match_size != old_size changed = match_size != old_size
try: try:
if changed: if changed:
self.auto.clear_img_cache()
self.cfg.unsaved_set_value('set_win_size', match_size) self.cfg.unsaved_set_value('set_win_size', match_size)
pos = self.auto.find_image_element(name, threshold, model=model) pos = self.auto.find_image_element(name, threshold, model=model)
finally: finally:
if changed: if changed:
self.cfg.unsaved_set_value('set_win_size', old_size) self.cfg.unsaved_set_value('set_win_size', old_size)
self.auto.clear_img_cache()
return (int(pos[0]), int(pos[1])) if pos else None return (int(pos[0]), int(pos[1])) if pos else None
# ---- 动手 (AALC 输入后端,由 config.yaml 决定后台消息/前台输入) ---- # ---- 动手 (AALC 输入后端,由 config.yaml 决定后台消息/前台输入) ----