From 624c8b5d6f6945732160974209d2b72a13062ae5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 5 Jan 2024 06:40:16 +0100 Subject: [PATCH 1/2] optimize camera mobj z stuff lol idk wanna see if this does anything --- src/p_mobj.c | 4 ++-- src/r_main.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/r_main.h | 1 + 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 5ad802f92..fe226b054 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -944,7 +944,7 @@ fixed_t P_CameraFloorZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, fix testy += y; // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy)) return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point @@ -1020,7 +1020,7 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f testy += y; // If the highest point is in the sector, then we have it easy! Just get the Z at that point - if (R_PointInSubsector(testx, testy)->sector == (boundsec ? boundsec : sector)) + if (R_IsPointInSector(boundsec ? boundsec : sector, testx, testy)) return P_GetZAt(slope, testx, testy); // If boundsec is set, we're looking for specials. In that case, iterate over every line in this sector to find the TRUE highest/lowest point diff --git a/src/r_main.c b/src/r_main.c index 44c388ec8..424346b95 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1049,6 +1049,48 @@ void R_Init(void) framecount = 0; } + +// +// R_IsPointInSector +// +boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y) +{ + size_t i; + size_t passes = 0; + + for (i = 0; i < sector->linecount; i++) + { + vertex_t *v1, *v2; + + v1 = sector->lines[i]->v1; + v2 = sector->lines[i]->v2; + + // make sure v1 is below v2 + if (v1->y > v2->y) + { + vertex_t *tmp = v1; + v1 = v2; + v2 = tmp; + } + else if (v1->y == v2->y) + // horizontal line, we can't match this + continue; + + if (v1->y <= y && y < v2->y) + { + // if the y axis in inside the line, find the point where we intersect on the x axis... + fixed_t vx = v1->x + (INT64)(v2->x - v1->x) * (y - v1->y) / (v2->y - v1->y); + + // ...and if that point is to the left of the point, count it as inside. + if (vx < x) + passes++; + } + } + + // and odd number of passes means we're inside the polygon. + return passes % 2; +} + // // R_PointInSubsector // diff --git a/src/r_main.h b/src/r_main.h index dadb1c9cf..3df5bd088 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -76,6 +76,7 @@ fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); +boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y); subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); -- 2.54.0 From 8900bf9edda4add9f0f31a05f18248da563f8cd1 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Feb 2024 21:15:09 +0100 Subject: [PATCH 2/2] Fix final edge cases in sector points --- src/r_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 424346b95..29a46cc72 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1060,10 +1060,14 @@ boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y) for (i = 0; i < sector->linecount; i++) { + line_t *line = sector->lines[i]; vertex_t *v1, *v2; - v1 = sector->lines[i]->v1; - v2 = sector->lines[i]->v2; + if (line->frontsector == line->backsector) + continue; + + v1 = line->v1; + v2 = line->v2; // make sure v1 is below v2 if (v1->y > v2->y) @@ -1076,7 +1080,7 @@ boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y) // horizontal line, we can't match this continue; - if (v1->y <= y && y < v2->y) + if (v1->y < y && y <= v2->y) { // if the y axis in inside the line, find the point where we intersect on the x axis... fixed_t vx = v1->x + (INT64)(v2->x - v1->x) * (y - v1->y) / (v2->y - v1->y); @@ -1091,6 +1095,7 @@ boolean R_IsPointInSector(sector_t *sector, fixed_t x, fixed_t y) return passes % 2; } + // // R_PointInSubsector // -- 2.54.0