From 4d9a82b720c8ce74b94f43f72ddd819ef21abbdf Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 18 Mar 2023 23:42:07 +0100 Subject: pre-declare integer types without cstddef/cstdint --- anim-crop-tool/main.cpp | 4 +- compat/enum-bitset.hpp | 10 ++--- compat/format.hpp | 12 +++--- compat/function2.hpp | 96 ++++++++++++++++++++--------------------- compat/int-hash.hpp | 7 ++- compat/integer-types.hpp | 61 ++++++++++++++++++++++++++ compat/prelude.hpp | 8 +--- draw/anim.cpp | 16 +++---- draw/anim.hpp | 4 +- draw/box.hpp | 2 +- draw/floor.cpp | 12 +++--- draw/quad-floor.hpp | 2 +- draw/quad-wall-n.hpp | 2 +- draw/quad-wall-w.hpp | 2 +- draw/quad.hpp | 2 +- draw/wall.cpp | 12 +++--- draw/wireframe.cpp | 2 +- draw/wireframe.hpp | 6 +-- editor/app.cpp | 6 +-- editor/app.hpp | 7 +-- editor/draw.cpp | 14 +++--- editor/editor.cpp | 4 +- editor/events.cpp | 4 +- editor/imgui-inspect.cpp | 2 +- editor/imgui-raii.hpp | 2 +- editor/imgui-tiles.cpp | 2 +- editor/inspect-types.cpp | 28 ++++++------ editor/inspect.cpp | 44 +++++++++---------- editor/inspect.hpp | 5 +-- editor/scenery-editor.cpp | 2 +- editor/tile-editor.cpp | 4 +- editor/tile-editor.hpp | 4 +- editor/update.cpp | 14 +++--- entity/constraints.hpp | 1 - entity/erased-constraints.cpp | 21 +++++---- entity/erased-constraints.hpp | 6 +-- entity/metadata.hpp | 25 ++++++----- floormat/events.hpp | 6 +-- floormat/main.hpp | 6 +-- loader/atlas.cpp | 2 +- loader/loader.hpp | 2 +- loader/texture.cpp | 4 +- main/clickable.hpp | 2 +- main/draw.cpp | 20 ++++----- main/events.cpp | 26 +++++------ main/main-impl.cpp | 6 +-- main/main-impl.hpp | 4 +- serialize/binary-reader.hpp | 8 ++-- serialize/binary-reader.inl | 12 +++--- serialize/binary-serializer.cpp | 4 +- serialize/binary-serializer.hpp | 14 +++--- serialize/binary-writer.hpp | 4 +- serialize/binary-writer.inl | 2 +- serialize/json-helper.cpp | 2 +- serialize/magnum-vector.hpp | 6 +-- serialize/magnum-vector2i.hpp | 6 +-- serialize/pass-mode.cpp | 2 +- serialize/scenery.cpp | 8 ++-- serialize/tile-atlas.cpp | 2 +- serialize/tile.cpp | 2 +- serialize/world-impl.hpp | 20 ++++----- serialize/world-reader.cpp | 48 ++++++++++----------- serialize/world-writer.cpp | 40 ++++++++--------- src/RTree.cpp | 2 +- src/RTree.h | 3 +- src/RTree.hpp | 2 +- src/anim-atlas.cpp | 34 +++++++-------- src/anim-atlas.hpp | 10 ++--- src/anim.hpp | 2 +- src/character.cpp | 6 +-- src/character.hpp | 4 +- src/chunk-collision.cpp | 12 +++--- src/chunk-render.cpp | 32 +++++++------- src/chunk.cpp | 14 +++--- src/chunk.hpp | 33 +++++++------- src/entity-type.hpp | 2 +- src/entity.cpp | 30 ++++++------- src/entity.hpp | 21 ++++----- src/global-coords.hpp | 36 ++++++++-------- src/local-coords.hpp | 22 +++++----- src/object-id.hpp | 8 ++++ src/precomp.hpp | 2 + src/random.cpp | 16 +++---- src/random.hpp | 10 ++--- src/rotation.hpp | 5 +-- src/rotation.inl | 2 +- src/scenery.cpp | 18 ++++---- src/scenery.hpp | 11 +++-- src/tile-atlas.cpp | 10 ++--- src/tile-atlas.hpp | 10 ++--- src/tile-defs.hpp | 3 +- src/tile-image.hpp | 3 +- src/tile-iterator.cpp | 8 ++-- src/tile-iterator.hpp | 17 ++++---- src/tile.cpp | 2 +- src/tile.hpp | 6 +-- src/world.cpp | 8 ++-- src/world.hpp | 43 +++++++++--------- test/bitmask.cpp | 6 +-- test/entity.cpp | 2 +- 100 files changed, 610 insertions(+), 558 deletions(-) create mode 100644 compat/integer-types.hpp create mode 100644 src/object-id.hpp diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 60931c62..a2a94e63 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -37,7 +37,7 @@ using floormat::Serialize::anim_atlas_; struct options { String input_dir, input_file, output_dir; - std::size_t nframes = 0; + size_t nframes = 0; anim_scale scale; }; @@ -165,7 +165,7 @@ static bool load_directory(anim_group& group, options& opts, anim_atlas_& atlas) group.frames.clear(); // atlas stores its entries through a pointer. // vector::reserve() is necessary to avoid use-after-free. - group.frames.reserve((std::size_t)max-1); + group.frames.reserve((size_t)max-1); for (unsigned i = 1; i < max; i++) { diff --git a/compat/enum-bitset.hpp b/compat/enum-bitset.hpp index ccf76434..ebbd9982 100644 --- a/compat/enum-bitset.hpp +++ b/compat/enum-bitset.hpp @@ -4,16 +4,16 @@ namespace floormat { template -requires (std::is_enum_v && std::is_same_v>>) -struct enum_bitset : std::bitset { +requires (std::is_enum_v && std::is_same_v>>) +struct enum_bitset : std::bitset { using enum_type = Enum; using value_type = std::underlying_type_t; - static constexpr auto COUNT = std::size_t{value_type(COUNT_)}; + static constexpr auto COUNT = size_t{value_type(COUNT_)}; using std::bitset::bitset; - constexpr bool operator[](Enum x) const { return std::bitset::operator[](std::size_t{value_type(x)}); } - constexpr decltype(auto) operator[](Enum x) { return std::bitset::operator[](std::size_t{value_type(x)}); } + constexpr bool operator[](Enum x) const { return std::bitset::operator[](size_t{value_type(x)}); } + constexpr decltype(auto) operator[](Enum x) { return std::bitset::operator[](size_t{value_type(x)}); } }; } // namespace floormat diff --git a/compat/format.hpp b/compat/format.hpp index bf6e8861..2a88abab 100644 --- a/compat/format.hpp +++ b/compat/format.hpp @@ -20,12 +20,12 @@ template<> struct formatter { #if !FMT_USE_NONTYPE_TEMPLATE_ARGS namespace floormat::detail::fmt { -template +template struct fmt_string final { - static constexpr std::size_t size = N; + static constexpr size_t size = N; char data[N]; - template + template consteval fmt_string(const char (&arr)[N]) noexcept { for (auto i = 0_uz; i < N; i++) data[i] = arr[i]; @@ -46,10 +46,10 @@ using namespace fmt::literals; namespace floormat { -template -std::size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args) +template +size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args) { - constexpr std::size_t n = N > 0 ? N - 1 : 0; + constexpr size_t n = N > 0 ? N - 1 : 0; auto result = fmt::format_to_n(buf, n, std::forward(fmt), std::forward(args)...); const auto len = std::min(n, result.size); if constexpr(N > 0) diff --git a/compat/function2.hpp b/compat/function2.hpp index 07b40338..cd23bad9 100644 --- a/compat/function2.hpp +++ b/compat/function2.hpp @@ -460,13 +460,13 @@ union data_accessor { /// The pointer we use if the object is on the heap void* ptr_; /// The first field of the inplace storage - std::size_t inplace_storage_; + size_t inplace_storage_; }; /// See opcode::op_fetch_empty static FU2_DETAIL_CXX14_CONSTEXPR void write_empty(data_accessor* accessor, bool empty) noexcept { - accessor->inplace_storage_ = std::size_t(empty); + accessor->inplace_storage_ = size_t(empty); } template @@ -482,7 +482,7 @@ using transfer_volatile_t = template FU2_DETAIL_CXX14_CONSTEXPR auto retrieve(std::true_type /*is_inplace*/, Accessor from, - std::size_t from_capacity) { + size_t from_capacity) { using type = transfer_const_t>*; /// Process the command by using the data inside the internal capacity @@ -495,7 +495,7 @@ FU2_DETAIL_CXX14_CONSTEXPR auto retrieve(std::true_type /*is_inplace*/, /// through the allocator template constexpr auto retrieve(std::false_type /*is_inplace*/, Accessor from, - std::size_t /*from_capacity*/) { + size_t /*from_capacity*/) { return from->ptr_; } @@ -591,11 +591,11 @@ using is_noexcept_noexcept = std::true_type; template \ struct function_trait { \ using pointer_type = Ret (*)(data_accessor CONST VOLATILE*, \ - std::size_t capacity, Args...); \ + size_t capacity, Args...); \ template \ struct internal_invoker { \ static Ret invoke(data_accessor CONST VOLATILE* data, \ - std::size_t capacity, Args... args) NOEXCEPT { \ + size_t capacity, Args... args) NOEXCEPT { \ auto obj = retrieve(std::integral_constant{}, \ data, capacity); \ auto box = static_cast(obj); \ @@ -608,7 +608,7 @@ using is_noexcept_noexcept = std::true_type; \ template \ struct view_invoker { \ - static Ret invoke(data_accessor CONST VOLATILE* data, std::size_t, \ + static Ret invoke(data_accessor CONST VOLATILE* data, size_t, \ Args... args) NOEXCEPT { \ \ auto ptr = static_cast(data->ptr_); \ @@ -627,7 +627,7 @@ using is_noexcept_noexcept = std::true_type; template \ struct empty_invoker { \ static Ret invoke(data_accessor CONST VOLATILE* /*data*/, \ - std::size_t /*capacity*/, Args... /*args*/) NOEXCEPT { \ + size_t /*capacity*/, Args... /*args*/) NOEXCEPT { \ throw_or_abort##NOEXCEPT(std::integral_constant{}); \ } \ }; \ @@ -649,7 +649,7 @@ struct invoke_table { using type = function_pointer_of; /// Return the function pointer itself - template + template static constexpr auto fetch(type pointer) noexcept { static_assert(Index == 0U, "The index should be 0 here!"); return pointer; @@ -680,7 +680,7 @@ struct invoke_table { function_pointer_of...> const*; /// Return the function pointer at the particular index - template + template static constexpr auto fetch(type table) noexcept { return std::get(*table); } @@ -756,18 +756,18 @@ struct invoke_table { } }; -template +template class operator_impl; #define FU2_DEFINE_FUNCTION_TRAIT(CONST, VOLATILE, NOEXCEPT, OVL_REF, REF) \ - template \ class operator_impl \ : operator_impl { \ \ - template \ + template \ friend class operator_impl; \ \ protected: \ @@ -791,13 +791,13 @@ class operator_impl; std::forward(args)...); \ } \ }; \ - template \ class operator_impl, \ Ret(Args...) CONST VOLATILE OVL_REF NOEXCEPT> \ : copyable { \ \ - template \ + template \ friend class operator_impl; \ \ protected: \ @@ -847,9 +847,9 @@ template > { using command_function_t = void (*)(vtable* /*this*/, opcode /*op*/, data_accessor* /*from*/, - std::size_t /*from_capacity*/, + size_t /*from_capacity*/, data_accessor* /*to*/, - std::size_t /*to_capacity*/); + size_t /*to_capacity*/); using invoke_table_t = invocation_table::invoke_table; @@ -864,8 +864,8 @@ class vtable> { /// The command table template static void process_cmd(vtable* to_table, opcode op, data_accessor* from, - std::size_t from_capacity, data_accessor* to, - std::size_t to_capacity) { + size_t from_capacity, data_accessor* to, + size_t to_capacity) { switch (op) { case opcode::op_move: { @@ -940,7 +940,7 @@ class vtable> { static void construct(std::true_type /*apply*/, Box&& box, vtable* to_table, data_accessor* to, - std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) { + size_t to_capacity) noexcept(HasStrongExceptGuarantee) { // Try to allocate the object inplace void* storage = retrieve(std::true_type{}, to, to_capacity); if (storage) { @@ -958,14 +958,14 @@ class vtable> { static void construct(std::false_type /*apply*/, Box&& /*box*/, vtable* /*to_table*/, data_accessor* /*to*/, - std::size_t /*to_capacity*/) noexcept(HasStrongExceptGuarantee) { + size_t /*to_capacity*/) noexcept(HasStrongExceptGuarantee) { } }; /// The command table static void empty_cmd(vtable* to_table, opcode op, data_accessor* /*from*/, - std::size_t /*from_capacity*/, data_accessor* to, - std::size_t /*to_capacity*/) { + size_t /*from_capacity*/, data_accessor* to, + size_t /*to_capacity*/) { switch (op) { case opcode::op_move: @@ -994,31 +994,31 @@ public: /// Initialize an object at the given position template static void init(vtable& table, T&& object, data_accessor* to, - std::size_t to_capacity) { + size_t to_capacity) { trait>::construct(std::true_type{}, std::forward(object), &table, to, to_capacity); } /// Moves the object at the given position - void move(vtable& to_table, data_accessor* from, std::size_t from_capacity, + void move(vtable& to_table, data_accessor* from, size_t from_capacity, data_accessor* to, - std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) { + size_t to_capacity) noexcept(HasStrongExceptGuarantee) { cmd_(&to_table, opcode::op_move, from, from_capacity, to, to_capacity); set_empty(); } /// Destroys the object at the given position void copy(vtable& to_table, data_accessor const* from, - std::size_t from_capacity, data_accessor* to, - std::size_t to_capacity) const { + size_t from_capacity, data_accessor* to, + size_t to_capacity) const { cmd_(&to_table, opcode::op_copy, const_cast(from), from_capacity, to, to_capacity); } /// Destroys the object at the given position void destroy(data_accessor* from, - std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) { + size_t from_capacity) noexcept(HasStrongExceptGuarantee) { cmd_(this, opcode::op_destroy, from, from_capacity, nullptr, 0U); } @@ -1026,7 +1026,7 @@ public: /// vtable void weak_destroy(data_accessor* from, - std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) { + size_t from_capacity) noexcept(HasStrongExceptGuarantee) { cmd_(this, opcode::op_weak_destroy, from, from_capacity, nullptr, 0U); } @@ -1038,13 +1038,13 @@ public: } /// Invoke the function at the given index - template + template constexpr decltype(auto) invoke(Args&&... args) const { auto thunk = invoke_table_t::template fetch(vtable_); return thunk(std::forward(args)...); } /// Invoke the function at the given index - template + template constexpr decltype(auto) invoke(Args&&... args) const volatile { auto thunk = invoke_table_t::template fetch(vtable_); return thunk(std::forward(args)...); @@ -1118,7 +1118,7 @@ public: return &storage_.accessor_; } - static constexpr std::size_t capacity() noexcept { + static constexpr size_t capacity() noexcept { return sizeof(storage_); } }; @@ -1128,7 +1128,7 @@ template class erasure : internal_capacity_holder { template friend class erasure; - template + template friend class operator_impl; using vtable_t = tables::vtable; @@ -1137,7 +1137,7 @@ class erasure : internal_capacity_holder { public: /// Returns the capacity of this erasure - static constexpr std::size_t capacity() noexcept { + static constexpr size_t capacity() noexcept { return internal_capacity_holder::capacity(); } @@ -1262,7 +1262,7 @@ public: /// /// We define this out of class to be able to forward the qualified /// erasure correctly. - template + template static constexpr decltype(auto) invoke(Erasure&& erasure, Args&&... args) { auto const capacity = erasure.capacity(); return erasure.vtable_.template invoke( @@ -1278,7 +1278,7 @@ class erasure> { template friend class erasure; - template + template friend class operator_impl; using property_t = property; @@ -1378,7 +1378,7 @@ public: return view_.ptr_ == nullptr; } - template + template static constexpr decltype(auto) invoke(Erasure&& erasure, T&&... args) { auto thunk = invoke_table_t::template fetch(erasure.invoke_table_); return thunk(&(erasure.view_), 0UL, std::forward(args)...); @@ -1515,7 +1515,7 @@ class function> template friend class function; - template + template friend class type_erasure::invocation_table::operator_impl; using property_t = property; @@ -1708,18 +1708,18 @@ bool operator!=(std::nullptr_t, function const& f) { } // Default intended object size of the function -using object_size = std::integral_constant; +using object_size = std::integral_constant; } // namespace detail } // namespace abi_400 /// Can be passed to function_base as template argument which causes /// the internal small buffer to be sized according to the given size, /// and aligned with the given alignment. -template +template struct capacity_fixed { - static constexpr std::size_t capacity = Capacity; - static constexpr std::size_t alignment = Alignment; + static constexpr size_t capacity = Capacity; + static constexpr size_t alignment = Alignment; }; /// Default capacity for small functor optimization @@ -1737,8 +1737,8 @@ struct capacity_none : capacity_fixed<0UL> {}; /// the given object without allocating memory for an applied type erasure. template struct capacity_can_hold { - static constexpr std::size_t capacity = sizeof(T); - static constexpr std::size_t alignment = alignof(T); + static constexpr size_t capacity = sizeof(T); + static constexpr size_t alignment = alignof(T); }; /// An adaptable function wrapper base for arbitrary functional types. @@ -1758,8 +1758,8 @@ struct capacity_can_hold { /// looks like the following example: /// ```cpp /// struct my_capacity { -/// static constexpr std::size_t capacity = sizeof(my_type); -/// static constexpr std::size_t alignment = alignof(my_type); +/// static constexpr size_t capacity = sizeof(my_type); +/// static constexpr size_t alignment = alignof(my_type); /// }; /// ``` /// diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp index 36f0c8b8..52b4c170 100644 --- a/compat/int-hash.hpp +++ b/compat/int-hash.hpp @@ -1,12 +1,11 @@ #pragma once -#include #include namespace floormat { -constexpr inline std::size_t int_hash(std::size_t x) noexcept +constexpr inline size_t int_hash(size_t x) noexcept { - if constexpr(sizeof(std::size_t) == 4) + if constexpr(sizeof(size_t) == 4) { // by Chris Wellons x ^= x >> 15; @@ -15,7 +14,7 @@ constexpr inline std::size_t int_hash(std::size_t x) noexcept x *= 0x297a2d39U; x ^= x >> 15; } - else if constexpr(sizeof(std::size_t) == 8) + else if constexpr(sizeof(size_t) == 8) { // NASAM by Pelle Evensen x ^= std::rotr(x, 25) ^ std::rotr(x, 47); diff --git a/compat/integer-types.hpp b/compat/integer-types.hpp new file mode 100644 index 00000000..0ec707d3 --- /dev/null +++ b/compat/integer-types.hpp @@ -0,0 +1,61 @@ +#pragma once + +namespace floormat { + +#ifdef _MSC_VER +#ifdef _WIN64 +typedef unsigned __int64 size_t; +typedef __int64 ptrdiff_t; +typedef __int64 intptr_t; +typedef unsigned __int64 uintptr_t; +#else +typedef unsigned int size_t; +typedef int ptrdiff_t; +typedef int intptr_t; +typedef unsigned int uintptr_t; +#endif +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef long long intmax_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef unsigned long long uintmax_t; +#elif __GNUG__ +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __INTPTR_TYPE__ intptr_t; +typedef __UINTPTR_TYPE__ uintptr_t; +typedef __INT8_TYPE__ int8_t; +typedef __INT16_TYPE__ int16_t; +typedef __INT32_TYPE__ int32_t; +typedef __INT64_TYPE__ int64_t; +typedef __UINT8_TYPE__ uint8_t; +typedef __UINT16_TYPE__ uint16_t; +typedef __UINT32_TYPE__ uint32_t; +typedef __UINT64_TYPE__ uint64_t; +typedef __INTMAX_TYPE__ intmax_t; +typedef __UINTMAX_TYPE__ uintmax_t; +#else +#include +#include +using ::std::size_t; +using ::std::std::ptrdiff_t; +using ::std::std::intptr_t; +using ::std::std::uintptr_t; +using ::std::int8_t; +using ::std::int16_t; +using ::std::int32_t; +using ::std::int64_t; +using ::std::intmax_t; +using ::std::uint8_t; +using ::std::uint16_t; +using ::std::uint32_t; +using ::std::uint64_t; +using ::std::uintmax_t; +#endif + +} // namespace floormat diff --git a/compat/prelude.hpp b/compat/prelude.hpp index 3516de98..8f011aa7 100644 --- a/compat/prelude.hpp +++ b/compat/prelude.hpp @@ -1,4 +1,5 @@ #pragma once +#include "integer-types.hpp" namespace floormat { #ifdef _MSC_VER @@ -31,11 +32,6 @@ template class Vector2; template class Vector3; template class Vector4; } // namespace Magnum::Math -namespace Magnum { -using Vector2uz = Math::Vector2; -using Vector3uz = Math::Vector3; -using Vector4uz = Math::Vector4; -} // namespace Magnum namespace floormat { using namespace ::Magnum; @@ -45,6 +41,6 @@ namespace floormat { using Debug [[maybe_unused]] = ::Corrade::Utility::Debug; using Error [[maybe_unused]] = ::Corrade::Utility::Error; namespace Path = Corrade::Utility::Path; // NOLINT(misc-unused-alias-decls) - consteval auto operator""_uz(unsigned long long int x) { return ::floormat::size_t(x); } + consteval auto operator""_uz(unsigned long long int x) { return size_t(x); } } // namespace floormat namespace nlohmann { using ::floormat::operator""_uz; } diff --git a/draw/anim.cpp b/draw/anim.cpp index 4af20b8f..60e9b54c 100644 --- a/draw/anim.cpp +++ b/draw/anim.cpp @@ -51,12 +51,12 @@ void anim_mesh::draw(tile_shader& shader, chunk& c) auto [mesh_] = c.ensure_scenery_mesh(); const auto& es = c.entities(); GL::MeshView mesh{mesh_}; - [[maybe_unused]] std::size_t draw_count = 0; + [[maybe_unused]] size_t draw_count = 0; const auto size = es.size(); - const auto max_index = std::uint32_t(size*quad_index_count - 1); + const auto max_index = uint32_t(size*quad_index_count - 1); - const auto do_draw = [&](std::size_t from, std::size_t to, anim_atlas* atlas) { + const auto do_draw = [&](size_t from, size_t to, anim_atlas* atlas) { atlas->texture().bind(0); mesh.setCount((int)(quad_index_count * (to-from))); mesh.setIndexRange((int)(from*quad_index_count), 0, max_index); @@ -64,14 +64,14 @@ void anim_mesh::draw(tile_shader& shader, chunk& c) draw_count++; }; - fm_debug_assert(std::size_t(mesh_.count()) <= size*quad_index_count); + fm_debug_assert(size_t(mesh_.count()) <= size*quad_index_count); struct last_ { - anim_atlas* atlas = nullptr; std::size_t run_from = 0; + anim_atlas* atlas = nullptr; size_t run_from = 0; operator bool() const { return atlas; } last_& operator=(std::nullptr_t) { atlas = nullptr; return *this; } } last; - std::size_t i = 0; + size_t i = 0; for (auto k = 0_uz; k < size; k++) { @@ -111,7 +111,7 @@ void anim_mesh::draw(tile_shader& shader, chunk& c) #endif } -void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, const Vector3& center, float depth) +void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, const Vector3& center, float depth) { const auto pos = atlas.frame_quad(center, r, frame); const auto& g = atlas.group(r); @@ -124,7 +124,7 @@ void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::si shader.draw(_mesh); } -void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy, Vector2b offset, float depth_offset) +void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth_offset) { const auto pos = Vector3(xy) * TILE_SIZE + Vector3(Vector2(offset), 0); const float depth = tile_shader::depth_value(xy, depth_offset); diff --git a/draw/anim.hpp b/draw/anim.hpp index b7d0a0cd..632a89e3 100644 --- a/draw/anim.hpp +++ b/draw/anim.hpp @@ -25,8 +25,8 @@ struct anim_mesh final anim_mesh(); void draw(tile_shader& shader, chunk& c); - void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, const Vector3& pos, float depth); - void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy, Vector2b offset, float depth_offset); + void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, const Vector3& pos, float depth); + void draw(tile_shader& shader, anim_atlas& atlas, rotation r, size_t frame, local_coords xy, Vector2b offset, float depth_offset); static void add_clickable(tile_shader& shader, const Vector2i& win_size, const std::shared_ptr& s, std::vector& list); private: diff --git a/draw/box.hpp b/draw/box.hpp index b187dc83..a6608e00 100644 --- a/draw/box.hpp +++ b/draw/box.hpp @@ -10,7 +10,7 @@ struct box final { box(Vector3 center, Vector3 size, float line_width); - static constexpr std::size_t num_vertices = 8, num_indexes = 12*2; + static constexpr size_t num_vertices = 8, num_indexes = 12*2; static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::Lines; using vertex_array = std::array; diff --git a/draw/floor.cpp b/draw/floor.cpp index 0f342a4e..6c5e1266 100644 --- a/draw/floor.cpp +++ b/draw/floor.cpp @@ -13,13 +13,13 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) { constexpr int quad_index_count = 6; const auto [mesh_, ids, size] = c.ensure_ground_mesh(); - struct { tile_atlas* atlas = nullptr; std::size_t pos = 0; } last; + struct { tile_atlas* atlas = nullptr; size_t pos = 0; } last; GL::MeshView mesh{mesh_}; - [[maybe_unused]] std::size_t draw_count = 0; - fm_debug_assert(std::size_t(mesh_.count()) == size*quad_index_count); + [[maybe_unused]] size_t draw_count = 0; + fm_debug_assert(size_t(mesh_.count()) == size*quad_index_count); - const auto do_draw = [&](std::size_t i, tile_atlas* atlas, std::uint32_t max_index) { + const auto do_draw = [&](size_t i, tile_atlas* atlas, uint32_t max_index) { if (atlas == last.atlas) return; if (auto len = i - last.pos; last.atlas && len > 0) @@ -33,8 +33,8 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) last = { atlas, i }; }; - const auto max_index = std::uint32_t(size*quad_index_count - 1); - std::size_t k; + const auto max_index = uint32_t(size*quad_index_count - 1); + size_t k; for (k = 0; k < size; k++) do_draw(k, c.ground_atlas_at(ids[k]), max_index); do_draw(size, nullptr, max_index); diff --git a/draw/quad-floor.hpp b/draw/quad-floor.hpp index 7d974798..84ab17e9 100644 --- a/draw/quad-floor.hpp +++ b/draw/quad-floor.hpp @@ -12,7 +12,7 @@ struct quad_floor final { quad_floor(Vector3 center, Vector2 size, float line_width); - static constexpr std::size_t num_vertices = 4, num_indexes = 0; + static constexpr size_t num_vertices = 4, num_indexes = 0; static constexpr auto primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; diff --git a/draw/quad-wall-n.hpp b/draw/quad-wall-n.hpp index f07d7d06..c490d8b2 100644 --- a/draw/quad-wall-n.hpp +++ b/draw/quad-wall-n.hpp @@ -11,7 +11,7 @@ struct quad_wall_n final { quad_wall_n(Vector3 center, Vector3 size, float line_width); - static constexpr std::size_t num_vertices = 4, num_indexes = 0; + static constexpr size_t num_vertices = 4, num_indexes = 0; static constexpr auto primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; diff --git a/draw/quad-wall-w.hpp b/draw/quad-wall-w.hpp index cca70b30..b90d53c3 100644 --- a/draw/quad-wall-w.hpp +++ b/draw/quad-wall-w.hpp @@ -11,7 +11,7 @@ struct quad_wall_w final { quad_wall_w(Vector3 center, Vector3 size, float line_width); - static constexpr std::size_t num_vertices = 4, num_indexes = 0; + static constexpr size_t num_vertices = 4, num_indexes = 0; static constexpr auto primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; diff --git a/draw/quad.hpp b/draw/quad.hpp index 7bccebae..c92e9544 100644 --- a/draw/quad.hpp +++ b/draw/quad.hpp @@ -10,7 +10,7 @@ struct quad final { quad(Vector3 start, Vector2 size, float line_width); - static constexpr std::size_t num_vertices = 4, num_indexes = 0; + static constexpr size_t num_vertices = 4, num_indexes = 0; static constexpr GL::MeshPrimitive primitive = GL::MeshPrimitive::LineLoop; using vertex_array = std::array; diff --git a/draw/wall.cpp b/draw/wall.cpp index a88844a6..d1370d45 100644 --- a/draw/wall.cpp +++ b/draw/wall.cpp @@ -16,12 +16,12 @@ wall_mesh::wall_mesh() = default; void wall_mesh::draw(tile_shader& shader, chunk& c) { const auto [mesh_, ids, size] = c.ensure_wall_mesh(); - struct { tile_atlas* atlas = nullptr; std::size_t pos = 0; } last; + struct { tile_atlas* atlas = nullptr; size_t pos = 0; } last; GL::MeshView mesh{mesh_}; - [[maybe_unused]] std::size_t draw_count = 0; - fm_debug_assert(std::size_t(mesh_.count()) == size*quad_index_count); + [[maybe_unused]] size_t draw_count = 0; + fm_debug_assert(size_t(mesh_.count()) == size*quad_index_count); - const auto do_draw = [&](std::size_t i, tile_atlas* atlas, std::uint32_t max_index) { + const auto do_draw = [&](size_t i, tile_atlas* atlas, uint32_t max_index) { if (atlas == last.atlas) return; if (auto len = i - last.pos; last.atlas && len > 0) @@ -35,8 +35,8 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) last = { atlas, i }; }; - const auto max_index = std::uint32_t(size*quad_index_count - 1); - std::size_t k; + const auto max_index = uint32_t(size*quad_index_count - 1); + size_t k; for (k = 0; k < size; k++) do_draw(k, c.wall_atlas_at(ids[k]), max_index); do_draw(size, nullptr, max_index); diff --git a/draw/wireframe.cpp b/draw/wireframe.cpp index 7acebc70..84e086d4 100644 --- a/draw/wireframe.cpp +++ b/draw/wireframe.cpp @@ -34,7 +34,7 @@ struct constant_buf { }; mesh_base::mesh_base(GL::MeshPrimitive primitive, ArrayView index_data, - std::size_t num_vertices, std::size_t num_indexes, GL::Texture2D* texture) : + size_t num_vertices, size_t num_indexes, GL::Texture2D* texture) : _vertex_buffer{Containers::Array{ValueInit, num_vertices}, GL::BufferUsage::DynamicDraw}, _constant_buffer{Containers::Array{ValueInit, num_vertices}}, _index_buffer{num_indexes == 0 ? GL::Buffer{NoCreate} : GL::Buffer{index_data}}, diff --git a/draw/wireframe.hpp b/draw/wireframe.hpp index 6d5249e1..922936ae 100644 --- a/draw/wireframe.hpp +++ b/draw/wireframe.hpp @@ -13,8 +13,8 @@ namespace wireframe { template concept traits = requires (const T& x) { - {T::num_vertices} -> std::convertible_to; - {T::num_indexes} -> std::convertible_to; + {T::num_vertices} -> std::convertible_to; + {T::num_indexes} -> std::convertible_to; {x.primitive} -> std::convertible_to; {x.make_vertex_array() } -> std::convertible_to>; {T::make_index_array() } -> std::convertible_to>; @@ -32,7 +32,7 @@ protected: GL::Mesh _mesh; mesh_base(GL::MeshPrimitive primitive, ArrayView index_data, - std::size_t num_vertices, std::size_t num_indexes, GL::Texture2D* texture); + size_t num_vertices, size_t num_indexes, GL::Texture2D* texture); void draw(tile_shader& shader); void set_subdata(ArrayView array); }; diff --git a/editor/app.cpp b/editor/app.cpp index 63394ded..71b34cb8 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -50,7 +50,7 @@ void app::ensure_player_character(world& w) return; _character_id = 0; - auto id = (std::uint64_t)-1; + auto id = (object_id)-1; for (const auto& [coord, c] : w.chunks()) { @@ -66,7 +66,7 @@ void app::ensure_player_character(world& w) } } - if (id != (std::uint64_t)-1) + if (id != (object_id)-1) _character_id = id; else { @@ -135,7 +135,7 @@ fm_settings app::parse_cmdline(int argc, const char* const* const argv) { Vector2us size; int n = 0, ret = std::sscanf(str.data(), "%hux%hu%n", &size.x(), &size.y(), &n); - if (ret != 2 || (std::size_t)n != str.size() || Vector2ui(size).product() == 0) + if (ret != 2 || (size_t)n != str.size() || Vector2ui(size).product() == 0) { Error{} << "invalid --geometry argument '%s'" << str; std::exit(EX_USAGE); diff --git a/editor/app.hpp b/editor/app.hpp index dc8fed2c..7f117f9c 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -10,6 +10,7 @@ #include "draw/box.hpp" #include "floormat/app.hpp" #include "keys.hpp" +#include "object-id.hpp" #include #include #include @@ -33,7 +34,7 @@ struct cursor_state final { struct clickable; -enum class Cursor: std::uint32_t { +enum class Cursor: uint32_t { Arrow, TextInput, Wait, Crosshair, WaitArrow, ResizeNWSE, ResizeNESW, ResizeWE, ResizeNS, ResizeAll, No, Hand, Hidden, HiddenLocked, @@ -96,7 +97,7 @@ private: void on_mouse_enter() noexcept override; void do_mouse_move(int modifiers); - void do_mouse_up_down(std::uint8_t button, bool is_down, int modifiers); + void do_mouse_up_down(uint8_t button, bool is_down, int modifiers); void do_camera(float dt, const key_set& cmds, int mods); void reset_camera_offset(); @@ -150,7 +151,7 @@ private: key_set keys; std::array key_modifiers = {}; std::vector inspectors; - std::uint64_t _character_id = 0; + object_id _character_id = 0; cursor_state cursor; popup_target _popup_target; diff --git a/editor/draw.cpp b/editor/draw.cpp index 5cd6a124..611e77fc 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -74,8 +74,8 @@ void app::draw_collision_boxes() using rtree_type = std::decay_t; using rect_type = typename rtree_type::Rect; - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { const chunk_coords pos{x, y}; auto& c = world[pos]; @@ -87,7 +87,7 @@ void app::draw_collision_boxes() { constexpr float maxf = 1 << 24, max2f[] = { maxf, maxf }, min2f[] = { -maxf, -maxf }; const auto* rtree = c.rtree(); - rtree->Search(min2f, max2f, [&](std::uint64_t data, const rect_type& rect) { + rtree->Search(min2f, max2f, [&](object_id data, const rect_type& rect) { [[maybe_unused]] auto x = std::bit_cast(data); Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); auto size = (end - start); @@ -110,8 +110,8 @@ void app::draw_collision_boxes() const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0], curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]); - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { const chunk_coords c_pos{x, y}; auto& c = world[c_pos]; @@ -127,7 +127,7 @@ void app::draw_collision_boxes() auto t0 = chunk_dist + curtile*TILE_SIZE2 + subpixel - half_tile; auto t1 = t0+Vector2(1e-4f); const auto* rtree = c.rtree(); - rtree->Search(t0.data(), t1.data(), [&](std::uint64_t data, const rect_type& rect) { + rtree->Search(t0.data(), t1.data(), [&](uint64_t data, const rect_type& rect) { [[maybe_unused]] auto x = std::bit_cast(data); Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); auto size = end - start; @@ -168,7 +168,7 @@ clickable* app::find_clickable_scenery(const Optional& pixel) { const auto pos_ = *pixel - c.dest.min() + Vector2i(c.src.min()); const auto pos = !c.mirrored ? pos_ : Vector2i(int(c.src.sizeX()) - 1 - pos_[0], pos_[1]); - std::size_t idx = unsigned(pos.y()) * c.stride + unsigned(pos.x()); + size_t idx = unsigned(pos.y()) * c.stride + unsigned(pos.x()); fm_assert(idx < c.bitmask.size()); if (c.bitmask[idx]) { diff --git a/editor/editor.cpp b/editor/editor.cpp index cfb36480..f09030dc 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -69,10 +69,10 @@ void editor::on_mouse_move(world& world, global_coords& pos, int mods) const auto [minx, maxx] = std::minmax(draw_coord.x, last.draw_coord.x); const auto [miny, maxy] = std::minmax(draw_coord.y, last.draw_coord.y); if (draw_offset[0]) - for (std::uint32_t i = minx; i <= maxx; i++) + for (uint32_t i = minx; i <= maxx; i++) on_click_(world, { i, draw_coord.y }, last.btn); else - for (std::uint32_t j = miny; j <= maxy; j++) + for (uint32_t j = miny; j <= maxy; j++) on_click_(world, { draw_coord.x, j }, last.btn); } else diff --git a/editor/events.cpp b/editor/events.cpp index 2fb8b567..4e0a2503 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -76,7 +76,7 @@ void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce Middle = mouse_button_middle, }; - const auto button = std::uint8_t(1 << (event.button-1)); + const auto button = uint8_t(1 << (event.button-1)); struct ev { using Button = Button_; @@ -175,7 +175,7 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept else { keys[x] = is_down; - key_modifiers[std::size_t(x)] = mods; + key_modifiers[size_t(x)] = mods; } } diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp index 42e7bec5..45b42b7b 100644 --- a/editor/imgui-inspect.cpp +++ b/editor/imgui-inspect.cpp @@ -19,7 +19,7 @@ void app::draw_inspector() constexpr auto max_inspectors = 4; // todo change later to 32 if (auto size = inspectors.size(); size > max_inspectors) { - auto end = inspectors.begin() + (std::ptrdiff_t)size - max_inspectors; + auto end = inspectors.begin() + (ptrdiff_t)size - max_inspectors; inspectors.erase(inspectors.begin(), end); } diff --git a/editor/imgui-raii.hpp b/editor/imgui-raii.hpp index 8df8de38..9888b70b 100644 --- a/editor/imgui-raii.hpp +++ b/editor/imgui-raii.hpp @@ -40,7 +40,7 @@ private: void text(StringView str, ImGuiTextFlags flags = ImGuiTextFlags_NoWidthForLargeClippedText); -template +template void text(const char (&buf)[N], ImGuiTextFlags_ flags = ImGuiTextFlags_NoWidthForLargeClippedText) { ImGui::TextEx(buf, buf + N - 1, flags); diff --git a/editor/imgui-tiles.cpp b/editor/imgui-tiles.cpp index 57cdecba..ead843a8 100644 --- a/editor/imgui-tiles.cpp +++ b/editor/imgui-tiles.cpp @@ -48,7 +48,7 @@ void app::draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const st push_style_color(ImGuiCol_ButtonHovered, color_hover), }; const bool perm_selected = ed.is_permutation_selected(atlas); - constexpr std::size_t per_row = 8; + constexpr size_t per_row = 8; for (auto i = 0_uz; i < N; i++) { const bool selected = ed.is_tile_selected(atlas, i); diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 85b77e46..f43bdc7a 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -32,10 +32,10 @@ struct entity_accessors { [](const scenery& x) { return x.r; }, [](scenery& x, rotation r) { x.rotate(x.index(), r); }, }, - entity::type::field{"frame"_s, + entity::type::field{"frame"_s, [](const scenery& x) { return x.frame; }, - [](scenery& x, std::uint16_t value) { x.frame = value; }, - [](const scenery& x) { return constraints::range{0, !x.atlas ? std::uint16_t(0) : std::uint16_t(x.atlas->info().nframes-1)}; } + [](scenery& x, uint16_t value) { x.frame = value; }, + [](const scenery& x) { return constraints::range{0, !x.atlas ? uint16_t(0) : uint16_t(x.atlas->info().nframes-1)}; } }, entity::type::field{"offset"_s, [](const scenery& x) { return x.offset; }, @@ -79,17 +79,17 @@ template<> struct has_anim_atlas : std::true_type { } }; -using enum_pair = std::pair; +using enum_pair = std::pair; template struct enum_values; -template +template struct enum_pair_array { std::array array; - std::size_t size; + size_t size; operator ArrayView() const noexcept { return {array.data(), size}; } }; -template enum_pair_array(std::array array, std::size_t) -> enum_pair_array; +template enum_pair_array(std::array array, size_t) -> enum_pair_array; template requires (!std::is_enum_v) @@ -99,10 +99,10 @@ struct enum_values : std::true_type { template struct enum_values : std::true_type { static constexpr auto ret = std::to_array({ - { "blocked"_s, (std::size_t)pass_mode::blocked, }, - { "see-through"_s, (std::size_t)pass_mode::see_through, }, - { "shoot-through"_s, (std::size_t)pass_mode::shoot_through, }, - { "pass"_s, (std::size_t)pass_mode::pass }, + { "blocked"_s, (size_t)pass_mode::blocked, }, + { "see-through"_s, (size_t)pass_mode::see_through, }, + { "shoot-through"_s, (size_t)pass_mode::shoot_through, }, + { "pass"_s, (size_t)pass_mode::pass }, }); static constexpr const auto& get() { return ret; } }; @@ -112,7 +112,7 @@ requires has_anim_atlas::value struct enum_values : std::false_type { static auto get(const U& x) { const anim_atlas& atlas = has_anim_atlas::get_atlas(x); - std::array array; + std::array array; constexpr std::pair values[] = { { "North"_s, rotation::N }, { "Northeast"_s, rotation::NE }, @@ -123,10 +123,10 @@ struct enum_values : std::false_type { { "West"_s, rotation::W }, { "Northwest"_s, rotation::NW }, }; - std::size_t i = 0; + size_t i = 0; for (auto [str, val] : values) if (atlas.check_rotation(val)) - array[i++] = enum_pair{str, (std::size_t)val}; + array[i++] = enum_pair{str, (size_t)val}; return enum_pair_array{array, i}; } }; diff --git a/editor/inspect.cpp b/editor/inspect.cpp index f68df7d1..0609c4be 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -16,7 +16,7 @@ namespace floormat::entities { namespace { -const char* label_left(StringView label, char* buf, std::size_t len) +const char* label_left(StringView label, char* buf, size_t len) { std::snprintf(buf, len, "##%s", label.data()); float width = ImGui::CalcItemWidth(), x = ImGui::GetCursorPosX(); @@ -28,12 +28,12 @@ const char* label_left(StringView label, char* buf, std::size_t len) } template struct IGDT_; -template<> struct IGDT_ : std::integral_constant {}; -template<> struct IGDT_ : std::integral_constant {}; -template<> struct IGDT_ : std::integral_constant {}; -template<> struct IGDT_ : std::integral_constant {}; -template<> struct IGDT_ : std::integral_constant {}; -template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; +template<> struct IGDT_ : std::integral_constant {}; template<> struct IGDT_ : std::integral_constant {}; template constexpr auto IGDT = IGDT_::value; @@ -43,7 +43,7 @@ using namespace entities; template requires std::is_integral_v constexpr bool eqv(T a, T b) { return a == b; } inline bool eqv(float a, float b) { return std::fabs(a - b) < 1e-8f; } inline bool eqv(const String& a, const String& b) { return a == b; } -template constexpr bool eqv(const Math::Vector& a, const Math::Vector& b) { return a == b; } +template constexpr bool eqv(const Math::Vector& a, const Math::Vector& b) { return a == b; } int corrade_string_resize_callback(ImGuiInputTextCallbackData* data) { @@ -51,7 +51,7 @@ int corrade_string_resize_callback(ImGuiInputTextCallbackData* data) { auto* my_str = reinterpret_cast(data->UserData); fm_assert(my_str->begin() == data->Buf); - *my_str = String{ValueInit, (std::size_t)data->BufSize}; + *my_str = String{ValueInit, (size_t)data->BufSize}; data->Buf = my_str->begin(); } return 0; @@ -59,7 +59,7 @@ int corrade_string_resize_callback(ImGuiInputTextCallbackData* data) template bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr, - const ArrayView>& list) + const ArrayView>& list) { if (list.isEmpty()) fm_assert(accessor.check_field_type()); @@ -101,7 +101,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r step2(!std::is_floating_point_v ? T(10) : T(1e-3f)); switch (repr) { - default: fm_warn_once("invalid repr enum value '%zu'", (std::size_t)repr); break; + default: fm_warn_once("invalid repr enum value '%zu'", (size_t)repr); break; case field_repr::input: ret = ImGui::InputScalar(label, igdt, &value, &step, &step2); break; case field_repr::slider: ret = ImGui::SliderScalar(label, igdt, &value, &min, &max); break; case field_repr::drag: ret = ImGui::DragScalar(label, igdt, &value, 1, &min, &max); break; @@ -109,7 +109,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r if constexpr(std::is_integral_v) { const char* preview = ""; - const auto old_value = (std::size_t)static_cast>(value); + const auto old_value = (size_t)static_cast>(value); for (const auto& [str, x] : list) if (x == old_value) { @@ -119,7 +119,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r if (auto b = begin_combo(label, preview)) for (const auto& [str, x] : list) { - const bool is_selected = x == (std::size_t)old_value; + const bool is_selected = x == (size_t)old_value; if (ImGui::Selectable(str.data(), is_selected)) value = T(x), ret = true; if (is_selected) @@ -141,7 +141,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r switch (repr) { default: - fm_warn_once("invalid repr enum value '%zu'", (std::size_t)repr); + fm_warn_once("invalid repr enum value '%zu'", (size_t)repr); break; case field_repr::input: ret = ImGui::InputScalarN(label, igdt, &value, T::Size, &step, &step2); @@ -171,7 +171,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r #define MAKE_SPEC(type, repr) \ template<> \ bool inspect_field(void* datum, const erased_accessor& accessor, \ - const ArrayView>& list) \ + const ArrayView>& list) \ { \ return do_inspect_field(datum, accessor, (repr), list); \ } @@ -179,7 +179,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r #define MAKE_SPEC2(type, repr) \ template<> \ bool inspect_field>(void* datum, const erased_accessor& accessor, \ - const ArrayView>& list) \ + const ArrayView>& list) \ { \ return do_inspect_field(datum, accessor, (repr), list); \ } @@ -197,12 +197,12 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r MAKE_SPEC_REPRS(type) \ MAKE_SPEC2(type, field_repr::cbx) -MAKE_SPEC_REPRS2(std::uint8_t) -MAKE_SPEC_REPRS2(std::int8_t) -MAKE_SPEC_REPRS2(std::uint16_t) -MAKE_SPEC_REPRS2(std::int16_t) -MAKE_SPEC_REPRS2(std::uint32_t) -MAKE_SPEC_REPRS2(std::int32_t) +MAKE_SPEC_REPRS2(uint8_t) +MAKE_SPEC_REPRS2(int8_t) +MAKE_SPEC_REPRS2(uint16_t) +MAKE_SPEC_REPRS2(int16_t) +MAKE_SPEC_REPRS2(uint32_t) +MAKE_SPEC_REPRS2(int32_t) MAKE_SPEC_REPRS2(float) MAKE_SPEC(bool, field_repr::input) MAKE_SPEC(String, field_repr::input) diff --git a/editor/inspect.hpp b/editor/inspect.hpp index 25ec8ec4..98649e13 100644 --- a/editor/inspect.hpp +++ b/editor/inspect.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include namespace floormat::entities { @@ -28,11 +27,11 @@ template using field_repr_drag = field_repr_ using field_repr_cbx = field_repr_; template bool inspect_field(void* datum, const entities::erased_accessor& accessor, - const ArrayView>& list); + const ArrayView>& list); template bool inspect_type(T& x); template requires std::is_enum_v bool inspect_field(void* datum, const entities::erased_accessor& accessor, - const ArrayView>& list) + const ArrayView>& list) { return inspect_field>>(datum, accessor, list); } diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index 45dd0288..562ca04f 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -84,7 +84,7 @@ void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s) // don't regen colliders const auto px = Vector2(pos.local()) * TILE_SIZE2; const auto es = c.entities(); - for (auto i = es.size()-1; i != (std::size_t)-1; i--) + for (auto i = es.size()-1; i != (size_t)-1; i--) { const auto& e = *es[i]; if (e.type != entity_type::scenery) diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index ffee3b66..4de40ab6 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -59,7 +59,7 @@ void tile_editor::clear_selection() _selection_mode = sel_none; } -void tile_editor::select_tile(const std::shared_ptr& atlas, std::size_t variant) +void tile_editor::select_tile(const std::shared_ptr& atlas, size_t variant) { fm_assert(atlas); clear_selection(); @@ -75,7 +75,7 @@ void tile_editor::select_tile_permutation(const std::shared_ptr& atl _permutation = { atlas, {} }; } -bool tile_editor::is_tile_selected(const std::shared_ptr& atlas, std::size_t variant) const +bool tile_editor::is_tile_selected(const std::shared_ptr& atlas, size_t variant) const { return atlas && _selection_mode == sel_tile && _selected_tile && atlas == _selected_tile.atlas && variant == _selected_tile.variant; diff --git a/editor/tile-editor.hpp b/editor/tile-editor.hpp index 5f2b00d6..321b75c6 100644 --- a/editor/tile-editor.hpp +++ b/editor/tile-editor.hpp @@ -48,9 +48,9 @@ public: editor_wall_rotation rotation() const noexcept { return _rotation; } void clear_selection(); - void select_tile(const std::shared_ptr& atlas, std::size_t variant); + void select_tile(const std::shared_ptr& atlas, size_t variant); void select_tile_permutation(const std::shared_ptr& atlas); - bool is_tile_selected(const std::shared_ptr& atlas, std::size_t variant) const; + bool is_tile_selected(const std::shared_ptr& atlas, size_t variant) const; bool is_permutation_selected(const std::shared_ptr& atlas) const; bool is_atlas_selected(const std::shared_ptr& atlas) const; bool is_anything_selected() const; diff --git a/editor/update.cpp b/editor/update.cpp index e9570208..0d8f692e 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -48,7 +48,7 @@ void app::do_mouse_move(int mods) _editor.on_mouse_move(M->world(), *cursor.tile, mods); } -void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) +void app::do_mouse_up_down(uint8_t button, bool is_down, int mods) { auto& w = M->world(); update_cursor_tile(cursor.pixel); @@ -136,7 +136,7 @@ void app::do_key(key k, int mods) { default: if (k >= key_NO_REPEAT) - fm_warn("unhandled key: '%zu'", std::size_t(k)); + fm_warn("unhandled key: '%zu'", size_t(k)); return; case key_rotate_tile: return do_rotate(false); @@ -178,13 +178,13 @@ void app::update_world(float dt) auto& world = M->world(); auto [minx, maxx, miny, maxy] = M->get_draw_bounds(); minx--; miny--; maxx++; maxy++; - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { auto& c = world[chunk_coords{x, y}]; const auto& es = c.entities(); const auto size = es.size(); - for (auto i = size-1; i != (std::size_t)-1; i--) + for (auto i = size-1; i != (size_t)-1; i--) { auto& e = *es[i]; e.update(i, dt); @@ -208,9 +208,9 @@ void app::set_cursor() if (!cursor.in_imgui) { if ([[maybe_unused]] auto* cl = find_clickable_scenery(cursor.pixel)) - M->set_cursor(std::uint32_t(Cursor::Hand)); + M->set_cursor(uint32_t(Cursor::Hand)); else - M->set_cursor(std::uint32_t(Cursor::Arrow)); + M->set_cursor(uint32_t(Cursor::Arrow)); } else set_cursor_from_imgui(); diff --git a/entity/constraints.hpp b/entity/constraints.hpp index b4989353..19ca37b2 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -1,6 +1,5 @@ #pragma once #include "erased-constraints.hpp" -#include #include #include #include diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp index 2c062bf1..552556cd 100644 --- a/entity/erased-constraints.cpp +++ b/entity/erased-constraints.cpp @@ -1,6 +1,5 @@ #include "erased-constraints.hpp" #include "compat/assert.hpp" -#include #include #include #include @@ -8,11 +7,11 @@ #include #include -static_assert(sizeof(std::size_t) == sizeof(std::uintptr_t)); -static_assert(sizeof(std::size_t) == sizeof(std::ptrdiff_t)); - namespace floormat::entities::erased_constraints { +static_assert(sizeof(size_t) == sizeof(uintptr_t)); +static_assert(sizeof(size_t) == sizeof(ptrdiff_t)); + template std::pair range::convert() const { static_assert(sizeof(T) <= sizeof(min)); @@ -106,13 +105,13 @@ template std::pair range::convert() const template using pair2 = std::pair; -template pair2 range::convert() const; -template pair2 range::convert() const; -template pair2 range::convert() const; -template pair2 range::convert() const; -template pair2 range::convert() const; -template pair2 range::convert() const; -template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; +template pair2 range::convert() const; template pair2 range::convert() const; template pair2 range::convert() const; template pair2 range::convert() const; diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp index c77d8166..4d38f456 100644 --- a/entity/erased-constraints.hpp +++ b/entity/erased-constraints.hpp @@ -6,7 +6,7 @@ namespace floormat::entities::erased_constraints { struct range final { - using U = std::size_t; + using U = size_t; using I = std::make_signed_t; enum type_ : unsigned char { type_none, @@ -30,8 +30,8 @@ struct range final }; struct max_length final { - std::size_t value = std::size_t(-1); - constexpr operator std::size_t() const { return value; } + size_t value = size_t(-1); + constexpr operator size_t() const { return value; } }; struct group final { diff --git a/entity/metadata.hpp b/entity/metadata.hpp index e2d9eb67..eece486f 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -5,7 +5,6 @@ #include "util.hpp" #include "concepts.hpp" #include "compat/defs.hpp" -#include #include #include #include @@ -23,7 +22,7 @@ template struct entity_accessors; namespace floormat::entities::detail { -template +template requires std::invocable(std::declval()))> constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple) { @@ -35,7 +34,7 @@ constexpr CORRADE_ALWAYS_INLINE void visit_tuple(F&& fun, Tuple&& tuple) visit_tuple(std::forward(fun), std::forward(tuple)); } -template +template requires std::is_invocable_r_v(std::declval()))> constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple) { @@ -53,22 +52,22 @@ template struct decay_tuple_; template struct decay_tuple_> { using type = std::tuple...>; }; template using decay_tuple = typename decay_tuple_::type; -template struct find_reader; +template struct find_reader; -template struct find_reader { +template struct find_reader { using type = Default; - static constexpr std::size_t index = I; + static constexpr size_t index = I; }; -template +template struct find_reader { using type = typename find_reader::type; - static constexpr std::size_t index = find_reader::index; + static constexpr size_t index = find_reader::index; }; -template +template requires FieldReader -struct find_reader { using type = F; static constexpr std::size_t index = I; }; +struct find_reader { using type = F; static constexpr size_t index = I; }; } // namespace floormat::entities::detail @@ -85,7 +84,7 @@ struct entity_field : entity_field_base { private: static constexpr auto default_predicate = constantly(field_status::enabled); static constexpr auto default_c_range = constantly(constraints::range{}); - static constexpr auto default_c_length = constantly(constraints::max_length{std::size_t(-1)}); + static constexpr auto default_c_length = constantly(constraints::max_length{size_t(-1)}); static constexpr auto default_c_group = constantly(StringView{}); using default_predicate_t = std::decay_t; using default_c_range_t = std::decay_t; @@ -95,7 +94,7 @@ private: using c_range = detail::find_reader, default_c_range_t, 0, Ts...>; using c_length = detail::find_reader; using c_group = detail::find_reader; - static constexpr std::size_t good_arguments = + static constexpr size_t good_arguments = unsigned(c_predicate::index != sizeof...(Ts)) + unsigned(c_range::index != sizeof...(Ts)) + unsigned(c_length::index != sizeof...(Ts)) + @@ -273,7 +272,7 @@ class entity_metadata final { public: static constexpr StringView class_name = name_of; static constexpr auto accessors = entities::entity_accessors::accessors(); - static constexpr std::size_t size = std::tuple_size_v>; + static constexpr size_t size = std::tuple_size_v>; static constexpr auto erased_accessors = erased_helper(accessors); }; diff --git a/floormat/events.hpp b/floormat/events.hpp index 44e54a05..c7d36379 100644 --- a/floormat/events.hpp +++ b/floormat/events.hpp @@ -16,7 +16,7 @@ struct mouse_button_event final { Vector2i position; int mods = 0; mouse_button button = mouse_button_none; - std::uint8_t click_count = 0; + uint8_t click_count = 0; }; struct mouse_move_event final { @@ -37,13 +37,13 @@ struct text_input_event final { struct text_editing_event final { Containers::StringView text; - std::int32_t start = 0, length = 0; + int32_t start = 0, length = 0; }; struct key_event final { int key = 0; int mods = 0; - std::uint8_t is_repeated = false; + uint8_t is_repeated = false; }; union alignas(alignof(void*)) any_event { diff --git a/floormat/main.hpp b/floormat/main.hpp index 3fbef522..b80ac289 100644 --- a/floormat/main.hpp +++ b/floormat/main.hpp @@ -23,7 +23,7 @@ struct anim_mesh; struct floormat_main { - struct draw_bounds final { std::int16_t minx, maxx, miny, maxy; }; + struct draw_bounds final { int16_t minx, maxx, miny, maxy; }; struct meshes final { floor_mesh& floor; wall_mesh& wall; @@ -55,8 +55,8 @@ struct floormat_main virtual ArrayView clickable_scenery() const noexcept = 0; virtual ArrayView clickable_scenery() noexcept = 0; - virtual void set_cursor(std::uint32_t cursor) noexcept = 0; - virtual std::uint32_t cursor() const noexcept = 0; + virtual void set_cursor(uint32_t cursor) noexcept = 0; + virtual uint32_t cursor() const noexcept = 0; virtual global_coords pixel_to_tile(Vector2d position) const noexcept = 0; virtual Vector2d pixel_to_tile_(Vector2d position) const noexcept = 0; diff --git a/loader/atlas.cpp b/loader/atlas.cpp index be8a2d23..a87d4ec1 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -84,7 +84,7 @@ std::shared_ptr loader_impl::anim_atlas(StringView name, StringView fm_soft_assert(anim_info.nframes == 1 || anim_info.fps > 0); const auto size = tex.pixels().size(); const auto width = size[1], height = size[0]; - fm_soft_assert(Vector2uz{anim_info.pixel_size} == Vector2uz{width, height}); + fm_soft_assert(anim_info.pixel_size[0] == width && anim_info.pixel_size[1] == height); auto atlas = std::make_shared(path, tex, std::move(anim_info)); return anim_atlas_map[atlas->name()] = atlas; diff --git a/loader/loader.hpp b/loader/loader.hpp index 577f45c5..e81abadf 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -7,7 +7,7 @@ namespace Magnum { using Vector2ub = Math::Vector2; } namespace floormat { struct serialized_scenery; } namespace Magnum::Trade { -template class ImageData; +template class ImageData; using ImageData2D = ImageData<2>; } // namespace Magnum::Trade diff --git a/loader/texture.cpp b/loader/texture.cpp index e14d0f34..5edef9ee 100644 --- a/loader/texture.cpp +++ b/loader/texture.cpp @@ -15,7 +15,7 @@ Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_) { ensure_plugins(); - constexpr std::size_t max_extension_length = 16; + constexpr size_t max_extension_length = 16; const auto N = prefix.size(); if (N > 0) fm_assert(prefix[N-1] == '/'); @@ -27,7 +27,7 @@ Trade::ImageData2D loader_impl::texture(StringView prefix, StringView filename_) if (N > 0) std::memcpy(filename, prefix.data(), N); std::memcpy(filename + N, filename_.data(), filename_.size()); - std::size_t len = filename_.size() + N; + size_t len = filename_.size() + N; for (const auto& extension : std::initializer_list{ ".tga", ".png", ".webp", }) { diff --git a/main/clickable.hpp b/main/clickable.hpp index 7311b451..38968d87 100644 --- a/main/clickable.hpp +++ b/main/clickable.hpp @@ -14,7 +14,7 @@ struct clickable final { BitArrayView bitmask; std::shared_ptr e; float depth; - std::uint32_t stride; + uint32_t stride; bool mirrored; }; diff --git a/main/draw.cpp b/main/draw.cpp index 84d90f65..5c36e8d1 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -43,7 +43,7 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept { auto vec = pixel_to_tile_(position); - const auto x = (std::int32_t)std::floor(vec[0]), y = (std::int32_t)std::floor(vec[1]); + const auto x = (int32_t)std::floor(vec[0]), y = (int32_t)std::floor(vec[1]); return { x, y }; } @@ -57,7 +57,7 @@ Vector2d main_impl::pixel_to_tile_(Vector2d position) const noexcept auto main_impl::get_draw_bounds() const noexcept -> draw_bounds { - using limits = std::numeric_limits; + using limits = std::numeric_limits; auto x0 = limits::max(), x1 = limits::min(), y0 = limits::max(), y1 = limits::min(); const auto win = Vector2d(window_size()); @@ -82,7 +82,7 @@ auto main_impl::get_draw_bounds() const noexcept -> draw_bounds void main_impl::update_collect_threshold() { const auto [minx, maxx, miny, maxy] = get_draw_bounds(); - const auto value = std::max(64_uz, (std::size_t)(maxx-minx+4)*(std::size_t)(maxy-minx+4)); + const auto value = std::max(64_uz, (size_t)(maxx-minx+4)*(size_t)(maxy-minx+4)); if (!(GL::Context::current().configurationFlags() & GL::Implementation::ContextConfigurationFlag::QuietLog)) fm_debug("collect threshold is now %zu", value); _world.set_collect_threshold(value); @@ -93,8 +93,8 @@ void main_impl::draw_world() noexcept const auto [minx, maxx, miny, maxy] = get_draw_bounds(); const auto sz = window_size(); - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { const chunk_coords pos{x, y}; if (!_world.contains(pos)) @@ -109,8 +109,8 @@ void main_impl::draw_world() noexcept GL::Renderer::enable(GL::Renderer::Feature::DepthTest); GL::defaultFramebuffer.clearDepthStencil(0, 0); - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { const chunk_coords pos{x, y}; auto& c = _world[pos]; @@ -125,8 +125,8 @@ void main_impl::draw_world() noexcept GL::Renderer::setDepthMask(false); - for (std::int16_t y = miny; y <= maxy; y++) - for (std::int16_t x = minx; x <= maxx; x++) + for (int16_t y = miny; y <= maxy; y++) + for (int16_t x = minx; x <= maxx; x++) { const chunk_coords pos{x, y}; auto& c = _world[pos]; @@ -149,7 +149,7 @@ void main_impl::draw_world() noexcept bool floormat_main::check_chunk_visible(const Vector2d& offset, const Vector2i& size) noexcept { constexpr Vector3d len = dTILE_SIZE * TILE_MAX_DIM20d; - enum : std::size_t { x, y, }; + enum : size_t { x, y, }; constexpr Vector2d p00 = tile_shader::project(Vector3d(0, 0, 0)), p10 = tile_shader::project(Vector3d(len[x], 0, 0)), p01 = tile_shader::project(Vector3d(0, len[y], 0)), diff --git a/main/events.cpp b/main/events.cpp index 6222f964..6888132a 100644 --- a/main/events.cpp +++ b/main/events.cpp @@ -17,32 +17,32 @@ void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event) void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event) { app.on_mouse_up_down({event.position() * _virtual_scale, - (SDL_Keymod)(std::uint16_t)event.modifiers(), - mouse_button(SDL_BUTTON((std::uint8_t)event.button())), - std::uint8_t(std::min(255, event.clickCount()))}, + (SDL_Keymod)(uint16_t)event.modifiers(), + mouse_button(SDL_BUTTON((uint8_t)event.button())), + uint8_t(std::min(255, event.clickCount()))}, true); } void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event) { app.on_mouse_up_down({event.position() * _virtual_scale, - (SDL_Keymod)(std::uint16_t)event.modifiers(), - mouse_button(SDL_BUTTON((std::uint8_t)event.button())), - std::uint8_t(std::min(255, event.clickCount()))}, + (SDL_Keymod)(uint16_t)event.modifiers(), + mouse_button(SDL_BUTTON((uint8_t)event.button())), + uint8_t(std::min(255, event.clickCount()))}, false); } void main_impl::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event) { app.on_mouse_move({event.position() * _virtual_scale, - (mouse_button)(std::uint8_t)std::uint32_t{event.buttons()}, - (SDL_Keymod)(std::uint16_t)event.modifiers()}); + (mouse_button)(uint8_t)uint32_t{event.buttons()}, + (SDL_Keymod)(uint16_t)event.modifiers()}); } void main_impl::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event) { app.on_mouse_scroll({event.offset(), event.position() * _virtual_scale, - (SDL_Keymod)(std::uint16_t)event.modifiers()}); + (SDL_Keymod)(uint16_t)event.modifiers()}); } void main_impl::textInputEvent(Platform::Sdl2Application::TextInputEvent& event) @@ -59,16 +59,16 @@ void main_impl::textEditingEvent(Platform::Sdl2Application::TextEditingEvent& ev void main_impl::keyPressEvent(Platform::Sdl2Application::KeyEvent& event) { - app.on_key_up_down({(SDL_Keycode)(std::uint32_t)event.key(), - (SDL_Keymod)(std::uint16_t)event.modifiers(), + app.on_key_up_down({(SDL_Keycode)(uint32_t)event.key(), + (SDL_Keymod)(uint16_t)event.modifiers(), event.isRepeated()}, true); } void main_impl::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event) { - app.on_key_up_down({(SDL_Keycode)(std::uint32_t)event.key(), - (SDL_Keymod)(std::uint16_t)event.modifiers(), + app.on_key_up_down({(SDL_Keycode)(uint32_t)event.key(), + (SDL_Keymod)(uint16_t)event.modifiers(), event.isRepeated()}, false); } diff --git a/main/main-impl.cpp b/main/main-impl.cpp index a971edcf..8cde3e2f 100644 --- a/main/main-impl.cpp +++ b/main/main-impl.cpp @@ -46,15 +46,15 @@ Vector2i floormat_main::window_size() const noexcept return _framebuffer_size; } -void main_impl::set_cursor(std::uint32_t cursor) noexcept +void main_impl::set_cursor(uint32_t cursor) noexcept { setCursor(Cursor(cursor)); } -std::uint32_t main_impl::cursor() const noexcept +uint32_t main_impl::cursor() const noexcept { using App = Platform::Sdl2Application; - return (std::uint32_t)static_cast(const_cast(this))->cursor(); + return (uint32_t)static_cast(const_cast(this))->cursor(); } } // namespace floormat diff --git a/main/main-impl.hpp b/main/main-impl.hpp index 9e8527ad..e968951e 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -71,8 +71,8 @@ struct main_impl final : Platform::Sdl2Application, floormat_main void debug_callback(unsigned src, unsigned type, unsigned id, unsigned severity, StringView str) const; - void set_cursor(std::uint32_t cursor) noexcept override; - std::uint32_t cursor() const noexcept override; + void set_cursor(uint32_t cursor) noexcept override; + uint32_t cursor() const noexcept override; private: fm_settings s; diff --git a/serialize/binary-reader.hpp b/serialize/binary-reader.hpp index 3c71c7fc..8251cb70 100644 --- a/serialize/binary-reader.hpp +++ b/serialize/binary-reader.hpp @@ -28,10 +28,10 @@ struct binary_reader final { constexpr binary_reader(It begin, It end) noexcept; constexpr void assert_end() noexcept(false); - constexpr std::size_t bytes_read() const noexcept { return num_bytes_read; } + constexpr size_t bytes_read() const noexcept { return num_bytes_read; } template constexpr T read() noexcept(false); - template constexpr std::array read() noexcept(false); - template constexpr auto read_asciiz_string() noexcept(false); + template constexpr std::array read() noexcept(false); + template constexpr auto read_asciiz_string() noexcept(false); binary_reader(binary_reader&&) noexcept = default; binary_reader& operator=(binary_reader&&) noexcept = default; @@ -41,7 +41,7 @@ struct binary_reader final { constexpr char peek() const; private: - std::size_t num_bytes_read = 0; + size_t num_bytes_read = 0; It it, end; }; diff --git a/serialize/binary-reader.inl b/serialize/binary-reader.inl index 587b9cd6..b83fefc6 100644 --- a/serialize/binary-reader.inl +++ b/serialize/binary-reader.inl @@ -19,8 +19,8 @@ template template constexpr T binary_reader::read() noexcept(false) { - constexpr std::size_t N = sizeof(T); - fm_soft_assert((std::ptrdiff_t)N <= std::distance(it, end)); + constexpr size_t N = sizeof(T); + fm_soft_assert((ptrdiff_t)N <= std::distance(it, end)); num_bytes_read += N; char buf[N]; for (auto i = 0_uz; i < N; i++) @@ -29,13 +29,13 @@ constexpr T binary_reader::read() noexcept(false) } template -template +template constexpr std::array binary_reader::read() noexcept(false) { std::array array; if (std::is_constant_evaluated()) array = {}; - fm_soft_assert(N <= (std::size_t)std::distance(it, end)); + fm_soft_assert(N <= (size_t)std::distance(it, end)); num_bytes_read += N; for (auto i = 0_uz; i < N; i++) array[i] = *it++; @@ -61,14 +61,14 @@ constexpr void operator<<(T& x, binary_reader& reader) noexcept(false) } template -template +template constexpr auto binary_reader::read_asciiz_string() noexcept(false) { static_assert(MAX > 0); struct fixed_string final { char buf[MAX]; - std::size_t len; + size_t len; constexpr operator StringView() const noexcept { return { buf, len, StringViewFlag::NullTerminated }; } }; diff --git a/serialize/binary-serializer.cpp b/serialize/binary-serializer.cpp index 12163792..ddd8b401 100644 --- a/serialize/binary-serializer.cpp +++ b/serialize/binary-serializer.cpp @@ -11,7 +11,7 @@ constexpr bool test1() { constexpr std::array bytes = { 1, 2, 3, 4 }; auto x = binary_reader(bytes.cbegin(), bytes.cend()); - return x.read() == 67305985; + return x.read() == 67305985; } static_assert(test1()); @@ -20,7 +20,7 @@ constexpr bool test2() { constexpr std::array bytes = { 4, 3, 2, 1 }; auto r = binary_reader(bytes.cbegin(), bytes.cend()); - const auto x = r.read(); + const auto x = r.read(); r.assert_end(); return x == 16909060; } diff --git a/serialize/binary-serializer.hpp b/serialize/binary-serializer.hpp index 338173c2..f277aae9 100644 --- a/serialize/binary-serializer.hpp +++ b/serialize/binary-serializer.hpp @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include #include @@ -10,14 +8,14 @@ namespace floormat::Serialize { static_assert(std::endian::native == std::endian::big || std::endian::native == std::endian::little); -template struct make_integer; -template using make_integer_t = typename make_integer::type; +template struct make_integer; +template using make_integer_t = typename make_integer::type; #define FM_SERIALIZE_MAKE_INTEGER(T) template<> struct make_integer { using type = T; } -FM_SERIALIZE_MAKE_INTEGER(std::uint8_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint16_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint32_t); -FM_SERIALIZE_MAKE_INTEGER(std::uint64_t); +FM_SERIALIZE_MAKE_INTEGER(uint8_t); +FM_SERIALIZE_MAKE_INTEGER(uint16_t); +FM_SERIALIZE_MAKE_INTEGER(uint32_t); +FM_SERIALIZE_MAKE_INTEGER(uint64_t); #undef FN_SERIALIZE_MAKE_INTEGER template diff --git a/serialize/binary-writer.hpp b/serialize/binary-writer.hpp index 098f9aa2..625bb53c 100644 --- a/serialize/binary-writer.hpp +++ b/serialize/binary-writer.hpp @@ -10,11 +10,11 @@ struct binary_writer final { explicit constexpr binary_writer(It it) noexcept; template constexpr void write(T x) noexcept; constexpr void write_asciiz_string(StringView str) noexcept; - constexpr std::size_t bytes_written() const noexcept { return _bytes_written; } + constexpr size_t bytes_written() const noexcept { return _bytes_written; } private: It it; - std::size_t _bytes_written; + size_t _bytes_written; }; template It, serializable T> diff --git a/serialize/binary-writer.inl b/serialize/binary-writer.inl index a847903d..3a5b83d6 100644 --- a/serialize/binary-writer.inl +++ b/serialize/binary-writer.inl @@ -15,7 +15,7 @@ template constexpr void binary_writer::write(T x) noexcept { _bytes_written += sizeof(T); - constexpr std::size_t N = sizeof(T); + constexpr size_t N = sizeof(T); const auto buf = std::bit_cast, T>(maybe_byteswap(x)); for (auto i = 0_uz; i < N; i++) *it++ = buf[i]; diff --git a/serialize/json-helper.cpp b/serialize/json-helper.cpp index 9c3b5034..c350f92e 100644 --- a/serialize/json-helper.cpp +++ b/serialize/json-helper.cpp @@ -16,7 +16,7 @@ static T open_stream(StringView filename) if (!s) { char errbuf[128]; - constexpr auto get_error_string = [] (char (&buf)[N]) + constexpr auto get_error_string = [] (char (&buf)[N]) { buf[0] = '\0'; #ifndef _WIN32 diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp index b8383d96..d1afc0db 100644 --- a/serialize/magnum-vector.hpp +++ b/serialize/magnum-vector.hpp @@ -5,14 +5,14 @@ namespace nlohmann { -template +template struct adl_serializer> { using vec = Magnum::Math::Vector; static void to_json(json& j, const vec& val); static void from_json(const json& j, vec& val); }; -template +template void adl_serializer>::to_json(json& j, const vec& val) { std::array array{}; @@ -22,7 +22,7 @@ void adl_serializer>::to_json(json& j, const vec& val to_json(j, array); } -template +template void adl_serializer>::from_json(const json& j, vec& val) { std::array array{}; diff --git a/serialize/magnum-vector2i.hpp b/serialize/magnum-vector2i.hpp index f63bd130..aa2c3939 100644 --- a/serialize/magnum-vector2i.hpp +++ b/serialize/magnum-vector2i.hpp @@ -14,7 +14,7 @@ struct adl_serializer> final static void to_json(json& j, const Magnum::Math::Vector2& val) { char buf[64]; - using type = std::conditional_t, std::intmax_t, std::uintmax_t>; + using type = std::conditional_t, intmax_t, uintmax_t>; constexpr auto format_string = std::is_signed_v ? "%jd x %jd" : "%ju x %ju"; snprintf(buf, sizeof(buf), format_string, (type)val[0], (type)val[1]); j = buf; @@ -23,12 +23,12 @@ struct adl_serializer> final { using namespace floormat; std::string str = j; - using type = std::conditional_t, std::intmax_t, std::uintmax_t>; + using type = std::conditional_t, intmax_t, uintmax_t>; constexpr auto format_string = std::is_signed_v ? "%jd x %jd%n" : "%ju x %ju%n"; type x = 0, y = 0; int n = 0; int ret = std::sscanf(str.data(), format_string, &x, &y, &n); - if (ret != 2 || (std::size_t)n != str.size() || x != (t)x || y != (t)y) + if (ret != 2 || (size_t)n != str.size() || x != (t)x || y != (t)y) fm_throw("failed to parse Vector2 '{}'"_cf, str); val = { (t)x, (t)y }; } diff --git a/serialize/pass-mode.cpp b/serialize/pass-mode.cpp index 6d52a5de..e06bf99d 100644 --- a/serialize/pass-mode.cpp +++ b/serialize/pass-mode.cpp @@ -26,7 +26,7 @@ void adl_serializer::to_json(json& j, pass_mode val) j = str; return; } - fm_throw("invalid pass mode '{}'"_cf, std::size_t(val)); + fm_throw("invalid pass mode '{}'"_cf, size_t(val)); } void adl_serializer::from_json(const json& j, pass_mode& val) diff --git a/serialize/scenery.cpp b/serialize/scenery.cpp index 3cd084cd..6bcd5fa9 100644 --- a/serialize/scenery.cpp +++ b/serialize/scenery.cpp @@ -38,7 +38,7 @@ constexpr struct { { rotation::NW, "nw"_s }, }; -template +template auto foo_from_string(StringView str, const T(&map)[N], const char* desc) { for (const auto& [value, str2] : map) @@ -47,13 +47,13 @@ auto foo_from_string(StringView str, const T(&map)[N], const char* desc) fm_throw("wrong {} string '{}'"_cf, desc, str); } -template +template StringView foo_to_string(auto type, const T(&map)[N], const char* desc) { for (const auto& [type2, str] : map) if (type2 == type) return str; - fm_throw("wrong {} enum '{}'"_cf, desc, (std::size_t)type); + fm_throw("wrong {} enum '{}'"_cf, desc, (size_t)type); } } // namespace @@ -153,7 +153,7 @@ void adl_serializer::from_json(const json& j, scenery_proto& f) f.type = entity_type::scenery; f.sc_type = scenery_type::door; f.r = r; - f.frame = std::uint16_t(f.atlas->group(r).frames.size()-1); + f.frame = uint16_t(f.atlas->group(r).frames.size()-1); f.pass = pass_mode::blocked; f.interactive = true; f.closing = false; diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index 068c1d9b..b56239c6 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -54,7 +54,7 @@ void adl_serializer>::from_json(const json& j, std:: { int m = p2 ? int(*p2) : -1; const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, std::uint8_t(*p)); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, uint8_t(*p)); } } } diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 8b756772..1b6158e7 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -12,7 +12,7 @@ inline void to_json(nlohmann::json& j, const tile_image_ref& val) { j = tile_ima inline void from_json(const nlohmann::json& j, tile_image_ref& val) { val = tile_image_proto(j); } struct local_coords_ final { - std::uint8_t x, y; + uint8_t x, y; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y) diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index 3487d854..0756250c 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -8,8 +8,6 @@ #include "src/rotation.hpp" #include "src/entity-type.hpp" #include -#include -#include #include #include @@ -32,10 +30,10 @@ struct entity_proto; namespace floormat::Serialize { -using tilemeta = std::uint8_t; -using atlasid = std::uint16_t; -using chunksiz = std::uint16_t; -using proto_t = std::uint16_t; +using tilemeta = uint8_t; +using atlasid = uint16_t; +using chunksiz = uint16_t; +using proto_t = uint16_t; namespace { @@ -43,15 +41,15 @@ template constexpr inline T int_max = std::numeric_limits::max(); #define file_magic ".floormat.save" -constexpr inline std::size_t atlas_name_max = 128; +constexpr inline size_t atlas_name_max = 128; constexpr inline auto null_atlas = (atlasid)-1LL; -constexpr inline std::size_t character_name_max = 128; +constexpr inline size_t character_name_max = 128; constexpr inline proto_t proto_version = 8; constexpr inline proto_t min_proto_version = 1; -constexpr inline auto chunk_magic = (std::uint16_t)~0xc0d3; -constexpr inline auto scenery_magic = (std::uint16_t)~0xb00b; +constexpr inline auto chunk_magic = (uint16_t)~0xc0d3; +constexpr inline auto scenery_magic = (uint16_t)~0xb00b; using pass_mode_i = std::underlying_type_t; constexpr inline pass_mode_i pass_mask = pass_mode_COUNT - 1; @@ -59,7 +57,7 @@ constexpr inline auto pass_bits = std::bit_width(pass_mask); using entity_type_i = std::underlying_type_t; template constexpr inline auto highbit = T(1) << sizeof(T)*8-1; -template +template constexpr inline auto highbits = (T(1) << N)-1 << sizeof(T)*8-N-off; constexpr inline atlasid meta_short_scenery_bit = highbit; diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 0b84dbf0..0a99f74f 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -28,12 +28,12 @@ private: void read_atlases(reader_t& reader); void read_sceneries(reader_t& reader); void read_chunks(reader_t& reader); - void read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i); + void read_old_scenery(reader_t& s, chunk_coords ch, size_t i); std::vector sceneries; std::vector> atlases; world* _world; - std::uint16_t PROTO = 0; + uint16_t PROTO = 0; }; reader_state::reader_state(world& world) noexcept : _world{&world} {} @@ -58,7 +58,7 @@ template bool read_entity_flags(binary_reader& s, U& e) { constexpr auto tag = entity_type_::value; - std::uint8_t flags; flags << s; + uint8_t flags; flags << s; e.pass = pass_mode(flags & pass_mask); if (e.type != tag) fm_abort("invalid entity type '%d'", (int)e.type); @@ -81,7 +81,7 @@ void reader_state::read_sceneries(reader_t& s) { (void)loader.sceneries(); - std::uint16_t magic; magic << s; + uint16_t magic; magic << s; if (magic != scenery_magic) fm_throw("bad scenery magic"_cf); atlasid sz; sz << s; @@ -91,7 +91,7 @@ void reader_state::read_sceneries(reader_t& s) auto i = 0_uz; while (i < sz) { - std::uint8_t num; num << s; + uint8_t num; num << s; fm_soft_assert(num > 0); auto str = s.read_asciiz_string(); auto sc = loader.scenery(str); @@ -103,7 +103,7 @@ void reader_state::read_sceneries(reader_t& s) bool short_frame = read_entity_flags(s, sc); fm_debug_assert(sc.atlas != nullptr); if (short_frame) - sc.frame = s.read(); + sc.frame = s.read(); else sc.frame << s; fm_soft_assert(sc.frame < sc.atlas->info().nframes); @@ -140,7 +140,7 @@ void reader_state::read_chunks(reader_t& s) { const auto N = s.read(); #ifndef FM_NO_DEBUG - [[maybe_unused]] std::size_t nbytes_read = 0; + [[maybe_unused]] size_t nbytes_read = 0; #endif for (auto k = 0_uz; k < N; k++) @@ -161,7 +161,7 @@ void reader_state::read_chunks(reader_t& s) SET_CHUNK_SIZE(); const tilemeta flags = s.read(); tile_ref t = c[i]; - using uchar = std::uint8_t; + using uchar = uint8_t; const auto make_atlas = [&]() -> tile_image_proto { atlasid id; if (PROTO < 8) [[unlikely]] @@ -173,8 +173,8 @@ void reader_state::read_chunks(reader_t& s) v << s; else v = flags & meta_short_variant_ - ? s.read() - : std::uint8_t(s.read()); + ? s.read() + : uint8_t(s.read()); auto atlas = lookup_atlas(id); fm_soft_assert(v < atlas->num_tiles()); return { atlas, v }; @@ -192,7 +192,7 @@ void reader_state::read_chunks(reader_t& s) read_old_scenery(s, ch, i); SET_CHUNK_SIZE(); } - std::uint32_t entity_count = 0; + uint32_t entity_count = 0; if (PROTO >= 8) [[likely]] entity_count << s; @@ -200,12 +200,12 @@ void reader_state::read_chunks(reader_t& s) for (auto i = 0_uz; i < entity_count; i++) { - std::uint64_t _id; _id << s; + object_id _id; _id << s; const auto oid = _id & (1ULL << 60)-1; fm_soft_assert(oid != 0); static_assert(entity_type_BITS == 3); const auto type = entity_type(_id >> 61); - const auto local = local_coords{s.read()}; + const auto local = local_coords{s.read()}; constexpr auto read_offsets = [](auto& s, auto& e) { s >> e.offset[0]; s >> e.offset[1]; @@ -219,10 +219,10 @@ void reader_state::read_chunks(reader_t& s) { case entity_type::character: { character_proto proto; - std::uint8_t id; id << s; + uint8_t id; id << s; proto.r = rotation(id >> sizeof(id)*8-1-rotation_BITS & rotation_MASK); if (read_entity_flags(s, proto)) - proto.frame = s.read(); + proto.frame = s.read(); else proto.frame << s; Vector2s offset_frac; @@ -249,7 +249,7 @@ void reader_state::read_chunks(reader_t& s) if (!exact) { if (read_entity_flags(s, sc)) - sc.frame = s.read(); + sc.frame = s.read(); else sc.frame << s; read_offsets(s, sc); @@ -276,7 +276,7 @@ void reader_state::read_chunks(reader_t& s) } } -void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) +void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, size_t i) { atlasid id; id << s; const bool exact = id & meta_short_scenery_bit; @@ -288,7 +288,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) if (!exact) { if (read_entity_flags(s, sc)) - sc.frame = s.read(); + sc.frame = s.read(); else sc.frame << s; if (PROTO >= 5) [[likely]] @@ -311,7 +311,7 @@ void reader_state::read_old_scenery(reader_t& s, chunk_coords ch, std::size_t i) if (PROTO >= 4) [[likely]] sc.delta << s; else - sc.delta = (std::uint16_t)Math::clamp(int(s.read() * 65535), 0, 65535); + sc.delta = (uint16_t)Math::clamp(int(s.read() * 65535), 0, 65535); } } global_coords coord{ch, local_coords{i}}; @@ -329,10 +329,10 @@ void reader_state::deserialize_world(ArrayView buf) proto << s; if (!(proto >= min_proto_version && proto <= proto_version)) fm_throw("bad proto version '{}' (should be between '{}' and '{}')"_cf, - (std::size_t)proto, (std::size_t)min_proto_version, (std::size_t)proto_version); + (size_t)proto, (size_t)min_proto_version, (size_t)proto_version); PROTO = proto; fm_assert(PROTO > 0); - std::uint64_t entity_counter = 0; + object_id entity_counter = 0; read_atlases(s); if (PROTO >= 3) [[likely]] read_sceneries(s); @@ -355,7 +355,7 @@ namespace floormat { world world::deserialize(StringView filename) { char errbuf[128]; - constexpr auto get_error_string = [] (char (&buf)[N]) -> const char* { + constexpr auto get_error_string = [] (char (&buf)[N]) -> const char* { buf[0] = '\0'; #ifndef _WIN32 (void)::strerror_r(errno, buf, std::size(buf)); @@ -372,9 +372,9 @@ world world::deserialize(StringView filename) } if (int ret = ::fseek(f, 0, SEEK_END); ret != 0) fm_throw("fseek(SEEK_END): {}"_cf, get_error_string(errbuf)); - std::size_t len; + size_t len; if (auto len_ = ::ftell(f); len_ >= 0) - len = (std::size_t)len_; + len = (size_t)len_; else fm_throw("ftell: {}"_cf, get_error_string(errbuf)); if (int ret = ::fseek(f, 0, SEEK_SET); ret != 0) diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index e04dad36..801657e5 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -166,7 +166,7 @@ scenery_pair writer_state::intern_scenery(const scenery& sc, bool create) template void write_entity_flags(binary_writer& s, const U& e) { - std::uint8_t flags = 0; + uint8_t flags = 0; auto pass = (pass_mode_i)e.pass; fm_assert((pass & pass_mask) == pass); flags |= pass; @@ -225,12 +225,12 @@ void writer_state::serialize_atlases() } constexpr auto atlasbuf_size0 = sizeof(atlasid) + sizeof(scenery); -constexpr auto atlasbuf_size1 = sizeof(std::uint8_t) + atlasbuf_size0*int_max + atlas_name_max; +constexpr auto atlasbuf_size1 = sizeof(uint8_t) + atlasbuf_size0*int_max + atlas_name_max; void writer_state::serialize_scenery() { fm_assert(scenery_map_size < scenery_id_max); - const std::size_t sz = scenery_map_size; + const size_t sz = scenery_map_size; std::vector vec; vec.reserve(scenery_map_size); for (const auto& x : scenery_map) for (const auto& s : x.second) @@ -246,12 +246,12 @@ void writer_state::serialize_scenery() return cmp == std::strong_ordering::less; }); - const auto atlasbuf_size = sizeof(std::uint16_t) + sizeof(sz) + atlasbuf_size1*sz; + const auto atlasbuf_size = sizeof(uint16_t) + sizeof(sz) + atlasbuf_size1*sz; scenery_buf.resize(atlasbuf_size); auto s = binary_writer{scenery_buf.begin()}; - s << std::uint16_t{scenery_magic}; + s << uint16_t{scenery_magic}; fm_assert(sz < scenery_id_max); s << (atlasid)sz; @@ -267,14 +267,14 @@ void writer_state::serialize_scenery() auto num = 1_uz; for (auto j = i+1; j < sz && vec[j].s->name == sc->name; j++) num++; - fm_assert(num < int_max); - s << (std::uint8_t)num; + fm_assert(num < int_max); + s << (uint8_t)num; s.write_asciiz_string(sc->name); } s << idx; write_entity_flags(s, sc->proto); if (sc->proto.frame <= 0xff) - s << (std::uint8_t)sc->proto.frame; + s << (uint8_t)sc->proto.frame; else s << sc->proto.frame; } @@ -288,7 +288,7 @@ const auto def_char_pass = character_proto{}.pass; void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) { fm_assert(chunk_buf.empty()); - const auto es_size = sizeof(std::uint32_t) + entity_size*c.entities().size(); + const auto es_size = sizeof(uint32_t) + entity_size*c.entities().size(); chunk_buf.resize(chunkbuf_size + es_size); auto s = binary_writer{chunk_buf.begin()}; @@ -337,17 +337,17 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) } } - const auto entity_count = (std::uint32_t)c.entities().size(); + const auto entity_count = (uint32_t)c.entities().size(); s << entity_count; fm_assert(entity_count == c.entities().size()); for (const auto& e_ : c.entities()) { const auto& e = *e_; - std::uint64_t oid = e.id; - fm_assert((oid & ((std::uint64_t)1 << 60)-1) == oid); + object_id oid = e.id; + fm_assert((oid & ((object_id)1 << 60)-1) == oid); static_assert(entity_type_BITS == 3); fm_assert(((entity_type_i)e.type & (1 << entity_type_BITS)-1) == (entity_type_i)e.type); - oid |= (std::uint64_t)e.type << 64 - entity_type_BITS; + oid |= (object_id)e.type << 64 - entity_type_BITS; s << oid; const auto local = e.coord.local(); s << local.to_index(); @@ -365,7 +365,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) fm_abort("invalid entity type '%d'", (int)e.type); case entity_type::character: { const auto& C = static_cast(e); - std::uint8_t id = 0; + uint8_t id = 0; const auto sc_exact = C.offset.isZero() && C.bbox_offset.isZero() && C.bbox_size == def_char_bbox_size; @@ -374,7 +374,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) s << id; write_entity_flags(s, C); if (C.frame <= 0xff) - s << (std::uint8_t)C.frame; + s << (uint8_t)C.frame; else s << C.frame; s << C.offset_frac[0]; @@ -403,7 +403,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) write_entity_flags(s, sc); fm_assert(sc.active || sc.delta == 0); if (sc.frame <= 0xff) - s << (std::uint8_t)sc.frame; + s << (uint8_t)sc.frame; else s << sc.frame; write_offsets(s, sc); @@ -473,7 +473,7 @@ ArrayView writer_state::serialize_world() len += sizeof(proto_t); len += atlas_buf.size(); len += scenery_buf.size(); - len += sizeof(std::uint64_t); + len += sizeof(object_id); len += sizeof(chunksiz); for (const auto& buf : chunk_bufs) len += buf.size(); @@ -487,7 +487,7 @@ ArrayView writer_state::serialize_world() len2 = std::distance(it, file_buf.end()); fm_assert(len1 <= len2); it = std::copy(std::cbegin(in), std::cend(in), it); - bytes_written += (std::size_t)len1; + bytes_written += (size_t)len1; }; const auto copy_int = [&](const T& value) { union { T x; char bytes[sizeof x]; } c = {.x = maybe_byteswap(value)}; @@ -497,7 +497,7 @@ ArrayView writer_state::serialize_world() copy_int((proto_t)proto_version); copy(atlas_buf); copy(scenery_buf); - copy_int((std::uint64_t)_world->entity_counter()); + copy_int((object_id)_world->entity_counter()); copy_int((chunksiz)_world->size()); for (const auto& buf : chunk_bufs) copy(buf); @@ -521,7 +521,7 @@ void world::serialize(StringView filename) { collect(true); char errbuf[128]; - constexpr auto get_error_string = [] (char (&buf)[N]) -> const char* { + constexpr auto get_error_string = [] (char (&buf)[N]) -> const char* { buf[0] = '\0'; #ifndef _WIN32 (void)::strerror_r(errno, buf, std::size(buf)); diff --git a/src/RTree.cpp b/src/RTree.cpp index 32323e69..81677922 100644 --- a/src/RTree.cpp +++ b/src/RTree.cpp @@ -1,3 +1,3 @@ #include "RTree.hpp" -template class RTree; +template class RTree; diff --git a/src/RTree.h b/src/RTree.h index 04d84863..9ef66f34 100644 --- a/src/RTree.h +++ b/src/RTree.h @@ -278,8 +278,7 @@ public: void ListTree(std::vector& vec, std::vector& temp) const; }; -#include -extern template class RTree; +extern template class RTree; //#undef RTREE_TEMPLATE //#undef RTREE_QUAL diff --git a/src/RTree.hpp b/src/RTree.hpp index 12b55157..da60a76f 100644 --- a/src/RTree.hpp +++ b/src/RTree.hpp @@ -1329,7 +1329,7 @@ void RTREE_QUAL::ListTree(std::vector& treeList, std::vector& toVis ASSERT(m_root); ASSERT(m_root->m_level >= 0); - std::size_t count = (std::size_t)Count(); + size_t count = (size_t)Count(); treeList.clear(); treeList.reserve(count); toVisit.clear(); diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 4c94a7af..73ce5995 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -10,14 +10,14 @@ namespace floormat { static constexpr const char name_array[][3] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", }; -static constexpr inline auto rot_count = std::size_t(rotation_COUNT); +static constexpr inline auto rot_count = size_t(rotation_COUNT); static_assert(std::size(name_array) == rot_count); static_assert(rot_count == 8); -std::uint8_t anim_atlas::rotation_to_index(StringView name) noexcept +uint8_t anim_atlas::rotation_to_index(StringView name) noexcept { - for (std::uint8_t i = 0; i < rot_count; i++) + for (uint8_t i = 0; i < rot_count; i++) if (name == StringView{name_array[i]}) return i; fm_abort("can't parse rotation name '%s'", name.data()); @@ -25,12 +25,12 @@ std::uint8_t anim_atlas::rotation_to_index(StringView name) noexcept decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_def& a) noexcept { - std::array array = { + std::array array = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; const auto ngroups = a.groups.size(); for (auto i = 0_uz; i < ngroups; i++) - array[rotation_to_index(a.groups[i].name)] = std::uint8_t(i); + array[rotation_to_index(a.groups[i].name)] = uint8_t(i); return array; } @@ -73,19 +73,19 @@ const anim_def& anim_atlas::info() const noexcept { return _info; } auto anim_atlas::group(rotation r) const noexcept -> const anim_group& { - const auto group_idx = _group_indices[std::size_t(r)]; + const auto group_idx = _group_indices[size_t(r)]; fm_assert(group_idx != 0xff); return _info.groups[group_idx]; } -auto anim_atlas::frame(rotation r, std::size_t frame) const noexcept -> const anim_frame& +auto anim_atlas::frame(rotation r, size_t frame) const noexcept -> const anim_frame& { const anim_group& g = group(r); fm_assert(frame < g.frames.size()); return g.frames[frame]; } -auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i, bool mirror) const noexcept -> texcoords +auto anim_atlas::texcoords_for_frame(rotation r, size_t i, bool mirror) const noexcept -> texcoords { const auto f = frame(r, i); const Vector2 p0(f.offset), p1(f.size); @@ -107,9 +107,9 @@ auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i, bool mirror) con }}; } -auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) const noexcept -> quad +auto anim_atlas::frame_quad(const Vector3& center, rotation r, size_t i) const noexcept -> quad { - enum : std::size_t { x, y, z }; + enum : size_t { x, y, z }; const auto f = frame(r, i); const auto gx = (float)f.ground[x]*.5f, gy = (float)f.ground[y]*.5f; const auto size = Vector2d(f.size); @@ -132,7 +132,7 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) const auto pixels = tex.pixels(); const auto size = pixels.size(); const auto width = size[1], height = size[0], - stride = (std::size_t)pixels.stride()[0], width0 = width & ~7u; + stride = (size_t)pixels.stride()[0], width0 = width & ~7u; const auto* const data = (const unsigned char*)pixels.data(); auto* const dest = (unsigned char*)array.data(); @@ -184,8 +184,8 @@ BitArrayView anim_atlas::bitmask() const rotation anim_atlas::next_rotation_from(rotation r) const noexcept { - constexpr auto count = std::size_t(rotation_COUNT); - for (auto i = std::size_t(r)+1; i < count; i++) + constexpr auto count = size_t(rotation_COUNT); + for (auto i = size_t(r)+1; i < count; i++) if (_group_indices[i] != 0xff) return rotation(i); for (auto i = 0_uz; i < count; i++) @@ -196,21 +196,21 @@ rotation anim_atlas::next_rotation_from(rotation r) const noexcept rotation anim_atlas::prev_rotation_from(rotation r) const noexcept { - using ssize = std::make_signed_t; + using ssize = std::make_signed_t; constexpr auto count = ssize(rotation_COUNT); if (r < rotation_COUNT) for (auto i = ssize(r)-1; i >= 0; i--) - if (_group_indices[std::size_t(i)] != 0xff) + if (_group_indices[size_t(i)] != 0xff) return rotation(i); for (auto i = count-1; i >= 0; i--) - if (_group_indices[std::size_t(i)] != 0xff) + if (_group_indices[size_t(i)] != 0xff) return rotation(i); fm_abort("where did the rotations go?!"); } bool anim_atlas::check_rotation(rotation r) const noexcept { - return r < rotation_COUNT && _group_indices[std::size_t(r)] < 0xff; + return r < rotation_COUNT && _group_indices[size_t(r)] < 0xff; } rotation anim_atlas::first_rotation() const noexcept diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index e84faf70..ff690efd 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -35,9 +35,9 @@ struct anim_atlas final const anim_def& info() const noexcept; const anim_group& group(rotation r) const noexcept; - const anim_frame& frame(rotation r, std::size_t frame) const noexcept; - texcoords texcoords_for_frame(rotation r, std::size_t frame, bool mirror) const noexcept; - quad frame_quad(const Vector3& center, rotation r, std::size_t frame) const noexcept; + const anim_frame& frame(rotation r, size_t frame) const noexcept; + texcoords texcoords_for_frame(rotation r, size_t frame, bool mirror) const noexcept; + quad frame_quad(const Vector3& center, rotation r, size_t frame) const noexcept; BitArrayView bitmask() const; @@ -55,13 +55,13 @@ private: String _name; BitArray _bitmask; anim_def _info; - std::array _group_indices = { + std::array _group_indices = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; GL::Texture2D _tex; static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept; - static std::uint8_t rotation_to_index(StringView name) noexcept; + static uint8_t rotation_to_index(StringView name) noexcept; }; } // namespace floormat diff --git a/src/anim.hpp b/src/anim.hpp index 8d5e6d27..c6315bcf 100644 --- a/src/anim.hpp +++ b/src/anim.hpp @@ -56,7 +56,7 @@ struct anim_def final std::vector groups; Vector2ui pixel_size; anim_scale scale = anim_scale{1}; - std::size_t nframes = 0, fps = 0, actionframe = 0; + size_t nframes = 0, fps = 0, actionframe = 0; }; } // namespace floormat diff --git a/src/character.cpp b/src/character.cpp index 7cded2ba..84289f01 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -79,7 +79,7 @@ int character::allocate_frame_time(float dt) constexpr int framerate_ = 65535/framerate; static_assert(framerate_ > 0); auto ret = d / framerate_; - delta = (std::uint16_t)std::clamp(d - ret*65535, 0, 65535); + delta = (uint16_t)std::clamp(d - ret*65535, 0, 65535); return ret; } @@ -97,7 +97,7 @@ void character::set_keys(bool L, bool R, bool U, bool D) b_D = D; } -bool character::update(std::size_t i, float dt) +bool character::update(size_t i, float dt) { auto [lr, ud, new_r] = arrows_to_dir(b_L, b_R, b_U, b_D); @@ -141,7 +141,7 @@ character::operator character_proto() const return ret; } -character::character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto) : +character::character(object_id id, struct chunk& c, entity_type type, const character_proto& proto) : entity{id, c, type, proto}, name{proto.name}, playable{proto.playable} diff --git a/src/character.hpp b/src/character.hpp index 751fc42e..f4c934fa 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -27,7 +27,7 @@ struct character final : entity explicit operator character_proto() const; void set_keys(bool L, bool R, bool U, bool D); - bool update(std::size_t i, float dt) override; + bool update(size_t i, float dt) override; String name; Vector2s offset_frac; @@ -39,7 +39,7 @@ private: static Vector2 move_vec(int left_right, int top_bottom); friend struct world; - character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto); + character(object_id id, struct chunk& c, entity_type type, const character_proto& proto); }; template<> struct entity_type_ : std::integral_constant {}; diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index fc7ab92a..fedfd877 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -11,7 +11,7 @@ chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &_rtree; } namespace { -constexpr Vector2 tile_start(std::size_t k) +constexpr Vector2 tile_start(size_t k) { constexpr auto half_tile = Vector2(TILE_SIZE2)/2; const local_coords coord{k}; @@ -26,27 +26,27 @@ Pair scenery_tile(local_coords local, Vector2b offset, Vecto return { min, min + size, }; } -constexpr Pair whole_tile(std::size_t k) +constexpr Pair whole_tile(size_t k) { auto min = tile_start(k); return { min, min + TILE_SIZE2, }; } -constexpr Pair wall_north(std::size_t k) +constexpr Pair wall_north(size_t k) { auto min = tile_start(k) - Vector2(0, 1); return { min, min + Vector2(TILE_SIZE2[0], 2), }; } -constexpr Pair wall_west(std::size_t k) +constexpr Pair wall_west(size_t k) { auto min = tile_start(k) - Vector2(1, 0); return { min, min + Vector2(2, TILE_SIZE2[1]), }; } -constexpr std::uint64_t make_id(collision_type type, pass_mode p, std::uint64_t id) +constexpr object_id make_id(collision_type type, pass_mode p, uint64_t id) { - return std::bit_cast(collision_data { (std::uint64_t)type, (std::uint64_t)p, id }); + return std::bit_cast(collision_data { (object_id)type, (object_id)p, id }); } } // namespace diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index b5e14926..7f4761e0 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -9,8 +9,8 @@ namespace floormat { -template -static auto make_index_array(std::size_t max) +template +static auto make_index_array(size_t max) { std::array, N*TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) for (auto i = 0_uz; i < max; i++) @@ -21,23 +21,23 @@ static auto make_index_array(std::size_t max) auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple { if (!_ground_modified) - return { ground_mesh, ground_indexes, std::size_t(ground_mesh.count()/6) }; + return { ground_mesh, ground_indexes, size_t(ground_mesh.count()/6) }; _ground_modified = false; - std::size_t count = 0; + size_t count = 0; for (auto i = 0_uz; i < TILE_COUNT; i++) if (_ground_atlases[i]) - ground_indexes[count++] = std::uint8_t(i); + ground_indexes[count++] = uint8_t(i); std::sort(ground_indexes.begin(), ground_indexes.begin() + count, - [this](std::uint8_t a, std::uint8_t b) { + [this](uint8_t a, uint8_t b) { return _ground_atlases[a] < _ground_atlases[b]; }); std::array, TILE_COUNT> vertexes; for (auto k = 0_uz; k < count; k++) { - const std::uint8_t i = ground_indexes[k]; + const uint8_t i = ground_indexes[k]; const auto& atlas = _ground_atlases[i]; const local_coords pos{i}; const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2); @@ -55,7 +55,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple GL::Mesh mesh{GL::MeshPrimitive::Triangles}; mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) .setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort) - .setCount(std::int32_t(6 * count)); + .setCount(int32_t(6 * count)); ground_mesh = Utility::move(mesh); return { ground_mesh, ground_indexes, count }; } @@ -63,23 +63,23 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple { if (!_walls_modified) - return { wall_mesh, wall_indexes, std::size_t(wall_mesh.count()/6) }; + return { wall_mesh, wall_indexes, size_t(wall_mesh.count()/6) }; _walls_modified = false; - std::size_t count = 0; + size_t count = 0; for (auto i = 0_uz; i < TILE_COUNT*2; i++) if (_wall_atlases[i]) - wall_indexes[count++] = std::uint16_t(i); + wall_indexes[count++] = uint16_t(i); std::sort(wall_indexes.begin(), wall_indexes.begin() + count, - [this](std::uint16_t a, std::uint16_t b) { + [this](uint16_t a, uint16_t b) { return _wall_atlases[a] < _wall_atlases[b]; }); std::array, TILE_COUNT*2> vertexes; for (auto k = 0_uz; k < count; k++) { - const std::uint16_t i = wall_indexes[k]; + const uint16_t i = wall_indexes[k]; const auto& atlas = _wall_atlases[i]; const auto& variant = _wall_variants[i]; const local_coords pos{i / 2u}; @@ -99,7 +99,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple GL::Mesh mesh{GL::MeshPrimitive::Triangles}; mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) .setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort) - .setCount(std::int32_t(6 * count)); + .setCount(int32_t(6 * count)); wall_mesh = Utility::move(mesh); return { wall_mesh, wall_indexes, count }; } @@ -113,7 +113,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple _scenery_modified = false; const auto count = fm_begin( - std::size_t ret = 0; + size_t ret = 0; for (const auto& e : _entities) ret += !e->is_dynamic(); return ret; @@ -149,7 +149,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple GL::Mesh mesh{GL::MeshPrimitive::Triangles}; mesh.addVertexBuffer(GL::Buffer{scenery_vertexes}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) .setIndexBuffer(GL::Buffer{scenery_indexes}, 0, GL::MeshIndexType::UnsignedShort) - .setCount(std::int32_t(6 * count)); + .setCount(int32_t(6 * count)); scenery_mesh = Utility::move(mesh); } return { scenery_mesh, }; diff --git a/src/chunk.cpp b/src/chunk.cpp index 3adce5de..d660d2c8 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -8,7 +8,7 @@ namespace floormat { namespace { -std::size_t _reload_no_ = 0; +size_t _reload_no_ = 0; bool is_log_quiet() { @@ -31,11 +31,11 @@ bool chunk::empty(bool force) const noexcept return true; } -tile_atlas* chunk::ground_atlas_at(std::size_t i) const noexcept { return _ground_atlases[i].get(); } -tile_atlas* chunk::wall_atlas_at(std::size_t i) const noexcept { return _wall_atlases[i].get(); } +tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground_atlases[i].get(); } +tile_atlas* chunk::wall_atlas_at(size_t i) const noexcept { return _wall_atlases[i].get(); } -tile_ref chunk::operator[](std::size_t idx) noexcept { return { *this, std::uint8_t(idx) }; } -tile_proto chunk::operator[](std::size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast(this), std::uint8_t(idx) }); } +tile_ref chunk::operator[](size_t idx) noexcept { return { *this, uint8_t(idx) }; } +tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast(this), uint8_t(idx) }); } tile_ref chunk::operator[](local_coords xy) noexcept { return operator[](xy.to_index()); } tile_proto chunk::operator[](local_coords xy) const noexcept { return operator[](xy.to_index()); } @@ -142,7 +142,7 @@ void chunk::add_entity(const std::shared_ptr& e) _entities.insert(it, e); } -void chunk::remove_entity(std::size_t i) +void chunk::remove_entity(size_t i) { fm_assert(_entities_sorted); fm_debug_assert(i < _entities.size()); @@ -152,7 +152,7 @@ void chunk::remove_entity(std::size_t i) if (bbox bb; _bbox_for_scenery(*e, bb)) _remove_bbox(bb); - _entities.erase(_entities.cbegin() + std::ptrdiff_t(i)); + _entities.erase(_entities.cbegin() + ptrdiff_t(i)); } const std::vector>& chunk::entities() const diff --git a/src/chunk.hpp b/src/chunk.hpp index d22ce7fe..f279433e 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -1,4 +1,5 @@ #pragma once +#include "object-id.hpp" #include "tile.hpp" #include "tile-iterator.hpp" #include @@ -22,9 +23,9 @@ enum class collision_type : unsigned char { }; struct collision_data final { - std::uint64_t tag : 2; - std::uint64_t pass : 2; - std::uint64_t data : 60; + uint64_t tag : 2; + uint64_t pass : 2; + uint64_t data : 60; }; struct chunk final @@ -33,8 +34,8 @@ struct chunk final friend struct entity; friend struct world; - tile_ref operator[](std::size_t idx) noexcept; - tile_proto operator[](std::size_t idx) const noexcept; + tile_ref operator[](size_t idx) noexcept; + tile_proto operator[](size_t idx) const noexcept; tile_ref operator[](local_coords xy) noexcept; tile_proto operator[](local_coords xy) const noexcept; @@ -68,13 +69,13 @@ struct chunk final struct ground_mesh_tuple final { GL::Mesh& mesh; - const ArrayView ids; - const std::size_t size; + const ArrayView ids; + const size_t size; }; struct wall_mesh_tuple final { GL::Mesh& mesh; - const ArrayView ids; - const std::size_t size; + const ArrayView ids; + const size_t size; }; struct scenery_mesh_tuple final { @@ -87,12 +88,12 @@ struct chunk final float depth = -1; }; - using RTree = ::RTree; + using RTree = ::RTree; ground_mesh_tuple ensure_ground_mesh() noexcept; - tile_atlas* ground_atlas_at(std::size_t i) const noexcept; + tile_atlas* ground_atlas_at(size_t i) const noexcept; wall_mesh_tuple ensure_wall_mesh() noexcept; - tile_atlas* wall_atlas_at(std::size_t i) const noexcept; + tile_atlas* wall_atlas_at(size_t i) const noexcept; scenery_mesh_tuple ensure_scenery_mesh() noexcept; void ensure_passability() noexcept; @@ -104,15 +105,15 @@ struct chunk final void add_entity(const std::shared_ptr& e); void add_entity_unsorted(const std::shared_ptr& e); void sort_entities(); - void remove_entity(std::size_t i); + void remove_entity(size_t i); const std::vector>& entities() const; private: std::array, TILE_COUNT> _ground_atlases; - std::array ground_indexes = {}; + std::array ground_indexes = {}; std::array _ground_variants = {}; std::array, TILE_COUNT*2> _wall_atlases; - std::array wall_indexes = {}; + std::array wall_indexes = {}; std::array _wall_variants = {}; std::vector> _entities; @@ -134,7 +135,7 @@ private: struct bbox final // NOLINT(cppcoreguidelines-pro-type-member-init) { - std::uint64_t id; + object_id id; Vector2i start, end; bool operator==(const bbox& other) const noexcept; diff --git a/src/entity-type.hpp b/src/entity-type.hpp index e1ed8fcc..70490645 100644 --- a/src/entity-type.hpp +++ b/src/entity-type.hpp @@ -5,6 +5,6 @@ namespace floormat { enum class entity_type : unsigned char { none, character, scenery, }; -constexpr inline std::size_t entity_type_BITS = 3; +constexpr inline size_t entity_type_BITS = 3; } // namespace floormat diff --git a/src/entity.cpp b/src/entity.cpp index efa4655f..820d0456 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -13,7 +13,7 @@ entity_proto::~entity_proto() noexcept = default; entity_proto::entity_proto() = default; entity_proto::entity_proto(const entity_proto&) = default; -entity::entity(std::uint64_t id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept : +entity::entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept : id{id}, c{&c}, atlas{proto.atlas}, offset{proto.offset}, bbox_offset{proto.bbox_offset}, bbox_size{proto.bbox_size}, delta{proto.delta}, @@ -35,7 +35,7 @@ entity::~entity() noexcept if (chunk::bbox bb; c->_bbox_for_scenery(*this, bb)) c->_remove_bbox(bb); c->_world->do_kill_entity(id); - const_cast(id) = 0; + const_cast(id) = 0; } Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset) @@ -43,7 +43,7 @@ Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset) switch (type) { default: - fm_warn_once("unknown entity type '%zu'", std::size_t(type)); + fm_warn_once("unknown entity type '%zu'", size_t(type)); [[fallthrough]]; case entity_type::scenery: return offset; @@ -76,7 +76,7 @@ struct chunk& entity::chunk() const return *c; } -std::size_t entity::index() const +size_t entity::index() const { auto& c = chunk(); auto& es = c._entities; @@ -84,10 +84,10 @@ std::size_t entity::index() const fm_assert(it != es.cend()); it = std::find_if(it, es.cend(), [id = id](const auto& x) { return x->id == id; }); fm_assert(it != es.cend()); - return (std::size_t)std::distance(es.cbegin(), it); + return (size_t)std::distance(es.cbegin(), it); } -void entity::rotate(std::size_t, rotation new_r) +void entity::rotate(size_t, rotation new_r) { fm_assert(atlas->check_rotation(new_r)); set_bbox(offset, rotate_point(bbox_offset, r, new_r), rotate_size(bbox_size, r, new_r), pass); @@ -129,7 +129,7 @@ bool entity::can_move_to(Vector2i delta) min = center - half_bbox, max = min + Vector2(bbox_size); bool ret = true; - c_.rtree()->Search(min.data(), max.data(), [&](std::uint64_t data, const auto&) { + c_.rtree()->Search(min.data(), max.data(), [&](object_id data, const auto&) { auto id2 = std::bit_cast(data).data; if (id2 != id) return ret = false; @@ -139,7 +139,7 @@ bool entity::can_move_to(Vector2i delta) return ret; } -std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r) +size_t entity::move(size_t i, Vector2i delta, rotation new_r) { auto& es = c->_entities; fm_debug_assert(i < es.size()); @@ -171,16 +171,16 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r) set_bbox_(offset_, bb_offset, bb_size, pass); const_cast(r) = new_r; auto pos1 = std::distance(es.cbegin(), it_); - if ((std::size_t)pos1 > i) + if ((size_t)pos1 > i) pos1--; //for (auto i = 0_uz; const auto& x : es) fm_debug("%zu %s %f", i++, x->atlas->name().data(), x->ordinal()); - if ((std::size_t)pos1 != i) + if ((size_t)pos1 != i) { //fm_debug("insert (%hd;%hd|%hhd;%hhd) %td -> %zu | %f", coord_.chunk().x, coord_.chunk().y, coord_.local().x, coord_.local().y, pos1, es.size(), e.ordinal()); - es.erase(es.cbegin() + (std::ptrdiff_t)i); + es.erase(es.cbegin() + (ptrdiff_t)i); es.insert(es.cbegin() + pos1, std::move(e_)); } - return std::size_t(pos1); + return size_t(pos1); } else { @@ -192,7 +192,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r) c->remove_entity(i); auto& es = c2._entities; auto it = std::lower_bound(es.cbegin(), es.cend(), e_, [=](const auto& a, const auto&) { return a->ordinal() < ord; }); - auto ret = (std::size_t)std::distance(es.cbegin(), it); + auto ret = (size_t)std::distance(es.cbegin(), it); e_->coord = coord_; set_bbox_(offset_, bb_offset, bb_size, pass); const_cast(r) = new_r; @@ -237,8 +237,8 @@ void entity::set_bbox(Vector2b offset_, Vector2b bbox_offset_, Vector2ub bbox_si c->_replace_bbox(bb0, bb, b0, b); } -bool entity::can_activate(std::size_t) const { return false; } -bool entity::activate(std::size_t) { return false; } +bool entity::can_activate(size_t) const { return false; } +bool entity::activate(size_t) { return false; } bool entity::is_dynamic() const { diff --git a/src/entity.hpp b/src/entity.hpp index 96e5477f..2ede577b 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -4,6 +4,7 @@ #include "src/rotation.hpp" #include "src/pass-mode.hpp" #include "src/entity-type.hpp" +#include "src/object-id.hpp" #include #include @@ -19,7 +20,7 @@ struct entity_proto std::shared_ptr atlas; Vector2b offset, bbox_offset; Vector2ub bbox_size = Vector2ub(iTILE_SIZE2); - std::uint16_t delta = 0, frame = 0; + uint16_t delta = 0, frame = 0; entity_type type : 3 = entity_type::none; rotation r : rotation_BITS = rotation::N; pass_mode pass : pass_mode_BITS = pass_mode::see_through; @@ -37,13 +38,13 @@ struct entity { fm_DECLARE_DELETED_COPY_ASSIGNMENT(entity); - const std::uint64_t id = 0; + const object_id id = 0; struct chunk* const c; std::shared_ptr atlas; global_coords coord; const Vector2b offset, bbox_offset; const Vector2ub bbox_size; - std::uint16_t delta = 0, frame = 0; + uint16_t delta = 0, frame = 0; const entity_type type; const rotation r = rotation::N; const pass_mode pass = pass_mode::see_through; @@ -54,25 +55,25 @@ struct entity float ordinal() const; static float ordinal(local_coords xy, Vector2b offset, entity_type type); struct chunk& chunk() const; - std::size_t index() const; + size_t index() const; explicit operator entity_proto() const; - virtual bool can_activate(std::size_t i) const; - virtual bool activate(std::size_t i); - virtual bool update(std::size_t i, float dt) = 0; - virtual void rotate(std::size_t i, rotation r); + virtual bool can_activate(size_t i) const; + virtual bool activate(size_t i); + virtual bool update(size_t i, float dt) = 0; + virtual void rotate(size_t i, rotation r); static Pair normalize_coords(global_coords coord, Vector2b cur_offset, Vector2i delta); [[nodiscard]] virtual bool can_move_to(Vector2i delta); - std::size_t move(std::size_t i, Vector2i delta, rotation new_r); + size_t move(size_t i, Vector2i delta, rotation new_r); virtual void set_bbox(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass); bool is_dynamic() const; friend struct world; protected: - entity(std::uint64_t id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept; + entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept; void set_bbox_(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass); }; diff --git a/src/global-coords.hpp b/src/global-coords.hpp index 46ef1514..b48a18d1 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -8,7 +8,7 @@ namespace floormat { struct chunk_coords final { - std::int16_t x = 0, y = 0; + int16_t x = 0, y = 0; constexpr bool operator==(const chunk_coords& other) const noexcept = default; constexpr Vector2i operator-(chunk_coords other) const noexcept; @@ -28,18 +28,18 @@ constexpr Vector2i chunk_coords::operator-(chunk_coords other) const noexcept } struct global_coords final { - using u0 = std::integral_constant; - using s0 = std::integral_constant; - std::uint32_t x = u0::value<<4, y = u0::value<<4; + using u0 = std::integral_constant; + using s0 = std::integral_constant; + uint32_t x = u0::value<<4, y = u0::value<<4; constexpr global_coords() noexcept = default; constexpr global_coords(chunk_coords c, local_coords xy) : - x{ std::uint32_t((c.x + s0::value) << 4) | (xy.x & 0x0f) }, - y{ std::uint32_t((c.y + s0::value) << 4) | (xy.y & 0x0f) } + x{ uint32_t((c.x + s0::value) << 4) | (xy.x & 0x0f) }, + y{ uint32_t((c.y + s0::value) << 4) | (xy.y & 0x0f) } {} - constexpr global_coords(std::uint32_t x, std::uint32_t y) noexcept : x{x}, y{y} {} - constexpr global_coords(std::int32_t x, std::int32_t y) noexcept : - x{std::uint32_t(x + (s0::value<<4))}, y{std::uint32_t(y + (s0::value<<4))} + constexpr global_coords(uint32_t x, uint32_t y) noexcept : x{x}, y{y} {} + constexpr global_coords(int32_t x, int32_t y) noexcept : + x{uint32_t(x + (s0::value<<4))}, y{uint32_t(y + (s0::value<<4))} {} constexpr local_coords local() const noexcept; @@ -58,17 +58,17 @@ struct global_coords final { constexpr local_coords global_coords::local() const noexcept { - return { std::uint8_t(x & 0x0f), std::uint8_t(y & 0x0f), }; + return { uint8_t(x & 0x0f), uint8_t(y & 0x0f), }; } constexpr chunk_coords global_coords::chunk() const noexcept { - return { std::int16_t(std::int32_t((x>>4) - u0::value)), std::int16_t(std::int32_t((y>>4) - u0::value)), }; + return { int16_t(int32_t((x>>4) - u0::value)), int16_t(int32_t((y>>4) - u0::value)), }; } constexpr Vector2i global_coords::to_signed() const noexcept { - return { std::int32_t(x - (s0::value<<4)), std::int32_t(y - (s0::value<<4)), }; + return { int32_t(x - (s0::value<<4)), int32_t(y - (s0::value<<4)), }; } constexpr Vector3i global_coords::to_signed3() const noexcept @@ -78,25 +78,25 @@ constexpr Vector3i global_coords::to_signed3() const noexcept constexpr global_coords global_coords::operator+(Vector2i vec) const noexcept { - return { std::uint32_t((std::int64_t)x+vec[0]), std::uint32_t((std::int64_t)y+vec[1]) }; + return { uint32_t((int64_t)x+vec[0]), uint32_t((int64_t)y+vec[1]) }; } constexpr global_coords& global_coords::operator+=(Vector2i vec) noexcept { - x = std::uint32_t((std::int64_t)x+vec[0]); - y = std::uint32_t((std::int64_t)y+vec[1]); + x = uint32_t((int64_t)x+vec[0]); + y = uint32_t((int64_t)y+vec[1]); return *this; } constexpr global_coords global_coords::operator-(Vector2i vec) const noexcept { - return { std::uint32_t((std::int64_t)x-vec[0]), std::uint32_t((std::int64_t)y-vec[1]) }; + return { uint32_t((int64_t)x-vec[0]), uint32_t((int64_t)y-vec[1]) }; } constexpr global_coords& global_coords::operator-=(Vector2i vec) noexcept { - x = std::uint32_t((std::int64_t)x-vec[0]); - y = std::uint32_t((std::int64_t)y-vec[1]); + x = uint32_t((int64_t)x-vec[0]); + y = uint32_t((int64_t)y-vec[1]); return *this; } diff --git a/src/local-coords.hpp b/src/local-coords.hpp index eef511d6..cb7a5c24 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -8,32 +8,32 @@ namespace floormat { struct local_coords final { - std::uint8_t x : 4 = 0, y : 4 = 0; - explicit constexpr local_coords(std::size_t idx) noexcept; + uint8_t x : 4 = 0, y : 4 = 0; + explicit constexpr local_coords(size_t idx) noexcept; constexpr local_coords() noexcept = default; - template requires (std::is_integral_v && sizeof(T) <= sizeof(std::size_t)) + template requires (std::is_integral_v && sizeof(T) <= sizeof(size_t)) constexpr local_coords(T x, T y) noexcept; - constexpr local_coords(std::uint8_t x, std::uint8_t y) noexcept : x{x}, y{y} {} - constexpr std::uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; } + constexpr local_coords(uint8_t x, uint8_t y) noexcept : x{x}, y{y} {} + constexpr uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; } constexpr bool operator==(const local_coords&) const noexcept = default; template explicit constexpr operator Math::Vector2() const noexcept { return Math::Vector2(T(x), T(y)); } template explicit constexpr operator Math::Vector3() const noexcept { return Math::Vector3(T(x), T(y), T(0)); } }; -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)} +constexpr local_coords::local_coords(size_t index) noexcept : + x{(uint8_t)(index % TILE_MAX_DIM)}, + y{(uint8_t)(index / TILE_MAX_DIM)} { fm_assert(index < TILE_COUNT); } template -requires (std::is_integral_v && sizeof(T) <= sizeof(std::size_t)) +requires (std::is_integral_v && sizeof(T) <= sizeof(size_t)) constexpr local_coords::local_coords(T x, T y) noexcept - : x{(std::uint8_t)x}, y{(std::uint8_t)y} + : x{(uint8_t)x}, y{(uint8_t)y} { - fm_assert((std::size_t)x < TILE_MAX_DIM && (std::size_t)y < TILE_MAX_DIM); + fm_assert((size_t)x < TILE_MAX_DIM && (size_t)y < TILE_MAX_DIM); } } // namespace floormat diff --git a/src/object-id.hpp b/src/object-id.hpp new file mode 100644 index 00000000..f88aed53 --- /dev/null +++ b/src/object-id.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "compat/integer-types.hpp" + +namespace floormat { + +using object_id = uint64_t; + +} // namespace floormat diff --git a/src/precomp.hpp b/src/precomp.hpp index 0abb304a..fe97f0a1 100644 --- a/src/precomp.hpp +++ b/src/precomp.hpp @@ -1,5 +1,7 @@ #pragma once +#include "compat/prelude.hpp" +#include "compat/integer-types.hpp" #include "compat/defs.hpp" #include "compat/assert.hpp" diff --git a/src/random.cpp b/src/random.cpp index 7888dbaa..6bb70808 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -4,31 +4,31 @@ namespace floormat { -static thread_local auto g = std::independent_bits_engine{std::ranlux48{}}; +static thread_local auto g = std::independent_bits_engine{std::ranlux48{}}; random_engine::~random_engine() = default; struct random_engine_impl final : random_engine { - std::size_t operator()() override; + size_t operator()() override; float operator()(float min, float max) override; }; -std::size_t random_engine_impl::operator()() +size_t random_engine_impl::operator()() { - if constexpr(sizeof(std::size_t) > sizeof(std::uint32_t)) + if constexpr(sizeof(size_t) > sizeof(uint32_t)) { - constexpr auto N = (sizeof(std::size_t) + sizeof(std::uint32_t)-1) / sizeof(std::uint32_t); + constexpr auto N = (sizeof(size_t) + sizeof(uint32_t)-1) / sizeof(uint32_t); static_assert(N >= 1); union { - std::size_t x; - std::uint32_t a[N]; + size_t x; + uint32_t a[N]; } ret; for (auto i = 0_uz; i < N; i++) ret.a[i] = g(); return ret.x; } else - return (std::size_t)g(); + return (size_t)g(); } float random_engine_impl::operator()(float min, float max) diff --git a/src/random.hpp b/src/random.hpp index e8e462e8..6f1ef7ee 100644 --- a/src/random.hpp +++ b/src/random.hpp @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include @@ -10,16 +8,16 @@ namespace floormat { struct random_engine { virtual ~random_engine(); - virtual std::common_type_t operator()() = 0; + virtual std::common_type_t operator()() = 0; template - requires (sizeof(T) <= sizeof(std::size_t)) + requires (sizeof(T) <= sizeof(size_t)) T operator()(T max) { - return static_cast(operator()() % static_cast(max)); + return static_cast(operator()() % static_cast(max)); } template - requires (sizeof(T) <= sizeof(std::size_t)) + requires (sizeof(T) <= sizeof(size_t)) T operator()(T min, T max) { return min + operator()(max-min); } diff --git a/src/rotation.hpp b/src/rotation.hpp index 39694336..471007c3 100644 --- a/src/rotation.hpp +++ b/src/rotation.hpp @@ -1,5 +1,4 @@ #pragma once -#include namespace floormat { @@ -7,8 +6,8 @@ enum class rotation : unsigned char { N, NE, E, SE, S, SW, W, NW, }; -constexpr inline std::size_t rotation_BITS = 3; -constexpr inline std::size_t rotation_MASK = (1 << rotation_BITS)-1; +constexpr inline size_t rotation_BITS = 3; +constexpr inline size_t rotation_MASK = (1 << rotation_BITS)-1; constexpr inline rotation rotation_COUNT = rotation{1 << rotation_BITS}; } // namespace floormat diff --git a/src/rotation.inl b/src/rotation.inl index 8f9e6012..fb5cefca 100644 --- a/src/rotation.inl +++ b/src/rotation.inl @@ -18,7 +18,7 @@ constexpr Triple rotation_symmetry(rotation r) }; fm_assert(r < rotation_COUNT); - auto idx = (std::size_t)r / 2; + auto idx = (size_t)r / 2; const auto& [r1, sym] = rotation_symmetries[idx]; return sym; } diff --git a/src/scenery.cpp b/src/scenery.cpp index 14bf691b..a424351f 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -17,12 +17,12 @@ scenery_proto::scenery_proto(const scenery_proto&) = default; scenery_proto::~scenery_proto() noexcept = default; scenery_proto::operator bool() const { return atlas != nullptr; } -bool scenery::can_activate(std::size_t) const +bool scenery::can_activate(size_t) const { return atlas && interactive; } -bool scenery::update(std::size_t, float dt) +bool scenery::update(size_t, float dt) { auto& s = *this; if (!s.active) @@ -37,17 +37,17 @@ bool scenery::update(std::size_t, float dt) case scenery_type::door: fm_assert(atlas); auto& anim = *atlas; - const auto hz = std::uint8_t(atlas->info().fps); + const auto hz = uint8_t(atlas->info().fps); const auto nframes = (int)anim.info().nframes; fm_debug_assert(anim.info().fps > 0 && anim.info().fps <= 0xff); auto delta_ = int(s.delta) + int(65535u * dt); delta_ = std::min(65535, delta_); const auto frame_time = int(1.f/hz * 65535); - const auto n = (std::uint8_t)std::clamp(delta_ / frame_time, 0, 255); - s.delta = (std::uint16_t)std::clamp(delta_ - frame_time*n, 0, 65535); + const auto n = (uint8_t)std::clamp(delta_ / frame_time, 0, 255); + s.delta = (uint16_t)std::clamp(delta_ - frame_time*n, 0, 65535); fm_debug_assert(s.delta >= 0); - const std::int8_t dir = s.closing ? 1 : -1; + const int8_t dir = s.closing ? 1 : -1; const int fr = s.frame + dir*n; s.active = fr > 0 && fr < nframes-1; pass_mode p; @@ -58,14 +58,14 @@ bool scenery::update(std::size_t, float dt) else p = pass_mode::see_through; set_bbox(offset, bbox_offset, bbox_size, p); - s.frame = (std::uint16_t)std::clamp(fr, 0, nframes-1); + s.frame = (uint16_t)std::clamp(fr, 0, nframes-1); if (!s.active) s.delta = s.closing = 0; return true; } } -bool scenery::activate(std::size_t) +bool scenery::activate(size_t) { auto& s = *this; if (s.active) @@ -111,7 +111,7 @@ scenery::operator scenery_proto() const return ret; } -scenery::scenery(std::uint64_t id, struct chunk& c, entity_type type_, const scenery_proto& proto) : +scenery::scenery(object_id id, struct chunk& c, entity_type type_, const scenery_proto& proto) : entity{id, c, type_, proto}, sc_type{proto.sc_type}, active{proto.active}, closing{proto.closing}, interactive{proto.interactive} { diff --git a/src/scenery.hpp b/src/scenery.hpp index 0c074e5e..a985d7d7 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -3,7 +3,6 @@ #include "tile-defs.hpp" #include "rotation.hpp" #include "entity.hpp" -#include #include #include #include @@ -18,7 +17,7 @@ struct world; enum class scenery_type : unsigned char { none, generic, door, }; -constexpr inline std::size_t scenery_type_BITS = 3; +constexpr inline size_t scenery_type_BITS = 3; struct scenery_proto : entity_proto { @@ -42,14 +41,14 @@ struct scenery final : entity unsigned char closing : 1 = false; unsigned char interactive : 1 = false; - bool can_activate(std::size_t i) const override; - bool activate(std::size_t i) override; - bool update(std::size_t i, float dt) override; + bool can_activate(size_t i) const override; + bool activate(size_t i) override; + bool update(size_t i, float dt) override; explicit operator scenery_proto() const; private: friend struct world; - scenery(std::uint64_t id, struct chunk& c, entity_type type, const scenery_proto& proto); + scenery(object_id id, struct chunk& c, entity_type type, const scenery_proto& proto); }; template<> struct entity_type_ : std::integral_constant {}; diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 68feb77b..3438e6a1 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -26,16 +26,16 @@ tile_atlas::tile_atlas(StringView name, const ImageView2D& image, Vector2ub tile .setSubImage(0, {}, image); } -std::array tile_atlas::texcoords_for_id(std::size_t i) const +std::array tile_atlas::texcoords_for_id(size_t i) const { fm_assert(i < num_tiles()); return texcoords_[i]; } -auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std::size_t i) -> texcoords +auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i) -> texcoords { const auto sz = pixel_size/Vector2ui{tile_count}; - const Vector2ui id = { std::uint32_t(i % tile_count[0]), std::uint32_t(i / tile_count[0]) }; + const Vector2ui id = { uint32_t(i % tile_count[0]), uint32_t(i / tile_count[0]) }; const Vector2 p0(id * sz), p1(sz); const auto x0 = p0.x()+.5f, x1 = p1.x()-1, y0 = p0.y()+.5f, y1 = p1.y()-1; return {{ @@ -48,14 +48,14 @@ auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std: auto tile_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count) -> std::unique_ptr { - const std::size_t N = Vector2ui{tile_count}.product(); + const size_t N = Vector2ui{tile_count}.product(); auto ptr = std::make_unique[]>(N); for (auto i = 0_uz; i < N; i++) ptr[i] = make_texcoords(pixel_size, tile_count, i); return ptr; } -std::size_t tile_atlas::num_tiles() const { return Vector2ui{dims_}.product(); } +size_t tile_atlas::num_tiles() const { return Vector2ui{dims_}.product(); } Optional tile_atlas::pass_mode() const { return passability; } enum pass_mode tile_atlas::pass_mode(enum pass_mode p) const { return passability ? *passability : p; } diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp index e4ac8412..4ea2c67d 100644 --- a/src/tile-atlas.hpp +++ b/src/tile-atlas.hpp @@ -17,13 +17,13 @@ struct tile_atlas final tile_atlas(StringView name, const ImageView2D& img, Vector2ub tile_count, Optional pass_mode); - texcoords texcoords_for_id(std::size_t id) const; + texcoords texcoords_for_id(size_t id) const; static constexpr quad floor_quad(Vector3 center, Vector2 size); static constexpr quad wall_quad_N(Vector3 center, Vector3 size); static constexpr quad wall_quad_W(Vector3 center, Vector3 size); - static constexpr std::array indices(std::size_t N); + static constexpr std::array indices(size_t N); [[maybe_unused]] Vector2ui pixel_size() const { return size_; } - std::size_t num_tiles() const; + size_t num_tiles() const; Vector2ub num_tiles2() const { return dims_; } GL::Texture2D& texture() { return tex_; } StringView name() const { return name_; } @@ -33,7 +33,7 @@ struct tile_atlas final private: static std::unique_ptr make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count); - static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std::size_t i); + static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i); std::unique_ptr texcoords_; GL::Texture2D tex_; @@ -43,7 +43,7 @@ private: Optional passability; }; -constexpr std::array tile_atlas::indices(std::size_t N) +constexpr std::array tile_atlas::indices(size_t N) { using u16 = UnsignedShort; return { /* 3--1 1 */ diff --git a/src/tile-defs.hpp b/src/tile-defs.hpp index b8ea0387..b260fe8a 100644 --- a/src/tile-defs.hpp +++ b/src/tile-defs.hpp @@ -1,12 +1,11 @@ #pragma once -#include #include #include namespace floormat { constexpr inline unsigned char TILE_MAX_DIM = 16; -constexpr inline std::size_t TILE_COUNT = TILE_MAX_DIM*TILE_MAX_DIM; +constexpr inline size_t TILE_COUNT = TILE_MAX_DIM*TILE_MAX_DIM; constexpr inline auto TILE_MAX_DIM20d = Magnum::Math::Vector3 { TILE_MAX_DIM, TILE_MAX_DIM, 0 }; constexpr inline auto iTILE_SIZE = Magnum::Math::Vector3 { 64, 64, 64 }; diff --git a/src/tile-image.hpp b/src/tile-image.hpp index 77424c62..3227dc6b 100644 --- a/src/tile-image.hpp +++ b/src/tile-image.hpp @@ -1,12 +1,11 @@ #pragma once -#include #include namespace floormat { struct tile_atlas; -using variant_t = std::uint8_t; +using variant_t = uint8_t; struct tile_image_proto final { diff --git a/src/tile-iterator.cpp b/src/tile-iterator.cpp index 9214faa9..ac0fff67 100644 --- a/src/tile-iterator.cpp +++ b/src/tile-iterator.cpp @@ -3,24 +3,24 @@ namespace floormat { -tile_iterator::tile_iterator(chunk& c, std::size_t pos) noexcept : c{&c}, pos{pos} {} +tile_iterator::tile_iterator(chunk& c, size_t pos) noexcept : c{&c}, pos{pos} {} tile_iterator::tile_iterator(const tile_iterator&) noexcept = default; tile_iterator& tile_iterator::operator=(const tile_iterator&) noexcept = default; tile_iterator& tile_iterator::operator++() noexcept { pos++; return *this; } tile_iterator tile_iterator::operator++(int) noexcept { auto it = *this; pos++; return it; } void tile_iterator::swap(tile_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); } bool operator==(const tile_iterator& a, const tile_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; } -tile_iterator_tuple tile_iterator::operator->() noexcept { return { tile_ref{*c, std::uint8_t(pos)}, pos, local_coords{pos} }; } +tile_iterator_tuple tile_iterator::operator->() noexcept { return { tile_ref{*c, uint8_t(pos)}, pos, local_coords{pos} }; } tile_iterator_tuple tile_iterator::operator*() noexcept { return operator->(); } -tile_const_iterator::tile_const_iterator(const chunk& c, std::size_t pos) noexcept : c{&c}, pos{pos} {} +tile_const_iterator::tile_const_iterator(const chunk& c, size_t pos) noexcept : c{&c}, pos{pos} {} tile_const_iterator::tile_const_iterator(const tile_const_iterator& x) noexcept = default; tile_const_iterator& tile_const_iterator::operator=(const tile_const_iterator& x) noexcept { if (this != &x) { c = x.c; pos = x.pos; } return *this; } tile_const_iterator& tile_const_iterator::operator++() noexcept { pos++; return *this; } tile_const_iterator tile_const_iterator::operator++(int) noexcept { auto it = *this; pos++; return it; } void tile_const_iterator::swap(tile_const_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); } bool operator==(const tile_const_iterator& a, const tile_const_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; } -tile_const_iterator_tuple tile_const_iterator::operator->() noexcept { return { tile_proto(tile_ref{*const_cast(c), std::uint8_t(pos)}), pos, local_coords{pos}, }; } +tile_const_iterator_tuple tile_const_iterator::operator->() noexcept { return { tile_proto(tile_ref{*const_cast(c), uint8_t(pos)}), pos, local_coords{pos}, }; } tile_const_iterator_tuple tile_const_iterator::operator*() noexcept { return operator->(); } } // namespace floormat diff --git a/src/tile-iterator.hpp b/src/tile-iterator.hpp index f5f717f6..f3b19dfc 100644 --- a/src/tile-iterator.hpp +++ b/src/tile-iterator.hpp @@ -3,7 +3,6 @@ #include "local-coords.hpp" #include "tile.hpp" -#include #include namespace floormat { @@ -13,7 +12,7 @@ struct tile_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-i tile_iterator_tuple* operator->() noexcept { return this; } tile_ref x; - std::size_t k; + size_t k; local_coords pt; }; @@ -22,18 +21,18 @@ struct tile_const_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-me tile_const_iterator_tuple* operator->() noexcept { return this; } tile_proto x; - std::size_t k; + size_t k; local_coords pt; }; class tile_iterator final { chunk* c; - std::size_t pos; + size_t pos; friend bool operator==(const tile_iterator&, const tile_iterator&) noexcept; public: - explicit tile_iterator(chunk& c, std::size_t pos) noexcept; + explicit tile_iterator(chunk& c, size_t pos) noexcept; tile_iterator(const tile_iterator&) noexcept; tile_iterator& operator=(const tile_iterator&) noexcept; @@ -44,7 +43,7 @@ public: tile_iterator_tuple operator->() noexcept; tile_iterator_tuple operator*() noexcept; - using difference_type = std::ptrdiff_t; + using difference_type = ptrdiff_t; using value_type = tile_iterator_tuple; using pointer = value_type; using reference = value_type; @@ -53,12 +52,12 @@ public: class tile_const_iterator final { const chunk* c; - std::size_t pos; + size_t pos; friend bool operator==(const tile_const_iterator&, const tile_const_iterator&) noexcept; public: - explicit tile_const_iterator(const chunk& c, std::size_t pos) noexcept; + explicit tile_const_iterator(const chunk& c, size_t pos) noexcept; tile_const_iterator(const tile_const_iterator&) noexcept; tile_const_iterator& operator=(const tile_const_iterator&) noexcept; @@ -69,7 +68,7 @@ public: tile_const_iterator_tuple operator->() noexcept; tile_const_iterator_tuple operator*() noexcept; - using difference_type = std::ptrdiff_t; + using difference_type = ptrdiff_t; using value_type = tile_const_iterator_tuple; using pointer = value_type; using reference = value_type; diff --git a/src/tile.cpp b/src/tile.cpp index 75ef71e7..5a85a09c 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -13,7 +13,7 @@ tile_image_proto tile_proto::ground() const noexcept { return { ground_atlas tile_image_proto tile_proto::wall_north() const noexcept { return { wall_north_atlas, wall_north_variant }; } tile_image_proto tile_proto::wall_west() const noexcept { return { wall_west_atlas, wall_west_variant }; } -tile_ref::tile_ref(struct chunk& c, std::uint8_t i) noexcept : _chunk{&c}, i{i} {} +tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {} std::shared_ptr tile_ref::ground_atlas() noexcept { return _chunk->_ground_atlases[i]; } std::shared_ptr tile_ref::wall_north_atlas() noexcept { return _chunk->_wall_atlases[i*2+0]; } diff --git a/src/tile.hpp b/src/tile.hpp index 5eed7633..f9d6adc8 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -20,7 +20,7 @@ struct tile_proto final struct tile_ref final { - tile_ref(struct chunk& c, std::uint8_t i) noexcept; + tile_ref(struct chunk& c, uint8_t i) noexcept; tile_image_ref ground() noexcept; tile_image_ref wall_north() noexcept; @@ -42,13 +42,13 @@ struct tile_ref final struct chunk& chunk() noexcept { return *_chunk; } const struct chunk& chunk() const noexcept { return *_chunk; } - std::size_t index() const noexcept { return i; } + size_t index() const noexcept { return i; } friend bool operator==(const tile_ref& a, const tile_ref& b) noexcept; private: struct chunk* _chunk; - std::uint8_t i; + uint8_t i; }; } //namespace floormat diff --git a/src/world.cpp b/src/world.cpp index d6099302..7dab8dee 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -49,7 +49,7 @@ world::~world() noexcept _entities.clear(); } -world::world(std::size_t capacity) : _chunks{capacity, hasher} +world::world(size_t capacity) : _chunks{capacity, hasher} { _chunks.max_load_factor(max_load_factor); } @@ -126,14 +126,14 @@ void world::do_make_entity(const std::shared_ptr& e, global_coords pos, e->c->add_entity_unsorted(e); } -void world::do_kill_entity(std::uint64_t id) +void world::do_kill_entity(object_id id) { fm_debug_assert(id > 0); auto cnt = _entities.erase(id); fm_debug_assert(cnt > 0); } -std::shared_ptr world::find_entity_(std::uint64_t id) +std::shared_ptr world::find_entity_(object_id id) { auto it = _entities.find(id); auto ret = it == _entities.end() ? nullptr : it->second.lock(); @@ -141,7 +141,7 @@ std::shared_ptr world::find_entity_(std::uint64_t id) return ret; } -void world::set_entity_counter(std::uint64_t value) +void world::set_entity_counter(object_id value) { fm_assert(value >= _entity_counter); _entity_counter = value; diff --git a/src/world.hpp b/src/world.hpp index 29d5a8dd..589bbd67 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -4,7 +4,6 @@ #include "chunk.hpp" #include "global-coords.hpp" #include "entity-type.hpp" -#include #include #include @@ -22,24 +21,24 @@ private: chunk_coords pos = invalid_coords; } _last_chunk; - static constexpr std::size_t initial_capacity = 64; + static constexpr size_t initial_capacity = 64; static constexpr float max_load_factor = .5; - static constexpr auto hasher = [](chunk_coords c) constexpr -> std::size_t { - return int_hash((std::size_t)c.y << 16 | (std::size_t)c.x); + static constexpr auto hasher = [](chunk_coords c) constexpr -> size_t { + return int_hash((size_t)c.y << 16 | (size_t)c.x); }; std::unordered_map _chunks; - std::unordered_map> _entities; - std::size_t _last_collection = 0; - std::size_t _collect_every = 64; + std::unordered_map> _entities; + size_t _last_collection = 0; + size_t _collect_every = 64; std::shared_ptr _unique_id = std::make_shared('A'); - std::uint64_t _entity_counter = 0; + object_id _entity_counter = 0; bool _teardown : 1 = false; - explicit world(std::size_t capacity); + explicit world(size_t capacity); void do_make_entity(const std::shared_ptr& e, global_coords pos, bool sorted); - void do_kill_entity(std::uint64_t id); - std::shared_ptr find_entity_(std::uint64_t id); + void do_kill_entity(object_id id); + std::shared_ptr find_entity_(object_id id); friend struct entity; @@ -58,18 +57,18 @@ public: void clear(); void collect(bool force = false); void maybe_collect(); - std::size_t size() const noexcept { return _chunks.size(); } + size_t size() const noexcept { return _chunks.size(); } const auto& chunks() const noexcept { return _chunks; } void serialize(StringView filename); static world deserialize(StringView filename); - void set_collect_threshold(std::size_t value) { _collect_every = value; } - std::size_t collect_threshold() const noexcept { return _collect_every; } + void set_collect_threshold(size_t value) { _collect_every = value; } + size_t collect_threshold() const noexcept { return _collect_every; } template - requires requires(chunk& c) { T{std::uint64_t(), c, entity_type(), std::declval()...}; } - std::shared_ptr make_entity(std::uint64_t id, global_coords pos, Xs&&... xs) + requires requires(chunk& c) { T{object_id(), c, entity_type(), std::declval()...}; } + std::shared_ptr make_entity(object_id id, global_coords pos, Xs&&... xs) { static_assert(std::is_base_of_v); auto ret = std::shared_ptr(new T{id, operator[](pos.chunk()), entity_type_::value, std::forward(xs)...}); @@ -77,12 +76,12 @@ public: return ret; } - template std::shared_ptr find_entity(std::uint64_t id); + template std::shared_ptr find_entity(object_id id); bool is_teardown() const { return _teardown; } - std::uint64_t entity_counter() const { return _entity_counter; } - [[nodiscard]] std::uint64_t make_id() { return ++_entity_counter; } - void set_entity_counter(std::uint64_t value); + object_id entity_counter() const { return _entity_counter; } + [[nodiscard]] object_id make_id() { return ++_entity_counter; } + void set_entity_counter(object_id value); world& operator=(world&& w) noexcept; world(world&& w) noexcept; @@ -92,14 +91,14 @@ public: template world::world(std::unordered_map&& chunks) : - world{std::max(initial_capacity, std::size_t(1/max_load_factor * 2 * chunks.size()))} + world{std::max(initial_capacity, size_t(1/max_load_factor * 2 * chunks.size()))} { for (auto&& [coord, c] : chunks) operator[](coord) = std::move(c); } template -std::shared_ptr world::find_entity(std::uint64_t id) +std::shared_ptr world::find_entity(object_id id) { static_assert(std::is_base_of_v); // make it a dependent name so that including "src/entity.hpp" isn't needed diff --git a/test/bitmask.cpp b/test/bitmask.cpp index 5398bce7..1b3deea9 100644 --- a/test/bitmask.cpp +++ b/test/bitmask.cpp @@ -16,7 +16,7 @@ namespace floormat { namespace { -constexpr std::size_t data_nbytes = 128; +constexpr size_t data_nbytes = 128; const unsigned char data_door_close[] = { #include "bitmask.embed.inc" }; @@ -45,7 +45,7 @@ void bitmask_test() { auto img = loader.texture(loader.SCENERY_PATH, "door-close"_s); auto bitmask = anim_atlas::make_bitmask(img); - fm_assert(img.pixelSize() == 4 && (std::size_t)img.size().product() >= data_nbytes); + fm_assert(img.pixelSize() == 4 && (size_t)img.size().product() >= data_nbytes); #ifdef DO_GENERATE for (auto i = 0_uz; i < data_nbytes; i++) { @@ -58,7 +58,7 @@ void bitmask_test() printf("\n"); fflush(stdout); #endif - const auto len = std::min(data_nbytes, (std::size_t)bitmask.size()+7 >> 3); + const auto len = std::min(data_nbytes, (size_t)bitmask.size()+7 >> 3); for (auto i = 0_uz; i < len; i++) if ((unsigned char)bitmask.data()[i] != data_door_close[i]) fm_abort("wrong value at bit %zu, should be' 0x%02hhx'", i, data_door_close[i]); diff --git a/test/entity.cpp b/test/entity.cpp index 88598cb2..40b7eb6b 100644 --- a/test/entity.cpp +++ b/test/entity.cpp @@ -215,7 +215,7 @@ constexpr void test_constraints() static_assert(foo.get_group(x) == "foo"_s); static_assert(m_foo.get_range(x) == constraints::range{}); - static_assert(m_foo.get_max_length(x) == (std::size_t)-1); + static_assert(m_foo.get_max_length(x) == (size_t)-1); static_assert(m_foo.get_group(x) == ""_s); constexpr auto foo2 = entity::type::field { -- cgit v1.2.3