mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
feat: 增加滑动加速度参数 acceleration_coef
acceleration_coef∈(-1,1),=0表示匀速,>0表示加速,<0表示减速 超出范围会往反方向滑动一段
This commit is contained in:
@@ -1063,9 +1063,11 @@ bool asst::Controller::click_without_scale(const Point& p)
|
||||
if (m_minitouch_enabled && m_minitouch_avaiable) {
|
||||
int x = static_cast<int>(p.x * m_minitouch_props.x_scaling);
|
||||
int y = static_cast<int>(p.y * m_minitouch_props.y_scaling);
|
||||
constexpr int WaitMs = 50;
|
||||
std::string minitouch_cmd = MinitouchCmd::down(x, y, true, WaitMs) + MinitouchCmd::up();
|
||||
return input_to_minitouch(minitouch_cmd, WaitMs);
|
||||
constexpr int duration = 50; // 点击从按下到抬起之间的持续时间,以毫秒计
|
||||
constexpr int wait_ms = 50; // 触点抬起后等待的时间,以毫秒计
|
||||
std::string minitouch_cmd =
|
||||
MinitouchCmd::down(x, y, true, duration) + MinitouchCmd::up() + MinitouchCmd::wait(wait_ms);
|
||||
return input_to_minitouch(minitouch_cmd, duration);
|
||||
}
|
||||
else {
|
||||
std::string cur_cmd =
|
||||
@@ -1079,7 +1081,8 @@ bool asst::Controller::click_without_scale(const Rect& rect)
|
||||
return click_without_scale(rand_point_in_rect(rect));
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe)
|
||||
bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe,
|
||||
double acceleration_coef)
|
||||
{
|
||||
int x1 = static_cast<int>(p1.x * m_control_scale);
|
||||
int y1 = static_cast<int>(p1.y * m_control_scale);
|
||||
@@ -1087,15 +1090,17 @@ bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, boo
|
||||
int y2 = static_cast<int>(p2.y * m_control_scale);
|
||||
// log.trace("Swipe, raw:", p1.x, p1.y, p2.x, p2.y, "corr:", x1, y1, x2, y2);
|
||||
|
||||
return swipe_without_scale(Point(x1, y1), Point(x2, y2), duration, extra_swipe);
|
||||
return swipe_without_scale(Point(x1, y1), Point(x2, y2), duration, extra_swipe, acceleration_coef);
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe)
|
||||
bool asst::Controller::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe,
|
||||
double acceleration_coef)
|
||||
{
|
||||
return swipe(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe);
|
||||
return swipe(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, acceleration_coef);
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int duration, bool extra_swipe)
|
||||
bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int duration, bool extra_swipe,
|
||||
double acceleration_coef)
|
||||
{
|
||||
int x1 = p1.x, y1 = p1.y;
|
||||
int x2 = p2.x, y2 = p2.y;
|
||||
@@ -1121,13 +1126,13 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
|
||||
_x2 = static_cast<int>(_x2 * m_minitouch_props.x_scaling);
|
||||
_y2 = static_cast<int>(_y2 * m_minitouch_props.y_scaling);
|
||||
|
||||
double move_times = static_cast<double>(_duration) / MoveInterval;
|
||||
double x_step = (_x2 - _x1) / move_times;
|
||||
double y_step = (_y2 - _y1) / move_times;
|
||||
// TODO: 加点随机因子,或者改成中间快两头慢
|
||||
for (int times = 1; times < move_times; ++times) {
|
||||
int cur_x = _x1 + static_cast<int>(x_step * times);
|
||||
int cur_y = _y1 + static_cast<int>(y_step * times);
|
||||
double acceleration = acceleration_coef * static_cast<double>(_x2 - _x1) / (_duration * _duration);
|
||||
double v0x = static_cast<double>(_x2 - _x1) / _duration - acceleration * _duration;
|
||||
double v0y = static_cast<double>(_y2 - _y1) / _duration - acceleration * _duration;
|
||||
|
||||
for (int cur_time = MoveInterval; cur_time < _duration; cur_time += MoveInterval) {
|
||||
int cur_x = _x1 + static_cast<int>(v0x * cur_time + acceleration * cur_time * cur_time);
|
||||
int cur_y = _y1 + static_cast<int>(v0y * cur_time + acceleration * cur_time * cur_time);
|
||||
if (cur_x < 0 || cur_x > m_minitouch_props.max_x || cur_y < 0 || cur_y > m_minitouch_props.max_y) {
|
||||
continue;
|
||||
}
|
||||
@@ -1174,9 +1179,10 @@ bool asst::Controller::swipe_without_scale(const Point& p1, const Point& p2, int
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::Controller::swipe_without_scale(const Rect& r1, const Rect& r2, int duration, bool extra_swipe)
|
||||
bool asst::Controller::swipe_without_scale(const Rect& r1, const Rect& r2, int duration, bool extra_swipe,
|
||||
double acceleration_coef)
|
||||
{
|
||||
return swipe_without_scale(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe);
|
||||
return swipe_without_scale(rand_point_in_rect(r1), rand_point_in_rect(r2), duration, extra_swipe, acceleration_coef);
|
||||
}
|
||||
|
||||
bool asst::Controller::connect(const std::string& adb_path, const std::string& address, const std::string& config)
|
||||
|
||||
@@ -57,10 +57,14 @@ namespace asst
|
||||
bool click_without_scale(const Point& p);
|
||||
bool click_without_scale(const Rect& rect);
|
||||
|
||||
bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false);
|
||||
bool swipe(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false);
|
||||
bool swipe_without_scale(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false);
|
||||
bool swipe_without_scale(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false);
|
||||
bool swipe(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false,
|
||||
double acceleration_coef = 0);
|
||||
bool swipe(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false,
|
||||
double acceleration_coef = 0);
|
||||
bool swipe_without_scale(const Point& p1, const Point& p2, int duration = 0, bool extra_swipe = false,
|
||||
double acceleration_coef = 0);
|
||||
bool swipe_without_scale(const Rect& r1, const Rect& r2, int duration = 0, bool extra_swipe = false,
|
||||
double acceleration_coef = 0);
|
||||
|
||||
std::pair<int, int> get_scale_size() const noexcept;
|
||||
|
||||
|
||||
@@ -186,7 +186,8 @@ bool ProcessTask::_run()
|
||||
case ProcessTaskAction::Swipe:
|
||||
exec_swipe_task(m_cur_task_ptr->specific_rect, m_cur_task_ptr->rect_move,
|
||||
m_cur_task_ptr->special_params.empty() ? 0 : m_cur_task_ptr->special_params.at(0),
|
||||
(m_cur_task_ptr->special_params.size() < 2) ? false : m_cur_task_ptr->special_params.at(1));
|
||||
(m_cur_task_ptr->special_params.size() < 2) ? false : m_cur_task_ptr->special_params.at(1),
|
||||
(m_cur_task_ptr->special_params.size() < 3) ? 0 : m_cur_task_ptr->special_params.at(2));
|
||||
break;
|
||||
case ProcessTaskAction::DoNothing:
|
||||
break;
|
||||
@@ -305,8 +306,8 @@ void ProcessTask::exec_click_task(const Rect& matched_rect)
|
||||
m_ctrler->click(matched_rect);
|
||||
}
|
||||
|
||||
void asst::ProcessTask::exec_swipe_task(const Rect& r1, const Rect& r2, int duration, bool extra_swipe)
|
||||
void asst::ProcessTask::exec_swipe_task(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double acceleration_coef)
|
||||
{
|
||||
MinitouchTempSwitcher switcher(m_ctrler);
|
||||
m_ctrler->swipe(r1, r2, duration, extra_swipe);
|
||||
m_ctrler->swipe(r1, r2, duration, extra_swipe, acceleration_coef);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace asst
|
||||
|
||||
std::pair<int, TimesLimitType> calc_time_limit() const;
|
||||
void exec_click_task(const Rect& matched_rect);
|
||||
void exec_swipe_task(const Rect& r1, const Rect& r2, int duration, bool extra_swipe);
|
||||
void exec_swipe_task(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double acceleration_coef);
|
||||
|
||||
std::shared_ptr<TaskInfo> m_cur_task_ptr = nullptr;
|
||||
std::vector<std::string> m_raw_tasks_name;
|
||||
|
||||
Reference in New Issue
Block a user