Skip to content

Commit 5f4ea4b

Browse files
committed
chore: use std::format
1 parent 610dfbb commit 5f4ea4b

25 files changed

+52
-112
lines changed

.github/workflows/build.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,10 @@ jobs:
223223
brew install cmake python ninja
224224
# ccache?
225225

226-
- name: Download fmtlib
227-
run: |
228-
sh tools/fetch-fmt.sh
229-
230226
- name: Install compiler
231227
run: |
232228
brew install llvm
233-
# 16
229+
# 17
234230

235231
# Download host arch tools for Thrift of ThriftControlUnit
236232
- name: Download host tools from MaaDeps

.github/workflows/test.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,10 @@ jobs:
233233
brew install cmake python ninja
234234
# ccache?
235235

236-
- name: Download fmtlib
237-
run: |
238-
sh tools/fetch-fmt.sh
239-
240236
- name: Install compiler
241237
run: |
242238
brew install llvm
243-
# 16
239+
# 17
244240

245241
- name: Bootstrap MaaDeps
246242
env:

cmake/config.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ endif()
3030

3131
if(APPLE)
3232
set(CMAKE_INSTALL_RPATH "@loader_path;@executable_path")
33-
add_compile_definitions(MAA_USE_FMTLIB)
3433
add_compile_options("-Wno-deprecated-declarations") # supress tmpnam
3534
if("${MAADEPS_TRIPLET}" STREQUAL "maa-arm64-osx")
3635
add_compile_options("-arch;arm64")

docs/en_us/4.1-BuildGuide.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ _Please note that you only need to read this chapter if you are ready to develop
1010
python3 tools/maadeps-download.py
1111
```
1212

13-
2. _(macOS only)_ Download fmt
14-
15-
```sh
16-
sh tools/fetch-fmt.sh
17-
```
18-
19-
3. Configure cmake
13+
2. Configure cmake
2014

2115
- Windows
2216

@@ -30,7 +24,7 @@ _Please note that you only need to read this chapter if you are ready to develop
3024
cmake --preset "NinjaMulti"
3125
```
3226

33-
4. Build the project using cmake
27+
3. Build the project using cmake
3428

3529
```bash
3630
cmake --build build --config Release

docs/zh_cn/4.1-构建指南.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ _请留意,仅当您准备开发 MaaFramework 本身时,才需要阅读本
1010
python3 tools/maadeps-download.py
1111
```
1212

13-
2. _(macOS only)_ 下载 fmt
14-
15-
```sh
16-
sh tools/fetch-fmt.sh
17-
```
18-
19-
3. 配置 cmake
13+
2. 配置 cmake
2014

2115
- Windows
2216

@@ -30,7 +24,7 @@ _请留意,仅当您准备开发 MaaFramework 本身时,才需要阅读本
3024
cmake --preset "NinjaMulti"
3125
```
3226

33-
4. 使用 cmake 构建工程
27+
3. 使用 cmake 构建工程
3428

3529
```bash
3630
cmake --build build --config Release

source/MaaAdbControlUnit/Input/MaatouchInput.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <array>
44
#include <cmath>
55
#include <ranges>
6+
#include <format>
67

78
#include "Utils/Codec.h"
8-
#include "Utils/Format.hpp"
99
#include "Utils/Logger.h"
1010

1111
MAA_CTRL_UNIT_NS_BEGIN
@@ -64,7 +64,7 @@ bool MaatouchInput::press_key(int key)
6464
static constexpr std::string_view kKeyUpFormat = "k {} u\nc\n";
6565

6666
bool ret =
67-
pipe_ios_->write(MAA_FMT::format(kKeyDownFormat, key)) && pipe_ios_->write(MAA_FMT::format(kKeyUpFormat, key));
67+
pipe_ios_->write(std::format(kKeyDownFormat, key)) && pipe_ios_->write(std::format(kKeyUpFormat, key));
6868

6969
if (!ret) {
7070
LogError << "failed to write";

source/MaaAdbControlUnit/Input/MinitouchInput.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <array>
44
#include <cmath>
55
#include <ranges>
6+
#include <format>
67

7-
#include "Utils/Format.hpp"
88
#include "Utils/Logger.h"
99

1010
MAA_CTRL_UNIT_NS_BEGIN

source/MaaAdbControlUnit/Input/MtouchHelper.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <array>
44
#include <cmath>
55
#include <ranges>
6+
#include <format>
67

7-
#include "Utils/Format.hpp"
88
#include "Utils/Logger.h"
99

1010
MAA_CTRL_UNIT_NS_BEGIN
@@ -70,8 +70,8 @@ bool MtouchHelper::click(int x, int y)
7070

7171
LogInfo << VAR(x) << VAR(y) << VAR(touch_x) << VAR(touch_y);
7272

73-
bool ret = pipe_ios_->write(MAA_FMT::format(kDownFormat, 0, touch_x, touch_y, press_)) &&
74-
pipe_ios_->write(MAA_FMT::format(kUpFormat, 0));
73+
bool ret = pipe_ios_->write(std::format(kDownFormat, 0, touch_x, touch_y, press_)) &&
74+
pipe_ios_->write(std::format(kUpFormat, 0));
7575

7676
if (!ret) {
7777
LogError << "failed to write";
@@ -110,7 +110,7 @@ bool MtouchHelper::swipe(int x1, int y1, int x2, int y2, int duration)
110110
auto start = std::chrono::steady_clock::now();
111111
auto now = start;
112112
bool ret = true;
113-
ret &= pipe_ios_->write(MAA_FMT::format(kDownFormat, 0, touch_x1, touch_y1, press_));
113+
ret &= pipe_ios_->write(std::format(kDownFormat, 0, touch_x1, touch_y1, press_));
114114
if (!ret) {
115115
LogError << "write error";
116116
return false;
@@ -127,19 +127,19 @@ bool MtouchHelper::swipe(int x1, int y1, int x2, int y2, int duration)
127127
std::this_thread::sleep_until(now + delay);
128128
now = std::chrono::steady_clock::now();
129129

130-
ret &= pipe_ios_->write(MAA_FMT::format(kMoveFormat, 0, tx, ty, press_));
130+
ret &= pipe_ios_->write(std::format(kMoveFormat, 0, tx, ty, press_));
131131
if (!ret) {
132132
LogWarn << "write error";
133133
}
134134
}
135135

136136
std::this_thread::sleep_until(now + delay);
137137
now = std::chrono::steady_clock::now();
138-
ret &= pipe_ios_->write(MAA_FMT::format(kMoveFormat, 0, touch_x2, touch_y2, press_));
138+
ret &= pipe_ios_->write(std::format(kMoveFormat, 0, touch_x2, touch_y2, press_));
139139

140140
std::this_thread::sleep_until(now + delay);
141141
now = std::chrono::steady_clock::now();
142-
ret &= pipe_ios_->write(MAA_FMT::format(kUpFormat, 0));
142+
ret &= pipe_ios_->write(std::format(kUpFormat, 0));
143143

144144
if (!ret) {
145145
LogError << "failed to write";
@@ -160,7 +160,7 @@ bool MtouchHelper::touch_down(int contact, int x, int y, int pressure)
160160

161161
LogInfo << VAR(contact) << VAR(x) << VAR(y) << VAR(touch_x) << VAR(touch_y);
162162

163-
bool ret = pipe_ios_->write(MAA_FMT::format(kDownFormat, contact, touch_x, touch_y, pressure));
163+
bool ret = pipe_ios_->write(std::format(kDownFormat, contact, touch_x, touch_y, pressure));
164164

165165
if (!ret) {
166166
LogError << "failed to write";
@@ -181,7 +181,7 @@ bool MtouchHelper::touch_move(int contact, int x, int y, int pressure)
181181

182182
LogInfo << VAR(contact) << VAR(x) << VAR(y) << VAR(touch_x) << VAR(touch_y);
183183

184-
bool ret = pipe_ios_->write(MAA_FMT::format(kMoveFormat, contact, touch_x, touch_y, pressure));
184+
bool ret = pipe_ios_->write(std::format(kMoveFormat, contact, touch_x, touch_y, pressure));
185185

186186
if (!ret) {
187187
LogError << "failed to write";
@@ -200,7 +200,7 @@ bool MtouchHelper::touch_up(int contact)
200200

201201
LogInfo << VAR(contact);
202202

203-
bool ret = pipe_ios_->write(MAA_FMT::format(kUpFormat, contact));
203+
bool ret = pipe_ios_->write(std::format(kUpFormat, contact));
204204

205205
if (!ret) {
206206
LogError << "failed to write";

source/MaaAdbControlUnit/Screencap/FastestWay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <ranges>
44
#include <unordered_set>
5+
#include <format>
56

6-
#include "Utils/Format.hpp"
77
#include "Utils/Logger.h"
88
#include "Utils/NoWarningCV.hpp"
99

source/MaaAdbControlUnit/Screencap/Minicap/MinicapBase.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <array>
44
#include <ranges>
5+
#include <format>
56

6-
#include "Utils/Format.hpp"
77
#include "Utils/Logger.h"
88
#include "Utils/NoWarningCV.hpp"
99

@@ -63,7 +63,7 @@ bool MinicapBase::init(int swidth, int sheight)
6363

6464
// TODO: 确认低版本是否使用minicap-nopie
6565
const auto bin_path = agent_path_ / path(target_arch) / path("bin") / path("minicap");
66-
const auto lib_path = agent_path_ / path(target_arch) / path("lib") / path(MAA_FMT::format("android-{}", fit_sdk)) /
66+
const auto lib_path = agent_path_ / path(target_arch) / path("lib") / path(std::format("android-{}", fit_sdk)) /
6767
path("minicap.so");
6868
if (!binary_->push(bin_path) || !library_->push(lib_path)) {
6969
return false;

source/MaaAdbControlUnit/Screencap/Minicap/MinicapDirect.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MinicapDirect.h"
22

3-
#include "Utils/Format.hpp"
3+
#include <format>
4+
45
#include "Utils/Logger.h"
56
#include "Utils/NoWarningCV.hpp"
67

@@ -12,7 +13,7 @@ std::optional<cv::Mat> MinicapDirect::screencap()
1213
int height = screencap_helper_.get_h();
1314

1415
auto res =
15-
binary_->invoke_bin_and_read_pipe(MAA_FMT::format("-P {}x{}@{}x{}/{} -s", width, height, width, height, 0));
16+
binary_->invoke_bin_and_read_pipe(std::format("-P {}x{}@{}x{}/{} -s", width, height, width, height, 0));
1617

1718
if (!res) {
1819
return std::nullopt;

source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "MinicapStream.h"
2-
#include "MinicapDef.h"
32

4-
#include "Utils/Format.hpp"
3+
#include <format>
4+
5+
#include "MinicapDef.h"
56
#include "Utils/Logger.h"
67
#include "Utils/NoWarningCV.hpp"
78

@@ -49,7 +50,7 @@ bool MinicapStream::init(int swidth, int sheight)
4950
uint32_t width = screencap_helper_.get_w();
5051
uint32_t height = screencap_helper_.get_h();
5152

52-
pipe_ios_ = binary_->invoke_bin(MAA_FMT::format("-P {}x{}@{}x{}/{}", width, height, width, height, 0));
53+
pipe_ios_ = binary_->invoke_bin(std::format("-P {}x{}@{}x{}/{}", width, height, width, height, 0));
5354

5455
if (!pipe_ios_) {
5556
LogError << "pipe_ios_ is nullptr";

source/MaaFramework/Controller/ControllerAgent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void ControllerAgent::init_recording()
509509
{
510510
auto recording_dir = GlobalOptionMgr::get_instance().log_dir() / "Recording";
511511
std::filesystem::create_directories(recording_dir);
512-
recording_path_ = recording_dir / MAA_FMT::format("MaaRecording_{}.txt", format_now_for_filename());
512+
recording_path_ = recording_dir / std::format("MaaRecording_{}.txt", format_now_for_filename());
513513
}
514514

515515
void ControllerAgent::append_recording(json::value info, const std::chrono::steady_clock::time_point& start_time,

source/MaaFramework/Task/Recognizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void Recognizer::show_hit_draw(const cv::Mat& image, const Result& res, const st
308308
return;
309309
}
310310

311-
const std::string kWinName = MAA_FMT::format("Hit: {}", task_name);
311+
const std::string kWinName = std::format("Hit: {}", task_name);
312312

313313
cv::Mat draw = image.clone();
314314

source/MaaFramework/Vision/ColorMatcher.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "ColorMatcher.h"
22

3-
#include "Utils/NoWarningCV.hpp"
3+
#include <format>
44

5-
#include "Utils/Format.hpp"
5+
#include "Utils/NoWarningCV.hpp"
66
#include "Utils/Logger.h"
77
#include "VisionUtils.hpp"
88

@@ -115,7 +115,7 @@ void ColorMatcher::draw_result(const cv::Rect& roi, const cv::Mat& color, const
115115
const auto& res = results[i];
116116
cv::rectangle(image_draw, res.box, color_draw, 1);
117117

118-
std::string flag = MAA_FMT::format("{}: {}, [{}, {}, {}, {}]", i, res.score, res.box.x, res.box.y,
118+
std::string flag = std::format("{}: {}, [{}, {}, {}, {}]", i, res.score, res.box.x, res.box.y,
119119
res.box.width, res.box.height);
120120
cv::putText(image_draw, flag, cv::Point(res.box.x, res.box.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color_draw, 1);
121121
if (i > 10 && res.score < 100) {

source/MaaFramework/Vision/FeatureMatcher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void FeatureMatcher::draw_result(const cv::Mat& templ, const std::vector<cv::Key
227227
const auto& res = results.at(i);
228228
cv::rectangle(image_draw, res.box, color, 1);
229229

230-
std::string flag = MAA_FMT::format("Cnt: {}, [{}, {}, {}, {}]", res.count, res.box.x, res.box.y, res.box.width,
230+
std::string flag = std::format("Cnt: {}, [{}, {}, {}, {}]", res.count, res.box.x, res.box.y, res.box.width,
231231
res.box.height);
232232
cv::putText(image_draw, flag, cv::Point(res.box.x, res.box.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
233233
}

source/MaaFramework/Vision/NeuralNetworkClassifier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void NeuralNetworkClassifier::draw_result(const Result& res) const
112112
for (size_t i = 0; i != param_.cls_size; ++i) {
113113
const auto color = i == res.cls_index ? cv::Scalar(0, 0, 255) : cv::Scalar(255, 0, 0);
114114
std::string text =
115-
MAA_FMT::format("{} {}: prob {:.3f}, raw {:.3f}", i, param_.labels[i], res.probs[i], res.raw[i]);
115+
std::format("{} {}: prob {:.3f}, raw {:.3f}", i, param_.labels[i], res.probs[i], res.raw[i]);
116116
cv::putText(image_draw, text, pt, cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
117117
pt.y += 20;
118118
}

source/MaaFramework/Vision/NeuralNetworkDetector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void NeuralNetworkDetector::draw_result(const cv::Rect& roi, const ResultsVec& r
167167

168168
const auto color = cv::Scalar(0, 0, 255);
169169
cv::rectangle(image_draw, my_box, color, 1);
170-
std::string flag = MAA_FMT::format("{} {} {:.3f}: [{}, {}, {}, {}]", res.cls_index, res.label, res.score,
170+
std::string flag = std::format("{} {} {:.3f}: [{}, {}, {}, {}]", res.cls_index, res.label, res.score,
171171
my_box.x, my_box.y, my_box.width, my_box.height);
172172
cv::putText(image_draw, flag, cv::Point(my_box.x, my_box.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
173173
}

source/MaaFramework/Vision/OCRer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void OCRer::draw_result(const cv::Rect& roi, const ResultsVec& results) const
141141

142142
const auto color = cv::Scalar(0, 0, 255);
143143
cv::rectangle(image_draw, my_box, color, 1);
144-
std::string flag = MAA_FMT::format("{}: [{}, {}, {}, {}]", i, my_box.x, my_box.y, my_box.width, my_box.height);
144+
std::string flag = std::format("{}: [{}, {}, {}, {}]", i, my_box.x, my_box.y, my_box.width, my_box.height);
145145
cv::putText(image_draw, flag, cv::Point(my_box.x, my_box.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
146146
}
147147

source/MaaFramework/Vision/TemplateMatcher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void TemplateMatcher::draw_result(const cv::Rect& roi, const cv::Mat& templ, con
130130
const auto& res = results.at(i);
131131
cv::rectangle(image_draw, res.box, color, 1);
132132

133-
std::string flag = MAA_FMT::format("{}: {:.3f}, [{}, {}, {}, {}]", i, res.score, res.box.x, res.box.y,
133+
std::string flag = std::format("{}: {:.3f}, [{}, {}, {}, {}]", i, res.score, res.box.x, res.box.y,
134134
res.box.width, res.box.height);
135135
cv::putText(image_draw, flag, cv::Point(res.box.x, res.box.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
136136
}

source/MaaFramework/Vision/VisionBase.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cv::Mat VisionBase::draw_roi(const cv::Rect& roi, const cv::Mat& base) const
3636
cv::putText(image_draw, name_, cv::Point(5, image_.rows - 5), cv::FONT_HERSHEY_SIMPLEX, 1, color, 2);
3737

3838
cv::rectangle(image_draw, roi, color, 1);
39-
std::string flag = MAA_FMT::format("ROI: [{}, {}, {}, {}]", roi.x, roi.y, roi.width, roi.height);
39+
std::string flag = std::format("ROI: [{}, {}, {}, {}]", roi.x, roi.y, roi.width, roi.height);
4040
cv::putText(image_draw, flag, cv::Point(roi.x, roi.y - 5), cv::FONT_HERSHEY_PLAIN, 1.2, color, 1);
4141

4242
return image_draw;
@@ -51,7 +51,7 @@ void VisionBase::handle_draw(const cv::Mat& draw) const
5151

5252
void VisionBase::save_image(const cv::Mat& image) const
5353
{
54-
std::string filename = MAA_FMT::format("{}_{}.png", name_, format_now_for_filename());
54+
std::string filename = std::format("{}_{}.png", name_, format_now_for_filename());
5555
auto filepath = GlobalOptionMgr::get_instance().log_dir() / "Vision" / filename;
5656
MAA_NS::imwrite(filepath, image);
5757
LogDebug << "save image to" << filepath;

source/include/Utils/Format.hpp

-28
This file was deleted.

0 commit comments

Comments
 (0)