Boring revision

This commit is contained in:
StupidBh
2022-02-26 18:10:08 +08:00
parent 5257ee212f
commit 037e11c75d
12 changed files with 31 additions and 32 deletions

View File

@@ -493,12 +493,12 @@ void Assistant::working_proc()
std::unique_lock<std::mutex> lock(m_mutex);
if (!m_thread_idle && !m_tasks_queue.empty()) {
auto task_ptr = m_tasks_queue.front();
const auto& task_ptr = m_tasks_queue.front();
m_tasks_queue.pop();
std::string cur_taskchain = task_ptr->get_task_chain();
std::string next_taskchain = m_tasks_queue.empty() ? std::string() : m_tasks_queue.front()->get_task_chain();
json::value callback_json = json::object{
json::value callback_json = json::object {
{ "taskchain", cur_taskchain },
{ "pre_taskchain", pre_taskchain }
};

View File

@@ -88,10 +88,14 @@ namespace asst
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, nullptr, nullptr);
std::string strTemp = str;
if (wstr)
if (wstr) {
delete[] wstr;
if (str)
wstr = nullptr;
}
if (str) {
delete[] str;
str = nullptr;
}
return strTemp;
#else // Don't fucking use gbk in linux!
return gbk_str;
@@ -104,17 +108,21 @@ namespace asst
const char* src_str = utf8_str.c_str();
int len = MultiByteToWideChar(CP_UTF8, 0, src_str, -1, nullptr, 0);
wchar_t* wszGBK = new wchar_t[len + 1];
memset(wszGBK, 0, len * 2 + 2);
memset(wszGBK, 0, len * 2LLU + 2LLU);
MultiByteToWideChar(CP_UTF8, 0, src_str, -1, wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, nullptr, 0, nullptr, nullptr);
char* szGBK = new char[len + 1];
memset(szGBK, 0, len + 1);
memset(szGBK, 0, len + 1LLU);
WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, nullptr, nullptr);
std::string strTemp(szGBK);
if (wszGBK)
if (wszGBK) {
delete[] wszGBK;
if (szGBK)
wszGBK = nullptr;
}
if (szGBK) {
delete[] szGBK;
szGBK = nullptr;
}
return strTemp;
#else // Don't fucking use gbk in linux!
return utf8_str;

View File

@@ -294,7 +294,7 @@ bool asst::BattleImageAnalyzer::hp_analyze()
range_upper = cv::Scalar(h_u, s_u, v_u);
std::unordered_map<std::string, std::string> num_hashs;
for (auto&& num : NumName) {
auto hashs_vec = std::dynamic_pointer_cast<HashTaskInfo>(
const auto &hashs_vec = std::dynamic_pointer_cast<HashTaskInfo>(
Task.get("BattleHp" + num))->hashs;
for (size_t i = 0; i != hashs_vec.size(); ++i) {
num_hashs.emplace(num + "_" + std::to_string(i), hashs_vec.at(i));

View File

@@ -1,4 +1,4 @@
#include "HashImageAnalyzer.h"
#include "HashImageAnalyzer.h"
#include "AsstUtils.hpp"
#include "Logger.hpp"
@@ -163,7 +163,7 @@ int asst::HashImageAnalyzer::hamming(std::string hash1, std::string hash2)
unsigned long long x = strtoull(hash1.substr(i, 16).c_str(), nullptr, 16)
^ strtoull(hash2.substr(i, 16).c_str(), nullptr, 16);
while (x) {
dist++;
++dist;
x = x & (x - 1);
}
}

View File

@@ -26,8 +26,7 @@ bool asst::InfrastControlTask::_run()
swipe_to_the_left_of_operlist();
optimal_calc();
bool ret = opers_choose();
if (!ret) {
if (!opers_choose()) {
m_all_available_opers.clear();
swipe_to_the_left_of_operlist();
continue;

View File

@@ -51,8 +51,7 @@ bool asst::InfrastOfficeTask::_run()
}
if (need_shift) {
optimal_calc();
bool ret = opers_choose();
if (!ret) {
if (!opers_choose()) {
m_all_available_opers.clear();
swipe_to_the_left_of_operlist();
continue;

View File

@@ -62,8 +62,7 @@ bool asst::InfrastPowerTask::_run()
}
if (need_shift) {
optimal_calc();
bool ret = opers_choose();
if (!ret) {
if (!opers_choose()) {
m_all_available_opers.clear();
swipe_to_the_left_of_operlist();
continue;

View File

@@ -37,10 +37,7 @@ void asst::InfrastProductionTask::set_product(std::string product_name) noexcept
bool asst::InfrastProductionTask::shift_facility_list()
{
LogTraceFunction;
if (!facility_list_detect()) {
return false;
}
if (need_exit()) {
if (!facility_list_detect() || need_exit()) {
return false;
}
const auto tab_task_ptr = Task.get("InfrastFacilityListTab" + facility_name());
@@ -124,8 +121,7 @@ bool asst::InfrastProductionTask::shift_facility_list()
opers_detect();
}
optimal_calc();
bool ret = opers_choose();
if (!ret) {
if (!opers_choose()) {
m_all_available_opers.clear();
swipe_to_the_left_of_operlist(2);
continue;
@@ -254,7 +250,7 @@ bool asst::InfrastProductionTask::optimal_calc()
std::unordered_map<std::string, int> skills_num;
for (int i = 0; i != m_all_available_opers.size(); ++i) {
auto comb = all_avaliable_combs.at(i);
const auto& comb = all_avaliable_combs.at(i);
bool out_of_num = false;
for (auto&& skill : comb.skills) {
@@ -451,7 +447,6 @@ bool asst::InfrastProductionTask::opers_choose()
LogTraceFunction;
bool has_error = false;
int count = 0;
auto& facility_info = Resrc.infrast().get_facility_info(facility_name());
int cur_max_num_of_opers = facility_info.max_num_of_opers - m_cur_num_of_lokced_opers;
@@ -495,7 +490,7 @@ bool asst::InfrastProductionTask::opers_choose()
});
cur_all_opers.erase(remove_iter, cur_all_opers.end());
Log.trace("after mood filter, opers size:", cur_all_opers.size());
int count = 0;
for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) {
Log.trace("to find", opt_iter->skills.begin()->names.front());
auto find_iter = std::find_if(

View File

@@ -48,7 +48,7 @@ bool asst::OcrImageAnalyzer::analyze()
preds_vec.emplace_back(m_pred);
TextRectProc all_pred = [&](TextRect& tr) -> bool {
for (auto pred : preds_vec) {
for (const auto &pred : preds_vec) {
if (pred && !pred(tr)) {
return false;
}

View File

@@ -44,7 +44,7 @@ bool RecruitTask::_run()
}
json::value info = basic_info();
info["what"] = "RecruitTagsDetected";
info["details"] = json::object{
info["details"] = json::object {
{ "tags", json::array(all_tags_json_vector) }
};
callback(AsstMsg::SubTaskExtraInfo, info);
@@ -56,7 +56,7 @@ bool RecruitTask::_run()
auto special_iter = std::find_first_of(SpecialTags.cbegin(), SpecialTags.cend(), all_tags_name.cbegin(), all_tags_name.cend());
if (special_iter != SpecialTags.cend()) {
info["what"] = "RecruitSpecialTag";
info["details"] = json::object{
info["details"] = json::object {
{ "tag", *special_iter }
};
callback(AsstMsg::SubTaskExtraInfo, info);

View File

@@ -13,7 +13,7 @@ bool asst::RoguelikeFormationImageAnalyzer::analyze()
return false;
}
opers_analyzer.sort_result();
const auto all_opers = opers_analyzer.get_result();
const auto& all_opers = opers_analyzer.get_result();
for (const MatchRect& oper_mr : all_opers) {
Oper oper;
oper.rect = oper_mr.rect;

View File

@@ -40,8 +40,7 @@ const cv::Mat asst::TemplResource::get_templ(const std::string& key) const noexc
return iter->second;
}
else {
const static cv::Mat empty;
return empty;
return cv::Mat();
}
}