Spaces:
Sleeping
Sleeping
File size: 2,590 Bytes
7056f70 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | // SPDX-License-Identifier: GPL-3.0-or-later
// 独立进程适配器:固定方向、全部原版维度,输出可解析的进度事件。
#include <je2be.hpp>
#include <nlohmann/json.hpp>
#include <algorithm>
#include <iostream>
#include <mutex>
#include <string>
using namespace je2be;
namespace fs=std::filesystem;
std::mutex outputMutex;
void emit(std::string phase, Rational<u64> const &p, u64 chunks=0) {
std::lock_guard<std::mutex> lock(outputMutex);
std::cout << nlohmann::json{{"phase",phase},{"done",p.fNum},{"total",p.fDen},{"chunks",chunks}}.dump() << std::endl;
}
struct JavaProgress:java::Progress {
bool reportConvert(Rational<u64> const &p,u64 n) override {emit("convert",p,n);return true;}
bool reportEntityPostProcess(Rational<u64> const &p) override {emit("entities",p);return true;}
bool reportCompaction(Rational<u64> const &p) override {emit("compact",p);return true;}
};
struct BedrockProgress:bedrock::Progress {
bool reportConvert(Rational<u64> const &p,u64 n) override {emit("convert",p,n);return true;}
bool reportTerraform(Rational<u64> const &p,u64 n) override {emit("terrain",p,n);return true;}
};
int main(int argc,char **argv) {
if(argc==2 && std::string(argv[1])=="--version") {
std::cout << R"({"engine":"je2be-core","commit":"8dfc4de1ba5c7f72e804abea8663380c0dbd5680","java_target":"1.21.10","bedrock_target":"1.21.120"})" << std::endl; return 0;
}
if(argc!=5) {std::cerr<<"usage: worldbridge-native java|bedrock INPUT OUTPUT TEMP\n";return 2;}
try {
fs::path input(argv[2]),output(argv[3]),temp(argv[4]);
if(!fs::is_directory(input)||fs::exists(output)) return 2;
fs::create_directories(temp);
Status status;
if(std::string(argv[1])=="java") {
java::Options options; options.fTempDirectory=temp; options.fDbTempDirectory=temp;
JavaProgress progress;status=java::Converter::Run(input,output,options,2,&progress);
} else if(std::string(argv[1])=="bedrock") {
bedrock::Options options;options.fTempDirectory=temp;
BedrockProgress progress;status=bedrock::Converter::Run(input,output,options,2,&progress);
} else return 2;
if(auto error=status.error();error) {
nlohmann::json trace=nlohmann::json::array();
for(auto const &p:error->fTrace) trace.push_back(p.fFile+":"+std::to_string(p.fLine));
std::cout<<nlohmann::json{{"error",error->fWhat},{"trace",trace}}.dump()<<std::endl;return 1;
}
std::cout<<R"({"phase":"complete","done":1,"total":1})"<<std::endl;return 0;
} catch(std::exception const &e) {std::cerr<<e.what()<<std::endl;return 1;}
}
|