summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/array-size.hpp2
-rw-r--r--editor/imgui-editors.cpp3
-rw-r--r--editor/inspect-draw.cpp3
-rw-r--r--editor/tests.cpp5
-rw-r--r--editor/tests/path-test.cpp11
-rw-r--r--editor/tests/raycast-test.cpp21
-rw-r--r--editor/wall-editor.cpp3
-rw-r--r--loader/texture.cpp5
-rw-r--r--loader/wall-traits.cpp3
-rw-r--r--serialize/wall-atlas.cpp5
-rw-r--r--src/anim-atlas.cpp3
-rw-r--r--src/search-astar.cpp3
-rw-r--r--src/search-cache.cpp3
-rw-r--r--src/search.cpp3
-rw-r--r--src/timer.cpp6
-rw-r--r--src/wall-atlas.cpp3
-rw-r--r--src/wall-atlas.hpp3
-rw-r--r--test/app.cpp3
-rw-r--r--test/bitmask.cpp5
19 files changed, 55 insertions, 38 deletions
diff --git a/compat/array-size.hpp b/compat/array-size.hpp
index ca545898..15eb66ab 100644
--- a/compat/array-size.hpp
+++ b/compat/array-size.hpp
@@ -3,7 +3,7 @@
namespace floormat::detail {
-template<typename T> struct array_size_; // todo! replace usages of arraySize & std::size
+template<typename T> struct array_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> {};
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index 4872f9a2..a2ddbf5b 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -1,5 +1,6 @@
#include "app.hpp"
#include "src/tile-constants.hpp"
+#include "compat/array-size.hpp"
#include "compat/format.hpp"
#include "imgui-raii.hpp"
#include "ground-editor.hpp"
@@ -83,7 +84,7 @@ void draw_editor_tile_pane_atlas(ground_editor& ed, StringView name, const std::
text(" (selected)");
}
const auto len = snformat(buf, "{:d}"_cf, N);
- fm_assert(len < std::size(buf));
+ fm_assert(len < array_size(buf));
ImGui::SameLine(window_width - ImGui::CalcTextSize(buf).x - style.FramePadding.x - 4*dpi[0]);
text({buf, len});
};
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index e495e7ad..c420c03e 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -1,4 +1,5 @@
#include "app.hpp"
+#include "compat/array-size.hpp"
#include "compat/format.hpp"
#include "inspect.hpp"
#include "floormat/main.hpp"
@@ -47,7 +48,7 @@ auto z = e.coord.z();
#else
entity_inspector_name(buf2, sizeof buf2, e.id);
entity_friendly_name(buf3, sizeof buf3, e);
- std::snprintf(buf, std::size(buf), "%s###%s", buf3, buf2);
+ std::snprintf(buf, array_size(buf), "%s###%s", buf3, buf2);
#endif
bool is_open = true;
diff --git a/editor/tests.cpp b/editor/tests.cpp
index d55da0c8..077e03dd 100644
--- a/editor/tests.cpp
+++ b/editor/tests.cpp
@@ -1,4 +1,5 @@
#include "tests-private.hpp"
+#include "compat/array-size.hpp"
#include "compat/safe-ptr.hpp"
#include "app.hpp"
#include "floormat/main.hpp"
@@ -20,7 +21,7 @@
namespace floormat::tests {
-static_assert(arraySize(tests_data::fields) <= (size_t)Test::COUNT);
+static_assert(array_size(tests_data::fields) <= (size_t)Test::COUNT);
Pointer<base_test> tests_data::make_test_none() { return {}; }
@@ -42,7 +43,7 @@ using namespace floormat::imgui;
void tests_data::switch_to(Test i)
{
- fm_assert((size_t)i < arraySize(fields));
+ fm_assert((size_t)i < array_size(fields));
current_index = Test::none;
current_test = make_test_none();
if (i < Test::COUNT)
diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp
index 4558fedd..63b59dd4 100644
--- a/editor/tests/path-test.cpp
+++ b/editor/tests/path-test.cpp
@@ -1,5 +1,6 @@
#include "../tests-private.hpp"
#include "../app.hpp"
+#include "compat/array-size.hpp"
#include "compat/shared-ptr-wrapper.hpp"
#include "compat/vector-wrapper.hpp"
#include "floormat/main.hpp"
@@ -187,7 +188,7 @@ void path_test::draw_ui(app&, float)
constexpr auto print_coord = [](auto&& buf, Vector3i c, Vector2i l, Vector2i p)
{
- std::snprintf(buf, std::size(buf), "(ch %dx%d) <%dx%d> {%dx%d px}", c.x(), c.y(), l.x(), l.y(), p.x(), p.y());
+ std::snprintf(buf, array_size(buf), "(ch %dx%d) <%dx%d> {%dx%d px}", c.x(), c.y(), l.x(), l.y(), p.x(), p.y());
};
constexpr auto do_column = [](StringView name)
@@ -226,21 +227,21 @@ void path_test::draw_ui(app&, float)
{
auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf);
do_column("dist");
- std::snprintf(buf, std::size(buf), "%d", (int)res.distance());
+ std::snprintf(buf, array_size(buf), "%d", (int)res.distance());
text(buf);
}
}
do_column("cost");
- std::snprintf(buf, std::size(buf), "%d", (int)res.cost());
+ std::snprintf(buf, array_size(buf), "%d", (int)res.cost());
text(buf);
do_column("length");
- std::snprintf(buf, std::size(buf), "%d", (int)res.path().size());
+ std::snprintf(buf, array_size(buf), "%d", (int)res.path().size());
text(buf);
do_column("time");
- std::snprintf(buf, std::size(buf), "%.1f ms", (double)(1000 * res.time()));
+ std::snprintf(buf, array_size(buf), "%.1f ms", (double)(1000 * res.time()));
text(buf);
}
}
diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp
index d1f72b70..6596303f 100644
--- a/editor/tests/raycast-test.cpp
+++ b/editor/tests/raycast-test.cpp
@@ -1,6 +1,7 @@
#include "../tests-private.hpp"
#include "editor/app.hpp"
#include "floormat/main.hpp"
+#include "compat/array-size.hpp"
#include "compat/shared-ptr-wrapper.hpp"
#include "../imgui-raii.hpp"
#include "src/critter.hpp"
@@ -27,7 +28,7 @@ struct pending_s
void print_coord(auto&& buf, Vector3i c, Vector2i l, Vector2i p)
{
- std::snprintf(buf, std::size(buf), "(ch %dx%d) <%dx%d> {%dx%d px}", c.x(), c.y(), l.x(), l.y(), p.x(), p.y());
+ std::snprintf(buf, array_size(buf), "(ch %dx%d) <%dx%d> {%dx%d px}", c.x(), c.y(), l.x(), l.y(), p.x(), p.y());
}
void print_coord_(auto&& buf, point pt)
@@ -40,7 +41,7 @@ void print_coord_(auto&& buf, point pt)
void print_vec2(auto&& buf, Vector2 vec)
{
- std::snprintf(buf, std::size(buf), "(%.2f x %.2f)", (double)vec.x(), (double)vec.y());
+ std::snprintf(buf, array_size(buf), "(%.2f x %.2f)", (double)vec.x(), (double)vec.y());
}
void do_column(StringView name)
@@ -197,7 +198,7 @@ struct raycast_test final : base_test
}
do_column("collider");
- std::snprintf(buf, std::size(buf), "%s @ %" PRIu64,
+ std::snprintf(buf, array_size(buf), "%s @ %" PRIu64,
type, uint64_t{result.collider.data});
{ auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf);
text(buf);
@@ -207,13 +208,13 @@ struct raycast_test final : base_test
ImGui::NewLine();
do_column("dir");
- std::snprintf(buf, std::size(buf), "%.4f x %.4f", (double)diag.dir.x(), (double)diag.dir.y());
+ std::snprintf(buf, array_size(buf), "%.4f x %.4f", (double)diag.dir.x(), (double)diag.dir.y());
text(buf);
if (!result.success)
{
do_column("tmin");
- std::snprintf(buf, std::size(buf), "%f / %f",
+ std::snprintf(buf, array_size(buf), "%f / %f",
(double)diag.tmin,
(double)(diag.tmin / diag.V.length()));
text(buf);
@@ -221,7 +222,7 @@ struct raycast_test final : base_test
else
{
do_column("tmin");
- std::snprintf(buf, std::size(buf), "%f / %f",
+ std::snprintf(buf, array_size(buf), "%f / %f",
(double)diag.V.length(), 1.0);
text(buf);
}
@@ -231,7 +232,7 @@ struct raycast_test final : base_test
text(buf);
do_column("||dir^-1||");
- std::snprintf(buf, std::size(buf), "%f x %f",
+ std::snprintf(buf, array_size(buf), "%f x %f",
(double)diag.dir_inv_norm.x(),
(double)diag.dir_inv_norm.y());
text(buf);
@@ -239,15 +240,15 @@ struct raycast_test final : base_test
ImGui::NewLine();
do_column("bbox-size");
- std::snprintf(buf, std::size(buf), "(%u x %u)", diag.size.x(), diag.size.y());
+ std::snprintf(buf, array_size(buf), "(%u x %u)", diag.size.x(), diag.size.y());
text(buf);
do_column("path-len");
- std::snprintf(buf, std::size(buf), "%zu", diag.path.size());
+ std::snprintf(buf, array_size(buf), "%zu", diag.path.size());
text(buf);
do_column("time");
- std::snprintf(buf, std::size(buf), "%.3f ms", (double)(1000 * result.time));
+ std::snprintf(buf, array_size(buf), "%.3f ms", (double)(1000 * result.time));
text(buf);
}
}
diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp
index 99d47643..57cdb8ed 100644
--- a/editor/wall-editor.cpp
+++ b/editor/wall-editor.cpp
@@ -1,4 +1,5 @@
#include "wall-editor.hpp"
+#include "compat/array-size.hpp"
#include "src/wall-defs.hpp"
#include "src/wall-atlas.hpp"
#include "src/world.hpp"
@@ -18,7 +19,7 @@ constexpr inline rot_pair rot_map[] = {
{ rotation::N, Direction_::N },
{ rotation::W, Direction_::W },
};
-static_assert(std::size(rot_map) == Direction_COUNT);
+static_assert(array_size(rot_map) == Direction_COUNT);
constexpr rotation dir_to_rot(Direction_ D)
{
diff --git a/loader/texture.cpp b/loader/texture.cpp
index fc180bc3..ce6fe3fa 100644
--- a/loader/texture.cpp
+++ b/loader/texture.cpp
@@ -1,6 +1,7 @@
#include "impl.hpp"
#include "compat/assert.hpp"
#include "compat/defs.hpp"
+#include "compat/array-size.hpp"
#include "compat/exception.hpp"
#include "compat/strerror.hpp"
#include <cstring>
@@ -29,11 +30,11 @@ Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_)
for (auto extension : { ".tga"_s, ".png"_s, ".webp"_s, })
{
- fm_soft_assert(len + extension.size() < std::size(buf));
+ fm_soft_assert(len + extension.size() < array_size(buf));
std::memcpy(buf + len, extension.data(), extension.size());
buf[len + extension.size()] = '\0';
auto path = StringView{buf, len + extension.size(), StringViewFlag::NullTerminated};
- fm_debug_assert(path.size() < std::size(buf));
+ fm_debug_assert(path.size() < array_size(buf));
auto& importer = extension == ".tga"_s ? tga_importer : image_importer;
if (Path::exists(path) && importer->openFile(path))
{
diff --git a/loader/wall-traits.cpp b/loader/wall-traits.cpp
index ecb88056..07ff7d9c 100644
--- a/loader/wall-traits.cpp
+++ b/loader/wall-traits.cpp
@@ -4,6 +4,7 @@
#include "loader.hpp"
#include "src/tile-defs.hpp"
#include "src/wall-atlas.hpp"
+#include "compat/array-size.hpp"
#include "compat/exception.hpp"
#include <cr/StringView.h>
#include <cr/Optional.h>
@@ -49,7 +50,7 @@ auto wall_traits::make_atlas(StringView name, const Cell&) -> std::shared_ptr<At
{
char file_buf[fm_FILENAME_MAX], json_buf[fm_FILENAME_MAX];
auto file = loader.make_atlas_path(file_buf, loader.WALL_TILESET_PATH, name);
- int json_size = std::snprintf(json_buf, std::size(json_buf), "%s.json", file_buf);
+ int json_size = std::snprintf(json_buf, array_size(json_buf), "%s.json", file_buf);
fm_soft_assert(json_size != 0 && (size_t)json_size <= std::size_t(json_buf));
auto json_name = StringView{json_buf, (size_t)json_size};
auto def = wall_atlas_def::deserialize(json_name);
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index 8e9ba21b..79eb36ac 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -6,6 +6,7 @@
#include "pass-mode.hpp"
#include "json-helper.hpp"
#include "corrade-array.hpp"
+#include "compat/array-size.hpp"
#include <utility>
#include <string_view>
#include <Corrade/Containers/ArrayViewStl.h>
@@ -56,7 +57,7 @@ direction_triple read_all_directions(const json& jroot)
count++;
direction_triple ret = { Array<Direction>{count}, {}, {}, };
auto& [array, map, mask] = ret;
- for (uint8_t i = 0, pos = 0; i < std::size(wall_atlas::directions); i++)
+ for (uint8_t i = 0, pos = 0; i < array_size(wall_atlas::directions); i++)
{
auto [str, dir] = wall_atlas::directions[i];
if (jroot.contains(str))
@@ -77,7 +78,7 @@ bool wall_atlas_def::operator==(const wall_atlas_def& other) const noexcept
return false;
if (direction_array.size() != other.direction_array.size())
return false;
- for (uint8_t i = 0; i < std::size(direction_map); i++)
+ for (uint8_t i = 0; i < array_size(direction_map); i++)
{
auto i1 = direction_map[i], i2 = other.direction_map[i];
if (!i1 != !i2)
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp
index 6509a494..cff16798 100644
--- a/src/anim-atlas.cpp
+++ b/src/anim-atlas.cpp
@@ -1,6 +1,7 @@
#include "anim-atlas.hpp"
#include "shaders/shader.hpp"
#include "compat/assert.hpp"
+#include "compat/array-size.hpp"
#include "compat/exception.hpp"
#include <Corrade/Containers/BitArrayView.h>
#include <Corrade/Containers/StridedArrayView.h>
@@ -12,7 +13,7 @@ namespace floormat {
static constexpr const char name_array[][3] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", };
static constexpr inline auto rot_count = size_t(rotation_COUNT);
-static_assert(std::size(name_array) == rot_count);
+static_assert(array_size(name_array) == rot_count);
static_assert(rot_count == 8);
uint8_t anim_atlas::rotation_to_index(StringView name)
diff --git a/src/search-astar.cpp b/src/search-astar.cpp
index af82ce90..3215cee7 100644
--- a/src/search-astar.cpp
+++ b/src/search-astar.cpp
@@ -6,6 +6,7 @@
#include "object.hpp"
#include "world.hpp"
#include "point.inl"
+#include "compat/array-size.hpp"
#include "compat/format.hpp"
#include "compat/vector-wrapper.hpp"
#include "compat/heap.hpp"
@@ -388,7 +389,7 @@ path_search_result astar::Dijkstra(world& w, const point from, const point to,
}
if (len)
{
- len = Math::min(len, std::size(buf)-1);
+ len = Math::min(len, array_size(buf)-1);
std::fwrite(buf, len, 1, stdout);
std::fflush(stdout);
}
diff --git a/src/search-cache.cpp b/src/search-cache.cpp
index dd73601f..cd83888b 100644
--- a/src/search-cache.cpp
+++ b/src/search-cache.cpp
@@ -2,6 +2,7 @@
#include "search-constants.hpp"
#include "point.hpp"
#include "world.hpp"
+#include "compat/array-size.hpp"
#include <bitset>
namespace floormat::Search {
@@ -18,7 +19,7 @@ struct cache::chunk_cache
x *= i;
return x;
}();
- static constexpr size_t rank = arraySize(dimensions);
+ static constexpr size_t rank = array_size(dimensions);
struct index { uint32_t value = 0; };
class chunk* chunk = nullptr;
diff --git a/src/search.cpp b/src/search.cpp
index af32e7a3..68ec0cce 100644
--- a/src/search.cpp
+++ b/src/search.cpp
@@ -6,6 +6,7 @@
#include "world.hpp"
#include "pass-mode.hpp"
#include "RTree-search.hpp"
+#include "compat/array-size.hpp"
#include "compat/function2.hpp"
#include <bit>
@@ -76,7 +77,7 @@ bool path_search::is_passable_(chunk* c0, const std::array<chunk*, 8>& neighbors
if (c2)
{
- static_assert(std::size(world::neighbor_offsets) == 8);
+ static_assert(array_size(world::neighbor_offsets) == 8);
constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
const auto off = Vector2(nb)*Vector2(chunk_size);
const auto min_ = min - off, max_ = max - off;
diff --git a/src/timer.cpp b/src/timer.cpp
index ad78f383..4fdab61d 100644
--- a/src/timer.cpp
+++ b/src/timer.cpp
@@ -72,16 +72,16 @@ float Time::to_milliseconds(const Ns& ts) noexcept
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.");
+ constexpr size_t fmtsize = array_size("Thu 01 Mon 197000 00:00:00.");
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);
const auto* tm = std::localtime(&time);
- auto len = std::strftime(buf, std::size(buf), fmt, tm);
+ auto len = std::strftime(buf, array_size(buf), fmt, tm);
fm_assert(len > 0 && len <= fmtsize);
auto len2 = std::sprintf(buf + len, "%03u", unsigned{ms.count()});
- fm_assert(len2 > 0 && len + (size_t)len2 < std::size(buf));
+ fm_assert(len2 > 0 && len + (size_t)len2 < array_size(buf));
return buf;
}
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 8ea687e4..991e1b45 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -1,5 +1,6 @@
#include "wall-atlas.hpp"
#include "tile-constants.hpp"
+#include "compat/array-size.hpp"
#include "compat/exception.hpp"
#include <utility>
#include <Corrade/Containers/StridedArrayView.h>
@@ -21,7 +22,7 @@ uint8_t direction_index_from_name(StringView s) noexcept(false)
StringView direction_index_to_name(size_t i) noexcept(false)
{
- fm_soft_assert(i < arraySize(wall_atlas::directions));
+ fm_soft_assert(i < array_size(wall_atlas::directions));
return wall_atlas::directions[i].name;
}
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index afd75f37..5cf4f244 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -3,6 +3,7 @@
#include "src/pass-mode.hpp"
#include "wall-defs.hpp"
#include "compat/defs.hpp"
+#include "compat/array-size.hpp"
#include <array>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/String.h>
@@ -57,7 +58,7 @@ struct Direction
{ "top"_s, &Direction::top, Group_::top },
{ "corner"_s, &Direction::corner, Group_::corner },
};
- static_assert(std::size(groups) == (size_t)Group_::COUNT);
+ static_assert(array_size(groups) == (size_t)Group_::COUNT);
static constexpr inline member_tuple groups_for_draw[] = {
{ "wall"_s, &Direction::wall, Group_::wall },
diff --git a/test/app.cpp b/test/app.cpp
index 4a80cb20..91c56b29 100644
--- a/test/app.cpp
+++ b/test/app.cpp
@@ -1,5 +1,6 @@
#include "app.hpp"
#include "loader/loader.hpp"
+#include "compat/array-size.hpp"
#include "compat/headless.hpp"
#include <stdlib.h> // NOLINT(*-deprecated-headers)
#include <cstdio>
@@ -48,7 +49,7 @@ int App::exec()
constexpr auto SV_flags = StringViewFlag::Global|StringViewFlag::NullTerminated;
constexpr auto name_prefix = "test_"_s;
-#define FM_TEST(name) { ( StringView{#name, arraySize(#name)-1, SV_flags} ), ( &(name) ), }
+#define FM_TEST(name) { ( StringView{#name, array_size(#name)-1, SV_flags} ), ( &(name) ), }
constexpr struct {
StringView name;
diff --git a/test/bitmask.cpp b/test/bitmask.cpp
index 3e04f737..574c840c 100644
--- a/test/bitmask.cpp
+++ b/test/bitmask.cpp
@@ -2,6 +2,7 @@
#include "src/anim-atlas.hpp"
#include "loader/loader.hpp"
#include "compat/assert.hpp"
+#include "compat/array-size.hpp"
#include <mg/Functions.h>
#include <mg/ImageData.h>
@@ -13,7 +14,7 @@ const unsigned char src[] = {
#include "bitmask.embed.inc"
};
-constexpr auto data_nbytes = arraySize(src);
+constexpr auto data_nbytes = array_size(src);
constexpr auto size = Vector2i{21, 52};
//static_assert(size_t{size.product()+7}/8 <= data_nbytes);
@@ -36,7 +37,7 @@ void bitmask_test()
fflush(stdout);
#endif
const auto len = Math::min(data_nbytes, (size_t)bitmask.size()+7 >> 3);
- fm_assert(arraySize(src) >= len);
+ fm_assert(array_size(src) >= len);
for (auto i = 0uz; i < len; i++)
{
auto a = (unsigned char)bitmask.data()[i];