bspinfo: output more lumps to json
This commit is contained in:
parent
ab4fa45306
commit
4b25b6b095
|
|
@ -21,12 +21,24 @@
|
||||||
#include <common/cmdlib.hh>
|
#include <common/cmdlib.hh>
|
||||||
#include <common/bspfile.hh>
|
#include <common/bspfile.hh>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <fmt/ostream.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
|
static std::string hex_string(const uint8_t* bytes, const size_t count) {
|
||||||
|
std::stringstream str;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
fmt::print(str, "{:x}", bytes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
||||||
|
|
||||||
static void serialize_bsp(const mbsp_t &bsp, const char *name) {
|
static void serialize_bsp(const mbsp_t &bsp, const char *name) {
|
||||||
json j = json::object();
|
json j = json::object();
|
||||||
|
|
||||||
|
|
@ -47,6 +59,18 @@ static void serialize_bsp(const mbsp_t &bsp, const char *name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bsp.visdatasize) {
|
||||||
|
j["visdata"] = hex_string(bsp.dvisdata, bsp.visdatasize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bsp.lightdatasize) {
|
||||||
|
j["lightdata"] = hex_string(bsp.dlightdata, bsp.lightdatasize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bsp.entdatasize) {
|
||||||
|
j["entdata"] = std::string(bsp.dentdata, static_cast<size_t>(bsp.entdatasize));
|
||||||
|
}
|
||||||
|
|
||||||
if (bsp.numleafs) {
|
if (bsp.numleafs) {
|
||||||
json &leafs = (j.emplace("leafs", json::array())).first.value();
|
json &leafs = (j.emplace("leafs", json::array())).first.value();
|
||||||
|
|
||||||
|
|
@ -81,6 +105,16 @@ static void serialize_bsp(const mbsp_t &bsp, const char *name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bsp.numvertexes) {
|
||||||
|
json &vertexes = (j.emplace("vertexes", json::array())).first.value();
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < bsp.numvertexes; i++) {
|
||||||
|
auto &src_vertex = bsp.dvertexes[i];
|
||||||
|
|
||||||
|
vertexes.insert(vertexes.end(), json::array({src_vertex.point[0], src_vertex.point[1], src_vertex.point[2]}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bsp.numnodes) {
|
if (bsp.numnodes) {
|
||||||
json &nodes = (j.emplace("nodes", json::array())).first.value();
|
json &nodes = (j.emplace("nodes", json::array())).first.value();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue