From 2611c3f6c20be2b3c9a24dacd01931870e705630 Mon Sep 17 00:00:00 2001 From: antopilo Date: Tue, 14 Mar 2023 23:16:50 -0400 Subject: [PATCH] Serialization of bsp hulls and deserialization --- .../src/Scene/Components/BSPBrushComponent.h | 30 +++++++++++++++++-- Nuake/src/Scene/Entities/Entity.cpp | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Nuake/src/Scene/Components/BSPBrushComponent.h b/Nuake/src/Scene/Components/BSPBrushComponent.h index 7edc9cf7..7262653c 100644 --- a/Nuake/src/Scene/Components/BSPBrushComponent.h +++ b/Nuake/src/Scene/Components/BSPBrushComponent.h @@ -35,9 +35,18 @@ namespace Nuake { { BEGIN_SERIALIZE(); - for (uint32_t i = 0; i < Meshes.size(); i++) + for (uint32_t i = 0; i < Hulls.size() - 1; i++) { - j["Meshes"][i] = Meshes[i]->Serialize(); + json hullPointsJson; + + const size_t hullSize = Hulls[i].size() - 1; + for (uint32_t j = 0; j < hullSize; j++) + { + hullPointsJson[j]["x"] = Hulls[i][j].x; + hullPointsJson[j]["y"] = Hulls[i][j].y; + hullPointsJson[j]["z"] = Hulls[i][j].z; + } + j["Hulls"][i] = hullPointsJson; } j["IsSolid"] = IsSolid; @@ -53,6 +62,23 @@ namespace Nuake { IsSolid = j["IsSolid"]; } + if (j.contains("Hulls")) + { + for (auto& h : j["Hulls"]) + { + std::vector hull; + hull.reserve(h.size()); + for (auto& point : h) + { + Vector3 pointPos; + DESERIALIZE_VEC3(point, pointPos); + hull.push_back(std::move(pointPos)); + } + + Hulls.push_back(hull); + } + } + return true; } }; diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index ab7a57d9..222ccbfc 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -83,6 +83,7 @@ namespace Nuake DESERIALIZE_COMPONENT(MeshColliderComponent); DESERIALIZE_COMPONENT(SphereColliderComponent); DESERIALIZE_COMPONENT(RigidBodyComponent); + DESERIALIZE_COMPONENT(BSPBrushComponent); return true; }