From dfe78064500088a2b11704bd0bb78c7302c6b15a Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Thu, 2 Feb 2023 15:06:21 +0100 Subject: [PATCH] Reorganized model data so as not to cause any memory alignment issues --- main.cpp | 10 ++++++---- ps1bsp.h | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 822cfcc..ae77c9e 100644 --- a/main.cpp +++ b/main.cpp @@ -343,8 +343,10 @@ int process_faces(const world_t* world, const TextureList& textures) ps1bsp_model_t outModel = { 0 }; outModel.boundingSphere = model->bound.toBoundingSphere(); outModel.origin = model->origin.convertWorldPosition(); - outModel.nodeId = (u_short)model->node_id0; - outModel.clipNodeId = (u_short)model->node_id1; + outModel.nodeId0 = (u_short)model->node_id0; + outModel.nodeId1 = (u_short)model->node_id1; + outModel.nodeId2 = (u_short)model->node_id2; + outModel.nodeId3 = (u_short)model->node_id3; outModels.push_back(outModel); } @@ -365,9 +367,9 @@ int process_faces(const world_t* world, const TextureList& textures) writeMapData(outPlanes, outHeader.planes, fbsp); writeMapData(outNodes, outHeader.nodes, fbsp); writeMapData(outLeaves, outHeader.leaves, fbsp); - writeMapData(outLeafFaces, outHeader.leafFaces, fbsp); - writeMapData(outVisData, outHeader.visData, fbsp); writeMapData(outModels, outHeader.models, fbsp); + writeMapData(outLeafFaces, outHeader.leafFaces, fbsp); // TODO: should round these up to multiples of 4 bytes so as not to cause alignment issues with subsequent data sets + writeMapData(outVisData, outHeader.visData, fbsp); // Write final header fseek(fbsp, 0, SEEK_SET); diff --git a/ps1bsp.h b/ps1bsp.h index 157559d..6e4eaed 100644 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -154,8 +154,10 @@ typedef struct SVECTOR boundingSphere; SVECTOR origin; - u_short nodeId; - u_short clipNodeId; + u_short nodeId0; + u_short nodeId1; + u_short nodeId2; + u_short nodeId3; } ps1bsp_model_t; // Pre-parsed and encoded entity data (this runs the risk of becoming too bloated)