feat.将随机操作延迟的逻辑做到了全局

This commit is contained in:
MistEO
2021-12-05 22:22:59 +08:00
parent 7ae93544d4
commit 23fc3c93dc
4 changed files with 22 additions and 26 deletions

View File

@@ -436,8 +436,28 @@ asst::Point asst::Controller::rand_point_in_rect(const Rect& rect)
return Point(x, y);
}
void asst::Controller::random_delay() const
{
auto& opt = resource.cfg().get_options();
if (opt.control_delay_upper != 0) {
LogTraceFunction;
static std::default_random_engine rand_engine(
std::chrono::system_clock::now().time_since_epoch().count());
static std::uniform_int_distribution<unsigned> rand_uni(
opt.control_delay_lower,
opt.control_delay_upper);
unsigned rand_delay = rand_uni(rand_engine);
log.trace("random_delay |", rand_delay, "ms");
std::this_thread::sleep_for(std::chrono::milliseconds(rand_delay));
}
}
int asst::Controller::push_cmd(const std::string& cmd)
{
random_delay();
std::unique_lock<std::mutex> lock(m_cmd_queue_mutex);
m_cmd_queue.emplace(cmd);
m_cmd_condvar.notify_one();

View File

@@ -67,6 +67,8 @@ namespace asst
bool screencap();
Point rand_point_in_rect(const Rect& rect);
void random_delay() const;
// 转换data中所有的crlf为lf有些模拟器自带的adbexec-out输出的\n会被替换成\r\n导致解码错误所以这里转一下回来点名批评mumu
static void convert_lf(std::vector<unsigned char>& data);

View File

@@ -179,38 +179,13 @@ bool ProcessTask::_run()
return true;
}
// 随机延时功能
bool asst::ProcessTask::delay_random()
{
auto& opt = resource.cfg().get_options();
if (opt.control_delay_upper != 0) {
static std::default_random_engine rand_engine(
std::chrono::system_clock::now().time_since_epoch().count());
static std::uniform_int_distribution<unsigned> rand_uni(
opt.control_delay_lower,
opt.control_delay_upper);
unsigned rand_delay = rand_uni(rand_engine);
return sleep(rand_delay);
}
return true;
}
void ProcessTask::exec_click_task(const Rect& matched_rect)
{
if (!delay_random()) {
return;
}
ctrler.click(matched_rect);
}
void asst::ProcessTask::exec_swipe_task(ProcessTaskAction action)
{
if (!delay_random()) {
return;
}
const auto&& [width, height] = ctrler.get_scale_size();
const static Rect right_rect(width * 0.8,

View File

@@ -26,7 +26,6 @@ namespace asst
protected:
virtual bool _run() override;
bool delay_random();
void exec_click_task(const Rect& matched_rect);
void exec_swipe_task(ProcessTaskAction action);