mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-23 09:01:45 +00:00
Optimize: 战斗中放慢截图速度, 降低CPU使用
This commit is contained in:
parent
9dc69c7fac
commit
ef5885767e
@ -88,6 +88,7 @@ enable_error_log_and_screenshot_save = yes
|
||||
enable_perspective_error_image_save = no
|
||||
use_adb_screenshot = yes
|
||||
use_adb_control = no
|
||||
combat_screenshot_interval = 1.
|
||||
|
||||
[Daily]
|
||||
enable_daily_mission = yes
|
||||
|
@ -60,5 +60,13 @@ class Timer:
|
||||
def reset(self):
|
||||
self._current = time.time()
|
||||
|
||||
def wait(self):
|
||||
"""
|
||||
Wait until timer reached.
|
||||
"""
|
||||
diff = self._current + self.limit - time.time()
|
||||
if diff > 0:
|
||||
time.sleep(diff)
|
||||
|
||||
def show(self):
|
||||
logger.info('%s s' % str(self.current()))
|
||||
|
@ -179,6 +179,7 @@ class Combat(HPBalancer, UrgentCommissionHandler, EnemySearchingHandler, Retirem
|
||||
self.combat_manual_reset()
|
||||
confirm_timer = Timer(10)
|
||||
confirm_timer.start()
|
||||
self.device.screenshot_interval_set(self.config.COMBAT_SCREENSHOT_INTERVAL)
|
||||
|
||||
while 1:
|
||||
self.device.screenshot()
|
||||
@ -192,7 +193,6 @@ class Combat(HPBalancer, UrgentCommissionHandler, EnemySearchingHandler, Retirem
|
||||
continue
|
||||
if self.handle_combat_manual():
|
||||
continue
|
||||
|
||||
if call_submarine_at_boss:
|
||||
pass
|
||||
else:
|
||||
@ -201,6 +201,7 @@ class Combat(HPBalancer, UrgentCommissionHandler, EnemySearchingHandler, Retirem
|
||||
|
||||
# End
|
||||
if self.handle_battle_status(save_get_items=save_get_items):
|
||||
self.device.screenshot_interval_set(0)
|
||||
break
|
||||
|
||||
def handle_battle_status(self, save_get_items=False):
|
||||
|
@ -20,10 +20,11 @@ class SubmarineCall(ModuleBase):
|
||||
Returns:
|
||||
bool: If call.
|
||||
"""
|
||||
if not self.config.SUBMARINE or self.config.SUBMARINE_MODE in ['do_not_use', 'hunt_only']:
|
||||
return False
|
||||
if self.submarine_call_flag:
|
||||
return False
|
||||
if not self.config.SUBMARINE or self.config.SUBMARINE_MODE in ['do_not_use', 'hunt_only']:
|
||||
self.submarine_call_flag = True
|
||||
return False
|
||||
if self.submarine_call_timer.reached():
|
||||
logger.info('Submarine call timer reached')
|
||||
self.submarine_call_flag = True
|
||||
|
@ -224,6 +224,7 @@ def main(ini_name=''):
|
||||
adb = emulator_parser.add_argument_group('ADB设置', '')
|
||||
adb.add_argument('--使用ADB截图', default=default('--使用ADB截图'), choices=['是', '否'], help='建议开启, 能减少CPU占用')
|
||||
adb.add_argument('--使用ADB点击', default=default('--使用ADB点击'), choices=['是', '否'], help='建议关闭, 能加快点击速度')
|
||||
adb.add_argument('--战斗中截图间隔', default=default('--战斗中截图间隔'), help='战斗中放慢截图速度, 降低CPU使用')
|
||||
|
||||
# ==========每日任务==========
|
||||
daily_parser = subs.add_parser('每日任务困难演习')
|
||||
|
@ -87,6 +87,7 @@ class AzurLaneConfig:
|
||||
SUBMARINE_MODE = ''
|
||||
SUBMARINE_CALL_AT_BOSS = False
|
||||
COMBAT_AUTO_MODE = 'combat_auto'
|
||||
COMBAT_SCREENSHOT_INTERVAL = 2
|
||||
|
||||
"""
|
||||
module.combat.hp_balance
|
||||
@ -364,6 +365,7 @@ class AzurLaneConfig:
|
||||
self.ENABLE_PERSPECTIVE_ERROR_IMAGE_SAVE = to_bool(option['enable_perspective_error_image_save'])
|
||||
self.USE_ADB_SCREENSHOT = to_bool(option['use_adb_screenshot'])
|
||||
self.USE_ADB_CONTROL = to_bool(option['use_adb_control'])
|
||||
self.COMBAT_SCREENSHOT_INTERVAL = float(option['combat_screenshot_interval'])
|
||||
|
||||
option = config['Setting']
|
||||
# Stop condition
|
||||
|
@ -115,6 +115,7 @@ dic_chi_to_eng = {
|
||||
'保存透视识别出错的图像': 'enable_perspective_error_image_save',
|
||||
'使用ADB截图': 'use_adb_screenshot',
|
||||
'使用ADB点击': 'use_adb_control',
|
||||
'战斗中截图间隔': 'combat_screenshot_interval',
|
||||
'打每日': 'enable_daily_mission',
|
||||
'打困难': 'enable_hard_campaign',
|
||||
'打演习': 'enable_exercise',
|
||||
|
@ -8,11 +8,13 @@ from retrying import retry
|
||||
|
||||
from module.device.connection import Connection
|
||||
from module.logger import logger
|
||||
from module.base.timer import Timer
|
||||
|
||||
|
||||
class Screenshot(Connection):
|
||||
_screenshot_method = 0
|
||||
_screenshot_method_fixed = False
|
||||
_screenshot_interval_timer = Timer(0.1)
|
||||
_adb = False
|
||||
_last_save_time = {}
|
||||
image: Image.Image
|
||||
@ -54,6 +56,8 @@ class Screenshot(Connection):
|
||||
Returns:
|
||||
PIL.Image.Image:
|
||||
"""
|
||||
self._screenshot_interval_timer.wait()
|
||||
self._screenshot_interval_timer.reset()
|
||||
adb = self.config.USE_ADB_SCREENSHOT
|
||||
self._adb = adb
|
||||
|
||||
@ -65,6 +69,7 @@ class Screenshot(Connection):
|
||||
self.image.load()
|
||||
if self.config.ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE:
|
||||
logger.screenshot_deque.append({'time': datetime.now(), 'image': self.image})
|
||||
|
||||
return self.image
|
||||
|
||||
def save_screenshot(self, genre='items'):
|
||||
@ -92,3 +97,10 @@ class Screenshot(Connection):
|
||||
else:
|
||||
self._last_save_time[genre] = now
|
||||
return False
|
||||
|
||||
def screenshot_interval_set(self, interval):
|
||||
if interval < 0.1:
|
||||
interval = 0.1
|
||||
if interval != self._screenshot_interval_timer.limit:
|
||||
logger.info(f'Screenshot interval set to {interval}s')
|
||||
self._screenshot_interval_timer.limit = interval
|
||||
|
Loading…
Reference in New Issue
Block a user