From 19f8ac81105c333a589ed7d1499cf36be9d778b3 Mon Sep 17 00:00:00 2001 From: tk Date: Sat, 19 Sep 2020 04:11:38 +0300 Subject: [PATCH] Add -visdist param from bjptools (#300) * Add support for -visdist param from bjp tools * add mention to man Co-authored-by: Shpuld Shpuldson --- include/vis/vis.hh | 1 + man/vis.1 | 2 ++ vis/flow.cc | 27 +++++++++++++++++++++++++++ vis/vis.cc | 5 +++++ 4 files changed, 35 insertions(+) diff --git a/include/vis/vis.hh b/include/vis/vis.hh index f9f9eb6f..b50d81cd 100644 --- a/include/vis/vis.hh +++ b/include/vis/vis.hh @@ -124,6 +124,7 @@ extern qboolean ambientsky; extern qboolean ambientwater; extern qboolean ambientslime; extern qboolean ambientlava; +extern int visdist; extern byte *uncompressed; extern int leafbytes; diff --git a/man/vis.1 b/man/vis.1 index f0c707c6..7b7dcbbb 100644 --- a/man/vis.1 +++ b/man/vis.1 @@ -51,6 +51,8 @@ Disable ambient sound generation for textures with names beginning with '*LAVA'. .IP "\fB-noambient\fP" Disable all ambient sound generation. +.IP "\fB-visdist n\fP" +Allow culling of areas further than n units. .SH AUTHOR Kevin Shanahan (aka Tyrann) - http://disenchant.net diff --git a/vis/flow.cc b/vis/flow.cc index 85dd94ce..75bb120d 100644 --- a/vis/flow.cc +++ b/vis/flow.cc @@ -417,6 +417,28 @@ SimpleFlood(portal_t *srcportal, int leafnum, byte *portalsee) } } +/* + ============================================================================ + Used for visdist to get the distance from a winding to a portal + ============================================================================ +*/ + +float +distFromWinding(winding_t *w, portal_t *p) +{ + float dist, mindist; + mindist = 1e20; + + for (int i = 0; i < w->numpoints; ++i) { + dist = fabs(DotProduct(w->points[i], p->plane.normal) - p->plane.dist); + + if (dist < mindist) + mindist = dist; + } + return mindist; +} + + /* ============== BasePortalVis @@ -479,6 +501,11 @@ BasePortalThread(void *dummy) if (j == w->numpoints) continue; // no points on back + if (visdist > 0) { + if (distFromWinding(tp->winding, p) > visdist || distFromWinding(p->winding, tp) > visdist) + continue; + } + portalsee[i] = 1; } diff --git a/vis/vis.cc b/vis/vis.cc index a61b9c2d..c0ca1394 100644 --- a/vis/vis.cc +++ b/vis/vis.cc @@ -47,6 +47,7 @@ qboolean ambientsky = true; qboolean ambientwater = true; qboolean ambientslime = true; qboolean ambientlava = true; +int visdist = 0; #if 0 void @@ -1269,6 +1270,10 @@ main(int argc, char **argv) ambientwater = false; ambientslime = false; ambientlava = false; + } else if (!strcmp(argv[i], "-visdist")) { + visdist = atoi(argv[i+1]); + i++; + logprint("visdist = %i\n", visdist); } else if (argv[i][0] == '-') Error("Unknown option \"%s\"", argv[i]); else