vis: code style updates
This commit is contained in:
parent
37fc62ca0e
commit
e3c6ace7ad
34
vis/flow.cc
34
vis/flow.cc
|
|
@ -2,7 +2,6 @@
|
||||||
#include <vis/leafbits.hh>
|
#include <vis/leafbits.hh>
|
||||||
#include <common/log.hh>
|
#include <common/log.hh>
|
||||||
#include <common/parallel.hh>
|
#include <common/parallel.hh>
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==============
|
==============
|
||||||
|
|
@ -27,28 +26,21 @@
|
||||||
static void ClipToSeparators(visstats_t &stats, const viswinding_t *source, const qplane3d src_pl, const viswinding_t *pass,
|
static void ClipToSeparators(visstats_t &stats, const viswinding_t *source, const qplane3d src_pl, const viswinding_t *pass,
|
||||||
viswinding_t *&target, unsigned int test, pstack_t &stack)
|
viswinding_t *&target, unsigned int test, pstack_t &stack)
|
||||||
{
|
{
|
||||||
size_t i, j, k, l;
|
|
||||||
qplane3d sep;
|
|
||||||
qvec3d v1, v2;
|
|
||||||
vec_t d;
|
|
||||||
int count;
|
|
||||||
bool fliptest;
|
|
||||||
vec_t len_sq;
|
|
||||||
|
|
||||||
// check all combinations
|
// check all combinations
|
||||||
for (i = 0; i < source->size(); i++) {
|
for (size_t i = 0; i < source->size(); i++) {
|
||||||
l = (i + 1) % source->size();
|
const size_t l = (i + 1) % source->size();
|
||||||
v1 = source->at(l) - source->at(i);
|
const qvec3d v1 = source->at(l) - source->at(i);
|
||||||
|
|
||||||
// find a vertex of pass that makes a plane that puts all of the
|
// find a vertex of pass that makes a plane that puts all of the
|
||||||
// vertexes of pass on the front side and all of the vertexes of
|
// vertexes of pass on the front side and all of the vertexes of
|
||||||
// source on the back side
|
// source on the back side
|
||||||
for (j = 0; j < pass->size(); j++) {
|
for (size_t j = 0; j < pass->size(); j++) {
|
||||||
|
|
||||||
// Which side of the source portal is this point?
|
// Which side of the source portal is this point?
|
||||||
// This also tells us which side of the separating plane has
|
// This also tells us which side of the separating plane has
|
||||||
// the source portal.
|
// the source portal.
|
||||||
d = src_pl.distance_to(pass->at(j));
|
bool fliptest;
|
||||||
|
vec_t d = src_pl.distance_to(pass->at(j));
|
||||||
if (d < -VIS_ON_EPSILON)
|
if (d < -VIS_ON_EPSILON)
|
||||||
fliptest = true;
|
fliptest = true;
|
||||||
else if (d > VIS_ON_EPSILON)
|
else if (d > VIS_ON_EPSILON)
|
||||||
|
|
@ -57,9 +49,10 @@ static void ClipToSeparators(visstats_t &stats, const viswinding_t *source, cons
|
||||||
continue; // Point lies in source plane
|
continue; // Point lies in source plane
|
||||||
|
|
||||||
// Make a plane with the three points
|
// Make a plane with the three points
|
||||||
v2 = pass->at(j) - source->at(i);
|
qplane3d sep;
|
||||||
|
const qvec3d v2 = pass->at(j) - source->at(i);
|
||||||
sep.normal = qv::cross(v1, v2);
|
sep.normal = qv::cross(v1, v2);
|
||||||
len_sq = qv::length2(sep.normal);
|
const vec_t len_sq = qv::length2(sep.normal);
|
||||||
|
|
||||||
// If points don't make a valid plane, skip it.
|
// If points don't make a valid plane, skip it.
|
||||||
if (len_sq < VIS_ON_EPSILON)
|
if (len_sq < VIS_ON_EPSILON)
|
||||||
|
|
@ -78,8 +71,9 @@ static void ClipToSeparators(visstats_t &stats, const viswinding_t *source, cons
|
||||||
// if all of the pass portal points are now on the positive side,
|
// if all of the pass portal points are now on the positive side,
|
||||||
// this is the separating plane
|
// this is the separating plane
|
||||||
//
|
//
|
||||||
count = 0;
|
int count = 0;
|
||||||
for (k = 0; k < pass->size(); k++) {
|
size_t k = 0;
|
||||||
|
for (; k < pass->size(); k++) {
|
||||||
if (k == j)
|
if (k == j)
|
||||||
continue;
|
continue;
|
||||||
d = sep.distance_to(pass->at(k));
|
d = sep.distance_to(pass->at(k));
|
||||||
|
|
@ -120,9 +114,7 @@ static void ClipToSeparators(visstats_t &stats, const viswinding_t *source, cons
|
||||||
|
|
||||||
static int CheckStack(leaf_t *leaf, threaddata_t *thread)
|
static int CheckStack(leaf_t *leaf, threaddata_t *thread)
|
||||||
{
|
{
|
||||||
pstack_t *p;
|
for (pstack_t *p = thread->pstack_head.next; p; p = p->next)
|
||||||
|
|
||||||
for (p = thread->pstack_head.next; p; p = p->next)
|
|
||||||
if (p->leaf == leaf)
|
if (p->leaf == leaf)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
79
vis/vis.cc
79
vis/vis.cc
|
|
@ -1,16 +1,16 @@
|
||||||
// vis.c
|
#include <vis/vis.hh>
|
||||||
|
|
||||||
|
#include <vis/leafbits.hh>
|
||||||
|
#include <common/log.hh>
|
||||||
|
#include <common/bsputils.hh>
|
||||||
|
#include <common/fs.hh>
|
||||||
|
#include <common/parallel.hh>
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <bit> // for std::countr_zero
|
#include <bit> // for std::countr_zero
|
||||||
#include <numeric> // for std::accumulate
|
#include <numeric> // for std::accumulate
|
||||||
|
|
||||||
#include <vis/leafbits.hh>
|
|
||||||
#include <vis/vis.hh>
|
|
||||||
#include <common/log.hh>
|
|
||||||
#include <common/bsputils.hh>
|
|
||||||
#include <common/fs.hh>
|
|
||||||
#include <common/parallel.hh>
|
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -116,8 +116,7 @@ viswinding_t *ClipStackWinding(visstats_t &stats, viswinding_t *in, pstack_t &st
|
||||||
{
|
{
|
||||||
vec_t dists[MAX_WINDING + 1];
|
vec_t dists[MAX_WINDING + 1];
|
||||||
int sides[MAX_WINDING + 1];
|
int sides[MAX_WINDING + 1];
|
||||||
int counts[3];
|
size_t i;
|
||||||
size_t i, j;
|
|
||||||
|
|
||||||
/* Fast test first */
|
/* Fast test first */
|
||||||
vec_t dot = split.distance_to(in->origin);
|
vec_t dot = split.distance_to(in->origin);
|
||||||
|
|
@ -131,7 +130,7 @@ viswinding_t *ClipStackWinding(visstats_t &stats, viswinding_t *in, pstack_t &st
|
||||||
if (in->size() > MAX_WINDING)
|
if (in->size() > MAX_WINDING)
|
||||||
FError("in->numpoints > MAX_WINDING ({} > {})", in->size(), MAX_WINDING);
|
FError("in->numpoints > MAX_WINDING ({} > {})", in->size(), MAX_WINDING);
|
||||||
|
|
||||||
counts[0] = counts[1] = counts[2] = 0;
|
int counts[3] = {0, 0, 0};
|
||||||
|
|
||||||
/* determine sides for each point */
|
/* determine sides for each point */
|
||||||
for (i = 0; i < in->size(); i++) {
|
for (i = 0; i < in->size(); i++) {
|
||||||
|
|
@ -191,7 +190,7 @@ viswinding_t *ClipStackWinding(visstats_t &stats, viswinding_t *in, pstack_t &st
|
||||||
const qvec3d &p2 = (*in)[(i + 1) % in->size()];
|
const qvec3d &p2 = (*in)[(i + 1) % in->size()];
|
||||||
qvec3d mid;
|
qvec3d mid;
|
||||||
vec_t fraction = dists[i] / (dists[i] - dists[i + 1]);
|
vec_t fraction = dists[i] / (dists[i] - dists[i + 1]);
|
||||||
for (j = 0; j < 3; j++) {
|
for (size_t j = 0; j < 3; j++) {
|
||||||
/* avoid round off error when possible */
|
/* avoid round off error when possible */
|
||||||
if (split.normal[j] == 1)
|
if (split.normal[j] == 1)
|
||||||
mid[j] = split.dist;
|
mid[j] = split.dist;
|
||||||
|
|
@ -295,11 +294,6 @@ static void UpdateMightsee(visstats_t &stats, const leaf_t &source, const leaf_t
|
||||||
*/
|
*/
|
||||||
static void PortalCompleted(visstats_t &stats, visportal_t *completed)
|
static void PortalCompleted(visstats_t &stats, visportal_t *completed)
|
||||||
{
|
{
|
||||||
int i, j, k, bit, numblocks;
|
|
||||||
int leafnum;
|
|
||||||
const visportal_t *p, *p2;
|
|
||||||
uint32_t changed;
|
|
||||||
|
|
||||||
portal_mutex.lock();
|
portal_mutex.lock();
|
||||||
|
|
||||||
completed->status = pstat_done;
|
completed->status = pstat_done;
|
||||||
|
|
@ -309,16 +303,16 @@ static void PortalCompleted(visstats_t &stats, visportal_t *completed)
|
||||||
* mightsee during the full vis so far.
|
* mightsee during the full vis so far.
|
||||||
*/
|
*/
|
||||||
const leaf_t &myleaf = leafs[completed->leaf];
|
const leaf_t &myleaf = leafs[completed->leaf];
|
||||||
for (i = 0; i < myleaf.numportals; i++) {
|
for (int i = 0; i < myleaf.numportals; i++) {
|
||||||
p = myleaf.portals[i];
|
const visportal_t *p = myleaf.portals[i];
|
||||||
if (p->status != pstat_done)
|
if (p->status != pstat_done)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto might = p->mightsee.data();
|
auto might = p->mightsee.data();
|
||||||
auto vis = p->visbits.data();
|
auto vis = p->visbits.data();
|
||||||
numblocks = (portalleafs + leafbits_t::mask) >> leafbits_t::shift;
|
int numblocks = (portalleafs + leafbits_t::mask) >> leafbits_t::shift;
|
||||||
for (j = 0; j < numblocks; j++) {
|
for (int j = 0; j < numblocks; j++) {
|
||||||
changed = might[j] & ~vis[j];
|
uint32_t changed = might[j] & ~vis[j];
|
||||||
if (!changed)
|
if (!changed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
@ -326,10 +320,10 @@ static void PortalCompleted(visstats_t &stats, visportal_t *completed)
|
||||||
* If any of these changed bits are still visible from another
|
* If any of these changed bits are still visible from another
|
||||||
* portal, we can't update yet.
|
* portal, we can't update yet.
|
||||||
*/
|
*/
|
||||||
for (k = 0; k < myleaf.numportals; k++) {
|
for (int k = 0; k < myleaf.numportals; k++) {
|
||||||
if (k == i)
|
if (k == i)
|
||||||
continue;
|
continue;
|
||||||
p2 = myleaf.portals[k];
|
const visportal_t *p2 = myleaf.portals[k];
|
||||||
if (p2->status == pstat_done)
|
if (p2->status == pstat_done)
|
||||||
changed &= ~p2->visbits.data()[j];
|
changed &= ~p2->visbits.data()[j];
|
||||||
else
|
else
|
||||||
|
|
@ -342,9 +336,9 @@ static void PortalCompleted(visstats_t &stats, visportal_t *completed)
|
||||||
* Update mightsee for any of the changed bits that survived
|
* Update mightsee for any of the changed bits that survived
|
||||||
*/
|
*/
|
||||||
while (changed) {
|
while (changed) {
|
||||||
bit = std::countr_zero(changed);
|
int bit = std::countr_zero(changed);
|
||||||
changed &= ~nth_bit(bit);
|
changed &= ~nth_bit(bit);
|
||||||
leafnum = (j << leafbits_t::shift) + bit;
|
int leafnum = (j << leafbits_t::shift) + bit;
|
||||||
UpdateMightsee(stats, leafs[leafnum], myleaf);
|
UpdateMightsee(stats, leafs[leafnum], myleaf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -363,8 +357,6 @@ static duration stateinterval;
|
||||||
*/
|
*/
|
||||||
static visstats_t LeafThread()
|
static visstats_t LeafThread()
|
||||||
{
|
{
|
||||||
visportal_t *p;
|
|
||||||
|
|
||||||
portal_mutex.lock();
|
portal_mutex.lock();
|
||||||
/* Save state if sufficient time has elapsed */
|
/* Save state if sufficient time has elapsed */
|
||||||
auto now = I_FloatTime();
|
auto now = I_FloatTime();
|
||||||
|
|
@ -374,7 +366,7 @@ static visstats_t LeafThread()
|
||||||
}
|
}
|
||||||
portal_mutex.unlock();
|
portal_mutex.unlock();
|
||||||
|
|
||||||
p = GetNextPortal();
|
visportal_t *p = GetNextPortal();
|
||||||
if (!p)
|
if (!p)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
@ -401,22 +393,16 @@ static std::vector<uint8_t> compressed;
|
||||||
|
|
||||||
static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
||||||
{
|
{
|
||||||
leaf_t *leaf;
|
|
||||||
uint8_t *outbuffer;
|
|
||||||
int i, j;
|
|
||||||
int numvis, numblocks;
|
|
||||||
const visportal_t *p;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Collect visible bits from all portals into buffer
|
* Collect visible bits from all portals into buffer
|
||||||
*/
|
*/
|
||||||
leaf = &leafs[clusternum];
|
leaf_t *leaf = &leafs[clusternum];
|
||||||
numblocks = (portalleafs + leafbits_t::mask) >> leafbits_t::shift;
|
int numblocks = (portalleafs + leafbits_t::mask) >> leafbits_t::shift;
|
||||||
for (i = 0; i < leaf->numportals; i++) {
|
for (int i = 0; i < leaf->numportals; i++) {
|
||||||
p = leaf->portals[i];
|
const visportal_t *p = leaf->portals[i];
|
||||||
if (p->status != pstat_done)
|
if (p->status != pstat_done)
|
||||||
FError("portal not done");
|
FError("portal not done");
|
||||||
for (j = 0; j < numblocks; j++)
|
for (int j = 0; j < numblocks; j++)
|
||||||
buffer.data()[j] |= p->visbits.data()[j];
|
buffer.data()[j] |= p->visbits.data()[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -430,11 +416,12 @@ static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
||||||
/*
|
/*
|
||||||
* Now expand the clusters into the full leaf visibility map
|
* Now expand the clusters into the full leaf visibility map
|
||||||
*/
|
*/
|
||||||
numvis = 0;
|
int numvis = 0;
|
||||||
|
|
||||||
|
uint8_t *outbuffer;
|
||||||
if (bsp->loadversion->game->id == GAME_QUAKE_II) {
|
if (bsp->loadversion->game->id == GAME_QUAKE_II) {
|
||||||
outbuffer = uncompressed.data() + clusternum * leafbytes;
|
outbuffer = uncompressed.data() + clusternum * leafbytes;
|
||||||
for (i = 0; i < portalleafs; i++) {
|
for (int i = 0; i < portalleafs; i++) {
|
||||||
if (buffer[i]) {
|
if (buffer[i]) {
|
||||||
outbuffer[i >> 3] |= nth_bit(i & 7);
|
outbuffer[i >> 3] |= nth_bit(i & 7);
|
||||||
numvis++;
|
numvis++;
|
||||||
|
|
@ -442,7 +429,7 @@ static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outbuffer = uncompressed.data() + clusternum * leafbytes_real;
|
outbuffer = uncompressed.data() + clusternum * leafbytes_real;
|
||||||
for (i = 0; i < portalleafs_real; i++) {
|
for (int i = 0; i < portalleafs_real; i++) {
|
||||||
if (buffer[bsp->dleafs[i + 1].cluster]) {
|
if (buffer[bsp->dleafs[i + 1].cluster]) {
|
||||||
outbuffer[i >> 3] |= nth_bit(i & 7);
|
outbuffer[i >> 3] |= nth_bit(i & 7);
|
||||||
numvis++;
|
numvis++;
|
||||||
|
|
@ -463,7 +450,7 @@ static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
||||||
// FIXME: not sure what this is supposed to be?
|
// FIXME: not sure what this is supposed to be?
|
||||||
totalvis += numvis;
|
totalvis += numvis;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < portalleafs_real; i++) {
|
for (int i = 0; i < portalleafs_real; i++) {
|
||||||
if (bsp->dleafs[i + 1].cluster == clusternum) {
|
if (bsp->dleafs[i + 1].cluster == clusternum) {
|
||||||
totalvis += numvis;
|
totalvis += numvis;
|
||||||
}
|
}
|
||||||
|
|
@ -486,7 +473,7 @@ static void ClusterFlow(int clusternum, leafbits_t &buffer, mbsp_t *bsp)
|
||||||
|
|
||||||
// Set pointers
|
// Set pointers
|
||||||
if (bsp->loadversion->game->id != GAME_QUAKE_II) {
|
if (bsp->loadversion->game->id != GAME_QUAKE_II) {
|
||||||
for (i = 0; i < portalleafs_real; i++) {
|
for (int i = 0; i < portalleafs_real; i++) {
|
||||||
if (bsp->dleafs[i + 1].cluster == clusternum) {
|
if (bsp->dleafs[i + 1].cluster == clusternum) {
|
||||||
bsp->dleafs[i + 1].visofs = visofs;
|
bsp->dleafs[i + 1].visofs = visofs;
|
||||||
}
|
}
|
||||||
|
|
@ -552,8 +539,6 @@ visstats_t CalcPortalVis(const mbsp_t *bsp)
|
||||||
*/
|
*/
|
||||||
visstats_t CalcVis(mbsp_t *bsp)
|
visstats_t CalcVis(mbsp_t *bsp)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if (LoadVisState()) {
|
if (LoadVisState()) {
|
||||||
logging::print("Loaded previous state. Resuming progress...\n");
|
logging::print("Loaded previous state. Resuming progress...\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -569,7 +554,7 @@ visstats_t CalcVis(mbsp_t *bsp)
|
||||||
//
|
//
|
||||||
logging::print("Expanding clusters...\n");
|
logging::print("Expanding clusters...\n");
|
||||||
leafbits_t buffer(portalleafs);
|
leafbits_t buffer(portalleafs);
|
||||||
for (i = 0; i < portalleafs; i++) {
|
for (int i = 0; i < portalleafs; i++) {
|
||||||
ClusterFlow(i, buffer, bsp);
|
ClusterFlow(i, buffer, bsp);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue