fix edge sharing

remove the "don't share edges if they have different contents" thing
This commit is contained in:
Jonathan 2022-07-10 03:21:36 -04:00
parent 8fc089aa34
commit f213f4aa45
2 changed files with 15 additions and 22 deletions

View File

@ -327,7 +327,7 @@ class mapentity_t;
struct face_fragment_t struct face_fragment_t
{ {
winding_t w; winding_t w;
std::vector<size_t> edges; // only filled in MakeFaceEdges std::vector<int64_t> edges; // only filled in MakeFaceEdges
std::optional<size_t> outputnumber; // only valid for original faces after std::optional<size_t> outputnumber; // only valid for original faces after
// write surfaces // write surfaces
}; };

View File

@ -65,9 +65,7 @@ struct hashvert_t
size_t num; size_t num;
}; };
using vertidx_t = size_t; static std::map<std::pair<size_t, size_t>, int64_t> hashedges;
using edgeidx_t = size_t;
static std::map<std::pair<vertidx_t, vertidx_t>, std::list<edgeidx_t>> hashedges;
static std::map<qvec3i, std::list<hashvert_t>> hashverts; static std::map<qvec3i, std::list<hashvert_t>> hashverts;
inline void InitHash() inline void InitHash()
@ -78,11 +76,6 @@ inline void InitHash()
hashedges.clear(); hashedges.clear();
} }
inline void AddHashEdge(size_t v1, size_t v2, size_t i)
{
hashedges[std::make_pair(v1, v2)].push_front(i);
}
inline qvec3i HashVec(const qvec3d &vec) inline qvec3i HashVec(const qvec3d &vec)
{ {
return {floor(vec[0]), floor(vec[1]), floor(vec[2])}; return {floor(vec[0]), floor(vec[1]), floor(vec[2])};
@ -141,6 +134,11 @@ inline size_t GetVertex(qvec3d vert)
//=========================================================================== //===========================================================================
inline void AddHashEdge(size_t v1, size_t v2, int64_t i)
{
hashedges.emplace(std::make_pair(v1, v2), i);
}
/* /*
================== ==================
GetEdge GetEdge
@ -150,7 +148,7 @@ Don't allow four way edges (FIXME: What is this?)
Returns a global edge number, possibly negative to indicate a backwards edge. Returns a global edge number, possibly negative to indicate a backwards edge.
================== ==================
*/ */
inline size_t GetEdge(mapentity_t *entity, const qvec3d &p1, const qvec3d &p2, const face_t *face) inline int64_t GetEdge(mapentity_t *entity, const qvec3d &p1, const qvec3d &p2, const face_t *face)
{ {
if (!face->contents.is_valid(options.target_game, false)) if (!face->contents.is_valid(options.target_game, false))
FError("Face with invalid contents"); FError("Face with invalid contents");
@ -158,21 +156,16 @@ inline size_t GetEdge(mapentity_t *entity, const qvec3d &p1, const qvec3d &p2, c
size_t v1 = GetVertex(p1); size_t v1 = GetVertex(p1);
size_t v2 = GetVertex(p2); size_t v2 = GetVertex(p2);
// search for an existing edge from v2->v1 // search for existing edges
const std::pair<int, int> edge_hash_key = std::make_pair(v2, v1); if (auto it = hashedges.find(std::make_pair(v1, v2)); it != hashedges.end()) {
return it->second;
auto it = hashedges.find(edge_hash_key); } else if (auto it = hashedges.find(std::make_pair(v2, v1)); it != hashedges.end()) {
if (it != hashedges.end()) { return -it->second;
for (const int i : it->second) {
if (pEdgeFaces1[i] == NULL && pEdgeFaces0[i]->contents.native == face->contents.native) {
pEdgeFaces1[i] = face;
return -i;
}
}
} }
/* emit an edge */ /* emit an edge */
size_t i = map.bsp.dedges.size(); int64_t i = map.bsp.dedges.size();
map.bsp.dedges.emplace_back(bsp2_dedge_t{static_cast<uint32_t>(v1), static_cast<uint32_t>(v2)}); map.bsp.dedges.emplace_back(bsp2_dedge_t{static_cast<uint32_t>(v1), static_cast<uint32_t>(v2)});
AddHashEdge(v1, v2, i); AddHashEdge(v1, v2, i);