From 61f714f8353f0eaff8ecb08f8d011fbd599714d2 Mon Sep 17 00:00:00 2001 From: StupidBh <2623615250@qq.com> Date: Sun, 2 Jan 2022 01:17:12 +0800 Subject: [PATCH] =?UTF-8?q?fix.=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9Bwarning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/AsstCaller.cpp | 3 +- src/MeoAssistant/AsstUtils.hpp | 4 +-- src/MeoAssistant/Controller.cpp | 30 +++++++++---------- src/MeoAssistant/InfrastAbstractTask.cpp | 8 ++--- .../InfrastFacilityImageAnalyzer.cpp | 2 +- src/MeoAssistant/InfrastOperImageAnalyzer.cpp | 4 +-- src/MeoAssistant/InfrastProductionTask.cpp | 8 ++--- src/MeoAssistant/ProcessTask.cpp | 20 +++++++------ src/MeoAssistant/RecruitTask.cpp | 2 +- src/MeoAssistant/TaskData.cpp | 7 +++-- tools/TestCaller/main.cpp | 2 +- 11 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/MeoAssistant/AsstCaller.cpp b/src/MeoAssistant/AsstCaller.cpp index 60c6259d4a..7c24b631db 100644 --- a/src/MeoAssistant/AsstCaller.cpp +++ b/src/MeoAssistant/AsstCaller.cpp @@ -113,6 +113,7 @@ bool AsstCatchFake(asst::Assistant* p_asst) return p_asst->catch_fake(); #else + (void*)p_asst; return false; #endif // LOG_TRACE } @@ -261,4 +262,4 @@ bool AsstAppendDebug(asst::Assistant* p_asst) #else return false; #endif // LOG_TRACE -} + } diff --git a/src/MeoAssistant/AsstUtils.hpp b/src/MeoAssistant/AsstUtils.hpp index c9b30d7770..671dae118a 100644 --- a/src/MeoAssistant/AsstUtils.hpp +++ b/src/MeoAssistant/AsstUtils.hpp @@ -80,8 +80,8 @@ namespace asst #ifdef _WIN32 const char* src_str = gbk_str.c_str(); int len = MultiByteToWideChar(CP_ACP, 0, src_str, -1, nullptr, 0); - wchar_t* wstr = new wchar_t[len + 1]; - memset(wstr, 0, len + 1); + wchar_t* wstr = new wchar_t[len + 1U]; + memset(wstr, 0, len + 1U); MultiByteToWideChar(CP_ACP, 0, src_str, -1, wstr, len); len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); char* str = new char[len + 1]; diff --git a/src/MeoAssistant/Controller.cpp b/src/MeoAssistant/Controller.cpp index df7d5e242f..020eddba92 100644 --- a/src/MeoAssistant/Controller.cpp +++ b/src/MeoAssistant/Controller.cpp @@ -23,13 +23,13 @@ #include "UserConfiger.h" asst::Controller::Controller() - : m_rand_engine(time(nullptr)) + : m_rand_engine(static_cast(time(nullptr))) { LogTraceFunction; #ifdef _WIN32 // 安全属性描述符 - m_pipe_sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); + m_pipe_sec_attr.nLength = sizeof SECURITY_ATTRIBUTES; m_pipe_sec_attr.lpSecurityDescriptor = nullptr; m_pipe_sec_attr.bInheritHandle = TRUE; @@ -140,12 +140,12 @@ bool asst::Controller::connect_adb(const std::string & address) if (cur_ratio >= DefaultRatio // 说明是宽屏或默认16:9,按照高度计算缩放 || std::fabs(cur_ratio - DefaultRatio) < DoubleDiff) { - int scale_width = cur_ratio * WindowHeightDefault; + int scale_width = static_cast(cur_ratio * WindowHeightDefault); m_scale_size = std::make_pair(scale_width, WindowHeightDefault); m_control_scale = static_cast(m_emulator_info.adb.display_height) / static_cast(WindowHeightDefault); } else { // 否则可能是偏正方形的屏幕,按宽度计算 - int scale_height = WindowWidthDefault / cur_ratio; + int scale_height = static_cast(WindowWidthDefault / cur_ratio); m_scale_size = std::make_pair(WindowWidthDefault, scale_height); m_control_scale = static_cast(m_emulator_info.adb.display_width) / static_cast(WindowWidthDefault); } @@ -265,13 +265,13 @@ bool asst::Controller::try_capture(const EmulatorInfo & info, bool without_handl // 转成宽字符的 wchar_t* class_wbuff = nullptr; if (!handle_info.class_name.empty()) { - size_t class_len = (handle_info.class_name.size() + 1) * 2; + int class_len = static_cast(handle_info.class_name.size() + 1U) * 2; class_wbuff = new wchar_t[class_len]; ::MultiByteToWideChar(CP_UTF8, 0, handle_info.class_name.c_str(), -1, class_wbuff, class_len); } wchar_t* window_wbuff = nullptr; if (!handle_info.window_name.empty()) { - size_t window_len = (handle_info.window_name.size() + 1) * 2; + int window_len = static_cast(handle_info.window_name.size() + 1U) * 2; window_wbuff = new wchar_t[window_len]; memset(window_wbuff, 0, window_len); ::MultiByteToWideChar(CP_UTF8, 0, handle_info.window_name.c_str(), -1, window_wbuff, window_len); @@ -528,7 +528,7 @@ void asst::Controller::random_delay() const auto& opt = Resrc.cfg().get_options(); if (opt.control_delay_upper != 0) { LogTraceFunction; - static std::default_random_engine rand_engine(time(nullptr)); + static std::default_random_engine rand_engine(static_cast(time(nullptr))); static std::uniform_int_distribution rand_uni( opt.control_delay_lower, opt.control_delay_upper); @@ -599,8 +599,8 @@ bool asst::Controller::screencap() int asst::Controller::click(const Point & p, bool block) { - int x = p.x * m_control_scale; - int y = p.y * m_control_scale; + int x = static_cast(p.x * m_control_scale); + int y = static_cast(p.y * m_control_scale); //log.trace("Click, raw:", p.x, p.y, "corr:", x, y); return click_without_scale(Point(x, y), block); @@ -632,10 +632,10 @@ int asst::Controller::click_without_scale(const Rect & rect, bool block) int asst::Controller::swipe(const Point & p1, const Point & p2, int duration, bool block, int extra_delay, bool extra_swipe) { - int x1 = p1.x * m_control_scale; - int y1 = p1.y * m_control_scale; - int x2 = p2.x * m_control_scale; - int y2 = p2.y * m_control_scale; + int x1 = static_cast(p1.x * m_control_scale); + int y1 = static_cast(p1.y * m_control_scale); + int x2 = static_cast(p2.x * m_control_scale); + int y2 = static_cast(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, block, extra_delay, extra_swipe); @@ -675,8 +675,8 @@ int asst::Controller::swipe_without_scale(const Point & p1, const Point & p2, in if (p2.x != p1.x) { double k = (double)(p2.y - p1.y) / (p2.x - p1.x); double temp = extra_swipe_dist / std::sqrt(1 + k * k); - end_x = p2.x + (p2.x > p1.x ? -1 : 1) * temp; - end_y = p2.y + (p2.y > p1.y ? -1 : 1) * std::fabs(k) * temp; + end_x = p2.x + static_cast((p2.x > p1.x ? -1.0 : 1.0) * temp); + end_y = p2.y + static_cast((p2.y > p1.y ? -1.0 : 1.0) * std::fabs(k) * temp); } else { end_x = p2.x; diff --git a/src/MeoAssistant/InfrastAbstractTask.cpp b/src/MeoAssistant/InfrastAbstractTask.cpp index c105cc2c11..abcc851f1f 100644 --- a/src/MeoAssistant/InfrastAbstractTask.cpp +++ b/src/MeoAssistant/InfrastAbstractTask.cpp @@ -16,12 +16,12 @@ asst::InfrastAbstractTask::InfrastAbstractTask(AsstCallback callback, void* call : AbstractTask(callback, callback_arg) { if (m_face_hash_thres == 0) { - m_face_hash_thres = std::dynamic_pointer_cast( - Task.get("InfrastOperFaceHash"))->templ_threshold; + m_face_hash_thres = static_cast(std::dynamic_pointer_cast( + Task.get("InfrastOperFaceHash"))->templ_threshold); } if (m_name_hash_thres == 0) { - m_name_hash_thres = std::dynamic_pointer_cast( - Task.get("InfrastOperNameHash"))->templ_threshold; + m_name_hash_thres = static_cast(std::dynamic_pointer_cast( + Task.get("InfrastOperNameHash"))->templ_threshold); } } diff --git a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp index 425170bb89..ec3d3c5a03 100644 --- a/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastFacilityImageAnalyzer.cpp @@ -71,7 +71,7 @@ bool asst::InfrastFacilityImageAnalyzer::analyze() mm_analyzer.sort_result(); max_score = cur_score; cur_facility_result = cur_res; - cor_suffix_index = i; + cor_suffix_index = static_cast(i); } } } diff --git a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp index b2d59c118c..9c819ed3bd 100644 --- a/src/MeoAssistant/InfrastOperImageAnalyzer.cpp +++ b/src/MeoAssistant/InfrastOperImageAnalyzer.cpp @@ -131,8 +131,8 @@ void asst::InfrastOperImageAnalyzer::mood_analyze() const auto prg_task_ptr = std::dynamic_pointer_cast( Task.get("InfrastOperMoodProgressBar")); - int prg_lower_limit = prg_task_ptr->templ_threshold; - int prg_diff_thres = prg_task_ptr->special_threshold; + uint8_t prg_lower_limit = static_cast(prg_task_ptr->templ_threshold); + int prg_diff_thres = static_cast(prg_task_ptr->special_threshold); Rect rect_move = prg_task_ptr->rect_move; for (auto&& oper : m_result) { diff --git a/src/MeoAssistant/InfrastProductionTask.cpp b/src/MeoAssistant/InfrastProductionTask.cpp index 2259d333aa..5b09ff9f36 100644 --- a/src/MeoAssistant/InfrastProductionTask.cpp +++ b/src/MeoAssistant/InfrastProductionTask.cpp @@ -93,7 +93,7 @@ bool asst::InfrastProductionTask::shift_facility_list() locked_analyzer.set_image(image); if (locked_analyzer.analyze()) { - m_cur_num_of_lokced_opers = locked_analyzer.get_result().size(); + m_cur_num_of_lokced_opers = static_cast(locked_analyzer.get_result().size()); } else { m_cur_num_of_lokced_opers = 0; @@ -186,7 +186,7 @@ size_t asst::InfrastProductionTask::opers_detect() const auto& cur_all_opers = oper_analyzer.get_result(); max_num_of_opers_per_page = (std::max)(max_num_of_opers_per_page, cur_all_opers.size()); - int cur_available_num = cur_all_opers.size(); + int cur_available_num = static_cast(cur_all_opers.size()); for (const auto& cur_oper : cur_all_opers) { if (cur_oper.skills.empty()) { --cur_available_num; @@ -306,7 +306,7 @@ bool asst::InfrastProductionTask::optimal_calc() continue; } // TODO:这里做成除了不等于,还可计算大于、小于等不同条件的 - int cur_value = Status.get(cond); + int cur_value = static_cast(Status.get(cond)); if (cur_value != cond_value) { meet_condition = false; break; @@ -586,7 +586,7 @@ asst::InfrastProductionTask::efficient_regex_calc( // TODO 报错! } std::string status_key = cur_formula.substr(pos + 1, rp_pos - pos - 1); - int status_value = Status.get(status_key); + int64_t status_value = Status.get(status_key); cur_formula.replace(pos, rp_pos - pos + 1, std::to_string(status_value)); } diff --git a/src/MeoAssistant/ProcessTask.cpp b/src/MeoAssistant/ProcessTask.cpp index 94caec9db7..c7a42d105c 100644 --- a/src/MeoAssistant/ProcessTask.cpp +++ b/src/MeoAssistant/ProcessTask.cpp @@ -190,7 +190,7 @@ void asst::ProcessTask::exec_stage_drops() if (start_times > 0) { int64_t duration = time(nullptr) - start_times; int64_t delay = duration * 1000 - m_cur_task_ptr->rear_delay; - m_rear_delay["StartButton2"] = delay; + m_rear_delay["StartButton2"] = static_cast(delay); } } @@ -213,15 +213,17 @@ void asst::ProcessTask::exec_swipe_task(ProcessTaskAction action) { const auto&& [width, height] = Ctrler.get_scale_size(); - const static Rect right_rect(width * 0.8, - height * 0.4, - width * 0.1, - height * 0.2); + const static Rect right_rect( + static_cast(width * 0.8), + static_cast(height * 0.4), + static_cast(width * 0.1), + static_cast(height * 0.2)); - const static Rect left_rect(width * 0.1, - height * 0.4, - width * 0.1, - height * 0.2); + const static Rect left_rect( + static_cast(width * 0.1), + static_cast(height * 0.4), + static_cast(width * 0.1), + static_cast(height * 0.2)); switch (action) { case asst::ProcessTaskAction::SwipeToTheLeft: diff --git a/src/MeoAssistant/RecruitTask.cpp b/src/MeoAssistant/RecruitTask.cpp index 5ce071f49f..ecf118c259 100644 --- a/src/MeoAssistant/RecruitTask.cpp +++ b/src/MeoAssistant/RecruitTask.cpp @@ -77,7 +77,7 @@ bool RecruitTask::_run() // 识别到的5个Tags,全组合排列 std::vector> all_combs; size_t len = all_tags.size(); - int count = (std::pow)(2, len); + int count = static_cast(std::pow(2, len)); for (int i = 0; i < count; ++i) { std::vector temp; for (int j = 0, mask = 1; j < len; ++j) { diff --git a/src/MeoAssistant/TaskData.cpp b/src/MeoAssistant/TaskData.cpp index 8d4e8f76d7..4b013fffcc 100644 --- a/src/MeoAssistant/TaskData.cpp +++ b/src/MeoAssistant/TaskData.cpp @@ -38,9 +38,12 @@ void asst::TaskData::clear_cache() noexcept bool asst::TaskData::parse(const json::value& json) { + auto to_lower = [](char c) -> char { + return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; + }; for (const auto& [name, task_json] : json.as_object()) { std::string algorithm_str = task_json.get("algorithm", "matchtemplate"); - std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), ::tolower); + std::transform(algorithm_str.begin(), algorithm_str.end(), algorithm_str.begin(), to_lower); AlgorithmType algorithm = AlgorithmType::Invaild; if (algorithm_str == "matchtemplate") { algorithm = AlgorithmType::MatchTemplate; @@ -98,7 +101,7 @@ bool asst::TaskData::parse(const json::value& json) task_info_ptr->algorithm = algorithm; task_info_ptr->name = name; std::string action = task_json.get("action", std::string()); - std::transform(action.begin(), action.end(), action.begin(), ::tolower); + std::transform(action.begin(), action.end(), action.begin(), to_lower); if (action == "clickself") { task_info_ptr->action = ProcessTaskAction::ClickSelf; } diff --git a/tools/TestCaller/main.cpp b/tools/TestCaller/main.cpp index 18cc050e6f..6aa5d2d108 100644 --- a/tools/TestCaller/main.cpp +++ b/tools/TestCaller/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char** argv) // } AsstStart(ptr); - ch = getchar(); + ch = static_cast(getchar()); } if (ptr) {