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/bspfile.hh>
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <fmt/ostream.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
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) {
|
||||
json j = json::object();
|
||||
|
||||
|
|
@ -46,6 +58,18 @@ static void serialize_bsp(const mbsp_t &bsp, const char *name) {
|
|||
model.push_back({ "numfaces", src_model.numfaces });
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
json &nodes = (j.emplace("nodes", json::array())).first.value();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue