From 26b537d5f2e4e48e0c183cca30ecb056a41cd3be Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 23 Feb 2023 09:51:16 +0100 Subject: wip --- entity/chunk.cpp | 13 +++++- entity/constraints.hpp | 2 + entity/erased-constraints.cpp | 97 ++++++++++++++++++++++++++++++++++++++----- entity/erased-constraints.hpp | 10 ++++- 4 files changed, 109 insertions(+), 13 deletions(-) (limited to 'entity') diff --git a/entity/chunk.cpp b/entity/chunk.cpp index 6857ac1d..f7b9aadc 100644 --- a/entity/chunk.cpp +++ b/entity/chunk.cpp @@ -2,6 +2,7 @@ #include "entity/accessor.hpp" #include "src/scenery.hpp" #include "src/anim-atlas.hpp" +#include "src/tile-defs.hpp" namespace floormat::entities { @@ -11,10 +12,20 @@ template<> struct entity_accessors { using entity = Entity; using frame_t = scenery::frame_t; constexpr auto tuple = std::make_tuple( - entity::type::field{"frame", + entity::type::field{"frame"_s, [](const scenery_ref& x) { return x.frame.frame; }, [](scenery_ref& x, frame_t value) { x.frame.frame = value; }, [](const scenery_ref& x) { return constraints::range{0, !x.atlas ? frame_t(0) : frame_t(x.atlas->info().nframes)}; } + }, + entity::type::field{"offset"_s, + [](const scenery_ref& x) { return x.frame.offset; }, + [](scenery_ref& x, Vector2b value) { x.frame.offset = value; }, + constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}) + }, + // todo pass_mode enum + entity::type::field{"interactive"_s, + [](const scenery_ref& x) { return x.frame.interactive; }, + [](scenery_ref& x, bool value) { x.frame.interactive = value; } } ); return tuple; diff --git a/entity/constraints.hpp b/entity/constraints.hpp index 99705047..cfe33bfe 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -18,6 +18,8 @@ template struct range constexpr bool operator==(const range&) const noexcept = default; }; +template range(T min, T max) -> range; + template constexpr range::operator erased_constraints::range() const noexcept { diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp index 031197eb..0826075e 100644 --- a/entity/erased-constraints.cpp +++ b/entity/erased-constraints.cpp @@ -3,15 +3,28 @@ #include #include #include +#include +#include +#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 { +namespace { +template struct is_magnum_vector_ final : std::false_type {}; +template struct is_magnum_vector_> : std::true_type {}; +template struct is_magnum_vector_> : std::true_type {}; +template struct is_magnum_vector_> : std::true_type {}; +template struct is_magnum_vector_> : std::true_type {}; +template constexpr bool is_magnum_vector = is_magnum_vector_::value; +} // namespace + template std::pair range::convert() const { - static_assert(sizeof(T) <= sizeof(std::size_t)); + static_assert(sizeof(T)*2 <= sizeof(*this)); using limits = std::numeric_limits; if (type == type_none) @@ -39,6 +52,47 @@ template std::pair range::convert() const } } } + else if constexpr(is_magnum_vector) + { + using U = typename T::Type; + constexpr auto Size = T::Size; + static_assert(Size >= 2 && Size <= 4); + T a, b; + if constexpr(std::is_integral_v) + { + if constexpr(std::is_signed_v) + { + fm_assert(type == type_int4); + for (std::size_t i = 0; i < Size; i++) + a[i] = U(min.i4[i]), b[i] = U(max.i4[i]); + } + else + { + if (type == type_int4) + { + for (std::size_t i = 0; i < Size; i++) + { + fm_assert(min.i4[i] >= 0 && max.i4[i] >= 0); + a[i] = U(min.i4[i]), b[i] = U(max.i4[i]); + } + } + else + { + fm_assert(type == type_uint4); + for (std::size_t i = 0; i < Size; i++) + a[i] = U(min.i4[i]), b[i] = U(max.i4[i]); + } + } + } + else + { + static_assert(std::is_floating_point_v); + fm_assert(type == type_float4); + for (std::size_t i = 0; i < Size; i++) + a[i] = U(min.f4[i]), b[i] = U(max.f4[i]); + } + return { a, b }; + } else { static_assert(std::is_floating_point_v); @@ -48,16 +102,37 @@ template std::pair range::convert() const } } -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -template std::pair range::convert() const; -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; +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; bool operator==(const range& a, const range& b) { diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp index 5a6cb939..c77d8166 100644 --- a/entity/erased-constraints.hpp +++ b/entity/erased-constraints.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include namespace floormat::entities::erased_constraints { @@ -7,11 +8,18 @@ struct range final { using U = std::size_t; using I = std::make_signed_t; - enum type_ : unsigned char { type_none, type_float, type_uint, type_int, }; + enum type_ : unsigned char { + type_none, + type_float, type_uint, type_int, + type_float4, type_uint4, type_int4, + }; union element { float f; U u; I i; + Math::Vector4 f4; + Math::Vector4 u4; + Math::Vector4 i4; }; element min {.i = 0}, max {.i = 0}; -- cgit v1.2.3