perf: auto start optimization + MAC fix (#9083)

I have no way to test for MAC
This commit is contained in:
uye
2024-05-17 09:27:50 +08:00
committed by GitHub
4 changed files with 62 additions and 54 deletions

View File

@@ -49,6 +49,10 @@ size_t asst::Controller::get_version() const noexcept
return m_controller->get_version();
}
asst::ControllerType asst::Controller::get_controller_type() const noexcept
{
return m_controller_type;
}
std::pair<int, int> asst::Controller::get_scale_size() const noexcept
{

View File

@@ -52,6 +52,8 @@ public:
size_t get_version() const noexcept;
ControllerType get_controller_type() const noexcept;
cv::Mat get_image(bool raw = false);
cv::Mat get_image_cache() const;
bool screencap(bool allow_reconnect = false);

View File

@@ -4,54 +4,54 @@
using namespace asst;
bool StartGameTaskPlugin::start_game_with_retries(size_t pipe_data_size_limit, bool newer_android)
const
{
int extra_runs = 0;
for (int i = 0; i < 30; ++i) {
if (need_exit()) {
return false;
}
if (!ctrler()->start_game(m_client_type)) {
return false;
}
if (ctrler()->get_pipe_data_size() > pipe_data_size_limit) {
if (newer_android || ++extra_runs > 3) {
return true;
}
}
sleep(1500);
}
return false;
}
bool StartGameTaskPlugin::_run()
{
if (m_client_type.empty()) {
return false;
}
// check for MAC / iOS
if (ctrler()->get_controller_type() == ControllerType::MacPlayTools) {
return ctrler()->start_game(m_client_type);
}
// check for android version, because it leads to different magic values
// >8: 167: magic value needs to be >164 but <172 (as that's max)
// <=8: 145: needs to be >85 but <153 (as that's max)
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/8966#issuecomment-2094369694
if (ctrler()->get_version() > 8) {
do {
if (!ctrler()->start_game(m_client_type)) {
return false;
}
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/8961#issue-2277568882
int pipe_data_size_limit = (ctrler()->get_version() > 8) ? 167 : 145;
// https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/8961#issue-2277568882
// 167: magic value needs to be >164 but <172 (as that's max)
if (ctrler()->get_pipe_data_size() > 167) {
return true;
}
// In Android 9 and above, there's a way to check if the game started correctly
// so no need for limited tries
bool newer_android = (ctrler()->get_version() > 8);
sleep(1500);
} while (true);
}
else {
do {
if (!ctrler()->start_game(m_client_type)) {
return false;
}
// 145: needs to be >85 but <153 (as that's max)
// magic value lowered because of different android version
if (ctrler()->get_pipe_data_size() > 145) {
// As there's no way to know (in Android < 8) if Ark has correctly started
// we run the command a few more times to be sure
for (auto _ = 3; _--;) {
sleep(1500);
if (!ctrler()->start_game(m_client_type)) {
return false;
}
}
return true;
}
sleep(1500);
} while (true);
}
return start_game_with_retries(pipe_data_size_limit, newer_android);
}
StartGameTaskPlugin& StartGameTaskPlugin::set_client_type(std::string client_type) noexcept

View File

@@ -5,26 +5,28 @@
namespace asst
{
inline static const std::string ClientTypeKey = "client_type";
inline static const std::string ClientTypeKey = "client_type";
class StartGameTaskPlugin : public AbstractTaskPlugin
class StartGameTaskPlugin : public AbstractTaskPlugin
{
public:
using AbstractTaskPlugin::AbstractTaskPlugin;
virtual ~StartGameTaskPlugin() noexcept override = default;
virtual bool verify(AsstMsg msg, const json::value& details) const override
{
public:
using AbstractTaskPlugin::AbstractTaskPlugin;
virtual ~StartGameTaskPlugin() noexcept override = default;
std::ignore = msg;
std::ignore = details;
return true;
}
virtual bool verify(AsstMsg msg, const json::value& details) const override
{
std::ignore = msg;
std::ignore = details;
return true;
}
StartGameTaskPlugin& set_client_type(std::string client_type) noexcept;
StartGameTaskPlugin& set_client_type(std::string client_type) noexcept;
protected:
bool _run() override;
protected:
bool _run() override;
bool start_game_with_retries(size_t pipe_data_size_limit, bool newer_android) const;
std::string m_client_type = "";
};
std::string m_client_type = "";
};
}