diff --git a/.gitmodules b/.gitmodules index 1fd0d4d3..ad0e89c9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "3rdparty/nanobench"] path = 3rdparty/nanobench url = https://github.com/martinus/nanobench +[submodule "3rdparty/subprocess.h"] + path = 3rdparty/subprocess.h + url = https://github.com/sheredom/subprocess.h diff --git a/3rdparty/subprocess.h b/3rdparty/subprocess.h new file mode 160000 index 00000000..a6789987 --- /dev/null +++ b/3rdparty/subprocess.h @@ -0,0 +1 @@ +Subproject commit a67899873722edddc22e66e41f6ae8a05a3a3a88 diff --git a/CMakeLists.txt b/CMakeLists.txt index 88e29bda..8d0f6a90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ endif() include_directories( "${CMAKE_SOURCE_DIR}/include" - "${CMAKE_SOURCE_DIR}/3rdparty/glm") + "${CMAKE_SOURCE_DIR}/3rdparty/subprocess.h") find_package (Threads) diff --git a/qbsp/test_qbsp.cc b/qbsp/test_qbsp.cc index 6e750415..2cb928c5 100644 --- a/qbsp/test_qbsp.cc +++ b/qbsp/test_qbsp.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -49,6 +50,51 @@ static mapentity_t LoadMap(const char *map) #include +static mbsp_t LoadTestmapRef(const std::filesystem::path &name) +{ + const char *destdir = test_quake2_maps_dir; + if (strlen(destdir) == 0) { + return {}; + } + + auto testmap_path = std::filesystem::path(testmaps_dir) / name; + auto map_in_game_path = fs::path(destdir) / name; + fs::copy(testmap_path, map_in_game_path, fs::copy_options::overwrite_existing); + + std::string map_string = map_in_game_path.generic_string(); + + const char *command_line[] = {R"(C:\Users\Eric\Documents\q2tools-220\x64\Debug\4bsp.exe)", + map_string.c_str(), + NULL}; + + struct subprocess_s subprocess; + int result = subprocess_create(command_line, 0, &subprocess); + if (0 != result) { + throw std::exception("error launching process"); + } + + int retcode; + if (0 != subprocess_join(&subprocess, &retcode)) { + throw std::exception("error joining"); + } + + // re-open the .bsp and return it + fs::path bsp_path = map_in_game_path; + bsp_path.replace_extension("bsp"); + + bspdata_t bspdata; + LoadBSPFile(bsp_path, &bspdata); + + bspdata.version->game->init_filesystem(bsp_path, options); + + ConvertBSPFormat(&bspdata, &bspver_generic); + + // write to .json for inspection + serialize_bsp(bspdata, std::get(bspdata.bsp), fs::path(bsp_path).replace_extension(".bsp.json")); + + return std::get(bspdata.bsp); +} + static mbsp_t LoadTestmap(const std::filesystem::path &name, std::vector extra_args = {}) { auto map_path = std::filesystem::path(testmaps_dir) / name;