summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-06 13:30:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-06 13:37:15 +0200
commit3534cd206bedef5ea75302d9abf879b15d1df89c (patch)
tree977f646ae1282ff7f539d2a524d1e354bfcf465d
parent4d6f747c4b8287e042363264a47265848ca2d92c (diff)
test: speed up compile time
Removes implicit includes to <windows.h> and <cr/StringView.h> from all files. Goes from 30 to 20 seconds.
-rw-r--r--compat/array-size.hpp19
-rw-r--r--compat/function2.hpp2
-rw-r--r--src/timer.cpp8
-rw-r--r--test/app.cpp25
-rw-r--r--test/app.hpp67
-rw-r--r--test/bitmask.cpp2
-rw-r--r--test/bptr.cpp2
-rw-r--r--test/coords.cpp2
-rw-r--r--test/critter.cpp2
-rw-r--r--test/dijkstra.cpp2
-rw-r--r--test/entity.cpp2
-rw-r--r--test/hash.cpp7
-rw-r--r--test/intrusive-ptr.cpp2
-rw-r--r--test/json.cpp6
-rw-r--r--test/loader.cpp6
-rw-r--r--test/magnum-math.cpp2
-rw-r--r--test/math.cpp2
-rw-r--r--test/path-search.cpp4
-rw-r--r--test/raycast.cpp2
-rw-r--r--test/region.cpp2
-rw-r--r--test/save.cpp8
-rw-r--r--test/script.cpp2
-rw-r--r--test/search-result.cpp2
-rw-r--r--test/wall-atlas.cpp2
-rw-r--r--test/wall-atlas2.cpp2
-rw-r--r--test/zzz_test_misc.cpp2
26 files changed, 102 insertions, 82 deletions
diff --git a/compat/array-size.hpp b/compat/array-size.hpp
new file mode 100644
index 00000000..ca545898
--- /dev/null
+++ b/compat/array-size.hpp
@@ -0,0 +1,19 @@
+#pragma once
+#include <array>
+
+namespace floormat::detail {
+
+template<typename T> struct array_size_; // todo! replace usages of arraySize & std::size
+template<typename T, size_t N> struct array_size_<T(&)[N]> : std::integral_constant<size_t, N> {};
+template<typename T, size_t N> struct array_size_<T[N]> : std::integral_constant<size_t, N> {};
+template<typename T, size_t N> struct array_size_<std::array<T, N>> : std::integral_constant<size_t, N> {};
+template<typename T, size_t N> struct array_size_<StaticArray<N, T>> : std::integral_constant<size_t, N> {};
+
+} // namespace floormat::detail
+
+namespace floormat {
+
+template<typename T> constexpr inline size_t static_array_size = detail::array_size_<T>::value;
+template<typename T> constexpr inline size_t array_size(const T&) noexcept { return detail::array_size_<T>::value; }
+
+} // namespace floormat
diff --git a/compat/function2.hpp b/compat/function2.hpp
index cd23bad9..54f00111 100644
--- a/compat/function2.hpp
+++ b/compat/function2.hpp
@@ -17,7 +17,7 @@
#define FU2_WITH_NO_FUNCTIONAL_HEADER
#include <cassert>
#include <cstddef>
-//#include <cstdlib>
+#include <cstdlib>
#include <memory>
#include <tuple>
#include <type_traits>
diff --git a/src/timer.cpp b/src/timer.cpp
index c03c61d6..ad78f383 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -1,5 +1,6 @@
#include "timer.hpp"
#include "compat/assert.hpp"
+#include "compat/array-size.hpp"
#include "nanosecond.hpp"
#include <ctime>
#include <cstdio>
@@ -18,11 +19,6 @@ using Millis = duration<unsigned, std::milli>;
namespace {
-template<typename T> struct array_size_; // todo! move to compat, replace usages of arraySize & std::size_t
-template<typename T, size_t N> struct array_size_<T(&)[N]> : std::integral_constant<size_t, N> {};
-template<typename T, size_t N> struct array_size_<std::array<T, N>> : std::integral_constant<size_t, N> {};
-template<typename T> constexpr inline auto array_size = array_size_<T>::value;
-
uint64_t get_time() noexcept { return duration_cast<Nsecs>(Clock::now().time_since_epoch()).count(); }
const uint64_t Epoch = get_time();
@@ -77,7 +73,7 @@ const char* format_datetime_to_string(char (&buf)[fm_DATETIME_BUF_SIZE])
{
constexpr const char* fmt = "%a, %d %b %Y %H:%M:%S.";
constexpr size_t fmtsize = std::size("Thu 01 Mon 197000 00:00:00.");
- static_assert(array_size<decltype(buf)> - fmtsize == 4);
+ static_assert(static_array_size<decltype(buf)> - fmtsize == 4);
const auto t = SystemClock::now();
const auto ms = duration_cast<Millis>(t.time_since_epoch()) % 1000;
const auto time = SystemClock::to_time_t(t);
diff --git a/test/app.cpp b/test/app.cpp
index 765bb802..91fd7b7c 100644
--- a/test/app.cpp
+++ b/test/app.cpp
@@ -1,4 +1,5 @@
#include "app.hpp"
+#include "compat/headless.hpp"
#include "loader/loader.hpp"
#include <stdlib.h> // NOLINT(*-deprecated-headers)
#include <cstdio>
@@ -6,8 +7,9 @@
#include <Magnum/Math/Functions.h>
#include <Magnum/Timeline.h>
#include <Magnum/GL/Context.h>
+#include <Magnum/Magnum.h>
-namespace floormat {
+namespace floormat::Test {
namespace {
@@ -20,7 +22,16 @@ bool is_log_quiet() // copy-pasted from src/chunk.cpp
} // namespace
-test_app::test_app(const Arguments& arguments):
+struct App final : private FM_APPLICATION
+{
+ using Application = FM_APPLICATION;
+ explicit App(const Arguments& arguments);
+ ~App();
+
+ int exec() override;
+};
+
+App::App(const Arguments& arguments):
Application {
arguments,
Configuration{}
@@ -28,12 +39,12 @@ test_app::test_app(const Arguments& arguments):
{
}
-test_app::~test_app()
+App::~App()
{
loader.destroy();
}
-int test_app::exec()
+int App::exec()
{
constexpr auto SV_flags = StringViewFlag::Global|StringViewFlag::NullTerminated;
constexpr auto name_prefix = "test_"_s;
@@ -122,7 +133,7 @@ int test_app::exec()
return 0;
}
-} // namespace floormat
+} // namespace floormat::Test
int main(int argc, char** argv)
{
@@ -133,6 +144,6 @@ int main(int argc, char** argv)
#else
::setenv("MAGNUM_LOG", "quiet", 0);
#endif
- floormat::test_app application{{argc, argv}};
- return application.exec();
+ auto app = floormat::Test::App{{argc, argv}};
+ return app.exec();
}
diff --git a/test/app.hpp b/test/app.hpp
index d7dfa19e..7e2381bc 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -1,8 +1,6 @@
#pragma once
#undef FM_NO_DEBUG
#include "compat/assert.hpp"
-#include "compat/headless.hpp"
-#include <Magnum/Magnum.h>
namespace floormat {
@@ -11,42 +9,37 @@ struct chunk_coords_;
class chunk;
class world;
-struct test_app final : private FM_APPLICATION
-{
- using Application = FM_APPLICATION;
- explicit test_app(const Arguments& arguments);
- ~test_app();
+} // namespace floormat
- static chunk& make_test_chunk(world& w, chunk_coords_ ch);
+namespace floormat::Test {
- int exec() override;
+chunk& make_test_chunk(world& w, chunk_coords_ ch);
- static void test_astar();
- static void test_astar_pool();
- static void test_bitmask();
- static void test_bptr();
- static void test_coords();
- static void test_critter();
- static void test_dijkstra();
- static void test_entity();
- static void test_hash();
- static void test_iptr();
- static void test_json();
- static void test_json2();
- static void test_json3();
- static void test_loader();
- static void test_loader2();
- static void test_loader3();
- static void test_magnum_math();
- static void test_math();
- static void test_raycast();
- static void test_region();
- static void test_save();
- static void test_saves();
- static void test_script();
- static void test_wall_atlas();
- static void test_wall_atlas2();
+void test_astar();
+void test_astar_pool();
+void test_bitmask();
+void test_bptr();
+void test_coords();
+void test_critter();
+void test_dijkstra();
+void test_entity();
+void test_hash();
+void test_iptr();
+void test_json();
+void test_json2();
+void test_json3();
+void test_loader();
+void test_loader2();
+void test_loader3();
+void test_magnum_math();
+void test_math();
+void test_raycast();
+void test_region();
+void test_save();
+void test_saves();
+void test_script();
+void test_wall_atlas();
+void test_wall_atlas2();
+void test_zzz_misc();
- static void test_zzz_misc();
-};
-} // namespace floormat
+} // namespace floormat::Test
diff --git a/test/bitmask.cpp b/test/bitmask.cpp
index a1bbd0de..369c1e54 100644
--- a/test/bitmask.cpp
+++ b/test/bitmask.cpp
@@ -48,7 +48,7 @@ void bitmask_test()
} // namespace
-void test_app::test_bitmask()
+void Test::test_bitmask()
{
bitmask_test();
//bitmask_benchmark();
diff --git a/test/bptr.cpp b/test/bptr.cpp
index 6050c4f5..e4672d66 100644
--- a/test/bptr.cpp
+++ b/test/bptr.cpp
@@ -338,7 +338,7 @@ void test9()
} // namespace
-void test_app::test_bptr()
+void Test::test_bptr()
{
test1();
test2();
diff --git a/test/coords.cpp b/test/coords.cpp
index 353b343a..86c26ef6 100644
--- a/test/coords.cpp
+++ b/test/coords.cpp
@@ -28,7 +28,7 @@ void test_normalize_point()
} // namespace
-void test_app::test_coords()
+void Test::test_coords()
{
test_normalize_point();
}
diff --git a/test/critter.cpp b/test/critter.cpp
index 950e2d01..d9fa486d 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -344,7 +344,7 @@ void test3(StringView instance_name, const Function& make_dt, double accel, rota
} // namespace
-void test_app::test_critter()
+void Test::test_critter()
{
const bool is_noisy = !Start{}.quiet;
if (is_noisy)
diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp
index 4d9f2187..7c43ee74 100644
--- a/test/dijkstra.cpp
+++ b/test/dijkstra.cpp
@@ -9,7 +9,7 @@
namespace floormat {
-void test_app::test_dijkstra()
+void Test::test_dijkstra()
{
[[maybe_unused]] constexpr bool debug = false;
diff --git a/test/entity.cpp b/test/entity.cpp
index 1aa65f3f..2bbdf29a 100644
--- a/test/entity.cpp
+++ b/test/entity.cpp
@@ -294,7 +294,7 @@ constexpr bool test_enum_range()
} // namespace
-void test_app::test_entity()
+void Test::test_entity()
{
static_assert(test_accessors());
static_assert(test_visitor());
diff --git a/test/hash.cpp b/test/hash.cpp
index 4e8d9d81..16ae3173 100644
--- a/test/hash.cpp
+++ b/test/hash.cpp
@@ -1,6 +1,7 @@
#include "app.hpp"
#include "compat/int-hash.hpp"
-#include <Corrade/Containers/StringView.h>
+#include "compat/array-size.hpp"
+#include <cr/StringView.h>
#include <bitset>
#include <memory>
@@ -11,7 +12,7 @@ namespace {
void test_simple()
{
constexpr StringView list[] = { "foo"_s, "bar"_s, "bar\0"_s, "bar2"_s, "baz"_s, };
- constexpr auto size = arraySize(list);
+ constexpr auto size = array_size(list);
size_t hashes[size] = {};
for (auto i = 0uz; i < size; i++)
@@ -63,7 +64,7 @@ void test_collisions()
} // namespace
-void test_app::test_hash()
+void Test::test_hash()
{
test_simple();
test_collisions();
diff --git a/test/intrusive-ptr.cpp b/test/intrusive-ptr.cpp
index aa221026..e019ee00 100644
--- a/test/intrusive-ptr.cpp
+++ b/test/intrusive-ptr.cpp
@@ -157,7 +157,7 @@ constexpr bool test_cexpr() // todo
} // namespace
-void test_app::test_iptr()
+void Test::test_iptr()
{
static_assert(test_cexpr());
test_copy();
diff --git a/test/json.cpp b/test/json.cpp
index 372465b5..e9ed166f 100644
--- a/test/json.cpp
+++ b/test/json.cpp
@@ -15,7 +15,7 @@
namespace floormat {
-void test_app::test_json() // NOLINT(readability-convert-member-functions-to-static)
+void Test::test_json() // NOLINT(readability-convert-member-functions-to-static)
{
fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
const auto output_dir = Path::join(loader.TEMP_PATH, "test/."_s);
@@ -32,7 +32,7 @@ void test_app::test_json() // NOLINT(readability-convert-member-functions-to-sta
}
}
-void test_app::test_json2()
+void Test::test_json2()
{
fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
const auto output_dir = Path::join(loader.TEMP_PATH, "test/."_s);
@@ -42,7 +42,7 @@ void test_app::test_json2()
atlas2->serialize(Path::join(output_dir, "atlas2.json"));
}
-void test_app::test_json3()
+void Test::test_json3()
{
fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
const auto output_dir = Path::join(loader.TEMP_PATH, "test/."_s);
diff --git a/test/loader.cpp b/test/loader.cpp
index 4bd8e4f3..d551276f 100644
--- a/test/loader.cpp
+++ b/test/loader.cpp
@@ -45,12 +45,12 @@ constexpr const char* sceneries[] = {
} // namespace
-void test_app::test_loader()
+void Test::test_loader()
{
fm_assert(loader.ground_atlas("texel")->pass_mode() == pass_mode::blocked);
}
-void test_app::test_loader2()
+void Test::test_loader2()
{
constexpr auto nonexistent = "__/nonexistent/__"_s;
@@ -92,7 +92,7 @@ void test_app::test_loader2()
}
}
-void test_app::test_loader3()
+void Test::test_loader3()
{
for (const auto& x : loader.ground_atlas_list())
{
diff --git a/test/magnum-math.cpp b/test/magnum-math.cpp
index a9b7e98d..60a2f2a4 100644
--- a/test/magnum-math.cpp
+++ b/test/magnum-math.cpp
@@ -57,7 +57,7 @@ constexpr bool compile_tests()
} // namespace
-void test_app::test_magnum_math()
+void Test::test_magnum_math()
{
static_assert(compile_tests());
}
diff --git a/test/math.cpp b/test/math.cpp
index 9befad18..64ab1164 100644
--- a/test/math.cpp
+++ b/test/math.cpp
@@ -91,7 +91,7 @@ constexpr bool test_ceil()
} // namespace
-void test_app::test_math()
+void Test::test_math()
{
static_assert(test_double_sqrt());
fm_assert(test_sqrt<float>());
diff --git a/test/path-search.cpp b/test/path-search.cpp
index 90accd3a..0ac6cefd 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -241,7 +241,7 @@ void test_bbox()
using enum rotation;
constexpr auto ch = chunk_coords_{0, 0, 0};
auto w = world();
- auto& c = test_app::make_test_chunk(w, ch);
+ auto& c = Test::make_test_chunk(w, ch);
constexpr auto is_passable_NESW = [](chunk& c, Vector2i coord, std::array<bool, 4> dirs)
{
@@ -342,7 +342,7 @@ void test_bbox()
} // namespace
-void test_app::test_astar()
+void Test::test_astar()
{
test_bbox();
}
diff --git a/test/raycast.cpp b/test/raycast.cpp
index 5a80f1dc..28ed4f67 100644
--- a/test/raycast.cpp
+++ b/test/raycast.cpp
@@ -87,7 +87,7 @@ auto run(point from, point to, world& w, bool b, float len)
} // namespace
-void test_app::test_raycast()
+void Test::test_raycast()
{
auto w = make_world();
{ constexpr auto from = point{{0, 0, 0}, {11,12}, {1,-32}};
diff --git a/test/region.cpp b/test/region.cpp
index ab0d552a..ed3c38f7 100644
--- a/test/region.cpp
+++ b/test/region.cpp
@@ -100,7 +100,7 @@ void test3()
} // namespace
-void test_app::test_region()
+void Test::test_region()
{
test1();
test2();
diff --git a/test/save.cpp b/test/save.cpp
index a853bf82..cf4ccd44 100644
--- a/test/save.cpp
+++ b/test/save.cpp
@@ -15,7 +15,7 @@ namespace floormat {
namespace Path = Corrade::Utility::Path;
-chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch)
+chunk& Test::make_test_chunk(world& w, chunk_coords_ ch)
{
chunk& c = w[ch];
c.mark_modified();
@@ -151,7 +151,7 @@ void run(StringView input, StringView tmp)
{
coord = {1, 1, 0};
w = world();
- auto& c = test_app::make_test_chunk(w, coord);
+ auto& c = Test::make_test_chunk(w, coord);
fm_assert(!c.empty(true));
}
w.serialize(tmp);
@@ -297,13 +297,13 @@ void test_save_objs()
} // namespace
-void test_app::test_save()
+void Test::test_save()
{
fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
test_save_1();
}
-void test_app::test_saves()
+void Test::test_saves()
{
fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt")));
test_save_2();
diff --git a/test/script.cpp b/test/script.cpp
index 45ce9b1d..d7106876 100644
--- a/test/script.cpp
+++ b/test/script.cpp
@@ -11,7 +11,7 @@ void test_script1()
} // namespace
-void test_app::test_script()
+void Test::test_script()
{
test_script1();
}
diff --git a/test/search-result.cpp b/test/search-result.cpp
index 2d5532c0..c2837e4f 100644
--- a/test/search-result.cpp
+++ b/test/search-result.cpp
@@ -27,7 +27,7 @@ size_t path_search_result_pool_access<Test_PathPool>::pool_size()
return ret;
}
-void test_app::test_astar_pool()
+void Test::test_astar_pool()
{
const auto& pool = psrpa::get_pool();
fm_assert(psrpa::pool_size() == 0);
diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp
index 4a761cfe..3106c7e7 100644
--- a/test/wall-atlas.cpp
+++ b/test/wall-atlas.cpp
@@ -129,7 +129,7 @@ void test_expected_size()
} // namespace floormat::Wall::detail
-void floormat::test_app::test_wall_atlas()
+void floormat::Test::test_wall_atlas()
{
using namespace floormat::Wall::detail;
using namespace floormat::Wall;
diff --git a/test/wall-atlas2.cpp b/test/wall-atlas2.cpp
index 3faa306f..d22399be 100644
--- a/test/wall-atlas2.cpp
+++ b/test/wall-atlas2.cpp
@@ -100,7 +100,7 @@ void test_concrete_wall()
} // namespace
-void test_app::test_wall_atlas2()
+void Test::test_wall_atlas2()
{
test_empty_wall();
test_loading();
diff --git a/test/zzz_test_misc.cpp b/test/zzz_test_misc.cpp
index b5a13884..22e0f2fc 100644
--- a/test/zzz_test_misc.cpp
+++ b/test/zzz_test_misc.cpp
@@ -9,7 +9,7 @@ void test_foo() {}
} // namespace
-void test_app::test_zzz_misc()
+void Test::test_zzz_misc()
{
test_foo();
}