Skip draft vision when Dota 2 is not the foreground window.
Prevents Alt-Tab desktop frames from advancing confirm streaks or burning strategy_tail polls. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+25
-7
@@ -34,7 +34,7 @@ import time
|
||||
|
||||
import mss
|
||||
|
||||
from capture import grab_frame, raw_dir_for_match, save_frame
|
||||
from capture import grab_frame, is_dota_foreground, raw_dir_for_match, save_frame
|
||||
from grid import bans, hero_table, read_grid
|
||||
from modes import detect_mode, load_mode_templates
|
||||
from recognize import recognize_image
|
||||
@@ -74,6 +74,8 @@ class DraftSession:
|
||||
# this many polls - catches the last reveal without hanging forever
|
||||
self.strategy_tail = g.get("strategy_tail_polls", 8)
|
||||
self.gsi_wait = g.get("strategy_gsi_wait", 3.0)
|
||||
# skip grab/recognize when Dota is not the foreground window
|
||||
self.require_foreground = bool(g.get("require_foreground", True))
|
||||
self.role_templates = load_role_templates()
|
||||
self.mode_templates = load_mode_templates()
|
||||
self.hero_names = {h["key"]: h["name_loc"] for h in hero_table()}
|
||||
@@ -104,6 +106,7 @@ class DraftSession:
|
||||
vision_done = False
|
||||
strategy_polls = 0
|
||||
freeze_at = 0.0
|
||||
skipped_fg = False
|
||||
|
||||
with mss.MSS() as sct:
|
||||
while True:
|
||||
@@ -116,6 +119,26 @@ class DraftSession:
|
||||
break
|
||||
|
||||
elapsed = time.monotonic() - started
|
||||
|
||||
# Vision finished: only wait on GSI / short timeout (no grab).
|
||||
if vision_done:
|
||||
gsi_hero = (gsi_fn() or {}).get("hero") if gsi_fn else None
|
||||
if gsi_hero or (elapsed - freeze_at) >= self.gsi_wait:
|
||||
break
|
||||
time.sleep(self.poll_interval)
|
||||
continue
|
||||
|
||||
# Desktop / other apps must not burn strategy_tail or confirm streaks.
|
||||
if self.require_foreground and not is_dota_foreground():
|
||||
if not skipped_fg:
|
||||
self.log("[draft] Dota 2 not foreground - skipping frames")
|
||||
skipped_fg = True
|
||||
time.sleep(self.poll_interval)
|
||||
continue
|
||||
if skipped_fg:
|
||||
self.log("[draft] Dota 2 foreground again - resuming vision")
|
||||
skipped_fg = False
|
||||
|
||||
frame = grab_frame(sct)
|
||||
last_frame = frame
|
||||
polls += 1
|
||||
@@ -123,7 +146,7 @@ class DraftSession:
|
||||
# Keep reading in strategy until the roster is full - the last
|
||||
# pick is often revealed on the same tick selection ends, and
|
||||
# a player who already locked may only see strategy UI.
|
||||
do_vision = not vision_done and (
|
||||
do_vision = (
|
||||
state == HERO_SELECTION
|
||||
or (state == STRATEGY_TIME and strategy_polls < self.strategy_tail)
|
||||
)
|
||||
@@ -177,11 +200,6 @@ class DraftSession:
|
||||
freeze_at = elapsed
|
||||
self.log("[draft] vision done - waiting on GSI for self hero")
|
||||
|
||||
if vision_done:
|
||||
gsi_hero = (gsi_fn() or {}).get("hero") if gsi_fn else None
|
||||
if gsi_hero or (elapsed - freeze_at) >= self.gsi_wait:
|
||||
break
|
||||
|
||||
time.sleep(self.poll_interval)
|
||||
|
||||
if best and not vision_done:
|
||||
|
||||
Reference in New Issue
Block a user