From 76a77ed8150790036e2cccbc90aa5d245664ee09 Mon Sep 17 00:00:00 2001 From: wootguy Date: Sat, 20 Apr 2024 16:40:08 -0700 Subject: [PATCH] fix map merger moving maps that don't overlap --- src/bsp/BspMerger.cpp | 39 ++++++++++++++++++++++++--------------- src/bsp/BspMerger.h | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/bsp/BspMerger.cpp b/src/bsp/BspMerger.cpp index a6d8175b..18354bb6 100644 --- a/src/bsp/BspMerger.cpp +++ b/src/bsp/BspMerger.cpp @@ -149,8 +149,8 @@ vector>> BspMerger::separate(vector& maps, vec3 ga bool noOverlap = true; for (int i = 0; i < blocks.size() && noOverlap; i++) { - for (int k = i + i; k < blocks.size(); k++) { - if (blocks[i].intersects(blocks[k])) { + for (int k = 0; k < blocks.size(); k++) { + if (i != k && blocks[i].intersects(blocks[k])) { noOverlap = false; break; } @@ -158,7 +158,16 @@ vector>> BspMerger::separate(vector& maps, vec3 ga } if (noOverlap) { - logf("Maps do not overlap. They will be merged without moving."); + logf("Maps do not overlap. They will be merged without moving.\n"); + + vector> col; + vector row; + for (const MAPBLOCK& block : blocks) { + row.push_back(block); + } + col.push_back(row); + orderedBlocks.push_back(col); + return orderedBlocks; } @@ -201,21 +210,21 @@ vector>> BspMerger::separate(vector& maps, vec3 ga for (int z = 0; z < idealMapsPerAxis && blockIdx < blocks.size(); z++) { targetMins.y = mergedMapMin.y; vector> col; - for (int y = 0; y < idealMapsPerAxis && blockIdx < blocks.size(); y++) { - targetMins.x = mergedMapMin.x; - vector row; - for (int x = 0; x < idealMapsPerAxis && blockIdx < blocks.size(); x++) { - MAPBLOCK& block = blocks[blockIdx]; + for (int y = 0; y < idealMapsPerAxis && blockIdx < blocks.size(); y++) { + targetMins.x = mergedMapMin.x; + vector row; + for (int x = 0; x < idealMapsPerAxis && blockIdx < blocks.size(); x++) { + MAPBLOCK& block = blocks[blockIdx]; - block.offset = targetMins - block.mins; - //logf("block %d: %.0f %.0f %.0f\n", blockIdx, targetMins.x, targetMins.y, targetMins.z); - //logf("%s offset: %.0f %.0f %.0f\n", block.map->name.c_str(), block.offset.x, block.offset.y, block.offset.z); + block.offset = targetMins - block.mins; + //logf("block %d: %.0f %.0f %.0f\n", blockIdx, targetMins.x, targetMins.y, targetMins.z); + //logf("%s offset: %.0f %.0f %.0f\n", block.map->name.c_str(), block.offset.x, block.offset.y, block.offset.z); - row.push_back(block); + row.push_back(block); - blockIdx++; - targetMins.x += maxDims.x; - } + blockIdx++; + targetMins.x += maxDims.x; + } col.push_back(row); targetMins.y += maxDims.y; } diff --git a/src/bsp/BspMerger.h b/src/bsp/BspMerger.h index 2ca46348..8a22f4ac 100644 --- a/src/bsp/BspMerger.h +++ b/src/bsp/BspMerger.h @@ -11,7 +11,7 @@ struct MAPBLOCK bool intersects(MAPBLOCK& other) { return (mins.x <= other.maxs.x && maxs.x >= other.mins.x) && (mins.y <= other.maxs.y && maxs.y >= other.mins.y) && - (mins.z <= other.maxs.z && maxs.y >= other.mins.z); + (mins.z <= other.maxs.z && maxs.z >= other.mins.z); } };