fix: set the params after controller created (#4090)

This commit is contained in:
MistEO
2023-03-27 22:10:14 +08:00
committed by GitHub
2 changed files with 31 additions and 2 deletions

View File

@@ -64,6 +64,18 @@ void asst::Controller::callback(AsstMsg msg, const json::value& details)
}
}
#define CHECK_EXIST(object, return_type) \
if (!object) { \
Log.error(#object, " is not inited"); \
return return_type; \
}
void asst::Controller::sync_params()
{
CHECK_EXIST(m_controller, );
m_controller->set_swipe_with_pause(m_swipe_with_pause);
}
cv::Mat asst::Controller::get_resized_image_cache() const
{
const static cv::Size d_size(m_scale_size.first, m_scale_size.second);
@@ -80,50 +92,59 @@ cv::Mat asst::Controller::get_resized_image_cache() const
bool asst::Controller::start_game(const std::string& client_type)
{
CHECK_EXIST(m_controller, false);
return m_controller->start_game(client_type);
}
bool asst::Controller::stop_game()
{
CHECK_EXIST(m_controller, false);
return m_controller->stop_game();
}
bool asst::Controller::click(const Point& p)
{
CHECK_EXIST(m_controller, false);
return m_scale_proxy->click(p);
}
bool asst::Controller::click(const Rect& rect)
{
CHECK_EXIST(m_controller, false);
return m_scale_proxy->click(rect);
}
bool asst::Controller::swipe(const Point& p1, const Point& p2, int duration, bool extra_swipe, double slope_in,
double slope_out, bool with_pause)
{
CHECK_EXIST(m_controller, false);
return m_scale_proxy->swipe(p1, p2, duration, extra_swipe, slope_in, slope_out, with_pause);
}
bool asst::Controller::swipe(const Rect& r1, const Rect& r2, int duration, bool extra_swipe, double slope_in,
double slope_out, bool with_pause)
{
CHECK_EXIST(m_controller, false);
return m_scale_proxy->swipe(r1, r2, duration, extra_swipe, slope_in, slope_out, with_pause);
}
bool asst::Controller::inject_input_event(InputEvent& event)
{
return m_scale_proxy->inject_input_event(event);
CHECK_EXIST(m_controller, false);
return m_controller->inject_input_event(event);
}
bool asst::Controller::press_esc()
{
LogTraceFunction;
CHECK_EXIST(m_controller, false);
return m_controller->press_esc();
}
asst::ControlFeat::Feat asst::Controller::support_features()
{
CHECK_EXIST(m_controller, ControlFeat::NONE);
return m_controller->support_features();
}
@@ -141,6 +162,8 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
return false;
}
sync_params();
m_uuid = m_controller->get_uuid();
// try to find the fastest way
@@ -182,6 +205,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
bool asst::Controller::inited() noexcept
{
CHECK_EXIST(m_controller, false);
return m_controller->inited();
}
@@ -204,7 +228,8 @@ void asst::Controller::set_touch_mode(const TouchMode& mode) noexcept
void asst::Controller::set_swipe_with_pause(bool enable) noexcept
{
m_controller->set_swipe_with_pause(enable);
m_swipe_with_pause = enable;
sync_params();
}
void asst::Controller::set_adb_lite_enabled(bool enable) noexcept
@@ -271,6 +296,7 @@ cv::Mat asst::Controller::get_image_cache() const
bool asst::Controller::screencap(bool allow_reconnect)
{
CHECK_EXIST(m_controller, false);
std::unique_lock<std::shared_mutex> image_lock(m_image_mutex);
return m_controller->screencap(m_cache_image, allow_reconnect);
}

View File

@@ -75,6 +75,7 @@ namespace asst
void clear_info() noexcept;
void callback(AsstMsg msg, const json::value& details);
void sync_params();
AsstCallback m_callback = nullptr;
@@ -94,6 +95,8 @@ namespace asst
std::pair<int, int> m_scale_size = { WindowWidthDefault, WindowHeightDefault };
bool m_swipe_with_pause = false;
mutable std::shared_mutex m_image_mutex;
cv::Mat m_cache_image;
};