Skip to content

Commit

Permalink
cleanup: code formatting pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwa committed Nov 19, 2024
1 parent 8038b73 commit 9f4cfb0
Show file tree
Hide file tree
Showing 73 changed files with 1,755 additions and 1,779 deletions.
321 changes: 180 additions & 141 deletions bsputil/bsputil.cc

Large diffs are not rendered by default.

404 changes: 197 additions & 207 deletions common/bspfile.cc

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions common/bspfile_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ std::string contentflags_t::to_string() const
static auto as_tuple(const surfflags_t &flags)
{
return std::tie(flags.native, flags.is_nodraw, flags.is_hintskip, flags.is_hint, flags.no_dirt, flags.no_shadow,
flags.no_bounce, flags.no_minlight, flags.no_expand, flags.no_phong, flags.light_ignore,
flags.surflight_rescale, flags.surflight_style, flags.surflight_color, flags.surflight_minlight_scale,
flags.surflight_atten,
flags.surflight_targetname, flags.phong_angle, flags.phong_angle_concave, flags.phong_group, flags.minlight,
flags.minlight_color, flags.light_alpha, flags.light_twosided, flags.maxlight, flags.lightcolorscale, flags.surflight_group,
flags.world_units_per_luxel, flags.object_channel_mask);
flags.no_bounce, flags.no_minlight, flags.no_expand, flags.no_phong, flags.light_ignore,
flags.surflight_rescale, flags.surflight_style, flags.surflight_color, flags.surflight_minlight_scale,
flags.surflight_atten, flags.surflight_targetname, flags.phong_angle, flags.phong_angle_concave,
flags.phong_group, flags.minlight, flags.minlight_color, flags.light_alpha, flags.light_twosided,
flags.maxlight, flags.lightcolorscale, flags.surflight_group, flags.world_units_per_luxel,
flags.object_channel_mask);
}

bool surfflags_t::needs_write() const
Expand All @@ -211,7 +211,8 @@ bool surfflags_t::is_valid(const gamedef_t *game) const
// gamedef_t

gamedef_t::gamedef_t(const char *friendly_name, const char *default_base_dir)
: friendly_name(friendly_name), default_base_dir(default_base_dir)
: friendly_name(friendly_name),
default_base_dir(default_base_dir)
{
}

Expand Down
31 changes: 14 additions & 17 deletions common/bspinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static faceextents_t get_face_extents(const mbsp_t &bsp, const bspxentries_t &bs
}

full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx, const std::vector<uint8_t> &litdata,
const std::vector<uint32_t> &hdr_litdata, bool use_bspx, bool use_decoupled)
const std::vector<uint32_t> &hdr_litdata, bool use_bspx, bool use_decoupled)
{
struct face_rect
{
Expand Down Expand Up @@ -428,9 +428,8 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx,
}

if (!is_hdr) {
auto in_pixel =
lightdata_source + ((is_lit ? 3 : 1) * rect.lightofs) +
(rect.extents.numsamples() * (is_rgb ? 3 : 1) * style_index);
auto in_pixel = lightdata_source + ((is_lit ? 3 : 1) * rect.lightofs) +
(rect.extents.numsamples() * (is_rgb ? 3 : 1) * style_index);

for (size_t y = 0; y < rect.extents.height(); y++) {
for (size_t x = 0; x < rect.extents.width(); x++) {
Expand All @@ -452,9 +451,7 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx,
} else {
// hdr

auto in_pixel =
hdr_lightdata_source + rect.lightofs +
(rect.extents.numsamples() * style_index);
auto in_pixel = hdr_lightdata_source + rect.lightofs + (rect.extents.numsamples() * style_index);

for (size_t y = 0; y < rect.extents.height(); y++) {
for (size_t x = 0; x < rect.extents.width(); x++) {
Expand Down Expand Up @@ -550,18 +547,18 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
}

stbi_write_hdr_to_func(
[](void *context, void *data, int size) {
std::ofstream &strm = *((std::ofstream *) context);
strm.write((const char *) data, size);
},
&strm, full_atlas.width, full_atlas.height, 3, temp.data());
[](void *context, void *data, int size) {
std::ofstream &strm = *((std::ofstream *)context);
strm.write((const char *)data, size);
},
&strm, full_atlas.width, full_atlas.height, 3, temp.data());
} else {
stbi_write_png_to_func(
[](void *context, void *data, int size) {
std::ofstream &strm = *((std::ofstream *) context);
strm.write((const char *) data, size);
},
&strm, full_atlas.width, full_atlas.height, 4, full_atlas.rgba8_samples.data(), full_atlas.width * 4);
[](void *context, void *data, int size) {
std::ofstream &strm = *((std::ofstream *)context);
strm.write((const char *)data, size);
},
&strm, full_atlas.width, full_atlas.height, 4, full_atlas.rgba8_samples.data(), full_atlas.width * 4);
}
logging::print("wrote {}\n", lightmaps_path);
}
Expand Down
6 changes: 2 additions & 4 deletions common/bsputils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,8 @@ qvec3b LM_Sample(const mbsp_t *bsp, const mface_t *face, const lit_variant_t *li
}
}

qvec3f LM_Sample_HDR(const mbsp_t *bsp, const mface_t *face,
const faceextents_t &faceextents,
int byte_offset_of_face, qvec2i coord,
const lit_variant_t *lit, const bspxentries_t *bspx)
qvec3f LM_Sample_HDR(const mbsp_t *bsp, const mface_t *face, const faceextents_t &faceextents, int byte_offset_of_face,
qvec2i coord, const lit_variant_t *lit, const bspxentries_t *bspx)
{
if (byte_offset_of_face == -1) {
return {0, 0, 0};
Expand Down
3 changes: 2 additions & 1 deletion common/bspxfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void bspx_lump_t::stream_read(std::istream &s)

// bspxbrushes_perbrush

void bspxbrushes_perbrush::stream_write(std::ostream &s) const {
void bspxbrushes_perbrush::stream_write(std::ostream &s) const
{
s <= bounds;
s <= contents;
s <= static_cast<uint16_t>(faces.size());
Expand Down
34 changes: 17 additions & 17 deletions common/decompile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ static std::vector<compiled_brush_t> DecompileLeafTaskGeometryOnly(
compiled_brush_t brush;
brush.source = task.brush;
brush.brush_offset = brush_offset;
brush.contents = bsp->loadversion->game->create_contents_from_native(
task.brush ? task.brush->contents : task.leaf ? task.leaf->contents : task.contents.value()
);
brush.contents = bsp->loadversion->game->create_contents_from_native(task.brush ? task.brush->contents
: task.leaf ? task.leaf->contents
: task.contents.value());

brush.sides.reserve(task.allPlanes.size());

Expand All @@ -837,8 +837,8 @@ static std::vector<compiled_brush_t> DecompileLeafTaskGeometryOnly(
return result;
}

static std::vector<compiled_brush_t> DecompileLeafTask(
const mbsp_t *bsp, const decomp_options &options, leaf_decompile_task &task, const std::optional<qvec3d> &brush_offset)
static std::vector<compiled_brush_t> DecompileLeafTask(const mbsp_t *bsp, const decomp_options &options,
leaf_decompile_task &task, const std::optional<qvec3d> &brush_offset)
{
std::vector<decomp_brush_t> finalBrushes;
if (bsp->loadversion->game->id == GAME_QUAKE_II && !options.ignoreBrushes) {
Expand Down Expand Up @@ -880,7 +880,9 @@ static std::vector<compiled_brush_t> DecompileLeafTask(
compiled_brush_t brush;
brush.source = task.brush;
brush.brush_offset = brush_offset;
brush.contents = bsp->loadversion->game->create_contents_from_native(task.brush ? task.brush->contents : task.leaf ? task.leaf->contents : task.contents.value());
brush.contents = bsp->loadversion->game->create_contents_from_native(task.brush ? task.brush->contents
: task.leaf ? task.leaf->contents
: task.contents.value());

for (auto &finalSide : finalBrush.sides) {
compiled_brush_side_t &side = brush.sides.emplace_back();
Expand Down Expand Up @@ -972,8 +974,7 @@ static std::vector<compiled_brush_t> DecompileLeafTaskLeafVisualization(
brush.source = task.brush;
brush.brush_offset = brush_offset;
brush.contents = bsp->loadversion->game->create_contents_from_native(
task.leaf ? task.leaf->contents : task.contents.value()
);
task.leaf ? task.leaf->contents : task.contents.value());

for (auto &finalSide : finalBrush.sides) {
compiled_brush_side_t &side = brush.sides.emplace_back();
Expand Down Expand Up @@ -1093,8 +1094,8 @@ static void AddMapBoundsToStack(std::vector<decomp_plane_t> &planestack, const m
}
}

static std::vector<compiled_brush_t> DecompileBrushTask(
const mbsp_t *bsp, const decomp_options &options, leaf_decompile_task &task, const std::optional<qvec3d> &brush_offset)
static std::vector<compiled_brush_t> DecompileBrushTask(const mbsp_t *bsp, const decomp_options &options,
leaf_decompile_task &task, const std::optional<qvec3d> &brush_offset)
{
for (size_t i = 0; i < task.brush->numsides; i++) {
const q2_dbrushside_qbism_t *side = &bsp->dbrushsides[task.brush->firstside + i];
Expand Down Expand Up @@ -1200,9 +1201,8 @@ static void DecompileEntity(

// decompile the leafs in parallel
compiledBrushes.resize(tasks.size());
tbb::parallel_for(static_cast<size_t>(0), tasks.size(), [&](size_t i) {
compiledBrushes[i] = DecompileLeafTaskGeometryOnly(bsp, tasks[i], brush_offset);
});
tbb::parallel_for(static_cast<size_t>(0), tasks.size(),
[&](size_t i) { compiledBrushes[i] = DecompileLeafTaskGeometryOnly(bsp, tasks[i], brush_offset); });
} else if (bsp->loadversion->game->id == GAME_QUAKE_II && !options.ignoreBrushes) {
std::unordered_map<const dbrush_t *, leaf_decompile_task> brushes;

Expand Down Expand Up @@ -1378,7 +1378,8 @@ void DecompileBSP(const mbsp_t *bsp, const decomp_options &options, std::ofstrea

// MARK: - leaf visualization

static std::vector<leaf_visualization_t> CompiledBrushesToLeafVisualization(std::vector<std::vector<compiled_brush_t>> in)
static std::vector<leaf_visualization_t> CompiledBrushesToLeafVisualization(
std::vector<std::vector<compiled_brush_t>> in)
{
std::vector<leaf_visualization_t> result;

Expand Down Expand Up @@ -1427,9 +1428,8 @@ std::vector<leaf_visualization_t> VisualizeLeafs(const mbsp_t &bsp, int modelnum

// decompile the leafs in parallel
compiledBrushes.resize(tasks.size());
tbb::parallel_for(static_cast<size_t>(0), tasks.size(), [&](size_t i) {
compiledBrushes[i] = DecompileLeafTaskLeafVisualization(&bsp, tasks[i], std::nullopt);
});
tbb::parallel_for(static_cast<size_t>(0), tasks.size(),
[&](size_t i) { compiledBrushes[i] = DecompileLeafTaskLeafVisualization(&bsp, tasks[i], std::nullopt); });

return CompiledBrushesToLeafVisualization(std::move(compiledBrushes));
}
3 changes: 2 additions & 1 deletion common/fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ struct wad_archive : archive_like

auto stream_data() { return std::tie(filepos, disksize, size, type, compression, pad, name); }

std::string name_as_string() const {
std::string name_as_string() const
{
size_t length = 0;

// count the number of leading non-null characters
Expand Down
18 changes: 6 additions & 12 deletions common/imglib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ struct q2_miptex_t
auto stream_data() { return std::tie(name, width, height, offsets, animname, flags, contents, value); }
};

std::optional<texture> load_wal(
std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
std::optional<texture> load_wal(std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
{
imemstream stream(file->data(), file->size(), std::ios_base::in | std::ios_base::binary);
stream >> endianness<std::endian::little>;
Expand Down Expand Up @@ -166,8 +165,7 @@ Quake/Half Life MIP
============================================================================
*/

std::optional<texture> load_mip(
std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
std::optional<texture> load_mip(std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
{
imemstream stream(file->data(), file->size());
stream >> endianness<std::endian::little>;
Expand Down Expand Up @@ -255,8 +253,7 @@ std::optional<texture> load_mip(
return tex;
}

std::optional<texture> load_stb(
std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
std::optional<texture> load_stb(std::string_view name, const fs::data &file, bool meta_only, const gamedef_t *game)
{
int x, y, channels_in_file;
stbi_uc *rgba_data = stbi_load_from_memory(file->data(), file->size(), &x, &y, &channels_in_file, 4);
Expand Down Expand Up @@ -370,8 +367,7 @@ std::optional<texture_meta> load_wal_meta(std::string_view name, const fs::data
}

// see .wal_json section in qbsp.rst for format documentation
std::optional<texture_meta> load_wal_json_meta(
std::string_view name, const fs::data &file, const gamedef_t *game)
std::optional<texture_meta> load_wal_json_meta(std::string_view name, const fs::data &file, const gamedef_t *game)
{
try {
auto json = json::parse(file->begin(), file->end());
Expand Down Expand Up @@ -406,8 +402,7 @@ std::optional<texture_meta> load_wal_json_meta(
if (contents.is_number_integer()) {
meta.contents_native = contents.get<int32_t>();
} else if (contents.is_string()) {
meta.contents_native =
game->contents_from_string(contents.get<std::string>());
meta.contents_native = game->contents_from_string(contents.get<std::string>());
} else if (contents.is_array()) {
int native = 0;
for (auto &content : contents) {
Expand Down Expand Up @@ -534,8 +529,7 @@ static qvec3b increase_saturation(const qvec3b &color)
}

// Load the specified texture from the BSP
static void AddTextureName(
std::string_view textureName, const mbsp_t *bsp, const settings::common_settings &options)
static void AddTextureName(std::string_view textureName, const mbsp_t *bsp, const settings::common_settings &options)
{
if (img::find(textureName)) {
return;
Expand Down
9 changes: 4 additions & 5 deletions common/litfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ uint32_t HDR_PackE5BRG9(qvec3f rgb)
constexpr int Emax = 31; // max allowed exponent bias value

// slightly under 2^16
constexpr float max_representable = \
(static_cast<float>((1 << N) - 1) / static_cast<float>(1 << N)) * \
static_cast<float>(1 << (Emax - B));
constexpr float max_representable =
(static_cast<float>((1 << N) - 1) / static_cast<float>(1 << N)) * static_cast<float>(1 << (Emax - B));

// clamp inputs
const float r = std::max(0.0f, std::min(rgb[0], max_representable));
Expand Down Expand Up @@ -119,7 +118,7 @@ qvec3f HDR_UnpackE5BRG9(uint32_t packed)

const uint32_t blue_int = (packed >> 18) & 0x1ff;
const uint32_t green_int = (packed >> 9) & 0x1ff;
const uint32_t red_int = packed & 0x1ff;
const uint32_t red_int = packed & 0x1ff;

const float multiplier = std::pow(2.0f, static_cast<float>(exponent));

Expand All @@ -130,7 +129,7 @@ lit_variant_t LoadLitFile(const fs::path &path)
{
std::ifstream stream(path, std::ios_base::in | std::ios_base::binary);
if (!stream.good()) {
return { lit_none() };
return {lit_none()};
}

stream >> endianness<std::endian::little>;
Expand Down
8 changes: 5 additions & 3 deletions common/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void init(std::optional<fs::path> filename, const settings::common_settings &set
}

logfile.open(p, settings.logappend.value() ? std::ios_base::app : std::ios_base::trunc);

if (logfile) {
print(flag::PROGRESS, "logging to {} ({})\n", p.string(), settings.logappend.value() ? "append" : "truncate");
fmt::print(logfile, "---- {} / ericw-tools {} ----\n", settings.program_name, ERICWTOOLS_VERSION);
Expand Down Expand Up @@ -190,7 +190,7 @@ static time_point last_percent_time;

static duration average_times_for_one_percent()
{
duration pt {};
duration pt{};

for (size_t i = 0; i < num_percent_times; i++) {
pt += one_percent_times[i];
Expand Down Expand Up @@ -298,7 +298,9 @@ void percent(uint64_t count, uint64_t max, bool displayElapsed)
dt /= diff;
register_average_time(dt);
last_percent_time = I_FloatTime();
print(flag::PERCENT, "[{:>3}%] est: {:%H:%M:%S}\r", pct, std::chrono::duration_cast<std::chrono::duration<long long>>(average_times_for_one_percent() * (100 - pct)));
print(flag::PERCENT, "[{:>3}%] est: {:%H:%M:%S}\r", pct,
std::chrono::duration_cast<std::chrono::duration<long long>>(
average_times_for_one_percent() * (100 - pct)));
} else {
print(flag::PERCENT, "[{:>3}%] ...\r", pct);
}
Expand Down
Loading

0 comments on commit 9f4cfb0

Please sign in to comment.