Skip to content

Commit

Permalink
Reformat everything
Browse files Browse the repository at this point in the history
  • Loading branch information
kduske committed Oct 24, 2022
1 parent 37a696e commit ad81b2a
Show file tree
Hide file tree
Showing 1,275 changed files with 81,015 additions and 45,640 deletions.
14 changes: 7 additions & 7 deletions app/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

extern void qt_set_sequence_auto_mnemonic(bool b);

int main(int argc, char* argv[]) {
int main(int argc, char* argv[])
{
// Set OpenGL defaults
// Needs to be done here before QApplication is created
// (see: https://doc.qt.io/qt-5/qsurfaceformat.html#setDefaultFormat)
Expand All @@ -41,8 +42,8 @@ int main(int argc, char* argv[]) {
QSurfaceFormat::setDefaultFormat(format);

// Makes all QOpenGLWidget in the application share a single context
// (default behaviour would be for QOpenGLWidget's in a single top-level window to share a
// context.) see: http://doc.qt.io/qt-5/qopenglwidget.html#context-sharing
// (default behaviour would be for QOpenGLWidget's in a single top-level window to share
// a context.) see: http://doc.qt.io/qt-5/qopenglwidget.html#context-sharing
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QSettings::setDefaultFormat(QSettings::IniFormat);

Expand All @@ -56,10 +57,9 @@ int main(int argc, char* argv[]) {
#endif

// Workaround bug in Qt's Ctrl+Click = RMB emulation (a macOS feature.)
// In Qt 5.13.0 / macOS 10.14.6, Ctrl+trackpad click+Drag produces no mouse events at all, but
// it should produce RMB down/move events.
// This environment variable disables Qt's emulation so we can implement it ourselves in
// InputEventRecorder::recordEvent
// In Qt 5.13.0 / macOS 10.14.6, Ctrl+trackpad click+Drag produces no mouse events at
// all, but it should produce RMB down/move events. This environment variable disables
// Qt's emulation so we can implement it ourselves in InputEventRecorder::recordEvent
qputenv("QT_MAC_DONT_OVERRIDE_CTRL_LMB", "1");

// Disable Qt OpenGL buglist; since we require desktop OpenGL 2.1 there's no point in
Expand Down
21 changes: 10 additions & 11 deletions common/benchmark/src/AABBTreeBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
#include "../../test/src/Catch2.h"
#include "BenchmarkUtils.h"

namespace TrenchBroom {
namespace TrenchBroom
{
using AABB = AABBTree<double, 3, Model::Node*>;
using BOX = AABB::Box;

TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]") {
const auto mapPath =
IO::Disk::getCurrentWorkingDir() + IO::Path("fixture/benchmark/AABBTree/ne_ruins.map");
TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]")
{
const auto mapPath = IO::Disk::getCurrentWorkingDir()
+ IO::Path("fixture/benchmark/AABBTree/ne_ruins.map");
const auto file = IO::Disk::openFile(mapPath);
auto fileReader = file->reader().buffer();

Expand All @@ -59,7 +61,8 @@ TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]") {
std::vector<AABB> trees(100);
timeLambda(
[&world, &trees]() {
for (auto& tree : trees) {
for (auto& tree : trees)
{
world->accept(kdl::overload(
[](auto&& thisLambda, Model::WorldNode* world_) {
world_->visitChildren(thisLambda);
Expand All @@ -74,12 +77,8 @@ TEST_CASE("AABBTreeBenchmark.benchBuildTree", "[AABBTreeBenchmark]") {
entity->visitChildren(thisLambda);
tree.insert(entity->physicalBounds(), entity);
},
[&](Model::BrushNode* brush) {
tree.insert(brush->physicalBounds(), brush);
},
[&](Model::PatchNode* patch) {
tree.insert(patch->physicalBounds(), patch);
}));
[&](Model::BrushNode* brush) { tree.insert(brush->physicalBounds(), brush); },
[&](Model::PatchNode* patch) { tree.insert(patch->physicalBounds(), patch); }));
}
},
"Add objects to AABB tree");
Expand Down
7 changes: 5 additions & 2 deletions common/benchmark/src/BenchmarkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
#endif

// the noinline is so you can see the timeLambda when profiling
template <class L> TB_NOINLINE static void timeLambda(L&& lambda, const std::string& message) {
template <class L>
TB_NOINLINE static void timeLambda(L&& lambda, const std::string& message)
{
const auto start = std::chrono::high_resolution_clock::now();
lambda();
const auto end = std::chrono::high_resolution_clock::now();

printf(
"Time elapsed for '%s': %fms\n", message.c_str(),
"Time elapsed for '%s': %fms\n",
message.c_str(),
std::chrono::duration<double>(end - start).count() * 1000.0);
}
20 changes: 13 additions & 7 deletions common/benchmark/src/IO/TestParserStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@

#include <string>

namespace TrenchBroom {
namespace IO {
namespace TrenchBroom
{
namespace IO
{
NullLogger TestParserStatus::_logger;

TestParserStatus::TestParserStatus()
: ParserStatus(_logger, "") {}
: ParserStatus(_logger, "")
{
}

size_t TestParserStatus::countStatus(LogLevel level) const {
size_t TestParserStatus::countStatus(LogLevel level) const
{
const auto it = m_statusCounts.find(level);
if (it == std::end(m_statusCounts))
return 0;
Expand All @@ -37,9 +42,10 @@ size_t TestParserStatus::countStatus(LogLevel level) const {

void TestParserStatus::doProgress(const double) {}

void TestParserStatus::doLog(const LogLevel level, const std::string& /* str */) {
m_statusCounts[level]++; // unknown map values are value constructed, which initializes to 0 for
// size_t
void TestParserStatus::doLog(const LogLevel level, const std::string& /* str */)
{
m_statusCounts[level]++; // unknown map values are value constructed, which initializes
// to 0 for size_t
}
} // namespace IO
} // namespace TrenchBroom
9 changes: 6 additions & 3 deletions common/benchmark/src/IO/TestParserStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
#include <map>
#include <string>

namespace TrenchBroom {
namespace IO {
class TestParserStatus : public ParserStatus {
namespace TrenchBroom
{
namespace IO
{
class TestParserStatus : public ParserStatus
{
private:
static NullLogger _logger;
using StatusCounts = std::map<LogLevel, size_t>;
Expand Down
52 changes: 32 additions & 20 deletions common/benchmark/src/Renderer/BrushRendererBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,23 @@
#include "../../test/src/Catch2.h"
#include "BenchmarkUtils.h"

namespace TrenchBroom {
namespace Renderer {
namespace TrenchBroom
{
namespace Renderer
{
static constexpr size_t NumBrushes = 64'000;
static constexpr size_t NumTextures = 256;

/**
* Both returned vectors need to be freed with VecUtils::clearAndDelete
*/
static std::pair<std::vector<Model::BrushNode*>, std::vector<Assets::Texture*>> makeBrushes() {
static std::pair<std::vector<Model::BrushNode*>, std::vector<Assets::Texture*>>
makeBrushes()
{
// make textures
std::vector<Assets::Texture*> textures;
for (size_t i = 0; i < NumTextures; ++i) {
for (size_t i = 0; i < NumTextures; ++i)
{
const auto textureName = "texture " + std::to_string(i);
textures.push_back(new Assets::Texture(textureName, 64, 64));
}
Expand All @@ -61,9 +66,11 @@ static std::pair<std::vector<Model::BrushNode*>, std::vector<Assets::Texture*>>

std::vector<Model::BrushNode*> result;
size_t currentTextureIndex = 0;
for (size_t i = 0; i < NumBrushes; ++i) {
for (size_t i = 0; i < NumBrushes; ++i)
{
Model::Brush brush = builder.createCube(64.0, "").value();
for (Model::BrushFace& face : brush.faces()) {
for (Model::BrushFace& face : brush.faces())
{
face.setTexture(textures.at((currentTextureIndex++) % NumTextures));
}
Model::BrushNode* brushNode = new Model::BrushNode(std::move(brush));
Expand All @@ -75,7 +82,8 @@ static std::pair<std::vector<Model::BrushNode*>, std::vector<Assets::Texture*>>
// want it mixed into the timing

BrushRenderer tempRenderer;
for (auto* brushNode : result) {
for (auto* brushNode : result)
{
tempRenderer.addBrush(brushNode);
}
tempRenderer.validate();
Expand All @@ -84,7 +92,8 @@ static std::pair<std::vector<Model::BrushNode*>, std::vector<Assets::Texture*>>
return {result, textures};
}

TEST_CASE("BrushRendererBenchmark.benchBrushRenderer", "[BrushRendererBenchmark]") {
TEST_CASE("BrushRendererBenchmark.benchBrushRenderer", "[BrushRendererBenchmark]")
{
auto brushesTextures = makeBrushes();
std::vector<Model::BrushNode*> brushes = brushesTextures.first;
std::vector<Assets::Texture*> textures = brushesTextures.second;
Expand All @@ -93,28 +102,28 @@ TEST_CASE("BrushRendererBenchmark.benchBrushRenderer", "[BrushRendererBenchmark]

timeLambda(
[&]() {
for (auto* brush : brushes) {
for (auto* brush : brushes)
{
r.addBrush(brush);
}
},
"add " + std::to_string(brushes.size()) + " brushes to BrushRenderer");
timeLambda(
[&]() {
if (!r.valid()) {
if (!r.valid())
{
r.validate();
}
},
"validate after adding " + std::to_string(brushes.size()) + " brushes to BrushRenderer");
"validate after adding " + std::to_string(brushes.size())
+ " brushes to BrushRenderer");

// Tiny change: remove the last brush
timeLambda([&]() { r.removeBrush(brushes.back()); }, "call removeBrush once");
timeLambda(
[&]() {
r.removeBrush(brushes.back());
},
"call removeBrush once");
timeLambda(
[&]() {
if (!r.valid()) {
if (!r.valid())
{
r.validate();
}
},
Expand All @@ -123,8 +132,10 @@ TEST_CASE("BrushRendererBenchmark.benchBrushRenderer", "[BrushRendererBenchmark]
// Large change: keep every second brush
timeLambda(
[&]() {
for (size_t i = 0; i < brushes.size(); ++i) {
if ((i % 2) == 0) {
for (size_t i = 0; i < brushes.size(); ++i)
{
if ((i % 2) == 0)
{
r.removeBrush(brushes[i]);
}
}
Expand All @@ -133,7 +144,8 @@ TEST_CASE("BrushRendererBenchmark.benchBrushRenderer", "[BrushRendererBenchmark]

timeLambda(
[&]() {
if (!r.valid()) {
if (!r.valid())
{
r.validate();
}
},
Expand Down
Loading

0 comments on commit ad81b2a

Please sign in to comment.