summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/format.hpp2
-rw-r--r--compat/prelude.hpp2
-rw-r--r--draw/anim.cpp10
-rw-r--r--editor/imgui-tiles.cpp2
-rw-r--r--editor/inspect.cpp2
-rw-r--r--entity/erased-constraints.cpp10
-rw-r--r--main/draw.cpp2
-rw-r--r--serialize/binary-reader.inl6
-rw-r--r--serialize/binary-writer.inl4
-rw-r--r--serialize/magnum-vector.hpp4
-rw-r--r--serialize/world-reader.cpp8
-rw-r--r--serialize/world-writer.cpp8
-rw-r--r--src/anim-atlas.cpp10
-rw-r--r--src/chunk-collision.cpp6
-rw-r--r--src/chunk-render.cpp20
-rw-r--r--src/chunk.cpp2
-rw-r--r--src/random.cpp4
-rw-r--r--src/tile-atlas.cpp2
-rw-r--r--test/serializer.cpp2
19 files changed, 54 insertions, 52 deletions
diff --git a/compat/format.hpp b/compat/format.hpp
index 1432d847..bf6e8861 100644
--- a/compat/format.hpp
+++ b/compat/format.hpp
@@ -27,7 +27,7 @@ struct fmt_string final {
template <std::size_t... Is>
consteval fmt_string(const char (&arr)[N]) noexcept {
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
data[i] = arr[i];
}
};
diff --git a/compat/prelude.hpp b/compat/prelude.hpp
index ab2fdfd2..5520ded8 100644
--- a/compat/prelude.hpp
+++ b/compat/prelude.hpp
@@ -47,3 +47,5 @@ namespace floormat {
using Error [[maybe_unused]] = ::Corrade::Utility::Error;
namespace Path = Corrade::Utility::Path; // NOLINT(misc-unused-alias-decls)
} // namespace floormat
+
+consteval auto operator""_uz(unsigned long long int x) { return ::floormat::types::size_t(x); }
diff --git a/draw/anim.cpp b/draw/anim.cpp
index 1e0d1bc4..acde5279 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -68,12 +68,12 @@ void anim_mesh::draw(tile_shader& shader, chunk& c)
Optional<last_> last;
const auto max_index = std::uint32_t(size*quad_index_count - 1);
- std::size_t last_id = 0;
- for (std::size_t k = 0; k < size; k++)
+ auto last_id = 0_uz;
+ for (auto k = 0_uz; k < size; k++)
{
auto id = ids[k];
auto [atlas, s] = c[id].scenery();
- for (std::size_t i = last_id+1; i < id; i++)
+ for (auto i = last_id+1; i < id; i++)
if (auto [atlas, s] = c[i].scenery();
atlas && atlas->info().fps > 0)
{
@@ -103,7 +103,7 @@ void anim_mesh::draw(tile_shader& shader, chunk& c)
draw(shader, *atlas, s.r, s.frame, local_coords{i}, s.offset);
}
else
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
if (auto [atlas, s] = c[i].scenery(); atlas)
draw(shader, *atlas, s.r, s.frame, local_coords{i}, s.offset);
@@ -120,7 +120,7 @@ void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::si
const auto& g = atlas.group(r);
const auto texcoords = atlas.texcoords_for_frame(r, frame, !g.mirror_from.isEmpty());
quad_data array;
- for (std::size_t i = 0; i < 4; i++)
+ for (auto i = 0_uz; i < 4; i++)
array[i] = { pos[i], texcoords[i], depth };
_vertex_buffer.setSubData(0, array);
atlas.texture().bind(0);
diff --git a/editor/imgui-tiles.cpp b/editor/imgui-tiles.cpp
index 9d84027f..57cdecba 100644
--- a/editor/imgui-tiles.cpp
+++ b/editor/imgui-tiles.cpp
@@ -49,7 +49,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st
};
const bool perm_selected = ed.is_permutation_selected(atlas);
constexpr std::size_t per_row = 8;
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
{
const bool selected = ed.is_tile_selected(atlas, i);
if (i > 0 && i % per_row == 0)
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index 82514cc9..0c45251b 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -155,7 +155,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r
ret = ImGui::SliderScalarN(label, igdt, &value, T::Size, &min, &max);
break;
}
- for (std::size_t i = 0; i < T::Size; i++)
+ for (auto i = 0_uz; i < T::Size; i++)
value[i] = std::clamp(value[i], min[i], max[i]);
}
diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp
index 2ac049d5..52bb784a 100644
--- a/entity/erased-constraints.cpp
+++ b/entity/erased-constraints.cpp
@@ -24,7 +24,7 @@ template<typename T> std::pair<T, T> range::convert() const
using U = typename T::Type;
constexpr auto Size = T::Size;
T a, b;
- for (std::size_t i = 0; i < Size; i++)
+ for (auto i = 0_uz; i < Size; i++)
a[i] = std::numeric_limits<U>::min(), b[i] = std::numeric_limits<U>::max();
return {a, b};
}
@@ -65,14 +65,14 @@ template<typename T> std::pair<T, T> range::convert() const
if constexpr(std::is_signed_v<U>)
{
fm_assert(type == type_int4);
- for (std::size_t i = 0; i < Size; i++)
+ for (auto i = 0_uz; i < Size; i++)
a[i] = U(min.i4[i]), b[i] = U(max.i4[i]);
}
else
{
if (type == type_int4)
{
- for (std::size_t i = 0; i < Size; i++)
+ for (auto i = 0_uz; i < Size; i++)
{
fm_assert(min.i4[i] >= 0 && max.i4[i] >= 0);
a[i] = U(min.i4[i]), b[i] = U(max.i4[i]);
@@ -81,7 +81,7 @@ template<typename T> std::pair<T, T> range::convert() const
else
{
fm_assert(type == type_uint4);
- for (std::size_t i = 0; i < Size; i++)
+ for (auto i = 0_uz; i < Size; i++)
a[i] = U(min.u4[i]), b[i] = U(max.u4[i]);
}
}
@@ -90,7 +90,7 @@ template<typename T> std::pair<T, T> range::convert() const
{
static_assert(std::is_floating_point_v<U>);
fm_assert(type == type_float4);
- for (std::size_t i = 0; i < Size; i++)
+ for (auto i = 0_uz; i < Size; i++)
a[i] = U(min.f4[i]), b[i] = U(max.f4[i]);
}
return { a, b };
diff --git a/main/draw.cpp b/main/draw.cpp
index 02f58541..62c7fbf7 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -122,7 +122,7 @@ void main_impl::draw_world() noexcept
if (check_chunk_visible(_shader.camera_offset(), sz))
{
_anim_mesh.draw(_shader, c);
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
const local_coords xy{i};
if (auto [atlas, s] = c[xy].scenery(); atlas)
diff --git a/serialize/binary-reader.inl b/serialize/binary-reader.inl
index 7b831f30..1234b08a 100644
--- a/serialize/binary-reader.inl
+++ b/serialize/binary-reader.inl
@@ -23,7 +23,7 @@ constexpr T binary_reader<It>::read() noexcept(false)
fm_soft_assert((std::ptrdiff_t)N <= std::distance(it, end));
num_bytes_read += N;
char buf[N];
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
buf[i] = *it++;
return maybe_byteswap(std::bit_cast<T, decltype(buf)>(buf));
}
@@ -37,7 +37,7 @@ constexpr std::array<char, N> binary_reader<It>::read() noexcept(false)
array = {};
fm_soft_assert(N <= (std::size_t)std::distance(it, end));
num_bytes_read += N;
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
array[i] = *it++;
return array;
}
@@ -74,7 +74,7 @@ constexpr auto binary_reader<It>::read_asciiz_string() noexcept(false)
};
fixed_string ret;
- for (std::size_t i = 0; i < MAX && it != end; i++)
+ for (auto i = 0_uz; i < MAX && it != end; i++)
{
const char c = *it++;
ret.buf[i] = c;
diff --git a/serialize/binary-writer.inl b/serialize/binary-writer.inl
index e5a7ba16..a847903d 100644
--- a/serialize/binary-writer.inl
+++ b/serialize/binary-writer.inl
@@ -17,7 +17,7 @@ constexpr void binary_writer<It>::write(T x) noexcept
_bytes_written += sizeof(T);
constexpr std::size_t N = sizeof(T);
const auto buf = std::bit_cast<std::array<char, N>, T>(maybe_byteswap(x));
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
*it++ = buf[i];
}
@@ -34,7 +34,7 @@ constexpr void binary_writer<It>::write_asciiz_string(StringView str) noexcept
fm_debug_assert(str.flags() & StringViewFlag::NullTerminated);
const auto sz = str.size();
_bytes_written += sz + 1;
- for (std::size_t i = 0; i < sz; i++)
+ for (auto i = 0_uz; i < sz; i++)
*it++ = str[i];
*it++ = '\0';
}
diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp
index 08997b90..b8383d96 100644
--- a/serialize/magnum-vector.hpp
+++ b/serialize/magnum-vector.hpp
@@ -16,7 +16,7 @@ template <std::size_t N, typename T>
void adl_serializer<Magnum::Math::Vector<N, T>>::to_json(json& j, const vec& val)
{
std::array<T, N> array{};
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
array[i] = val[i];
using nlohmann::to_json;
to_json(j, array);
@@ -28,7 +28,7 @@ void adl_serializer<Magnum::Math::Vector<N, T>>::from_json(const json& j, vec& v
std::array<T, N> array{};
using nlohmann::from_json;
from_json(j, array);
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
val[i] = array[i];
}
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 4f31b88b..3060579f 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -73,14 +73,14 @@ void reader_state::read_sceneries(reader_t& s)
fm_soft_assert(sz < scenery_id_max);
sceneries.resize(sz);
- std::size_t i = 0;
+ auto i = 0_uz;
while (i < sz)
{
std::uint8_t num; num << s;
fm_soft_assert(num > 0);
auto str = s.read_asciiz_string<atlas_name_max>();
const auto sc_ = loader.scenery(str);
- for (std::size_t n = 0; n < num; n++)
+ for (auto n = 0_uz; n < num; n++)
{
atlasid id; id << s;
fm_soft_assert(id < sz);
@@ -120,7 +120,7 @@ void reader_state::read_chunks(reader_t& s)
{
const auto N = s.read<chunksiz>();
- for (std::size_t k = 0; k < N; k++)
+ for (auto k = 0_uz; k < N; k++)
{
std::decay_t<decltype(chunk_magic)> magic;
magic << s;
@@ -130,7 +130,7 @@ void reader_state::read_chunks(reader_t& s)
coord.x << s;
coord.y << s;
auto& chunk = (*_world)[coord];
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
const tilemeta flags = s.read<tilemeta>();
tile_ref t = chunk[i];
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp
index 6bb033ab..2a58a51b 100644
--- a/serialize/world-writer.cpp
+++ b/serialize/world-writer.cpp
@@ -256,7 +256,7 @@ void writer_state::serialize_scenery()
s << (atlasid)sz;
StringView last;
- for (std::size_t i = 0; i < sz; i++)
+ for (auto i = 0_uz; i < sz; i++)
{
fm_debug_assert(s.bytes_written() + atlasbuf_size1 < atlasbuf_size);
const auto& [sc, idx] = vec[i];
@@ -264,8 +264,8 @@ void writer_state::serialize_scenery()
{
fm_assert(sc->name.size() < atlas_name_max);
last = sc->name;
- std::size_t num = 1;
- for (std::size_t j = i+1; j < sz && vec[j].s->name == sc->name; j++)
+ auto num = 1_uz;
+ for (auto j = i+1; j < sz && vec[j].s->name == sc->name; j++)
num++;
fm_assert(num < int_max<std::uint8_t>);
s << (std::uint8_t)num;
@@ -292,7 +292,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord)
s << chunk_magic << coord.x << coord.y;
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
const tile_proto x = c[i];
const auto ground = x.ground(), wall_north = x.wall_north(), wall_west = x.wall_west();
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp
index 655bcf5e..ffade2d6 100644
--- a/src/anim-atlas.cpp
+++ b/src/anim-atlas.cpp
@@ -29,7 +29,7 @@ decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_d
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
const auto ngroups = a.groups.size();
- for (std::size_t i = 0; i < ngroups; i++)
+ for (auto i = 0_uz; i < ngroups; i++)
array[rotation_to_index(a.groups[i].name)] = std::uint8_t(i);
return array;
}
@@ -140,10 +140,10 @@ BitArray anim_atlas::make_bitmask(const ImageView2D& tex)
fm_assert(tex.pixelSize() == 4);
fm_assert(pixels.stride()[1] == 4);
- for (std::size_t j = 0; j < height; j++)
+ for (auto j = 0_uz; j < height; j++)
{
constexpr unsigned char amin = 32;
- std::size_t i = 0;
+ auto i = 0_uz;
for (; i < width0; i += 8)
{
const auto src_idx = (j*stride + i*4)+3, dst_idx = (height-j-1)*width + i>>3;
@@ -179,7 +179,7 @@ rotation anim_atlas::next_rotation_from(rotation r) const noexcept
for (auto i = std::size_t(r)+1; i < count; i++)
if (_group_indices[i] != 0xff)
return rotation(i);
- for (std::size_t i = 0; i < count; i++)
+ for (auto i = 0_uz; i < count; i++)
if (_group_indices[i] != 0xff)
return rotation(i);
fm_abort("where did the rotations go?!");
@@ -206,7 +206,7 @@ bool anim_atlas::check_rotation(rotation r) const noexcept
rotation anim_atlas::first_rotation() const noexcept
{
- for (std::size_t i = 0; i < rot_count; i++)
+ for (auto i = 0_uz; i < rot_count; i++)
if (_group_indices[i] == 0)
return rotation(i);
fm_abort("unreachable! can't find first rotation");
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index d41c02c8..5b85de1e 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -60,7 +60,7 @@ void chunk::ensure_passability() noexcept
_rtree.RemoveAll();
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
auto tile = operator[](i);
if (auto s = tile.scenery())
@@ -71,7 +71,7 @@ void chunk::ensure_passability() noexcept
_rtree.Insert(start.data(), end.data(), id);
}
}
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
if (const auto* atlas = ground_atlas_at(i))
if (atlas->pass_mode(pass_mode::pass) != pass_mode::pass)
@@ -81,7 +81,7 @@ void chunk::ensure_passability() noexcept
_rtree.Insert(start.data(), end.data(), id);
}
}
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
auto tile = operator[](i);
if (const auto* atlas = tile.wall_north_atlas().get())
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 48425f72..e54260dd 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -12,7 +12,7 @@ template<std::size_t N = 1>
static auto make_index_array(std::size_t max)
{
std::array<std::array<UnsignedShort, 6>, N*TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init)
- for (std::size_t i = 0; i < max; i++)
+ for (auto i = 0_uz; i < max; i++)
array[i] = tile_atlas::indices(i);
return array;
}
@@ -30,7 +30,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
_ground_modified = false;
std::size_t count = 0;
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
if (_ground_atlases[i])
ground_indexes[count++] = std::uint8_t(i);
@@ -40,7 +40,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
});
std::array<std::array<vertex, 4>, TILE_COUNT> vertexes;
- for (std::size_t k = 0; k < count; k++)
+ for (auto k = 0_uz; k < count; k++)
{
const std::uint8_t i = ground_indexes[k];
const auto& atlas = _ground_atlases[i];
@@ -49,7 +49,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
const auto texcoords = atlas->texcoords_for_id(_ground_variants[i]);
const float depth = tile_shader::depth_value(pos);
auto& v = vertexes[k];
- for (std::size_t j = 0; j < 4; j++)
+ for (auto j = 0_uz; j < 4; j++)
v[j] = { quad[j], texcoords[j], depth };
}
@@ -72,7 +72,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
_walls_modified = false;
std::size_t count = 0;
- for (std::size_t i = 0; i < TILE_COUNT*2; i++)
+ for (auto i = 0_uz; i < TILE_COUNT*2; i++)
if (_wall_atlases[i])
wall_indexes[count++] = std::uint16_t(i);
@@ -82,7 +82,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
});
std::array<std::array<vertex, 4>, TILE_COUNT*2> vertexes;
- for (std::size_t k = 0; k < count; k++)
+ for (auto k = 0_uz; k < count; k++)
{
const std::uint16_t i = wall_indexes[k];
const auto& atlas = _wall_atlases[i];
@@ -93,7 +93,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
const float depth = tile_shader::depth_value(pos);
const auto texcoords = atlas->texcoords_for_id(variant);
auto& v = vertexes[k];
- for (std::size_t j = 0; j < 4; j++)
+ for (auto j = 0_uz; j < 4; j++)
v[j] = { quad[j], texcoords[j], depth, };
}
@@ -116,7 +116,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
_scenery_modified = false;
std::size_t count = 0;
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
if (const auto& atlas = _scenery_atlases[i]; atlas && atlas->info().fps == 0)
scenery_indexes[count++] = std::uint8_t(i);
@@ -127,7 +127,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
});
#endif
std::array<std::array<vertex, 4>, TILE_COUNT> vertexes;
- for (std::size_t k = 0; k < count; k++)
+ for (auto k = 0_uz; k < count; k++)
{
const std::uint8_t i = scenery_indexes[k];
const local_coords pos{i};
@@ -139,7 +139,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
const auto texcoords = atlas->texcoords_for_frame(fr.r, fr.frame, !group.mirror_from.isEmpty());
const float depth = tile_shader::depth_value(pos, tile_shader::scenery_depth_offset);
auto& v = vertexes[k];
- for (std::size_t j = 0; j < 4; j++)
+ for (auto j = 0_uz; j < 4; j++)
v[j] = { quad[j], texcoords[j], depth };
}
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 033e1831..774a874c 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -7,7 +7,7 @@ bool chunk::empty(bool force) const noexcept
{
if (!force && !_maybe_empty)
return false;
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
if (_ground_atlases[i] || _wall_atlases[i*2 + 0] || _wall_atlases[i*2 + 1] || _scenery_atlases[i])
return _maybe_empty = false;
return true;
diff --git a/src/random.cpp b/src/random.cpp
index d3e45292..7888dbaa 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -17,13 +17,13 @@ std::size_t random_engine_impl::operator()()
{
if constexpr(sizeof(std::size_t) > sizeof(std::uint32_t))
{
- constexpr std::size_t N = (sizeof(std::size_t) + sizeof(std::uint32_t)-1) / sizeof(std::uint32_t);
+ constexpr auto N = (sizeof(std::size_t) + sizeof(std::uint32_t)-1) / sizeof(std::uint32_t);
static_assert(N >= 1);
union {
std::size_t x;
std::uint32_t a[N];
} ret;
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
ret.a[i] = g();
return ret.x;
}
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index b13b9ea8..68feb77b 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -50,7 +50,7 @@ auto tile_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count
{
const std::size_t N = Vector2ui{tile_count}.product();
auto ptr = std::make_unique<std::array<Vector2, 4>[]>(N);
- for (std::size_t i = 0; i < N; i++)
+ for (auto i = 0_uz; i < N; i++)
ptr[i] = make_texcoords(pixel_size, tile_count, i);
return ptr;
}
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 3e1e6a97..71b1a3f1 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -37,7 +37,7 @@ chunk test_app::make_test_chunk()
static bool chunks_equal(const chunk& a, const chunk& b)
{
- for (std::size_t i = 0; i < TILE_COUNT; i++)
+ for (auto i = 0_uz; i < TILE_COUNT; i++)
{
const auto &a1 = a[i], &b1 = b[i];
if (a1 != b1)