diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:25:32 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-20 23:25:32 +0200 |
commit | 4213fa8a986ccfdf03783638862a9aacf3ea8601 (patch) | |
tree | e1d78e3dcc74ce6c2605ff31e035fb7e4ad36453 | |
parent | d22abc50862f7243228c93fd2fd3878b37821487 (diff) |
rename macros
-rw-r--r-- | anim-crop-tool/atlas.cpp | 5 | ||||
-rw-r--r-- | anim-crop-tool/main.cpp | 4 | ||||
-rw-r--r-- | compat/assert.hpp | 47 | ||||
-rw-r--r-- | main/app.cpp | 4 | ||||
-rw-r--r-- | main/debug.cpp | 2 | ||||
-rw-r--r-- | main/editor.cpp | 12 | ||||
-rw-r--r-- | main/loader-impl.cpp | 12 | ||||
-rw-r--r-- | shaders/tile-shader.cpp | 2 | ||||
-rw-r--r-- | src/local-coords.hpp | 4 | ||||
-rw-r--r-- | src/tile-atlas.cpp | 2 | ||||
-rw-r--r-- | test/const-math.cpp | 28 |
11 files changed, 64 insertions, 58 deletions
diff --git a/anim-crop-tool/atlas.cpp b/anim-crop-tool/atlas.cpp index a48ad359..b099435b 100644 --- a/anim-crop-tool/atlas.cpp +++ b/anim-crop-tool/atlas.cpp @@ -12,7 +12,7 @@ void anim_atlas_row::add_entry(const anim_atlas_entry& x) frame.offset = {xpos, ypos}; frame.size = {mat.cols, mat.rows}; - ASSERT(mat.rows > 0 && mat.cols > 0); + fm_assert(mat.rows > 0 && mat.cols > 0); data.push_back(x); xpos += mat.cols; max_height = std::max(mat.rows, max_height); @@ -23,7 +23,8 @@ void anim_atlas::advance_row() auto& row = rows.back(); if (row.data.empty()) return; - ASSERT(row.xpos > 0); ASSERT(row.max_height > 0); + fm_assert(row.xpos > 0); + fm_assert(row.max_height > 0); ypos += row.max_height; maxx = std::max(row.xpos, maxx); rows.push_back({{}, 0, 0, ypos}); diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 11b1d165..126c3aa3 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -89,12 +89,12 @@ static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const if (opts.scale == 0.0) { - ASSERT(opts.width || opts.height); + fm_assert(opts.width || opts.height); if (opts.width) opts.scale = (double)opts.width / size.width; else opts.scale = (double)opts.height / size.height; - ASSERT(opts.scale > 1e-6); + fm_assert(opts.scale > 1e-6); } const cv::Size dest_size = { diff --git a/compat/assert.hpp b/compat/assert.hpp index 0d3efd09..44b401fa 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -9,23 +9,27 @@ # pragma GCC diagnostic ignored "-Wunused-macros" #endif -#define emit_debug(pfx, ...) \ - do { \ - if (!std::is_constant_evaluated()) { \ - if constexpr (sizeof(pfx) > 1) \ - std::fputs((pfx), stderr); \ - std::fprintf(stderr, __VA_ARGS__); \ - std::fputc('\n', stderr); \ - std::fflush(stderr); \ - } \ +#define fm_EMIT_DEBUG(pfx, ...) \ + do { \ + if (!std::is_constant_evaluated()) { \ + if constexpr (sizeof(pfx) > 1) \ + std::fputs((pfx), stderr); \ + std::fprintf(stderr, __VA_ARGS__); \ + std::fputc('\n', stderr); \ + std::fflush(stderr); \ + } \ } while (false) -#define ABORT(...) do { emit_debug("fatal: ", __VA_ARGS__); std::abort(); } while (false) +#define fm_abort(...) \ + do { \ + fm_EMIT_DEBUG("fatal: ", __VA_ARGS__); \ + std::abort(); \ + } while (false) -#define ASSERT(...) \ +#define fm_assert(...) \ do { \ if (!(__VA_ARGS__)) { \ - emit_debug("", "assertion failed: '%s' in %s:%d", \ + fm_EMIT_DEBUG("", "assertion failed: '%s' in %s:%d", \ #__VA_ARGS__, __FILE__, __LINE__); \ std::abort(); \ } \ @@ -34,20 +38,24 @@ #define ASSERT_EXPR(var, expr, cond) \ ([&] { \ decltype(auto) var = (expr); \ - ASSERT(cond); \ + fm_assert(cond); \ return (var); \ })() -#define WARN(...) emit_debug("warning: ", __VA_ARGS__) -#define ERR(...) emit_debug("error: ", __VA_ARGS__) -#define MESSAGE(...) emit_debug("", __VA_ARGS__) -#define DEBUG(...) emit_debug("", __VA_ARGS__) +#define fm_warn(...) fm_EMIT_DEBUG("warning: ", __VA_ARGS__) +#define fm_error(...) fm_EMIT_DEBUG("error: ", __VA_ARGS__) +#define fm_log(...) fm_EMIT_DEBUG("", __VA_ARGS__) +#define fm_debug(...) fm_EMIT_DEBUG("", __VA_ARGS__) + +#ifdef __GNUG__ +# pragma GCC diagnostic pop +#endif namespace floormat { template<bool> struct static_warning_ final { - [[deprecated]] constexpr static_warning_() = default; + [[deprecated("compile-time warning valuated to 'true'")]] constexpr static_warning_() = default; }; template<> @@ -59,6 +67,3 @@ struct static_warning_<true> final { } // namespace floormat -#ifdef __GNUG__ -# pragma GCC diagnostic pop -#endif diff --git a/main/app.cpp b/main/app.cpp index a5062a82..5fa7dfb9 100644 --- a/main/app.cpp +++ b/main/app.cpp @@ -55,7 +55,7 @@ app::app(const Arguments& arguments, app_settings opts): reset_camera_offset(); #if 1 - ASSERT(framebufferSize() == windowSize()); + fm_assert(framebufferSize() == windowSize()); _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize()); recalc_viewport(windowSize()); #else @@ -88,7 +88,7 @@ void app::recalc_viewport(Vector2i size) void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event) { - ASSERT(event.framebufferSize() == event.windowSize()); + fm_assert(event.framebufferSize() == event.windowSize()); recalc_viewport(event.windowSize()); } diff --git a/main/debug.cpp b/main/debug.cpp index 2b7d9e1d..3383948b 100644 --- a/main/debug.cpp +++ b/main/debug.cpp @@ -38,7 +38,7 @@ void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type switch (severity) { using enum GL::DebugOutput::Severity; - case Notification: std::fputs("DEBUG ", stdout); break; + case Notification: std::fputs("fm_debug ", stdout); break; case Low: std::fputs("INFO ", stdout); break; case Medium: std::fputs("NOTICE ", stdout); break; case High: std::fputs("ERROR ", stdout); break; diff --git a/main/editor.cpp b/main/editor.cpp index 38697a30..cfe793b9 100644 --- a/main/editor.cpp +++ b/main/editor.cpp @@ -51,7 +51,7 @@ std::shared_ptr<tile_atlas> tile_type::atlas(Containers::StringView str) if (auto ptr = maybe_atlas(str); ptr) return ptr; else - ABORT("no such atlas: %s", str.cbegin()); + fm_abort("no such atlas: %s", str.cbegin()); } void tile_type::clear_selection() @@ -63,7 +63,7 @@ void tile_type::clear_selection() void tile_type::select_tile(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant) { - ASSERT(atlas); + fm_assert(atlas); clear_selection(); _selection_mode = sel_tile; _selected_tile = { atlas, variant }; @@ -71,7 +71,7 @@ void tile_type::select_tile(const std::shared_ptr<tile_atlas>& atlas, std::uint8 void tile_type::select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas) { - ASSERT(atlas); + fm_assert(atlas); clear_selection(); _selection_mode = sel_perm; _permutation = { atlas, {} }; @@ -79,13 +79,13 @@ void tile_type::select_tile_permutation(const std::shared_ptr<tile_atlas>& atlas bool tile_type::is_tile_selected(const std::shared_ptr<tile_atlas>& atlas, std::uint8_t variant) { - ASSERT(atlas); + fm_assert(atlas); return _selection_mode == sel_tile && _selected_tile == std::make_tuple(atlas, variant); } bool tile_type::is_permutation_selected(const std::shared_ptr<tile_atlas>& atlas) { - ASSERT(atlas); + fm_assert(atlas); return _selection_mode == sel_perm && std::get<0>(_permutation) == atlas; } @@ -135,7 +135,7 @@ void tile_type::place_tile(world& world, global_coords pos) switch (_mode) { case editor_mode::select: - WARN("wrong tile mode 'select'"); break; + fm_warn("wrong tile mode 'select'"); break; case editor_mode::floor: case editor_mode::walls: diff --git a/main/loader-impl.cpp b/main/loader-impl.cpp index 8112b350..9816fd40 100644 --- a/main/loader-impl.cpp +++ b/main/loader-impl.cpp @@ -48,7 +48,7 @@ std::string loader_impl::shader(Containers::StringView filename) shader_res = std::make_optional<Utility::Resource>("floormat/shaders"); auto ret = shader_res->getString(filename); if (ret.isEmpty()) - ABORT("can't find shader resource '%s'", filename.cbegin()); + fm_abort("can't find shader resource '%s'", filename.cbegin()); return ret; } @@ -66,19 +66,19 @@ std::shared_ptr<tile_atlas> loader_impl::tile_atlas(Containers::StringView name, Trade::ImageData2D loader_impl::tile_texture(Containers::StringView filename_) { static_assert(IMAGE_PATH[sizeof(IMAGE_PATH)-2] == '/'); - ASSERT(filename_.size() < 4096); + fm_assert(filename_.size() < 4096); char* const filename = (char*)alloca(filename_.size() + sizeof(IMAGE_PATH)); std::memcpy(filename, IMAGE_PATH, sizeof(IMAGE_PATH)-1); std::strcpy(filename + sizeof(IMAGE_PATH)-1, filename_.cbegin()); if (!tga_importer || !tga_importer->openFile(filename)) { const auto path = Utility::Path::currentDirectory(); - MESSAGE("note: current working directory: '%s'", path->data()); - ABORT("can't open tile image '%s'", filename); + fm_log("note: current working directory: '%s'", path->data()); + fm_abort("can't open tile image '%s'", filename); } auto img = tga_importer->image2D(0); if (!img) - ABORT("can't allocate tile image for '%s'", filename); + fm_abort("can't allocate tile image for '%s'", filename); auto ret = std::move(*img); return ret; } @@ -103,7 +103,7 @@ void loader_impl::set_application_working_directory() std::error_code error; std::filesystem::current_path(path, error); if (error.value()) { - WARN("failed to change working directory to '%s' (%s)", + fm_warn("failed to change working directory to '%s' (%s)", path.string().data(), error.message().data()); } } diff --git a/shaders/tile-shader.cpp b/shaders/tile-shader.cpp index 87238f5a..11dc7c49 100644 --- a/shaders/tile-shader.cpp +++ b/shaders/tile-shader.cpp @@ -57,7 +57,7 @@ void tile_shader::_draw() if (const auto offset = Vector2{(float)_camera_offset[0], (float)_camera_offset[1]}; offset != _real_camera_offset) { - ASSERT(offset[0] < 1 << 24 && offset[1] < 1 << 24); + fm_assert(offset[0] < 1 << 24 && offset[1] < 1 << 24); _real_camera_offset = offset; setUniform(OffsetUniform, offset); } diff --git a/src/local-coords.hpp b/src/local-coords.hpp index f5615f9a..1e7fbbed 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -20,7 +20,7 @@ constexpr local_coords::local_coords(std::size_t index) noexcept : x{(std::uint8_t)(index % TILE_MAX_DIM)}, y{(std::uint8_t)(index / TILE_MAX_DIM)} { - ASSERT(index < TILE_COUNT); + fm_assert(index < TILE_COUNT); } template<std::integral T> @@ -28,7 +28,7 @@ requires (sizeof(T) <= sizeof(std::size_t)) constexpr local_coords::local_coords(T x, T y) noexcept : x{(std::uint8_t)x}, y{(std::uint8_t)y} { - ASSERT(static_cast<std::size_t>(x) < TILE_MAX_DIM && static_cast<std::size_t>(y) < TILE_MAX_DIM); + fm_assert(static_cast<std::size_t>(x) < TILE_MAX_DIM && static_cast<std::size_t>(y) < TILE_MAX_DIM); } } // namespace floormat diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 6688536f..d08b4798 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -25,7 +25,7 @@ tile_atlas::tile_atlas(Containers::StringView name, const ImageView2D& image, Ve std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t i) const { - ASSERT(i < (size_/dims_).product()); + fm_assert(i < (size_/dims_).product()); return texcoords_[i]; } diff --git a/test/const-math.cpp b/test/const-math.cpp index 2b8cbc3c..63baff4d 100644 --- a/test/const-math.cpp +++ b/test/const-math.cpp @@ -21,13 +21,13 @@ static constexpr void test_float2() { const vec a{(T)1, (T)2}, b{(T)2, (T)3}; - ASSERT(a[0] == (T)1 && a[1] == (T)2); - ASSERT(a + b == vec{(T)3, (T)5}); - ASSERT(a - b == vec{(T)-1, (T)-1}); - ASSERT(a * b == vec{(T)2, (T)6}); - ASSERT(b / a == vec{(T)2, (T)1.5}); - ASSERT(b.product() == (T)6); - ASSERT(b.sum() == (T)5); + fm_assert(a[0] == (T)1 && a[1] == (T)2); + fm_assert(a + b == vec{(T)3, (T)5}); + fm_assert(a - b == vec{(T)-1, (T)-1}); + fm_assert(a * b == vec{(T)2, (T)6}); + fm_assert(b / a == vec{(T)2, (T)1.5}); + fm_assert(b.product() == (T)6); + fm_assert(b.sum() == (T)5); } template<typename ivec> @@ -37,13 +37,13 @@ static constexpr void test_int() constexpr auto vec = [](auto x, auto y) { return ivec{(I)x, (I)y}; }; const auto a = vec(3, 5), b = vec(11, 7); - ASSERT(a[0] == 3 && a[1] == 5); - ASSERT(a + b == vec(14,12)); - ASSERT(b - a == vec(8, 2)); - ASSERT(b % a == vec(2, 2)); - ASSERT(b / a == vec(3, 1)); - ASSERT(a.product() == 15); - ASSERT(a.sum() == 8); + fm_assert(a[0] == 3 && a[1] == 5); + fm_assert(a + b == vec(14,12)); + fm_assert(b - a == vec(8, 2)); + fm_assert(b % a == vec(2, 2)); + fm_assert(b / a == vec(3, 1)); + fm_assert(a.product() == 15); + fm_assert(a.sum() == 8); } static constexpr void* compile_tests() |