Skip to content

Commit

Permalink
feat: pipeling smoking
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 23, 2023
1 parent 90243bd commit 3dfe620
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
[submodule "assets/config/MaaAgentBinary"]
path = assets/config/MaaAgentBinary
url = https://github.com/MaaAssistantArknights/MaaAgentBinary.git
[submodule "test/TestingSet"]
path = test/TestingSet
url = https://github.com/MaaAssistantArknights/MaaFwTestingSet.git
branch = master
10 changes: 10 additions & 0 deletions 3rdparty/include/meojson/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ class exception : public std::exception

template <typename parsing_t>
auto parse(const parsing_t& content);

template <typename char_t>
auto parse(char_t* content);

template <typename istream_t,
typename = std::enable_if_t<std::is_base_of_v<std::basic_istream<typename istream_t::char_type>, istream_t>>>
auto parse(istream_t& istream, bool check_bom);
Expand Down Expand Up @@ -2372,6 +2376,12 @@ MEOJSON_INLINE auto parse(const parsing_t& content)
return parser<string_t, parsing_t>::parse(content);
}

template <typename char_t>
MEOJSON_INLINE auto parse(char_t* content)
{
return parse(std::basic_string_view<std::decay_t<char_t>> { content });
}

template <typename istream_t, typename _>
MEOJSON_INLINE auto parse(istream_t& ifs, bool check_bom)
{
Expand Down
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ set(CMAKE_MAP_IMPORTED_CONFIG_DebWithRelDeps "DebWithRelDeps;Release;")
set(Boost_NO_WARN_NEW_VERSIONS 1)

option(USE_MAADEPS "use third-party libraries built by MaaDeps" ON)
option(BUILD_SAMPLE "build a demo" OFF)
option(WITH_ADB_CONTROLLER "build with adb controller" ON)
option(WITH_THRIFT_CONTROLLER "build with thrift controller" ON)
option(WITH_DEBUGGING_CONTROLLER "build with debugging controller" ON)
option(WITH_GRPC "build with protobuf and grpc" ON)
option(BUILD_SAMPLE "build a demo" OFF)
option(BUILD_TESTING "build testing" OFF)

if(USE_MAADEPS)
include(${PROJECT_SOURCE_DIR}/MaaDeps/maadeps.cmake)
Expand Down Expand Up @@ -61,6 +62,10 @@ add_subdirectory(source)
if(BUILD_SAMPLE)
add_subdirectory(sample/cpp)
endif()
if (BUILD_TESTING)
add_subdirectory(test/source)
add_subdirectory(test/TestingSet)
endif()

if(USE_MAADEPS)
maadeps_install(bin)
Expand Down
7 changes: 4 additions & 3 deletions source/MaaDebuggingControlUnit/ControlUnitMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ MAA_DBG_CTRL_UNIT_NS_BEGIN
std::shared_ptr<ControlUnitAPI> create_controller_unit(MaaStringView read_path, MaaStringView wirte_path,
MaaDebuggingControllerType type, MaaStringView config)
{
LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type);
LogFunc << VAR(read_path) << VAR(wirte_path) << VAR(type) << VAR(config);

auto filepath = MAA_NS::path(read_path);
std::ignore = wirte_path;
json::value jconfig = json::parse(config).value_or(json::object());

std::shared_ptr<ScreencapAPI> screencap_unit = nullptr;
auto screencap_type = type & MaaDebuggingControllerType_Screencap_Mask;
Expand All @@ -28,9 +29,9 @@ std::shared_ptr<ControlUnitAPI> create_controller_unit(MaaStringView read_path,
}

auto device_info_unit = std::make_shared<VirtualInfo>(filepath);
bool parsed = device_info_unit->parse(config);
bool parsed = device_info_unit->parse(jconfig);
if (!parsed) {
LogError << "failed to parse config" << VAR(config);
LogError << "failed to parse config" << VAR(jconfig);
return nullptr;
}

Expand Down
16 changes: 9 additions & 7 deletions source/MaaDebuggingControlUnit/Screencap/ReadIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@

MAA_DBG_CTRL_UNIT_NS_BEGIN

ReadIndex::ReadIndex(std::filesystem::path indexfile) : indexfile_(std::move(indexfile)) {}
ReadIndex::ReadIndex(std::filesystem::path root) : root_(std::move(root)) {}

bool ReadIndex::init(int swidth, int sheight)
{
LogInfo << VAR(indexfile_) << VAR(swidth) << VAR(sheight);
LogInfo << VAR(root_) << VAR(swidth) << VAR(sheight);

swidth_ = swidth;
sheight_ = sheight;
filepaths_.clear();
index_ = 0;

if (!std::filesystem::exists(indexfile_)) {
LogError << "indexfile not exist" << VAR(indexfile_);
if (!std::filesystem::exists(root_)) {
LogError << "root not exist" << VAR(root_);
return false;
}

std::ifstream ifs(indexfile_);
auto imagelist = root_ / "imagelist.txt";

std::ifstream ifs(imagelist);
if (!ifs.is_open()) {
LogError << "open indexfile failed" << VAR(indexfile_);
LogError << "open root failed" << VAR(root_);
return false;
}

Expand All @@ -39,7 +41,7 @@ bool ReadIndex::init(int swidth, int sheight)
image_path = line;
}
else {
image_path = indexfile_.parent_path() / line;
image_path = imagelist.parent_path() / line;
}
if (!std::filesystem::exists(image_path)) {
LogError << "image not exist" << VAR(image_path);
Expand Down
4 changes: 2 additions & 2 deletions source/MaaDebuggingControlUnit/Screencap/ReadIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MAA_DBG_CTRL_UNIT_NS_BEGIN
class ReadIndex : public ScreencapAPI
{
public:
ReadIndex(std::filesystem::path indexfile);
ReadIndex(std::filesystem::path root);
virtual ~ReadIndex() override = default;

public: // from ScreencapAPI
Expand All @@ -21,7 +21,7 @@ class ReadIndex : public ScreencapAPI
int swidth_ = 0;
int sheight_ = 0;

std::filesystem::path indexfile_;
std::filesystem::path root_;
std::vector<std::filesystem::path> filepaths_;
size_t index_ = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions source/MaaFramework/API/MaaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ MaaControllerHandle MaaAdbControllerCreateV2(MaaStringView adb_path, MaaStringVi

#pragma message("The build without adb controller")

std::ignore = config;

LogError << "The build without adb controller";
return nullptr;

Expand Down Expand Up @@ -106,6 +108,8 @@ MaaControllerHandle MaaDebuggingControllerCreate(MaaStringView read_path, MaaStr

#pragma message("The build without debugging controller")

std::ignore = config;

LogError << "The build without debugging controller";
return nullptr;

Expand Down
12 changes: 9 additions & 3 deletions source/MaaToolKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ target_include_directories(

target_compile_definitions(MaaToolKit PRIVATE MAA_TOOLKIT_EXPORTS)

target_link_libraries(MaaToolKit MaaFramework MaaUtils MaaAdbControlUnit HeaderOnlyLibraries Boost::system)

add_dependencies(MaaToolKit MaaFramework MaaUtils MaaAdbControlUnit)
target_link_libraries(MaaToolKit MaaFramework MaaUtils HeaderOnlyLibraries Boost::system)
if (WITH_ADB_CONTROLLER)
target_link_libraries(MaaFramework MaaAdbControlUnit)
endif(WITH_ADB_CONTROLLER)

add_dependencies(MaaToolKit MaaFramework MaaUtils)
if (WITH_ADB_CONTROLLER)
add_dependencies(MaaFramework MaaAdbControlUnit)
endif(WITH_ADB_CONTROLLER)

install(
TARGETS MaaToolKit
Expand Down
18 changes: 18 additions & 0 deletions source/MaaToolKit/Device/DeviceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ std::vector<std::string> DeviceMgr::request_adb_serials(const std::filesystem::p
{
LogFunc << VAR(adb_path);

#ifdef WITH_ADB_CONTROLLER

std::string str_adb = path_to_utf8_string(adb_path);
std::string str_config = adb_config.to_string();
auto mgr = MAA_ADB_CTRL_UNIT_NS::create_device_list_obj(str_adb.c_str(), str_config.c_str());
Expand All @@ -50,13 +52,22 @@ std::vector<std::string> DeviceMgr::request_adb_serials(const std::filesystem::p
}

return *devices_opt;

#else

std::ignore = adb_config;
return {};

#endif
}

bool DeviceMgr::request_adb_connect(const std::filesystem::path& adb_path, const std::string& serial,
const json::value& adb_config) const
{
LogFunc << VAR(adb_path) << VAR(serial);

#ifdef WITH_ADB_CONTROLLER

std::string str_adb = path_to_utf8_string(adb_path);
std::string str_config = adb_config.to_string();
auto mgr = MAA_ADB_CTRL_UNIT_NS::create_connection(str_adb.c_str(), serial.c_str(), 0, str_config.c_str());
Expand All @@ -66,6 +77,13 @@ bool DeviceMgr::request_adb_connect(const std::filesystem::path& adb_path, const
}

return mgr->connect();

#else

std::ignore = adb_config;
return false;

#endif
}

std::vector<std::string> DeviceMgr::check_available_adb_serials(const std::filesystem::path& adb_path,
Expand Down
1 change: 1 addition & 0 deletions test/TestingSet
Submodule TestingSet added at 043fb8
14 changes: 14 additions & 0 deletions test/source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
file(
GLOB_RECURSE
testing_src
*.cpp
*.h
*.hpp)

add_executable(testing ${testing_src})

target_link_libraries(testing MaaFramework)

add_dependencies(testing MaaFramework)

install(TARGETS testing RUNTIME DESTINATION bin)
19 changes: 19 additions & 0 deletions test/source/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <filesystem>

#include "module/PipelineSmoking.h"

#include "MaaFramework/MaaAPI.h"

int main([[maybe_unused]] int argc, char** argv)
{
auto cur_dir = std::filesystem::path(argv[0]).parent_path();

std::string logging_dir = (cur_dir / "debug").string();
MaaSetGlobalOption(MaaGlobalOption_Logging, (void*)logging_dir.c_str(), logging_dir.size());
bool on = true;
MaaSetGlobalOption(MaaGlobalOption_DebugMode, &on, sizeof(on));

bool ret = pipeline_smoking(cur_dir);

return ret ? 0 : -1;
}
57 changes: 57 additions & 0 deletions test/source/module/PipelineSmoking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "PipelineSmoking.h"

#include <iostream>

#include <meojson/json.hpp>

#include "MaaFramework/MaaAPI.h"

bool pipeline_smoking(const std::filesystem::path& cur_dir)
{
auto testing_path = cur_dir.parent_path() / "test" / "PipelineSmoking";
auto result_path = cur_dir / "debug";
json::value debug_config = { { "device_info", json::object {
{ "uuid", testing_path.string() },
{ "screen_width", 1280 },
{ "screen_height", 720 },
{ "orientation", 0 },
} } };
auto config = debug_config.dumps(4);

auto controller_handle =
MaaDebuggingControllerCreate(testing_path.string().c_str(), result_path.string().c_str(),
MaaDebuggingControllerType_Screencap_ReadIndex, config.c_str(), nullptr, nullptr);

auto ctrl_id = MaaControllerPostConnection(controller_handle);

auto resource_handle = MaaResourceCreate(nullptr, nullptr);
auto resource_dir = cur_dir.parent_path() / "test" / "PipelineSmoking" / "resource";
auto res_id = MaaResourcePostPath(resource_handle, resource_dir.string().c_str());

MaaControllerWait(controller_handle, ctrl_id);
MaaResourceWait(resource_handle, res_id);

auto maa_handle = MaaCreate(nullptr, nullptr);
MaaBindResource(maa_handle, resource_handle);
MaaBindController(maa_handle, controller_handle);

auto destroy = [&]() {
MaaDestroy(maa_handle);
MaaResourceDestroy(resource_handle);
MaaControllerDestroy(controller_handle);
};

if (!MaaInited(maa_handle)) {
std::cout << __FUNCTION__ << " | Failed to init" << std::endl;

destroy();
return false;
}

auto task_id = MaaPostTask(maa_handle, "Wilderness", MaaTaskParam_Empty);
MaaWaitTask(maa_handle, task_id);

destroy();

return true;
}
3 changes: 3 additions & 0 deletions test/source/module/PipelineSmoking.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <filesystem>

bool pipeline_smoking(const std::filesystem::path& cur_dir);

0 comments on commit 3dfe620

Please sign in to comment.