From 9635cdf7f40a0108cf3b2d4c9d2aaa4a304cfd31 Mon Sep 17 00:00:00 2001 From: Horror Proton <107091537+horror-proton@users.noreply.github.com> Date: Mon, 13 May 2024 18:35:50 +0800 Subject: [PATCH] feat: add compile def to disable emulator extras --- src/MaaCore/Common/AsstConf.h | 4 ++++ src/MaaCore/Controller/AdbController.cpp | 12 +++++++++++- src/MaaCore/Controller/AdbController.h | 6 ++++++ src/MaaCore/Controller/MumuExtras.cpp | 3 +++ src/MaaCore/Controller/MumuExtras.h | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/MaaCore/Common/AsstConf.h b/src/MaaCore/Common/AsstConf.h index 2e2c39445c..6aba33b1ef 100644 --- a/src/MaaCore/Common/AsstConf.h +++ b/src/MaaCore/Common/AsstConf.h @@ -8,6 +8,10 @@ #endif #endif +#if !defined (ASST_WITH_EMULATOR_EXTRAS) +#define ASST_WITH_EMULATOR_EXTRAS 1 +#endif + #ifdef _MSC_VER #define ASST_DO_PRAGMA(x) __pragma(x) #elif defined(__GNUC__) diff --git a/src/MaaCore/Controller/AdbController.cpp b/src/MaaCore/Controller/AdbController.cpp index b7c984ef9b..180854c07c 100644 --- a/src/MaaCore/Controller/AdbController.cpp +++ b/src/MaaCore/Controller/AdbController.cpp @@ -196,8 +196,11 @@ void asst::AdbController::callback(AsstMsg msg, const json::value& details) } } -void asst::AdbController::init_mumu_extras(const AdbCfg& adb_cfg) +void asst::AdbController::init_mumu_extras(const AdbCfg& adb_cfg [[maybe_unused]]) { +#if !ASST_WITH_EMULATOR_EXTRAS + Log.error("MaaCore is not compiled with ASST_WITH_EMULATOR_EXTRAS"); +#else if (adb_cfg.extras.empty()) { LogWarn << "adb_cfg.extras is empty"; return; @@ -207,6 +210,7 @@ void asst::AdbController::init_mumu_extras(const AdbCfg& adb_cfg) int mumu_index = adb_cfg.extras.get("index", 0); int mumu_display = adb_cfg.extras.get("display", 0); m_mumu_extras.init(mumu_path, mumu_index, mumu_display); +#endif } void asst::AdbController::close_socket() noexcept @@ -486,6 +490,7 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect Log.info("Encode is not supported"); } +#if ASST_WITH_EMULATOR_EXTRAS if (m_mumu_extras.inited()) { start_time = high_resolution_clock::now(); if (m_mumu_extras.screencap()) { @@ -502,13 +507,16 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect Log.info("MumuExtras is not supported"); } } +#endif static const std::unordered_map MethodName = { { AdbProperty::ScreencapMethod::UnknownYet, "UnknownYet" }, { AdbProperty::ScreencapMethod::RawByNc, "RawByNc" }, { AdbProperty::ScreencapMethod::RawWithGzip, "RawWithGzip" }, { AdbProperty::ScreencapMethod::Encode, "Encode" }, +#if ASST_WITH_EMULATOR_EXTRAS { AdbProperty::ScreencapMethod::MumuExtras, "MumuExtras" }, +#endif }; Log.info( "The fastest way is", @@ -545,6 +553,7 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect case AdbProperty::ScreencapMethod::Encode: screencap_ret = screencap(m_adb.screencap_encode, decode_encode, allow_reconnect); break; +#if ASST_WITH_EMULATOR_EXTRAS case AdbProperty::ScreencapMethod::MumuExtras: { auto img_opt = m_mumu_extras.screencap(); screencap_ret = img_opt.has_value(); @@ -552,6 +561,7 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect image_payload = img_opt.value(); } } break; +#endif default: break; } diff --git a/src/MaaCore/Controller/AdbController.h b/src/MaaCore/Controller/AdbController.h index 096af9493a..198862b776 100644 --- a/src/MaaCore/Controller/AdbController.h +++ b/src/MaaCore/Controller/AdbController.h @@ -1,5 +1,7 @@ #pragma once +#include "Common/AsstConf.h" + #include "ControllerAPI.h" #include @@ -152,7 +154,9 @@ protected: RawByNc, RawWithGzip, Encode, +#if ASST_WITH_EMULATOR_EXTRAS MumuExtras, +#endif } screencap_method = ScreencapMethod::UnknownYet; } m_adb; @@ -170,6 +174,8 @@ protected: std::deque m_screencap_cost; // 截图用时 int m_screencap_times = 0; // 截图次数 +#if ASST_WITH_EMULATOR_EXTRAS MumuExtras m_mumu_extras; +#endif }; } // namespace asst diff --git a/src/MaaCore/Controller/MumuExtras.cpp b/src/MaaCore/Controller/MumuExtras.cpp index 9ae7c5fded..3321f75039 100644 --- a/src/MaaCore/Controller/MumuExtras.cpp +++ b/src/MaaCore/Controller/MumuExtras.cpp @@ -1,5 +1,7 @@ #include "MumuExtras.h" +#if ASST_WITH_EMULATOR_EXTRAS + #include "Utils/Logger.hpp" #include "Utils/NoWarningCV.h" @@ -194,3 +196,4 @@ void MumuExtras::disconnect_mumu() } } +#endif diff --git a/src/MaaCore/Controller/MumuExtras.h b/src/MaaCore/Controller/MumuExtras.h index 81557943fd..709328b9de 100644 --- a/src/MaaCore/Controller/MumuExtras.h +++ b/src/MaaCore/Controller/MumuExtras.h @@ -1,5 +1,9 @@ #pragma once +#include "Common/AsstConf.h" + +#if ASST_WITH_EMULATOR_EXTRAS + #include #include #include @@ -65,3 +69,4 @@ private: std::function input_event_key_up_func_; }; } +#endif