diff --git a/common/log.cc b/common/log.cc index 08a917c8..c9a53027 100644 --- a/common/log.cc +++ b/common/log.cc @@ -64,6 +64,10 @@ static std::mutex print_mutex; void print(flag logflag, const char *str) { + if (!(mask & logflag)) { + return; + } + print_mutex.lock(); if (logflag != flag::PERCENT) { @@ -88,7 +92,7 @@ void print(flag logflag, const char *str) static time_point start_time; static bool is_timing = false; -void percent(uint64_t count, uint64_t max) +void percent(uint64_t count, uint64_t max, bool displayElapsed) { if (!is_timing) { start_time = I_FloatTime(); @@ -98,7 +102,9 @@ void percent(uint64_t count, uint64_t max) if (count == max) { auto elapsed = I_FloatTime() - start_time; is_timing = false; - print(flag::PERCENT, "[100%] time elapsed: {:.3}\n", elapsed); + if (displayElapsed) { + print(flag::PERCENT, "[100%] time elapsed: {:.3}\n", elapsed); + } } else { print(flag::PERCENT, "[{:>3}%]\r", static_cast((static_cast(count) / max) * 100)); } diff --git a/include/common/log.hh b/include/common/log.hh index c7351795..010ece5d 100644 --- a/include/common/log.hh +++ b/include/common/log.hh @@ -109,5 +109,5 @@ inline void assert_(bool success, const char *expr, const char *file, int line) // bar will "finish" and be inoperable. // Only use this by hand if you absolutely need to; otherwise, // use 's parallel_for(_each) -void percent(uint64_t count, uint64_t max); +void percent(uint64_t count, uint64_t max, bool displayElapsed = true); }; \ No newline at end of file diff --git a/include/common/polylib.hh b/include/common/polylib.hh index 63f6716c..28be710f 100644 --- a/include/common/polylib.hh +++ b/include/common/polylib.hh @@ -381,6 +381,7 @@ public: } count = new_size; + isVector = count > N; } void clear() diff --git a/light/phong.cc b/light/phong.cc index 0e005b5e..caf83c66 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -451,6 +451,29 @@ void CalculateVertexNormals(const mbsp_t *bsp) // build the "face -> faces to smooth with" map for (auto &f : bsp->dfaces) { + // Q2 shading groups + const int f_phongValue = Q2_FacePhongValue(bsp, &f); + if (f_phongValue) { + for (int j = 0; j < f.numedges; j++) { + const int v = Face_VertexAtIndex(bsp, &f, j); + // walk over all faces incident to f (we will walk over neighbours multiple times, doesn't matter) + for (const mface_t *f2 : vertsToFaces[v]) { + if (f2 == &f) + continue; + + const int f2_phongValue = Q2_FacePhongValue(bsp, f2); + if (f_phongValue != f2_phongValue) + continue; + + // we've already checked f_phongValue is nonzero, so smooth these two faces. + smoothFaces[&f].insert(f2); + } + } + + continue; + } + + // Q1 phong angle stuff const auto f_points = GLM_FacePoints(bsp, &f); const qvec3d f_norm = Face_Normal(bsp, &f); const qplane3d f_plane = Face_Plane(bsp, &f); @@ -504,30 +527,6 @@ void CalculateVertexNormals(const mbsp_t *bsp) } } - // Q2: build the "face -> faces to smooth with" map - // FIXME: merge this into the above loop - for (auto &f : bsp->dfaces) { - const int f_phongValue = Q2_FacePhongValue(bsp, &f); - if (f_phongValue == 0) - continue; - - for (int j = 0; j < f.numedges; j++) { - const int v = Face_VertexAtIndex(bsp, &f, j); - // walk over all faces incident to f (we will walk over neighbours multiple times, doesn't matter) - for (const mface_t *f2 : vertsToFaces[v]) { - if (f2 == &f) - continue; - - const int f2_phongValue = Q2_FacePhongValue(bsp, f2); - if (f_phongValue != f2_phongValue) - continue; - - // we've already checked f_phongValue is nonzero, so smooth these two faces. - smoothFaces[&f].insert(f2); - } - } - } - logging::print(logging::flag::VERBOSE, " {} faces for smoothing\n", smoothFaces.size()); // finally do the smoothing for each face diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 81c44b85..794bb906 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -1003,7 +1003,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int dst->bounds += brush->bounds; } - logging::percent(src->nummapbrushes, src->nummapbrushes); + logging::percent(src->nummapbrushes, src->nummapbrushes, src == pWorldEnt()); } /* diff --git a/qbsp/portals.cc b/qbsp/portals.cc index ff538844..ffd591be 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -622,7 +622,8 @@ void PortalizeWorld(const mapentity_t *entity, node_t *headnode, const int hulln MakeHeadnodePortals(entity, headnode); CutNodePortals_r(headnode, &state); - logging::percent(splitnodes, splitnodes); + + logging::percent(splitnodes, splitnodes, entity == pWorldEnt()); if (hullnum <= 0) { /* save portal file for vis tracing */ diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index b87db374..e07b78d1 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -731,7 +731,7 @@ static void PartitionSurfaces(std::vector &surfaces, node_t *node) LinkConvexFaces(surfaces, node); return; } - + logging::percent(splitnodes++, csgmergefaces); node->facelist = LinkNodeFaces(*split); @@ -826,7 +826,8 @@ node_t *SolidBSP(const mapentity_t *entity, std::vector &surfhead, bo mapsurfaces = surfhead.size(); PartitionSurfaces(surfhead, headnode); - logging::percent(csgmergefaces, csgmergefaces); + + logging::percent(csgmergefaces, csgmergefaces, entity == pWorldEnt()); logging::print(logging::flag::STAT, " {:8} split nodes\n", splitnodes.load()); logging::print(logging::flag::STAT, " {:8} solid leafs\n", c_solid.load()); diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 90c5a98c..1c4a7aba 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -104,7 +104,7 @@ std::list::iterator SubdivideFace(std::list::iterator it, st std::tie(front, back) = SplitFace(f, plane); if (!front || !back) { - logging::print("didn't split\n"); + //logging::print("didn't split\n"); break; // FError("Didn't split the polygon"); } @@ -355,7 +355,7 @@ static int MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress) FindFaceEdges(entity, f); } - logging::percent(++progress, splitnodes.load()); + logging::percent(progress, splitnodes, entity); progress = MakeFaceEdges_r(entity, node->children[0], progress); progress = MakeFaceEdges_r(entity, node->children[1], progress); @@ -495,6 +495,7 @@ int MakeFaceEdges(mapentity_t *entity, node_t *headnode) firstface = static_cast(map.bsp.dfaces.size()); MakeFaceEdges_r(entity, headnode, 0); + logging::percent(splitnodes, splitnodes, entity == pWorldEnt()); pEdgeFaces0.clear(); pEdgeFaces1.clear();