From f43f9da361c7bed3942e36e16f52a97c4622a8e1 Mon Sep 17 00:00:00 2001 From: Garux Date: Wed, 18 Jan 2023 21:33:23 +0600 Subject: [PATCH] mbspc: * improve decompilation quality of Q1, HL maps greatly (texturing correctness, less brushes) #87 #92 --- tools/mbspc/mbspc/map_hl.c | 12 ++++++++---- tools/mbspc/mbspc/map_q1.c | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tools/mbspc/mbspc/map_hl.c b/tools/mbspc/mbspc/map_hl.c index c745aee1..6057f1a0 100644 --- a/tools/mbspc/mbspc/map_hl.c +++ b/tools/mbspc/mbspc/map_hl.c @@ -708,6 +708,8 @@ bspbrush_t *HL_TextureBrushes(bspbrush_t *brushlist, int modelnum) hl_miptex_t *miptex; bspbrush_t *brush, *nextbrush, *prevbrush, *newbrushes, *brushlistend; vec_t defaultvec[4] = {1, 0, 0, 0}; + const int firstFaceId = hl_dmodels[modelnum].firstface; + const int lastFaceId = firstFaceId + hl_dmodels[modelnum].numfaces; if (!modelnum) qprintf("texturing brushes\n"); if (!modelnum) qprintf("%5d brushes", numbrushes = 0); @@ -738,11 +740,13 @@ bspbrush_t *HL_TextureBrushes(bspbrush_t *brushlist, int modelnum) //least number of brushes if (!lessbrushes) { - for (i = 0; i < hl_numfaces; i++) + for (i = firstFaceId; i < lastFaceId; i++) { //the face must be in the same plane as the node plane that created //this brush side - if (hl_dfaces[i].planenum == hl_dnodes[sidenodenum].planenum) + if (hl_dfaces[i].planenum == hl_dnodes[sidenodenum].planenum + //and also on the plane side, where winding is + && (DotProduct( hl_dplanes[hl_dfaces[i].planenum].normal, mapplanes[side->planenum].normal) > 0) == !hl_dfaces[i].side) { //get the area the face and the brush side overlap area = HL_FaceOnWinding(&hl_dfaces[i], side->winding); @@ -797,13 +801,13 @@ bspbrush_t *HL_TextureBrushes(bspbrush_t *brushlist, int modelnum) } //end for //if the brush was split the original brush is removed //and we just continue with the next one in the list - if (i < hl_numfaces) break; + if (i < lastFaceId) break; } //end if else { //find the face with the largest overlap with this brush side //for texturing the brush side - for (i = 0; i < hl_numfaces; i++) + for (i = firstFaceId; i < lastFaceId; i++) { //the face must be in the same plane as the node plane that created //this brush side diff --git a/tools/mbspc/mbspc/map_q1.c b/tools/mbspc/mbspc/map_q1.c index 3649ffe9..24084cfd 100644 --- a/tools/mbspc/mbspc/map_q1.c +++ b/tools/mbspc/mbspc/map_q1.c @@ -764,6 +764,8 @@ bspbrush_t *Q1_TextureBrushes(bspbrush_t *brushlist, int modelnum) q1_miptex_t *miptex; bspbrush_t *brush, *nextbrush, *prevbrush, *newbrushes, *brushlistend; vec_t defaultvec[4] = {1, 0, 0, 0}; + const int firstFaceId = q1_dmodels[modelnum].firstface; + const int lastFaceId = firstFaceId + q1_dmodels[modelnum].numfaces; if (!modelnum) qprintf("texturing brushes\n"); if (!modelnum) qprintf("%5d brushes", numbrushes = 0); @@ -794,11 +796,13 @@ bspbrush_t *Q1_TextureBrushes(bspbrush_t *brushlist, int modelnum) //least number of brushes if (!lessbrushes) { - for (i = 0; i < q1_numfaces; i++) + for (i = firstFaceId; i < lastFaceId; i++) { //the face must be in the same plane as the node plane that created //this brush side - if (q1_dfaces[i].planenum == q1_dnodes[sidenodenum].planenum) + if (q1_dfaces[i].planenum == q1_dnodes[sidenodenum].planenum + //and also on the plane side, where winding is + && (DotProduct( q1_dplanes[q1_dfaces[i].planenum].normal, mapplanes[side->planenum].normal) > 0) == !q1_dfaces[i].side) { //get the area the face and the brush side overlap area = Q1_FaceOnWinding(&q1_dfaces[i], side->winding); @@ -853,13 +857,13 @@ bspbrush_t *Q1_TextureBrushes(bspbrush_t *brushlist, int modelnum) } //end for //if the brush was split the original brush is removed //and we just continue with the next one in the list - if (i < q1_numfaces) break; + if (i < lastFaceId) break; } //end if else { //find the face with the largest overlap with this brush side //for texturing the brush side - for (i = 0; i < q1_numfaces; i++) + for (i = firstFaceId; i < lastFaceId; i++) { //the face must be in the same plane as the node plane that created //this brush side