From 30d4c8e5c26aa89a64998ef1da350d4d80359237 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jan 2024 09:01:36 +0100 Subject: cw --- compat/reverse-index-sequence.hpp | 11 +++++++++++ draw/quad-floor.cpp | 1 - draw/quad-floor.hpp | 1 - draw/quad-wall-n.hpp | 2 -- draw/quad-wall-w.cpp | 1 - draw/quad-wall-w.hpp | 1 - draw/wireframe-meshes.hpp | 1 - editor/app.hpp | 3 ++- editor/ctor.cpp | 1 + serialize/packbits-read.cpp | 4 ++-- serialize/packbits-read.hpp | 15 +++++++++++---- serialize/packbits-write.cpp | 23 +++++++++++++++-------- serialize/packbits-write.hpp | 20 ++++++++++---------- serialize/world-impl.hpp | 13 ++++++++----- 14 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 compat/reverse-index-sequence.hpp diff --git a/compat/reverse-index-sequence.hpp b/compat/reverse-index-sequence.hpp new file mode 100644 index 00000000..c60caa5c --- /dev/null +++ b/compat/reverse-index-sequence.hpp @@ -0,0 +1,11 @@ +#pragma once +#include + +namespace floormat { + +template +constexpr std::index_sequence reverse_index_sequence(std::index_sequence); +template +using make_reverse_index_sequence = decltype(reverse_index_sequence(std::make_index_sequence{})); + +} // namespace floormat diff --git a/draw/quad-floor.cpp b/draw/quad-floor.cpp index dd1b3bef..5b3619ac 100644 --- a/draw/quad-floor.cpp +++ b/draw/quad-floor.cpp @@ -1,7 +1,6 @@ #include "quad-floor.hpp" #include "wireframe.hpp" #include -#include namespace floormat::wireframe { diff --git a/draw/quad-floor.hpp b/draw/quad-floor.hpp index b289ab84..0c52dbc3 100644 --- a/draw/quad-floor.hpp +++ b/draw/quad-floor.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace floormat::wireframe { diff --git a/draw/quad-wall-n.hpp b/draw/quad-wall-n.hpp index d607ffe3..7dd875d7 100644 --- a/draw/quad-wall-n.hpp +++ b/draw/quad-wall-n.hpp @@ -1,9 +1,7 @@ #pragma once - #include #include #include -#include namespace floormat::wireframe { diff --git a/draw/quad-wall-w.cpp b/draw/quad-wall-w.cpp index 898b602d..95a6ffb5 100644 --- a/draw/quad-wall-w.cpp +++ b/draw/quad-wall-w.cpp @@ -1,6 +1,5 @@ #include "quad-wall-w.hpp" #include "wireframe.hpp" -#include namespace floormat::wireframe { diff --git a/draw/quad-wall-w.hpp b/draw/quad-wall-w.hpp index a96e8d83..d478e68c 100644 --- a/draw/quad-wall-w.hpp +++ b/draw/quad-wall-w.hpp @@ -3,7 +3,6 @@ #include #include #include -#include namespace floormat::wireframe { diff --git a/draw/wireframe-meshes.hpp b/draw/wireframe-meshes.hpp index ca514ff5..cc8898f3 100644 --- a/draw/wireframe-meshes.hpp +++ b/draw/wireframe-meshes.hpp @@ -6,7 +6,6 @@ #include "quad-wall-n.hpp" #include "quad-wall-w.hpp" #include "quad.hpp" -#include #include namespace floormat::wireframe { diff --git a/editor/app.hpp b/editor/app.hpp index fd24e495..dad4f539 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -7,7 +7,6 @@ #include "src/global-coords.hpp" #include "src/object-id.hpp" #include "editor-enums.hpp" -#include "tests.hpp" #include #include #include @@ -38,6 +37,8 @@ struct critter; struct point; class editor; template struct shared_ptr_wrapper; +struct tests_data; +struct tests_data_; struct cursor_state final { diff --git a/editor/ctor.cpp b/editor/ctor.cpp index 9c1f64fc..36a35ae5 100644 --- a/editor/ctor.cpp +++ b/editor/ctor.cpp @@ -2,6 +2,7 @@ #include "compat/enum-bitset.hpp" #include "src/world.hpp" #include "editor.hpp" +#include "tests.hpp" #include "draw/wireframe-meshes.hpp" #include "floormat/main.hpp" #include diff --git a/serialize/packbits-read.cpp b/serialize/packbits-read.cpp index f21a0de9..6b4a13d4 100644 --- a/serialize/packbits-read.cpp +++ b/serialize/packbits-read.cpp @@ -3,11 +3,11 @@ namespace floormat { -using namespace floormat::detail_Pack_input; +using namespace floormat::Pack; namespace { -template constexpr inline T lowbits = (T{1} << N)-T{1}; +template constexpr inline T lowbits = N == sizeof(T)*8 ? (T)-1 : (T{1} << N)-T{1}; static_assert(!input{65535}.check_zero()); static_assert(input{65535}.advance<16>() == 0); diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp index dc21d7ee..6f5dd883 100644 --- a/serialize/packbits-read.hpp +++ b/serialize/packbits-read.hpp @@ -5,7 +5,7 @@ #include #include "compat/assert.hpp" -namespace floormat::detail_Pack_input { +namespace floormat::Pack { template struct input_bits final @@ -114,10 +114,17 @@ constexpr void read_(Place&, input, std::index_sequence, empty_p template using make_pack = empty_pack_tuple...>; -} // namespace floormat::detail_Pack_input +} // namespace floormat::Pack -namespace floormat::pack { +namespace floormat { +template +constexpr T pack_write(const std::tuple...>& tuple) +{ + constexpr size_t nbits = sizeof(T)*8; + return Pack::write_(tuple, Pack::output{T{0}}, make_reverse_index_sequence{}); +} +constexpr uint8_t pack_write(const std::tuple<>&) = delete; -} // namespace floormat::pack +} // namespace floormat diff --git a/serialize/packbits-write.cpp b/serialize/packbits-write.cpp index 045d6283..5db0fa1b 100644 --- a/serialize/packbits-write.cpp +++ b/serialize/packbits-write.cpp @@ -1,6 +1,10 @@ #include "packbits-write.hpp" -namespace floormat::detail_Pack_output { +namespace floormat { + +namespace { + +using namespace floormat::Pack; using u32 = uint32_t; using u16 = uint16_t; @@ -22,18 +26,21 @@ static_assert(write_( output{0}, make_reverse_index_sequence<3>{}) == 0b000101110); -static_assert(write(std::tuple{f32<2>{0b10}, f32<3>{0b011}, f32<3>{0b01}}) == 0b00101110); -//static_assert(write(std::tuple{f32<2>{0b10}, f32<3>{0b1011}, f32<3>{0b001}}) == 0b000101110); -static_assert(write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<3>{0b01}}) == 0b00101110); -//static_assert(write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<4>{0b01}}) == 0b00101110); -//static_assert(write(std::tuple{}) == 0); +static_assert(pack_write(std::tuple{f32<2>{0b10}, f32<3>{0b011}, f32<3>{0b01}}) == 0b00101110); +//static_assert(pack_write(std::tuple{f32<2>{0b10}, f32<3>{0b1011}, f32<3>{0b001}}) == 0b000101110); +static_assert(pack_write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<3>{0b01}}) == 0b00101110); +//static_assert(pack_write(std::tuple{f8<2>{0b10}, f8<3>{0b011}, f8<4>{0b01}}) == 0b00101110); +//static_assert(pack_write(std::tuple{}) == 0); +static_assert(pack_write(std::tuple{f8<1>{0b1}, f8<3>{0b101}, f8<2>{0b10}}) == 0b101011); #if 0 // check disasembly u32 foo1(u32 a, u32 b, u32 c); u32 foo1(u32 a, u32 b, u32 c) { - return write(std::tuple{f32<2>{a}, f32<3>{b}, f32<3>{c}}); + return pack_write(std::tuple{f32<2>{a}, f32<3>{b}, f32<3>{c}}); } #endif -} // namespace floormat::detail_Pack_output +} // namespace + +} // namespace floormat diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index 09ec820e..5a8eae52 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -1,11 +1,12 @@ #pragma once #include "compat/assert.hpp" +#include "compat/reverse-index-sequence.hpp" #include #include #include #include -namespace floormat::detail_Pack_output { +namespace floormat::Pack { template struct output @@ -26,11 +27,6 @@ struct output_field T value; }; -template -constexpr std::index_sequence reverse_index_sequence(std::index_sequence); -template -using make_reverse_index_sequence = decltype(reverse_index_sequence(std::make_index_sequence{})); - template struct is_output_field : std::bool_constant {}; template struct is_output_field> : std::bool_constant { static_assert(N > 0); }; @@ -57,13 +53,17 @@ constexpr CORRADE_ALWAYS_INLINE T write_(const Tuple&, output return st.value; } +} // namespace floormat::Pack + +namespace floormat { + template -constexpr T write(const std::tuple...>& tuple) +constexpr T pack_write(const std::tuple...>& tuple) { constexpr size_t nbits = sizeof(T)*8; - return write_(tuple, output{T{0}}, make_reverse_index_sequence{}); + return Pack::write_(tuple, Pack::output{T{0}}, make_reverse_index_sequence{}); } -constexpr uint8_t write(const std::tuple<>&) = delete; +constexpr uint8_t pack_write(const std::tuple<>&) = delete; -} // namespace floormat::detail_Pack_output +} // namespace floormat diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index 5efd9bbc..ce4d9a8c 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -9,7 +9,7 @@ #include "src/object-type.hpp" #include #include -#include +#include /* protocol changelog: * 1) Initial version. @@ -44,9 +44,12 @@ using atlasid = uint16_t; using chunksiz = uint16_t; using proto_t = uint16_t; -namespace { +template struct int_traits; + +template struct int_traits { static constexpr T max = T(-1); }; +template struct int_traits { static constexpr T max = T(-1)&~(T(1) << sizeof(T)*8-1); }; -template constexpr inline T int_max = std::numeric_limits::max(); +namespace { #define file_magic ".floormat.save" @@ -67,8 +70,8 @@ constexpr inline auto pass_mask = (1 << pass_mode_BITS)-1; template constexpr inline auto highbits = (T(1) << N)-1 << sizeof(T)*8-N-off; -template -constexpr T lowbits = T((T{1} << N)-T{1}); +template +constexpr T lowbits = N == sizeof(T)*8 ? (T)-1 : T((T{1} << N)-T{1}); constexpr inline uint8_t meta_short_scenery_bit = highbits; constexpr inline uint8_t meta_rotation_bits = highbits; -- cgit v1.2.3