vis: parallel CalcAmbientSounds

This commit is contained in:
Eric Wasylishen 2023-06-19 18:41:05 -06:00
parent 010fbe5a3b
commit 50c1e38a27
1 changed files with 30 additions and 22 deletions

View File

@ -20,7 +20,7 @@
#include <common/log.hh> #include <common/log.hh>
#include <vis/vis.hh> #include <vis/vis.hh>
#include <common/bsputils.hh> #include <common/bsputils.hh>
#include <common/parallel.hh>
/* /*
Some textures (sky, water, slime, lava) are considered ambien sound emiters. Some textures (sky, water, slime, lava) are considered ambien sound emiters.
@ -60,45 +60,51 @@ void CalcAmbientSounds(mbsp_t *bsp)
{ {
logging::funcheader(); logging::funcheader();
const mface_t *surf; // fast path for -noambient
const mtexinfo_t *info; if (vis_options.noambientsky.value() && vis_options.noambientwater.value() && vis_options.noambientslime.value() &&
int i, j, k, l; vis_options.noambientlava.value()) {
mleaf_t *leaf, *hit; for (int i = 0; i < portalleafs_real; i++) {
uint8_t *vis; mleaf_t *leaf = &bsp->dleafs[i + 1];
float d, maxd; for (int j = 0; j < NUM_AMBIENTS; j++) {
ambient_type_t ambient_type; leaf->ambient_level[j] = 0;
float dists[NUM_AMBIENTS]; }
float vol; }
return;
}
for (i = 0; i < portalleafs_real; i++) { logging::parallel_for(0, portalleafs_real, [&bsp](int i) {
leaf = &bsp->dleafs[i + 1]; mleaf_t *leaf = &bsp->dleafs[i + 1];
float dists[NUM_AMBIENTS];
// //
// clear ambients // clear ambients
// //
for (j = 0; j < NUM_AMBIENTS; j++) for (int j = 0; j < NUM_AMBIENTS; j++)
dists[j] = 1020; dists[j] = 1020;
uint8_t *vis;
if (portalleafs != portalleafs_real) { if (portalleafs != portalleafs_real) {
vis = &uncompressed[leaf->cluster * leafbytes_real]; vis = &uncompressed[leaf->cluster * leafbytes_real];
} else { } else {
vis = &uncompressed[i * leafbytes_real]; vis = &uncompressed[i * leafbytes_real];
} }
for (j = 0; j < portalleafs_real; j++) { for (int j = 0; j < portalleafs_real; j++) {
if (!(vis[j >> 3] & nth_bit(j & 7))) if (!(vis[j >> 3] & nth_bit(j & 7)))
continue; continue;
// //
// check this leaf for sound textures // check this leaf for sound textures
// //
hit = &bsp->dleafs[j + 1]; mleaf_t *hit = &bsp->dleafs[j + 1];
for (k = 0; k < hit->nummarksurfaces; k++) { for (int k = 0; k < hit->nummarksurfaces; k++) {
surf = BSP_GetFace(bsp, bsp->dleaffaces[hit->firstmarksurface + k]); const mface_t *surf = BSP_GetFace(bsp, bsp->dleaffaces[hit->firstmarksurface + k]);
info = &bsp->texinfo[surf->texinfo]; const mtexinfo_t *info = &bsp->texinfo[surf->texinfo];
const auto &miptex = bsp->dtex.textures[info->miptex]; const auto &miptex = bsp->dtex.textures[info->miptex];
ambient_type_t ambient_type;
if (!Q_strncasecmp(miptex.name.data(), "sky", 3) && !vis_options.noambientsky.value()) if (!Q_strncasecmp(miptex.name.data(), "sky", 3) && !vis_options.noambientsky.value())
ambient_type = AMBIENT_SKY; ambient_type = AMBIENT_SKY;
else if (!Q_strncasecmp(miptex.name.data(), "*water", 6) && !vis_options.noambientwater.value()) else if (!Q_strncasecmp(miptex.name.data(), "*water", 6) && !vis_options.noambientwater.value())
@ -114,8 +120,9 @@ void CalcAmbientSounds(mbsp_t *bsp)
// find distance from source leaf to polygon // find distance from source leaf to polygon
aabb3d bounds = SurfaceBBox(bsp, surf); aabb3d bounds = SurfaceBBox(bsp, surf);
maxd = 0; float maxd = 0;
for (l = 0; l < 3; l++) { for (int l = 0; l < 3; l++) {
float d;
if (bounds.mins()[l] > leaf->maxs[l]) if (bounds.mins()[l] > leaf->maxs[l])
d = bounds.mins()[l] - leaf->maxs[l]; d = bounds.mins()[l] - leaf->maxs[l];
else if (bounds.maxs()[l] < leaf->mins[l]) else if (bounds.maxs()[l] < leaf->mins[l])
@ -132,7 +139,8 @@ void CalcAmbientSounds(mbsp_t *bsp)
} }
} }
for (j = 0; j < NUM_AMBIENTS; j++) { for (int j = 0; j < NUM_AMBIENTS; j++) {
float vol;
if (dists[j] < 100) if (dists[j] < 100)
vol = 1.0; vol = 1.0;
else { else {
@ -142,7 +150,7 @@ void CalcAmbientSounds(mbsp_t *bsp)
} }
leaf->ambient_level[j] = (uint8_t)(vol * 255); leaf->ambient_level[j] = (uint8_t)(vol * 255);
} }
} });
} }
/* /*