build: only use <fmt/core.h>, other headers have a heavy compilation time impact

This commit is contained in:
Eric Wasylishen 2023-07-02 17:08:14 -06:00
parent 33ffec3424
commit 7691706bda
15 changed files with 149 additions and 115 deletions

View File

@ -24,7 +24,7 @@
#include <common/settings.hh>
#include <fstream>
#include <fmt/ostream.h>
#include <common/json.hh>
#include "common/fs.hh"

View File

@ -30,6 +30,7 @@
#include <common/mathlib.hh>
#include <common/fs.hh>
#include <common/settings.hh>
#include <common/ostream.hh>
#include <map>
#include <set>
@ -37,7 +38,6 @@
#include <algorithm> // std::sort
#include <string>
#include <fstream>
#include <fmt/ostream.h>
/* FIXME - share header with qbsp, etc. */
struct wadinfo_t
@ -848,7 +848,7 @@ int bsputil_main(int argc, char **argv)
for (const auto &ent : ents.entities) {
strm << "{\n";
for (const auto &epair : ent.epairs) {
fmt::print(strm, "\"{}\" \"{}\"\n", epair.first, epair.second);
ewt::print(strm, "\"{}\" \"{}\"\n", epair.first, epair.second);
}
if (!ent.map_brushes.empty()) {
strm << ent.map_brushes;

View File

@ -47,6 +47,7 @@ add_library(common STATIC
../include/common/settings.hh
../include/common/prtfile.hh
../include/common/vectorutils.hh
../include/common/ostream.hh
)
target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb TBB::tbbmalloc fmt::fmt nlohmann_json::nlohmann_json)

View File

@ -21,11 +21,11 @@
#include <common/log.hh>
#include <common/cmdlib.hh>
#include <common/bspfile.hh>
#include <common/ostream.hh>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <fmt/ostream.h>
#include <fmt/core.h>
#include <common/json.hh>
#include "common/fs.hh"
#include "common/imglib.hh"
@ -37,13 +37,13 @@
static std::string hex_string(const uint8_t *bytes, const size_t count)
{
std::stringstream str;
std::string str;
for (size_t i = 0; i < count; ++i) {
fmt::print(str, "{:x}", bytes[i]);
fmt::format_to(std::back_inserter(str), "{:x}", bytes[i]);
}
return str.str();
return str;
}
/**
@ -504,14 +504,14 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
const int vertnum = Face_VertexAtIndex(bsp, face, i);
const qvec3f normal = bsp->dplanes[face->planenum].normal;
const qvec3f &pos = bsp->dvertexes[vertnum];
fmt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
fmt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]);
ewt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
ewt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]);
qvec2f tc = tcs[i];
tc[1] = 1.0 - tc[1];
fmt::print(f, "vt {:.9} {:.9}\n", tc[0], tc[1]);
ewt::print(f, "vt {:.9} {:.9}\n", tc[0], tc[1]);
}
f << "f";
@ -519,7 +519,7 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
// .obj vertexes start from 1
// .obj faces are CCW, quake is CW, so reverse the order
const int vertindex = vertcount + (face->numedges - 1 - i) + 1;
fmt::print(f, " {0}/{0}/{0}", vertindex);
ewt::print(f, " {0}/{0}/{0}", vertindex);
}
f << '\n';

View File

@ -28,6 +28,7 @@
#include <common/polylib.hh>
#include <common/fs.hh>
#include <common/log.hh>
#include <common/ostream.hh>
#include <fstream>
#include <vector>
@ -37,7 +38,6 @@
#include <tuple>
#include <fmt/core.h>
#include <fmt/ostream.h>
#include "tbb/parallel_for.h"
@ -152,10 +152,10 @@ struct compiled_brush_t
}
if (source) {
fmt::print(stream, "// generated from brush #{}\n", static_cast<ptrdiff_t>(source - bsp->dbrushes.data()));
ewt::print(stream, "// generated from brush #{}\n", static_cast<ptrdiff_t>(source - bsp->dbrushes.data()));
}
fmt::print(stream, "{{\n");
ewt::print(stream, "{{\n");
for (auto &side : sides) {
planepoints p;
@ -177,11 +177,11 @@ struct compiled_brush_t
}
#if 0
fmt::print(stream, "// side #{}: {} {}\n", static_cast<ptrdiff_t>(side.source -
ewt::print(stream, "// side #{}: {} {}\n", static_cast<ptrdiff_t>(side.source -
bsp->dbrushsides.data()), side.plane.normal, side.plane.dist);
#endif
fmt::print(stream, "( {} ) ( {} ) ( {} ) {} [ {} {} {} {} ] [ {} {} {} {} ] {} {} {}", p[0], p[1], p[2],
ewt::print(stream, "( {} ) ( {} ) ( {} ) {} [ {} {} {} {} ] [ {} {} {} {} ] {} {} {}", p[0], p[1], p[2],
side.texture_name, side.valve.axis.at(0, 0), side.valve.axis.at(0, 1), side.valve.axis.at(0, 2),
side.valve.shift[0], side.valve.axis.at(1, 0), side.valve.axis.at(1, 1), side.valve.axis.at(1, 2),
side.valve.shift[1], 0.0, side.valve.scale[0], side.valve.scale[1]);
@ -209,14 +209,14 @@ struct compiled_brush_t
if (!meta || !((meta->contents & ~(Q2_CONTENTS_SOLID | Q2_CONTENTS_WINDOW)) ==
(contents.native & ~(Q2_CONTENTS_SOLID | Q2_CONTENTS_WINDOW)) &&
meta->flags == side.flags.native && meta->value == side.value)) {
fmt::print(stream, " {} {} {}", contents.native, side.flags.native, side.value);
ewt::print(stream, " {} {} {}", contents.native, side.flags.native, side.value);
}
}
fmt::print(stream, "\n");
ewt::print(stream, "\n");
}
fmt::print(stream, "}}\n");
ewt::print(stream, "}}\n");
}
};
@ -1099,7 +1099,7 @@ static void DecompileEntity(
}
// First, print the key/values for this entity
fmt::print(file, "{{\n");
ewt::print(file, "{{\n");
for (const auto &keyValue : dict) {
if (keyValue.first == "model" && !keyValue.second.empty() && keyValue.second[0] == '*') {
// strip "model" "*NNN" key/values
@ -1127,7 +1127,7 @@ static void DecompileEntity(
continue;
}
fmt::print(file, "\"{}\" \"{}\"\n", keyValue.first, keyValue.second);
ewt::print(file, "\"{}\" \"{}\"\n", keyValue.first, keyValue.second);
}
std::vector<std::vector<compiled_brush_t>> compiledBrushes;
@ -1312,7 +1312,7 @@ static void DecompileEntity(
}
}
fmt::print(file, "}}\n");
ewt::print(file, "}}\n");
}
void DecompileBSP(const mbsp_t *bsp, const decomp_options &options, std::ofstream &file)

View File

@ -19,13 +19,12 @@
#include <common/entdata.h>
#include <sstream>
#include <cstdlib> // atoi()
#include <common/bsputils.hh>
#include <common/parser.hh>
#include <fmt/ostream.h>
#include <fmt/core.h>
entdict_t::entdict_t(std::initializer_list<keyvalue_t> l)
: keyvalues(l)

View File

@ -22,9 +22,9 @@
#include <common/log.hh>
#include <common/fs.hh>
#include <common/bspfile.hh>
#include <common/ostream.hh>
#include <fstream>
#include <fmt/ostream.h>
constexpr const char *PORTALFILE = "PRT1";
constexpr const char *PORTALFILE2 = "PRT2";
@ -175,11 +175,11 @@ prtfile_t LoadPrtFile(const fs::path &name, const bspversion_t *loadversion)
static void WriteDebugPortal(const polylib::winding_t &w, std::ofstream &portalFile)
{
fmt::print(portalFile, "{} {} {} ", w.size(), 0, 0);
ewt::print(portalFile, "{} {} {} ", w.size(), 0, 0);
for (int i = 0; i < w.size(); i++) {
fmt::print(portalFile, "({} {} {}) ", w.at(i)[0], w.at(i)[1], w.at(i)[2]);
ewt::print(portalFile, "({} {} {}) ", w.at(i)[0], w.at(i)[1], w.at(i)[2]);
}
fmt::print(portalFile, "\n");
ewt::print(portalFile, "\n");
}
void WriteDebugPortals(const std::vector<polylib::winding_t> &portals, fs::path name)
@ -190,9 +190,9 @@ void WriteDebugPortals(const std::vector<polylib::winding_t> &portals, fs::path
if (!portal_file)
FError("Failed to open {}: {}", name, strerror(errno));
fmt::print(portal_file, "PRT1\n");
fmt::print(portal_file, "{}\n", 0);
fmt::print(portal_file, "{}\n", portal_count);
ewt::print(portal_file, "PRT1\n");
ewt::print(portal_file, "{}\n", 0);
ewt::print(portal_file, "{}\n", portal_count);
for (auto &p : portals) {
WriteDebugPortal(p, portal_file);
}

36
include/common/ostream.hh Normal file
View File

@ -0,0 +1,36 @@
/* Copyright (C) 2023 Eric Wasylishen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
See file, 'COPYING', for details.
*/
#pragma once
#include <fmt/core.h>
#include <ostream>
#include <iterator>
namespace ewt
{
/**
* replacement for fmt::print from fmt/ostream.h with less compilation time impact.
*/
template<typename... T>
inline void print(std::ostream &stream, fmt::format_string<T...> format, T &&...args)
{
fmt::vformat_to(std::ostream_iterator<char>(stream), format, fmt::make_format_args(args...));
}
} // namespace ewt

View File

@ -21,7 +21,6 @@
#include <cstdint>
#include <iostream>
#include <fmt/ostream.h>
#include <fmt/chrono.h>
#include <light/lightgrid.hh>
@ -39,6 +38,7 @@
#include <common/fs.hh>
#include <common/imglib.hh>
#include <common/parallel.hh>
#include <common/ostream.hh>
#if defined(HAVE_EMBREE) && defined(__SSE2__)
#include <xmmintrin.h>
@ -1206,8 +1206,8 @@ static void ExportObjFace(std::ofstream &f, const mbsp_t *bsp, const mface_t *fa
const int vertnum = Face_VertexAtIndex(bsp, face, i);
const qvec3f normal = GetSurfaceVertexNormal(bsp, face, i).normal;
const qvec3f &pos = bsp->dvertexes[vertnum];
fmt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
fmt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]);
ewt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
ewt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]);
}
f << "f";
@ -1215,7 +1215,7 @@ static void ExportObjFace(std::ofstream &f, const mbsp_t *bsp, const mface_t *fa
// .obj vertexes start from 1
// .obj faces are CCW, quake is CW, so reverse the order
const int vertindex = *vertcount + (face->numedges - 1 - i) + 1;
fmt::print(f, " {}//{}", vertindex, vertindex);
ewt::print(f, " {}//{}", vertindex, vertindex);
}
f << '\n';

View File

@ -26,8 +26,6 @@
#include <algorithm>
#include <string>
#include <utility>
#include <fmt/ostream.h>
#include <fmt/chrono.h>
#include <light/light.hh>
#include <light/entities.hh>

View File

@ -32,13 +32,13 @@
#include <common/log.hh>
#include <common/bsputils.hh>
#include <common/qvec.hh>
#include <common/ostream.hh>
#include <atomic>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <fmt/ostream.h>
using namespace std;
@ -275,12 +275,12 @@ static void CalcPoints_Debug(const lightsurf_t *surf, const mbsp_t *bsp)
f << "{\n";
f << "\"classname\" \"light\"\n";
fmt::print(f, "\"origin\" \"{}\"\n", point);
fmt::print(f, "\"mangle\" \"{}\"\n", mangle);
fmt::print(f, "\"face\" \"{}\"\n", sample.realfacenum);
fmt::print(f, "\"occluded\" \"{}\"\n", sample.occluded);
fmt::print(f, "\"s\" \"{}\"\n", s);
fmt::print(f, "\"t\" \"{}\"\n", t);
ewt::print(f, "\"origin\" \"{}\"\n", point);
ewt::print(f, "\"mangle\" \"{}\"\n", mangle);
ewt::print(f, "\"face\" \"{}\"\n", sample.realfacenum);
ewt::print(f, "\"occluded\" \"{}\"\n", sample.occluded);
ewt::print(f, "\"s\" \"{}\"\n", s);
ewt::print(f, "\"t\" \"{}\"\n", t);
f << "}\n";
}
}
@ -2533,7 +2533,7 @@ static void WritePPM(const fs::path &fname, int width, int height, const uint8_t
qfile_t file = SafeOpenWrite(fname);
// see: http://netpbm.sourceforge.net/doc/ppm.html
fmt::print(file.get(), "P6 {} {} 255 ", width, height);
ewt::print(file.get(), "P6 {} {} 255 ", width, height);
int bytes = width * height * 3;
Q_assert(bytes == SafeWrite(file, rgbdata, bytes));
}

View File

@ -22,12 +22,12 @@
#include <qbsp/qbsp.hh>
#include <common/log.hh>
#include <common/ostream.hh>
#include <qbsp/brush.hh>
#include <qbsp/map.hh>
#include <unordered_set>
#include <fstream>
#include <fmt/ostream.h>
#include <list>
static std::ofstream InitObjFile(const std::string &filesuffix)
@ -66,23 +66,23 @@ static void ExportObjFace(
// export the vertices and uvs
for (int i = 0; i < w.size(); i++) {
const qvec3d &pos = w[i];
fmt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
ewt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
qvec3d uv = texinfo.vecs.uvs(pos, width, height);
// not sure why -v is needed, .obj uses (0, 0) in the top left apparently?
fmt::print(f, "vt {:.9} {:.9}\n", uv[0], -uv[1]);
ewt::print(f, "vt {:.9} {:.9}\n", uv[0], -uv[1]);
}
if (!mtlname.empty()) {
fmt::print(f, "usemtl {}\n", mtlname);
ewt::print(f, "usemtl {}\n", mtlname);
}
f << 'f';
for (int i = 0; i < w.size(); i++) {
// .obj vertexes start from 1
// .obj faces are CCW, quake is CW, so reverse the order
const int vertindex = *vertcount + (w.size() - 1 - i) + 1;
fmt::print(f, " {}/{}", vertindex, vertindex);
ewt::print(f, " {}/{}", vertindex, vertindex);
}
f << '\n';
@ -92,9 +92,9 @@ static void ExportObjFace(
static void WriteContentsMaterial(std::ofstream &mtlf, contentflags_t contents, float r, float g, float b)
{
// fixme-brushbsp
fmt::print(mtlf, "newmtl contents{}\n", contents.native);
ewt::print(mtlf, "newmtl contents{}\n", contents.native);
mtlf << "Ka 0 0 0\n";
fmt::print(mtlf, "Kd {} {} {}\n", r, g, b);
ewt::print(mtlf, "Kd {} {} {}\n", r, g, b);
mtlf << "Ks 0 0 0\n";
mtlf << "illum 0\n";
}

View File

@ -30,7 +30,6 @@
#include <utility>
#include <optional>
#include <fstream>
#include <fmt/ostream.h>
#include <qbsp/brush.hh>
#include <qbsp/map.hh>
@ -41,6 +40,7 @@
#include <common/fs.hh>
#include <common/imglib.hh>
#include <common/qvec.hh>
#include <common/ostream.hh>
#include <pareto/spatial_map.h>
@ -3051,10 +3051,10 @@ inline void WriteMapBrushMap(const fs::path &name, const std::vector<mapbrush_t>
if (!f)
FError("Can't write {}", name);
fmt::print(f, "{{\n\"classname\" \"worldspawn\"\n");
ewt::print(f, "{{\n\"classname\" \"worldspawn\"\n");
for (auto &brush : list) {
fmt::print(f, "{{\n");
ewt::print(f, "{{\n");
for (auto &face : brush.faces) {
qvec3d corner = {};
@ -3070,25 +3070,25 @@ inline void WriteMapBrushMap(const fs::path &name, const std::vector<mapbrush_t>
winding_t w = BaseWindingForPlane<winding_t>(plane);
fmt::print(f, "( {} ) ", w[0]);
fmt::print(f, "( {} ) ", w[1]);
fmt::print(f, "( {} ) ", w[2]);
ewt::print(f, "( {} ) ", w[0]);
ewt::print(f, "( {} ) ", w[1]);
ewt::print(f, "( {} ) ", w[2]);
#if 0
if (face.visible) {
fmt::print(f, "skip 0 0 0 1 1\n");
ewt::print(f, "skip 0 0 0 1 1\n");
} else {
fmt::print(f, "nonvisible 0 0 0 1 1\n");
ewt::print(f, "nonvisible 0 0 0 1 1\n");
}
#endif
fmt::print(f, "{} 0 0 0 1 1\n", face.texname);
ewt::print(f, "{} 0 0 0 1 1\n", face.texname);
}
fmt::print(f, "}}\n");
ewt::print(f, "}}\n");
}
fmt::print(f, "}}\n");
ewt::print(f, "}}\n");
f.close();
}
@ -3455,9 +3455,9 @@ static void fprintDoubleAndSpc(std::ofstream &f, double v)
{
int rounded = rint(v);
if (static_cast<double>(rounded) == v) {
fmt::print(f, "{} ", rounded);
ewt::print(f, "{} ", rounded);
} else if (std::isfinite(v)) {
fmt::print(f, "{:0.17} ", v);
ewt::print(f, "{:0.17} ", v);
} else {
printf("WARNING: suppressing nan or infinity\n");
f << "0 ";
@ -3485,7 +3485,7 @@ static void ConvertMapFace(std::ofstream &f, const mapface_t &mapface, const con
const texdef_quake_ed_t quakeed =
TexDef_BSPToQuakeEd(mapface.get_plane(), texture, texinfo.vecs, mapface.planepts);
fmt::print(f, "{} ", mapface.texname);
ewt::print(f, "{} ", mapface.texname);
fprintDoubleAndSpc(f, quakeed.shift[0]);
fprintDoubleAndSpc(f, quakeed.shift[1]);
fprintDoubleAndSpc(f, quakeed.rotate);
@ -3502,7 +3502,7 @@ static void ConvertMapFace(std::ofstream &f, const mapface_t &mapface, const con
case conversion_t::valve: {
const texdef_valve_t valve = TexDef_BSPToValve(texinfo.vecs);
fmt::print(f, "{} [ ", mapface.texname);
ewt::print(f, "{} [ ", mapface.texname);
fprintDoubleAndSpc(f, valve.axis.at(0, 0));
fprintDoubleAndSpc(f, valve.axis.at(0, 1));
fprintDoubleAndSpc(f, valve.axis.at(0, 2));
@ -3540,7 +3540,7 @@ static void ConvertMapFace(std::ofstream &f, const mapface_t &mapface, const con
fprintDoubleAndSpc(f, bp.at(1, 2));
// N.B.: always print the Q2/Q3 flags
fmt::print(f, ") ) {} ", mapface.texname);
ewt::print(f, ") ) {} ", mapface.texname);
if (mapface.raw_info.has_value()) {
f << mapface.raw_info->contents.native << " " << mapface.raw_info->flags.native << " "
@ -3578,7 +3578,7 @@ static void ConvertEntity(std::ofstream &f, const mapentity_t &entity, const con
f << "{\n";
for (const auto &[key, value] : entity.epairs) {
fmt::print(f, "\"{}\" \"{}\"\n", key, value);
ewt::print(f, "\"{}\" \"{}\"\n", key, value);
}
for (auto &mapbrush : entity.mapbrushes) {
@ -3771,35 +3771,35 @@ void WriteBspBrushMap(std::string_view filename_suffix, const bspbrush_t::contai
if (!f)
FError("Can't write {}", name);
fmt::print(f, "{{\n\"classname\" \"worldspawn\"\n");
ewt::print(f, "{{\n\"classname\" \"worldspawn\"\n");
for (auto &brush : list) {
if (!brush) {
continue;
}
fmt::print(f, "{{\n");
ewt::print(f, "{{\n");
for (auto &face : brush->sides) {
winding_t w = BaseWindingForPlane<winding_t>(face.get_plane());
fmt::print(f, "( {} ) ", w[0]);
fmt::print(f, "( {} ) ", w[1]);
fmt::print(f, "( {} ) ", w[2]);
ewt::print(f, "( {} ) ", w[0]);
ewt::print(f, "( {} ) ", w[1]);
ewt::print(f, "( {} ) ", w[2]);
#if 0
if (face.visible) {
fmt::print(f, "skip 0 0 0 1 1\n");
ewt::print(f, "skip 0 0 0 1 1\n");
} else {
fmt::print(f, "nonvisible 0 0 0 1 1\n");
ewt::print(f, "nonvisible 0 0 0 1 1\n");
}
#endif
fmt::print(f, "{} 0 0 0 1 1\n", map.miptex[face.get_texinfo().miptex].name);
ewt::print(f, "{} 0 0 0 1 1\n", map.miptex[face.get_texinfo().miptex].name);
}
fmt::print(f, "}}\n");
ewt::print(f, "}}\n");
}
fmt::print(f, "}}\n");
ewt::print(f, "}}\n");
f.close();
}

View File

@ -28,13 +28,13 @@
#include <qbsp/tree.hh>
#include <common/log.hh>
#include <common/ostream.hh>
#include <climits>
#include <vector>
#include <set>
#include <list>
#include <unordered_set>
#include <utility>
#include <fmt/ostream.h>
static bool LeafSealsMap(const node_t *node)
{
@ -251,7 +251,7 @@ void WriteLeakTrail(std::ofstream &leakfile, qvec3d point1, const qvec3d &point2
vec_t dist = qv::normalizeInPlace(vector);
while (dist > qbsp_options.leakdist.value()) {
fmt::print(leakfile, "{}\n", point1);
ewt::print(leakfile, "{}\n", point1);
point1 += vector * qbsp_options.leakdist.value();
dist -= qbsp_options.leakdist.value();
}

View File

@ -22,13 +22,13 @@
#include <qbsp/prtfile.hh>
#include <common/log.hh>
#include <common/ostream.hh>
#include <qbsp/map.hh>
#include <qbsp/portals.hh>
#include <qbsp/qbsp.hh>
#include <qbsp/tree.hh>
#include <fstream>
#include <fmt/ostream.h>
/*
==============================================================================
@ -41,9 +41,9 @@ PORTAL FILE GENERATION
static void WriteFloat(std::ofstream &portalFile, vec_t v)
{
if (fabs(v - Q_rint(v)) < ZERO_EPSILON)
fmt::print(portalFile, "{} ", (int)Q_rint(v));
ewt::print(portalFile, "{} ", (int)Q_rint(v));
else
fmt::print(portalFile, "{} ", v);
ewt::print(portalFile, "{} ", v);
}
static void WritePortals_r(node_t *node, std::ofstream &portalFile, bool clusters)
@ -89,19 +89,19 @@ static void WritePortals_r(node_t *node, std::ofstream &portalFile, bool cluster
*/
plane2 = w->plane();
if (qv::dot(p->plane.get_normal(), plane2.normal) < 1.0 - ANGLEEPSILON) {
fmt::print(portalFile, "{} {} {} ", w->size(), back, front);
ewt::print(portalFile, "{} {} {} ", w->size(), back, front);
} else {
fmt::print(portalFile, "{} {} {} ", w->size(), front, back);
ewt::print(portalFile, "{} {} {} ", w->size(), front, back);
}
for (i = 0; i < w->size(); i++) {
fmt::print(portalFile, "(");
ewt::print(portalFile, "(");
WriteFloat(portalFile, w->at(i)[0]);
WriteFloat(portalFile, w->at(i)[1]);
WriteFloat(portalFile, w->at(i)[2]);
fmt::print(portalFile, ") ");
ewt::print(portalFile, ") ");
}
fmt::print(portalFile, "\n");
ewt::print(portalFile, "\n");
}
}
@ -117,7 +117,7 @@ static int WritePTR2ClusterMapping_r(node_t *node, std::ofstream &portalFile, in
/* If we're in the next cluster, start a new line */
if (node->viscluster != viscluster) {
fmt::print(portalFile, "-1\n");
ewt::print(portalFile, "-1\n");
viscluster++;
}
@ -125,7 +125,7 @@ static int WritePTR2ClusterMapping_r(node_t *node, std::ofstream &portalFile, in
if (node->viscluster != viscluster)
FError("Internal error: Detail cluster mismatch");
fmt::print(portalFile, "{} ", node->visleafnum);
ewt::print(portalFile, "{} ", node->visleafnum);
return viscluster;
}
@ -218,37 +218,37 @@ static void WritePortalfile(node_t *headnode, portal_state_t &state)
// q2 uses a PRT1 file, but with clusters.
// (Since q2bsp natively supports clusters, we don't need PRT2.)
if (qbsp_options.target_game->id == GAME_QUAKE_II) {
fmt::print(portalFile, "PRT1\n");
fmt::print(portalFile, "{}\n", state.num_visclusters.count.load());
fmt::print(portalFile, "{}\n", state.num_visportals.count.load());
ewt::print(portalFile, "PRT1\n");
ewt::print(portalFile, "{}\n", state.num_visclusters.count.load());
ewt::print(portalFile, "{}\n", state.num_visportals.count.load());
WritePortals_r(headnode, portalFile, true);
return;
}
/* If no detail clusters, just use a normal PRT1 format */
if (!state.uses_detail) {
fmt::print(portalFile, "PRT1\n");
fmt::print(portalFile, "{}\n", state.num_visleafs.count.load());
fmt::print(portalFile, "{}\n", state.num_visportals.count.load());
ewt::print(portalFile, "PRT1\n");
ewt::print(portalFile, "{}\n", state.num_visleafs.count.load());
ewt::print(portalFile, "{}\n", state.num_visportals.count.load());
WritePortals_r(headnode, portalFile, false);
} else if (qbsp_options.forceprt1.value()) {
/* Write a PRT1 file for loading in the map editor. Vis will reject it. */
fmt::print(portalFile, "PRT1\n");
fmt::print(portalFile, "{}\n", state.num_visclusters.count.load());
fmt::print(portalFile, "{}\n", state.num_visportals.count.load());
ewt::print(portalFile, "PRT1\n");
ewt::print(portalFile, "{}\n", state.num_visclusters.count.load());
ewt::print(portalFile, "{}\n", state.num_visportals.count.load());
WritePortals_r(headnode, portalFile, true);
} else {
/* Write a PRT2 */
fmt::print(portalFile, "PRT2\n");
fmt::print(portalFile, "{}\n", state.num_visleafs.count.load());
fmt::print(portalFile, "{}\n", state.num_visclusters.count.load());
fmt::print(portalFile, "{}\n", state.num_visportals.count.load());
ewt::print(portalFile, "PRT2\n");
ewt::print(portalFile, "{}\n", state.num_visleafs.count.load());
ewt::print(portalFile, "{}\n", state.num_visclusters.count.load());
ewt::print(portalFile, "{}\n", state.num_visportals.count.load());
WritePortals_r(headnode, portalFile, true);
check = WritePTR2ClusterMapping_r(headnode, portalFile, 0);
if (check != state.num_visclusters.count.load() - 1) {
FError("Internal error: Detail cluster mismatch");
}
fmt::print(portalFile, "-1\n");
ewt::print(portalFile, "-1\n");
}
}
@ -293,12 +293,12 @@ static void WriteDebugPortal(const portal_t *p, std::ofstream &portalFile)
{
const winding_t *w = &p->winding;
fmt::print(portalFile, "{} {} {} ", w->size(), 0, 0);
ewt::print(portalFile, "{} {} {} ", w->size(), 0, 0);
for (int i = 0; i < w->size(); i++) {
fmt::print(portalFile, "({} {} {}) ", w->at(i)[0], w->at(i)[1], w->at(i)[2]);
ewt::print(portalFile, "({} {} {}) ", w->at(i)[0], w->at(i)[1], w->at(i)[2]);
}
fmt::print(portalFile, "\n");
ewt::print(portalFile, "\n");
}
static void WriteTreePortals_r(node_t *node, std::ofstream &portalFile)
@ -357,9 +357,9 @@ void WriteDebugTreePortalFile(tree_t &tree, std::string_view filename_suffix)
if (!portalFile)
FError("Failed to open {}: {}", name, strerror(errno));
fmt::print(portalFile, "PRT1\n");
fmt::print(portalFile, "{}\n", 0);
fmt::print(portalFile, "{}\n", portal_count);
ewt::print(portalFile, "PRT1\n");
ewt::print(portalFile, "{}\n", 0);
ewt::print(portalFile, "{}\n", portal_count);
WriteTreePortals_r(tree.headnode, portalFile);
logging::print(logging::flag::STAT, " {:8} tree portals written to {}\n", portal_count, name);
@ -385,9 +385,9 @@ void WriteDebugPortals(std::vector<portal_t *> portals, std::string_view filenam
if (!portal_file)
FError("Failed to open {}: {}", name, strerror(errno));
fmt::print(portal_file, "PRT1\n");
fmt::print(portal_file, "{}\n", 0);
fmt::print(portal_file, "{}\n", portal_count);
ewt::print(portal_file, "PRT1\n");
ewt::print(portal_file, "{}\n", 0);
ewt::print(portal_file, "{}\n", portal_count);
for (auto &p : portals) {
if (p->winding) {
WriteDebugPortal(p, portal_file);