perf: 公招回调整理,更新meojson

This commit is contained in:
MistEO
2022-08-17 23:32:41 +08:00
parent d7d871c9ae
commit a0cb73191c
2 changed files with 62 additions and 52 deletions

View File

@@ -216,9 +216,13 @@ namespace json
array(const raw_array& arr);
array(raw_array&& arr) noexcept;
array(std::initializer_list<raw_array::value_type> init_list);
array(raw_array::size_type size);
explicit array(const value& val);
explicit array(value&& val);
template<typename ArrayType> array(ArrayType arr);
template<typename ArrayType, typename EnableT = std::enable_if_t<
std::is_constructible_v<value, typename ArrayType::value_type>>>
array(ArrayType arr);
~array() noexcept = default;
@@ -309,7 +313,9 @@ namespace json
object(std::initializer_list<raw_object::value_type> init_list);
explicit object(const value& val);
explicit object(value&& val);
template <typename MapType> object(MapType map);
template <typename MapType, typename EnableT = std::enable_if_t<
std::is_constructible_v<raw_object::value_type, typename MapType::value_type>>>
object(MapType map);
~object() = default;
@@ -600,12 +606,14 @@ namespace json
}
template <typename Type>
MEOJSON_INLINE std::optional<Type> value::find(size_t pos) const {
MEOJSON_INLINE std::optional<Type> value::find(size_t pos) const
{
return is_array() ? as_array().template find<Type>(pos) : std::nullopt;
}
template <typename Type>
MEOJSON_INLINE std::optional<Type> value::find(const std::string& key) const {
MEOJSON_INLINE std::optional<Type> value::find(const std::string& key) const
{
return is_object() ? as_object().template find<Type>(key) : std::nullopt;
}
@@ -1029,6 +1037,13 @@ namespace json
;
}
MEOJSON_INLINE
array::array(raw_array::size_type size)
: _array_data(size)
{
;
}
MEOJSON_INLINE array::array(const value& val)
: array(val.as_array())
{
@@ -1041,12 +1056,9 @@ namespace json
;
}
template<typename ArrayType>
template<typename ArrayType, typename EnableT>
MEOJSON_INLINE array::array(ArrayType arr)
{
static_assert(
std::is_constructible<value, typename ArrayType::value_type>::value,
"Parameter can't be used to construct a value");
_array_data.assign(
std::make_move_iterator(arr.begin()),
std::make_move_iterator(arr.end()));
@@ -1906,12 +1918,9 @@ namespace json
return out;
}
template <typename MapType> object::object(MapType map)
template <typename MapType, typename EnableT>
object::object(MapType map)
{
static_assert(std::is_constructible<raw_object::value_type,
typename MapType::value_type>::value,
"Parameter can't be used to construct a "
"object::raw_object::value_type");
_object_data.insert(
std::make_move_iterator(map.begin()),
std::make_move_iterator(map.end()));

View File

@@ -293,37 +293,38 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
bool has_special_tag = false;
bool has_robot_tag = false;
json::value info = basic_info();
std::vector<json::value> tag_json_vector;
ranges::transform(tags, std::back_inserter(tag_json_vector), std::mem_fn(&TextRect::text));
info["details"]["tags"] = json::array(tag_json_vector);
// tags result
{
json::value info = basic_info();
std::vector<json::value> tag_json_vector;
ranges::transform(tags, std::back_inserter(tag_json_vector), std::mem_fn(&TextRect::text));
info["what"] = "RecruitTagsDetected";
info["details"] = json::object{ { "tags", json::array(tag_json_vector) } };
callback(AsstMsg::SubTaskExtraInfo, info);
json::value cb_info = info;
cb_info["what"] = "RecruitTagsDetected";
callback(AsstMsg::SubTaskExtraInfo, cb_info);
}
// special tags
const std::vector<std::string> SpecialTags = { "高级资深干员", "资深干员" };
auto special_iter = ranges::find_first_of(SpecialTags, tag_names);
if (special_iter != SpecialTags.cend()) [[unlikely]] {
json::value info = basic_info();
info["what"] = "RecruitSpecialTag";
info["details"] = json::object{ { "tag", *special_iter } };
callback(AsstMsg::SubTaskExtraInfo, info);
has_special_tag = true;
if (auto special_iter = ranges::find_first_of(SpecialTags, tag_names);
special_iter != SpecialTags.cend()) [[unlikely]] {
has_special_tag = true;
json::value cb_info = info;
cb_info["what"] = "RecruitSpecialTag";
cb_info["details"]["tag"] = *special_iter;
callback(AsstMsg::SubTaskExtraInfo, cb_info);
}
// robot tags
const std::vector<std::string> RobotTags = { "支援机械" };
auto robot_iter = ranges::find_first_of(RobotTags, tag_names);
if (robot_iter != RobotTags.cend()) [[unlikely]] {
json::value info = basic_info();
info["what"] = "RecruitSpecialTag";
info["details"] = json::object{ { "tag", *robot_iter } };
callback(AsstMsg::SubTaskExtraInfo, info);
has_robot_tag = true;
if (auto robot_iter = ranges::find_first_of(RobotTags, tag_names);
robot_iter != RobotTags.cend()) [[unlikely]] {
has_robot_tag = true;
json::value cb_info = info;
cb_info["what"] = "RecruitSpecialTag";
cb_info["details"]["tag"] = *robot_iter;
callback(AsstMsg::SubTaskExtraInfo, cb_info);
}
std::vector<RecruitCombs> result_vec = recruit_calc::get_all_combs(tag_names);
@@ -365,8 +366,6 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
const auto& final_combination = result_vec.front();
{
json::value info = basic_info();
json::value results_json;
results_json["result"] = json::array();
results_json["level"] = final_combination.min_level;
@@ -391,9 +390,11 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
comb_json["level"] = comb.min_level;
results_json["result"].as_array().emplace_back(std::move(comb_json));
}
info["what"] = "RecruitResult";
info["details"] = results_json;
callback(AsstMsg::SubTaskExtraInfo, info);
info["details"] |= results_json.as_object();
json::value cb_info = info;
cb_info["what"] = "RecruitResult";
callback(AsstMsg::SubTaskExtraInfo, cb_info);
}
if (need_exit()) return {};
@@ -405,13 +406,13 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
&& !(m_skip_robot && has_robot_tag)
) {
if (refresh_count > refresh_limit) [[unlikely]] {
json::value info = basic_info();
info["what"] = "RecruitError";
info["why"] = "刷新次数达到上限";
info["details"] = json::object{
json::value cb_info = basic_info();
cb_info["what"] = "RecruitError";
cb_info["why"] = "刷新次数达到上限";
cb_info["details"] = json::object{
{ "refresh_limit", refresh_limit }
};
callback(AsstMsg::SubTaskError, info);
callback(AsstMsg::SubTaskError, cb_info);
return {};
}
@@ -420,13 +421,13 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
++refresh_count;
{
json::value info = basic_info();
info["what"] = "RecruitTagsRefreshed";
info["details"] = json::object{
json::value cb_info = basic_info();
cb_info["what"] = "RecruitTagsRefreshed";
cb_info["details"] = json::object{
{ "count", refresh_count },
{ "refresh_limit", refresh_limit }
};
callback(AsstMsg::SubTaskExtraInfo, info);
callback(AsstMsg::SubTaskExtraInfo, cb_info);
Log.trace("recruit tags refreshed", std::to_string(refresh_count), " times, rerunning recruit task");
}
@@ -491,12 +492,12 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
}
{
json::value info = basic_info();
info["what"] = "RecruitTagsSelected";
info["details"] = json::object{
json::value cb_info = basic_info();
cb_info["what"] = "RecruitTagsSelected";
cb_info["details"] = json::object{
{ "tags", json::array(final_combination.tags) }
};
callback(AsstMsg::SubTaskExtraInfo, info);
callback(AsstMsg::SubTaskExtraInfo, cb_info);
}
calc_task_result_type result;